Using the powerful functions of Crystal Reports to achieve statistical analysis of applications and print and export is a good choice for. NET application development reports on the Microsoft platform. The design, development, configuration, and deployment of Crystal Reports still bring some troubles to beginners. Is there a relatively simple and easy-to-use method for designing, developing, configuring, and deploying Crystal Reports? This document provides a simple and flexible method.
This article includes the following content:
- Data Binding in non-Object Mode of Crystal Reports
- Simple deployment of Crystal Reports
P.s. The crystal reports described in this article are Crystal Reports for Visual Studio. NET. In principle, this version is runtime free authorization for unlimited users. Vs ide version 2008 and Crystal Reports version 10
- Data Binding in non-Object Mode of Crystal Reports
There are many data binding modes for Crystal Reports, including dataset, datareader, and objectcollection. In a specific system project, most of us provide support for report data through the specified business database. This article will mainly describe a flexible mode for non-database data binding. For reports that are bound in this mode, you do not need to set the information about the database verification parameters (dblogon, the specific data source can be from the database, XML files, and other semi-structured data.
- In the solution explorer of the vs ide project, create a folder for storing report files, such as reprotfilesfolder.
- Right-click the new folder and choose add new item ...)
- Select "XML schema" and name the file demo. XSD.
- Open the schema file with dataset Editor, click "CTRL + ALT + s", open "Server Explorer", and find the database connection used by the current project, drag the data tables involved in the report Presentation to the design area.
- The table to be dragged can be a table with a key-value relationship or a non-relational table, or even save the XSD file through a temporary table created in the stored procedure.
- Right-click the new folder and choose add new item ...)
- Select crystal report, name the report file demo. Rpt, and click Add)
- In the open Crystal Report Wizard window, select "use Report Wizard" and click OK
- On the data Wizard Page of the Report Wizard, select "create new connection-Database File"
- Click "+" in front of the database file. The Select data file window is displayed. Find the created demo. XSD file and click "open"
- Now, we just added it to the demo. the two data tables in XSD will appear under the subnode of the "data file" node. Select the data table and click ">" to add the table to the "selected table" list.
- Click "Next" to add an implicit key-value relationship between tables.
- Click Finish to generate a blank report.
- Design qualified reports based on actual business conditions and save report files, such
- The design work has come to an end, and data binding will be performed below.
- Create a new webform page and add crystalreportviewer to the page, as shown in
- First, reference the Crystal Reports assembly on the background page.
Using crystaldecisions. crystalreports. engine;
Using crystaldecisions. shared;
- Define Variables
Private reportdocument;
- Add custom Method
/// <Summary> /// Initialize the report /// </Summary> Private void configurecrystalreports () { // RePort Printing file for the current business String rptfile = ""; // Print the dataset of the current business report Dataset DS = NULL; # Region If (session ["RF"] = NULL) { Rptfile = server. mappath ("demo. rpt "); Session ["RF"] = rptfile; } Else Rptfile = session ["RF"]. tostring (); # Endregion # Region If (session ["PD"] = NULL) { DS = new dataset (); String SQL = ""; SQL = "select * From salesmaster where bitemserialnumber = '000000 '"; Dataset masterds = fill in master table data // Add the master table to the report Dataset DS. Merge (masterds ); // Use the same method to add sub-tables or other tables, or even the relationship between tables.// The preceding method can also read data from other data sources, including access database and XML data. Session ["PD"] = Ds; } Else DS = (Dataset) session ["PD"]; # Endregion If (session ["reportdocument"] = NULL) { ReportDocument = new reportdocument (); ReportDocument. Load (rptfile ); ReportDocument. setdatasource (DS ); Session ["reportdocument"] = reportdocument; } Else ReportDocument = (reportdocument) session ["reportdocument"]; Reportviewer. reportsource = reportdocument; } |
- Add response. expires =-1 in the page_load method of the page;
- Add page Initialization Method
/// <Summary> /// Page initialization event /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> Protected void page_init (Object sender, eventargs E) { Configurecrystalreports (); } |
- Now, the Data Binding and display of the report is complete. After the project is compiled, you can view the report effect in the browser. The flexibility of this method lies in
- After that, you can delete the. XSD Schema file and run it, or remove the. XSD file from the project.
- Data Reading, whether from SQL Server, access, or XML data, can be bound to a report as long as it complies with the table schema we set.
- You can also modify and enhance the configurecrystalreports method, create a system management page, and select and set data sources on the Management page.
- Simple deployment of Crystal Reports
The reason for deploying the Crystal Report to the target server is that the. NET Framework installation does not cover the merging items of the crystal report. Previously, I heard that programmers installed vs ide on the server to deploy the support of Crystal Reports to the server. Therefore, a simple method is provided here.
- In the Development machine environment where vs IDE is installed, open the resource manager.
Vs2005:
% SystemRoot %/program files/Microsoft Visual Studio 8/SDK/V2.0/bootstrapper/packages/crystalreports
Vs2008:
% SystemRoot %:/program files/Microsoft sdks/Windows/v6.0a/bootstrapper/packages/crystalreports10_5
- Find the crredist2005_x86.msi or crredist2008_x86.msi file in the preceding folder and install it on the server.