Developing RDLC reports using the general framework

Source: Internet
Author: User

RDLC is Microsoft's own reporting software, although not some third-party reporting software is powerful, but as VisualStudio Integrated reporting tools, in the case of customer requirements are not high, it is very worthwhile, this article will introduce through The general code generator and The general framework quickly develop a reporting program.

The first step, build RDLC Report File

the traditional way of development is through VisualStudio creates the RDLC report file, but this is inefficient, not suitable for a large number of report development, and through the general code generator can quickly generate a large number of report formats, greatly improve development efficiency, The resulting report files can be opened in VisualStudio and continue to be modified without affecting the production of complex report formats. The process of generating the RDLC report file with the General code generator is as follows:

after the build is saved as a report file with the suffix. rdlc.

Step two, make the report Viewer

if it is WinForm Program, this step is very simple, just need to create a new form, and then drag the ReportViewer control from the Toolbox onto the form and set Dock = Fill on it . If ReportViewer is not found in the toolbox and needs to beadded manually, there may be no ReportViewer in the Toolbox, but the ReportViewer item is checkedwhen manually added . Then you need to uncheck, then open and then tick Add.

RDLC can deliver data to a report by adding a dataset, but the flexibility is too poor for project requirements. Here, we use the dynamic way to transport the data to the report, and make the general Report viewer, so that when the report is added, we simply generate a new RDLC file and assign it to the Report Viewer, and then transfer the specified data.

So we modify the background code of the Report Viewer:

1 usingSystem;
2usingSystem.Collections.Generic;
3usingSystem.ComponentModel;
4usingSystem.Data;
5usingSystem.Drawing;
6usingSystem.Text;
7usingSystem.Windows.Forms;
8
9namespaceSample.Market.WinForm
Ten{
One PublicPartialclassFrmreport:form
A{
-/// <summary>
-        ///rdlc file path, supporting relative paths
the        /// </summary>
- PublicstringReportpath {Get;Set; }
-
-/// <summary>
+        ///Report Data source
-        /// </summary>
+ PublicDataTable DataSource {Get;Set; }
A
at PublicFrmreport ()
-{
-InitializeComponent ();
-}
-
-PrivatevoidFrmreport_load (Objectsender, EventArgs e)
in{
-//Show Report Code
toReportviewer1.processingmode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
+ReportViewer1.LocalReport.ReportPath = This. Reportpath;
-ReportViewer1.LocalReport.DataSources.Clear ();
theREPORTVIEWER1.LOCALREPORT.DATASOURCES.ADD (NewMicrosoft.Reporting.WinForms.ReportDataSource ("DataSet1", This. DataSource));
*Reportviewer1.refreshreport ();
$}
Panax Notoginseng}
-}


The code that calls the Report Viewer to open the report is as follows:

1DataTable dt = Goodslogic.getalldata ();
2Frmreport frm =NewFrmreport ();
3frm. Reportpath ="REPORTS\\GOODSREPORT.RDLC";
4frm. DataSource = DT;
5frm. Show ();

The Getalldata method code for Goodslogic is as follows:

1 / /<summary>

2        ///Get all data
3        /// </summary>
4        /// <returns></returns>
5 PublicDataTable Getalldata ()
6{
7returnDatamanager.default.createquery<goods> (). ToTable ();
8}

you can see that by The general framework is easy to take to the report data, and then call the Report Viewer to display the report, the code is very simple, the final result is as follows:

If you need to modify the format of the report, such as column widths, headings, and so on, you can open the. rdlc file in VisualStudio for editing, or modify the template in Code Builder to regenerate the report file.

You may also notice that the column header of the report is missing on the next page, to make the column header appear on each page need to make the following modifications to the report file:

You might think that every single report is too cumbersome to modify, so let's change the template.

Compare the pre-and modified. rdlc files with the text comparison tool first, and find only one row:

Then we also add this line to the template:

Rebuild the report file, and then open the report, and you can see that each page can display column headers.

General code Generator Please click here to download:

General framework and Code generator

Developing RDLC reports using the general framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.