ASP. NET Crystal Reports from entry to flexible applications

Source: Internet
Author: User
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:

  1. Data Binding in non-Object Mode of Crystal Reports
  2. 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

  1. 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.

    1. In the solution explorer of the vs ide project, create a folder for storing report files, such as reprotfilesfolder.
    2. Right-click the new folder and choose add new item ...)
    3. Select "XML schema" and name the file demo. XSD.
    4. 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.
       
    5. 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.
    6. Right-click the new folder and choose add new item ...)
    7. Select crystal report, name the report file demo. Rpt, and click Add)
    8. In the open Crystal Report Wizard window, select "use Report Wizard" and click OK
    9. On the data Wizard Page of the Report Wizard, select "create new connection-Database File"
    10. Click "+" in front of the database file. The Select data file window is displayed. Find the created demo. XSD file and click "open"
    11. 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.
    12. Click "Next" to add an implicit key-value relationship between tables.
    13. Click Finish to generate a blank report.
    14. Design qualified reports based on actual business conditions and save report files, such
    15. The design work has come to an end, and data binding will be performed below.
    16. Create a new webform page and add crystalreportviewer to the page, as shown in
    17. First, reference the Crystal Reports assembly on the background page.
      Using crystaldecisions. crystalreports. engine;
      Using crystaldecisions. shared;
    18. Define Variables
      Private reportdocument;
    19. 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;
      }

    20. Add response. expires =-1 in the page_load method of the page;
    21. 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 ();
      }
    22. 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
      1. After that, you can delete the. XSD Schema file and run it, or remove the. XSD file from the project.
      2. 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.
      3. You can also modify and enhance the configurecrystalreports method, create a system management page, and select and set data sources on the Management page.
  2. 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.
    1. 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
    2. Find the crredist2005_x86.msi or crredist2008_x86.msi file in the preceding folder and install it on the server.
Related Article

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.