XtraReport DocumentViewer set report document programmatically - winforms

I am using DevXpress 14.
I want to use only one form name "FrmViewer" which contain DocumentVier to load any report I want.
This is the code, the datasource is not null (debugged), but the message is "The document contain no page". I think I missed some method of the documentViewer to start print
public FrmViewer(PhieuNhap pn)
{
InitializeComponent();
RptPhieuNhap rpt = new RptPhieuNhap();
rpt.DataSource = pn.ChiTietPhieuNhap;
rpt.nhacungcap.Value = pn.NhaCungCap.TenCC;
rpt.sophieu.Value = pn.SoPhieu;
documentViewer1.PrintingSystem = rpt.PrintingSystem;
}

You most likely need to call rpt.CreateDocument();
See here for more details:
https://www.devexpress.com/Support/Center/Question/Details/Q528191

Related

How to remove/disable the print button from the DocumentViewer in code (when on its own thread)?

I am running the following code in a background thread as an STA apartment to provide a Print Preview in a document viewer:
// Print Preview
public static void PrintPreview(FixedDocument fixeddocument)
{
MemoryStream ms = new MemoryStream();
using (Package p = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite))
{
Uri u = new Uri("pack://TemporaryPackageUri.xps");
PackageStore.AddPackage(u, p);
XpsDocument doc = new XpsDocument(p, CompressionOption.Maximum, u.AbsoluteUri);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
writer.Write(fixeddocument.DocumentPaginator);
var previewWindow = new Window();
var docViewer = new DocumentViewer();
previewWindow.Content = docViewer;
THIS FAILS ---> docViewer.CommandBindings.Remove(???Print Button???);
FixedDocumentSequence fixedDocumentSequence = doc.GetFixedDocumentSequence();
docViewer.Document = fixedDocumentSequence as IDocumentPaginatorSource;
previewWindow.ShowDialog();
PackageStore.RemovePackage(u);
doc.Close();
}
}
All works well. However, since this is running in its own thread--not the main thread--the print dialogue on the Document Viewer crashes.
In code, how can I remove and/or disable the Print button from the DocumentViewer?? (I have read everything I could find in Google, and it all is in XAML, not very helpful).
Any help is much appreciated. TIA
Update#1: The only way I can see to do this, is to drop the Print Button from the control template and use a custom Document Viewer. A workable style is given at Document Viewer Style.
It still would be nice if I could simply remove the button from the system Document viewer?
Using the method from this answer, you can alter the visibility of the PrintButton programmatically like this. Let's say I put the method in a class called UIElementHelper:
var button = UIElementHelper.FindChild<Button>(docViewer, "PrintButton");
button.Visibility = Visibility.Collapsed;

How to show computed property values in EPiServer 8?

In page edit mode I want to show a read-only text that is based on a page property value. The text could for example be "A content review reminder email will be sent 2015-10-10", where the date is based on the page published date + six months (a value that will be configurable and therefore can change anytime). So far I've tried to accomplish something like this by adding another property on the page.
I've added the property CurrentReviewReminderDate to an InformationPage class we use. In page edit mode the property name is shown, but it doesn't have a value. How do I do to show the value in page edit mode (preferably as a label)?
[CultureSpecific]
[Display(
Name = "Review reminder date",
Description = "On this date a reminder will be sent to the selected mail to remember to verify page content",
Order = 110)]
[Editable(false)]
public virtual string CurrentReviewReminderDate
{
get
{
var daysUntilFirstLevelReminder =
int.Parse(WebConfigurationManager.AppSettings["PageReviewReminder_DaysUntilFirstLevelReminder"]);
if (CheckPublishedStatus(PagePublishedStatus.Published))
{
return StartPublish.AddDays(daysUntilFirstLevelReminder).ToString();
}
return "";
}
set
{
this.SetPropertyValue(p => p.CurrentReviewReminderDate, value);
}
}
EPiServer internally uses the GetPropertyValue method (i.e. the opposite of SetPropertyValue) when retrieving content for the UI.
This makes sense, otherwise your "made-up" value would be stored as the real value whenever the content is saved. This would make fall-back values etc impossible to implement.
So, this is by-design (and quite wisely so) in EPiServer. :)
However, you can customize how properties work by:
Using custom editors by applying UI hints
Modifying property metadata (for example, to display a generated value as a watermark in a textbox without interfering with the actual value being saved)
I could be misunderstanding what you're trying to do, but off the top of my head it looks like a custom editor could be a viable option for your use case?
Another solution would be to hook into the LoadedPage-event and add the value from there. This might not be the best way performance-wise since you need to do a CreateWritableClone, but depending on the site it might not matter.
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class EventInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
ServiceLocator.Current.GetInstance<IContentEvents>().LoadedContent += eventRegistry_LoadedContent;
}
void eventRegistry_LoadedContent(object sender, ContentEventArgs e)
{
var p = e.Content as EventPage;
if (p != null)
{
p = p.CreateWritableClone() as EventPage;
p.EventDate = p.StartPublish.AddDays(10);
e.Content = p;
}
}
}

How to write condition on Filter String in code Reports Winforms devexpress?

I designed a report form and map fields with columns of tables from dataset. Now I need to set condition, so I used FilterString. Inside report form DetailReport, I wrote code like this:
DetailReport.FilterString = "[InvoiceNumber] = " + temp;
Now I need this same code (FilterString) for whole form that is top left of form Report Task some properties are available in that Data Source there we add dataset, Data Member, Data Adapter then FilterString is available.
Now I am able to add FilterString in Designer but I need to add FilterString in code ??
I Tried this one but not working
FilterString= "[InvoiceNumber] = " + temp"
I seggest you set the report FilterString property when you call for your XtraReport (for example : when you click on the print button of your form). Here is an code example :
private void simpleButton1_Click(object sender, EventArgs e) {
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Some code like setting the report datasource
// Specify the report's filter string.
report.FilterString = "[InvoiceNumber] = myValue";
// Show the report's print preview.
pt.ShowPreviewDialog();
}
This code was taken from the DevExpress online documentation article : XtraReportBase.FilterString Property
Once you set the filter for the report, in the for you need to have it do:
public string p = "";
....
using (XtraReport_yourreport x = new XtraReport_yourreport ())
{
p = x.FilterString;
}

Using DataTables from Database to populate program on startup without getting System.IndexOutOfRange messages

Hi Everybody and THANK YOU IN ADVANCE!! for any and all help
I am an absolute newbie to coding and programming (4-5months)
I am using visual studio 2012 and coding in C#
I am making a windows form application that connects to a database in SQL Server management studio
basically i have two combo boxes that need to be populated with the data from the db on start up.
I have created a method to populate the combo boxes and the program works 100%
the boxes do populate on start up with no data missing, all rows are displayed in the combo boxes and everything does exactly what its supposed to do and when its supposed to do it...
HOWEVER!
every time i run my program i get this message 5 times (as the code that generates the message is used 5 times)
System.IndexOutOfRangeException:There is no row at position 0
at System.Data.RBTree1.GetNodeByIndex(Int32 userIndex)
at System.Data.DataRowCollection.get_Item(Int32 index)
BEFORE the actual program starts and runs properly.??? (its driving me nuts!!)
here is all my relevant code
the code below is from my actual form
as you can see i am using update_combobox(); in the initalizeComponent section to get
it to populate at start up
namespace DB_Program
{
public partial class Form1 : Form
{
DataClass dc = new DataClass();
public Form1()
{
Thread t = new Thread(new ThreadStart(SplashScreen));
t.Start();
Thread.Sleep(5000);
InitializeComponent();
t.Abort();
update_ComboBox();
}
here is my code from my form that makes it possible
private void update_ComboBox()
{
DataSet pList = dc.PListPop();
cboBoxPList.DataSource = pList.Tables[0];
cboBoxPList.DisplayMember = "PName";
cboBoxPList.ValueMember = "PName";
DataSet devList = dl.DevListPop();
cboBoxDev.DataSource = devList.Tables[0];
cboBoxDev.DisplayMember = "LName";
cboBoxDev.ValueMember = "LName";
}
public String getDate(String pName)
{
String date = null;
DataTable dTable = new DataTable();
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("SelPro", conn);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add("#PName", SqlDbType.VarChar).Value = pName;
sda.Fill(dTable);
date = dTable.Rows[0]["StartDate"].ToString();
}
catch (Exception GSD)
{
string a = GSD.StackTrace.ToString();
MessageBox.Show(GSD.ToString());
}
finally
{
if (conn != null)
{
conn.Close();
}
}
return date;
}
according to my messages these are the lines that generates the messages, the first message relates to the code directly above
date = dTable.Rows[0]["StartDate"].ToString();
date = dTable.Rows[0]["PlannedEndDate"].ToString();
FirstName = dTable.Rows[0]["FirstName"].ToString();
Spec = dTable.Rows[0]["Specialty"].ToString();
PID = (int) dTable.Rows[0]["PID"];
PLEASE PLEASE PLEASE somebody end my frustrating nightmare!
i need the program to stay and run exactly as is, all i am trying to do is whatever i need to so that the program runs WITHOUT giving me those messages
once again thank you!
Its All good please ignore this question as i have managed to solve it myself!
there is no error in the code the problem lay in the property tab settings
that was generating things it shouldn't

ReportViewer databinding (WPF)

I have a rdlc file and I try to show it using report viewer control in WPF. My DataSource is called 'OfficeDataSet' and DataSet used in report is called 'Address'. I try to initialize report viewer (I put it in WindowsFormsHost) like this:
private void PrepareReport()
{
reportDataSource = new ReportDataSource();
officeDataSet = new OfficeDataSet();
adapter = new AddressTableAdapter();
adapter.Fill(officeDataSet.Address);
reportDataSource.Name = "OfficeDataSet_Address";
reportDataSource.Value = officeDataSet.Address;
viewerInstance.LocalReport.DataSources.Add(reportDataSource);
viewerInstance.LocalReport.ReportEmbeddedResource = "WpfApplication1.Reports.TestReport.rdlc";
viewerInstance.Location = new System.Drawing.Point(0, 0);
viewerInstance.RefreshReport();
}
but I got the message "A data source instance has not been supplied for the data source 'Address'".
Anybody know what can be wrong with this code? (I'm totally new in WPF and Reporting Services).
If i remember well, the datasource into the report file should have the same name (or maybe value) as the reportDataSource. So in your report file the datasource should be called "OfficeDataSet_Address".

Resources