Dynamically bind the data source of the page report (PageReport) in Silverlight

original
2014/06/11 11:58
Number of readings 242

In ActiveReports 7, a new report model, PageReport (page layout report), is introduced. This report model is subdivided into two specific display forms:
Fixed page layout report model (FPL) is a pioneer in ActiveReports 7 NET report model, through which you can easily design report templates with complex formats. You just need to define the page size, and then add the required controls in a visual way and set the data filling method. The remaining work will be automatically completed by the report engine.
O Continuous page layout report model (CPL) mainly controls the layout of reports through data areas, and can automatically display data in pages. This report model is very suitable for displaying multiple data sets in the same report, and it does not need to control the display position of data in the page. The continuous page layout report also allows users to hide/display the report content by folding/expanding.
Now let's see if the PageReport data source is dynamically bound in the Silverlight platform. The report created in this article uses the continuous page layout model (CPL).

Step 1: Create a Silverlight project


Create a Silverlight application named [PageReportDataSource_Silverlight_CSharp] in VS2010

 one

Specify the Silverlight version used by the application. We select Silverlight 4 and create a new Web project

 two

So we have created a basic Silverlight application.

Step 2: Add PageReport


Add a PageReport in the [PageReportDataSource_Silverlight_CSharp. Web] project,
In the Add Project dialog box, we select the ActiveReports 7 Page Report template type. The newly added PageReport defaults to "Fixed Page Layout Report (FPL)". We open the design view of PageReport, and then we can see a [Report] menu item in the VS menu. At this time, we can convert the report to "Continuous Page Layout Report (CPL)" through the [Convert to CPL Report] menu item in the [Report] menu

 three

After completing the above operations, we will add a Table control to the PageReport1 report, and set the cell display content as shown in the figure below

Now that we have completed the development of all reports, we need to bind the data source to PageReport

Step 3: Get the report content to be displayed by the Viewer control


Next, we use a WebService to return the report content required by the Viewer.
In the [PageReportDataSource_Silverlight_CSharp. Web] project, add a WebService, and select the Web Service template under the Web category in the Add Project dialog box

 four

Switch to the code view of ReportService.asmx and add the following code:

 [WebMethod]
     public Byte[] GetProductsReport()
 {
         //Create a blank page report
 GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport();
         //Load report layout
 rpt.Load( new System.IO.FileInfo(Server. MapPath(" PageReport1.rdlx ")));
         //Create and set up a data source
 GrapeCity.ActiveReports.PageReportModel.DataSource myDataSource = new GrapeCity.ActiveReports.PageReportModel.DataSource();
 myDataSource.Name = " DataSource1 ";
 myDataSource.ConnectionProperties.DataProvider = " OLEDB ";
 myDataSource.ConnectionProperties.ConnectString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Reels.mdb ";
         //Set Data Set
 GrapeCity.ActiveReports.PageReportModel.DataSet myDataSet = new GrapeCity.ActiveReports.PageReportModel.DataSet();
 GrapeCity.ActiveReports.PageReportModel.Query myQuery = new GrapeCity.ActiveReports.PageReportModel.Query();
 myDataSet.Name = " DataSet1 ";
 myQuery.DataSourceName = " DataSource1 ";
 myQuery.CommandType = GrapeCity.ActiveReports.PageReportModel.QueryCommandType.Text;
 myQuery.CommandText = GrapeCity.ActiveReports.Expressions.ExpressionInfo.FromString(" SELECT TOP 50 * FROM Product ");
 myDataSet.Query = myQuery;
         //Add Field
 GrapeCity.ActiveReports.PageReportModel.Field _field = new
 GrapeCity.ActiveReports.PageReportModel.Field(" ProductID ", " ProductID ", null );
 myDataSet.Fields.Add(_field);
 _field = new GrapeCity.ActiveReports.PageReportModel.Field(" InStock ", " InStock ", null );
 myDataSet.Fields.Add(_field);
 _field = new GrapeCity.ActiveReports.PageReportModel.Field(" Price ", " Price ", null );
 myDataSet.Fields.Add(_field);
         //Bind data source and data set to report
 rpt.Report.DataSources.Add(myDataSource);
 rpt.Report.DataSets.Add(myDataSet);
         //Save report in Rdf format
 GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension rdfe = new GrapeCity.ActiveReports.Export.Rdf.RdfRenderingExtension();
 GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider ms = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
 rpt.Run();
 rpt.Document.Render(rdfe, ms);
 GrapeCity.ActiveReports.Document.SectionDocument doc_rdf = new GrapeCity.ActiveReports.Document.SectionDocument();
 doc_rdf.Load(ms.GetPrimaryStream(). OpenStream() as System.IO.MemoryStream);
         return doc_rdf.Content;
 }

 

Step 4: Browse the report content in Silverlight


Switch to the [PageReportDataSource_Silverlight_CSharp] project and open the design view of "MainPage. xaml". At this time, you can see a viewer control under the "ActiveReports 7" category of the VS toolbox. Add the control to "MainPage. xaml"

 six

In the [PageReportDataSource_Silverlight_CSharp] project, add a reference to ReportService.asmx:

 seven

After completing the above operations, switch to the code view of "MainPage. xaml" and add Viewer Code of the Loaded event:

     private  void viewer1_Loaded( object sender, RoutedEventArgs e)
 {
         //Load report from WebService
 ReportServiceReference.ReportServiceSoapClient client = new ReportServiceReference.ReportServiceSoapClient();
 client.GetProductsReportAsync();
 client.GetProductsReportCompleted += new EventHandler<ReportServiceReference.GetProductsReportCompletedEventArgs>(client_GetProductsReportCompleted);
 }
     void client_GetProductsReportCompleted( object sender, ReportServiceReference.GetProductsReportCompletedEventArgs e)
 {
         //Show Report
 System.IO.MemoryStream ms = new System.IO.MemoryStream(e.Result);
 GrapeCity.Viewer.Common.StreamDocumentLoader loader = new GrapeCity.Viewer.Common.StreamDocumentLoader(ms,  GrapeCity.Viewer.Common.DocumentFormat.Rdf);
 viewer1.LoadDocument(loader);
 }

 

By running the project, we can get the following results:

 eight

Source code download: Dynamically bind the data source of the page report (PageReport) in Silverlight

 

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top