|
The report layouts that are kept in simple hard disk files is so trivial for modern world, that a lot of programmers want to use databases for the storing of reports. This article does not describe how to store the report in database, however you can find here the detailed information about opening of the already stored reports. The reports saved in database or in the resource files can be opened via custom ResourceLocator class.
Here is a sample of ResourceLocator that opens report saved in dataset:
(C#)
using System; using System.Data; using DataDynamics.Reports.Extensibility;
namespace myNamespace { internal class myLocator : ResourceLocator { public override Resource GetResource(ResourceInfo resourceInfo) { Resource res; if (resourceInfo.Name.LastIndexOf("ReportName") > 0) { DataSet ds = frmPreview.GetData(); DataView dv = ds.Tables[0].DefaultView; dv.RowFilter = "Reportname='ReportName'"; System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); System.IO.MemoryStream ms = new System.IO.MemoryStream(enc.GetBytes(dv[0]["Reportsource"].ToString())); res = new Resource(ms, new Uri("DDReport:")); }
if (res.Value == null) { throw new Exception("The report was not found!"); } return res; } } }
(VB.NET)
Imports DataDynamics.Reports.Extensibility
Friend Class myLocator Inherits ResourceLocator
Public Overrides Function GetResource(ByVal resourceInfo As DataDynamics.Reports.Extensibility.ResourceInfo) As DataDynamics.Reports.Extensibility.Resource Dim res As Resource = Nothing If resourceInfo.Name.LastIndexOf("ReportName") > 0 Then Dim ds As DataSet = frmPreview.GetData() Dim dv As DataView = ds.Tables(0).DefaultView() dv.RowFilter = "Reportname='ReportName'" Dim enc As New System.Text.UTF8Encoding Dim ms As IO.MemoryStream = New IO.MemoryStream(enc.GetBytes(dv(0)("Reportsource").ToString())) res = New Resource(ms, New Uri("DDReport:")) End If
If res.Value Is Nothing Then Throw New Exception("The report was not found!") End If
Return res End Function End Class
Note : 1) Do not forget to bind the resource locator with the report, e.g.:
(C#) DataDynamics.Reports.ReportDefinition repd =new DataDynamics.Reports.ReportDefinition(t_reader); repd.ResourceLocator = new myLocator();
(VB.NET) Dim repd As New DataDynamics.Reports.ReportDefinition(t_reader) repd.ResourceLocator = New myLocator
2) In the "Jump to report" box of JumpToReport action you will need to set the DDReport:ReportName.
Applies To: Data Dynamics Reports 1.0
|