The Basics of SharpShooter Reports.WPF

 

The basics of SharpShooter Reports.WPF


Report Template

Passing Parameters

Registering Data Sources

Registering SubReports

Rendering

Editing Templates


It is recommended to use PerpetuumSoft.Reporting.WPF.ReportSource as a report data source in the WPF Viewer. PerpetuumSoft.Reporting.WPF.ReportSource (unlike ReportSlot) contains properties which allow registering DataSources, SubReports and set parameters in one component without using any additional components such as ReportManager.


Report Template

 

A report template is set via the Source parameter. It is possible to use 3 variants to set a template:

Source contains a template which is serialized into XML. This variant is convenient when reports are stored into a data base. Source will include the changed template after you edit the template in run time.

Source contains the reference to the Assembly resource. Only Relative URI is supported. Since the report is embedded into assembly during the compilation, it is impossible to change the template in run time. If you try to invoke DesignTemplate for such template, you get the InvalidOperationException exception.

Source contains the reference to a file. This is the simplest way to store the changed templates. The templates are stored in files on disks. You can use both absolute and relative path to access to them.  

 

Passing Parameters

 

ReportSource contains a collection of named Parameters objects. This collection allows the setting of reports parameters. Note, that initially the collection is empty, i.e. you should add parameters to the collection (not to set parameters via indexer). You can use any object of .NET Framework as parameters.

Note, that, as a rule, you refer to the parameters NOT from UI THREAD. You should keep this in mind when you develop an application. Besides that there are some limitations on the use of the DependencyObject’s parameters.  

 

Registering Data Sources

 

ReportSource contains a collection of named DataSources objects for setting a data source. Thus, to add a new data source, you should add an object to the DataSource Collection. You can use any object of .NET Framework as data sources.

Note, that, as a rule, the component refers to the data sources NOT from UI THREAD. You should keep this in mind when you develop an application. Besides that there are some limitations on the use of the DependencyObject’s parameters.

 

Registering SubReports

 

SubReports are represented by the objects of the SubReportSource type. These objects (like ReportSource) contain a template, but don’t contain separate DataSources, Parameters and Subreports collections. These collections are taken from ReportSource which SubReportSource belongs to. Thus, to add the SubReport template you should create the SubReportSource object, set Source in it and register SubReportSource in the SubReports collection of ReportSource. You should also register all the needed parameters, data sources and nested subreports in ReportSource, which you added SubReportSource to.

Note that SubReportSource must be added to the Report.Source.SubReports collection when you invoke SubReportSource.DesignTemplate. If this condition is not fulfilled then you get the InvalidOperationException exception.  

One more essential point in SubReportSource use is that one SubReportSource can’t be simultaneously added to several SubReports collections of different ReportSources. (But in case, if you remove SubReportSource from the collection, you can add it to the collection of the other ReportSource). If you try to add SubReportSource to several collections, you get the InvalidOperationException exception.

 

Rendering

 

You can render ReportSource as follows:

Set ReportSource as a Source for ReportViewer. Invoke the ReportViewer.RenderDocument() method. The report will be rendered asynchronously and ReportViewer will display the message about rendering process.

If you invoke the ReportSource.RenderDocument() method, the report will be rendered synchronously.

If you invoke the ReportSource.Prepare() method, the report will be rendered asynchronously. If you set ReportSource as Source of ReportViewer, ReportViewer will display the message about rendering process. If Source was changed before the rendering, then the message won’t be displayed.

Note that if ReportSource is set as ReportViewer.Source then at successful report rendering ReportViewer will display a report. Otherwise you get an error message.

 

Editing Templates

 

The most convenient way to edit a template is to edit this template in run time (i.e. by invoking editor from your application, registering real data sources). The designer displays real data structures and in preview you get your real report. Be advised that if a template is loaded from the application resource, then it is impossible to edit the template. But you can change the way of storage to file method for the development time, and change it back for the release.

Note that after you edited the template and closed the designer with saving of changes in the report, the report is not rendered automatically. To refresh the report you should execute rendering by one of the methods.

Add Feedback