Crystal Report production and use

Source: Internet
Author: User
Tags microsoft sql server 2005

Crystal ReportProduction and Use

This article is divided into the following six parts:

1. functions of Crystal Report for. NET

Ii. Overall Crystal Report Structure

Iii. Report Data Access Execution Mode

Iv. Report Type

V. layout of the Crystal Report designer

Vi. specific example of Crystal Report

 

Recently, the project is coming to an end and should be summarized as required. In order to help new programmers who develop reports in the. net environment, a document is also prepared for new personnel training.

I believe that reports in most applications are a headache for programmers. However, the. net environment contains a powerful Report tool: Crystal Report. It can interact well with databases and make various beautiful reports and analysis charts. It can solve problems for developers. For example:

 

Since 1993, Crystal Report is part of the Visual Studio suite. Currently

The report standards in Visual Studio. NET play a leading role in the field of writing Windows reports, promoting the future development of Web reports. The latest Visual Studio. NET and Crystal Report9.0 in the integrated development environment (IDE), thus enhancing Visual Studio. NET development function, Crystal Report provides developers with the API as much as possible.

1. functions of Crystal Report for. NET

By integrating the Report processing function of Crystal Report into your own database applications, Windows applications and Web developers can save development time to meet users' needs. Crystal Report SUPPORTS most popular development languages and can be easily added to any application.

Specifically, the functions of Crystal Report are as follows:

1. Comprehensive database access:

Crystal Report contains more than 35 data source drivers, which can access an XML, enterprise, and relational database.

2. Extensive design formats and designs:

With Crystal Report, you can convert a database to highly interactive content. You can select from more than 100 format options, including parameters, ing, cross tabulation, and hyperlink, to enhance the impact of reports.

3. Powerful chart design functions:

Crystal Report can contain various and easy-to-read charts in reports (it provides a wide range of Report types, such as bar charts, line charts, area charts, pie charts, Gantt charts, and stock charts ).

4. Flexible Application Integration Technology:

Crystal Report provides flexible Java, COM, And. NET sdks and embedded Report Application Server, which can closely integrate reports with Enterprise Web applications. By using Crystal Report's "zero" client browser, you can provide the most terminal support with rich Report interaction, creation, and modification functions.

5. Powerful report export:

All reports of Crystal Reprort can be exported in multiple formats: XML, PDF, HTML, and Microsoft Excel.

Ii. Overall Crystal Report Structure

To display a two-layer Crystal Report, you must:

Interface:

You only need to use a browser in the Winform form or Web program.

Background:

1. Crystal Report Engine (CREngine. dll)

Merge the data and Report files and output the data in different formats. Convert THE Crystal Report to the concise html on the. aspx page.

2. Crystal Report Designer (CRDesigner. dll)

You can use Crystal Report Designer to create reports, including titles, data insertion, formulas, tables, and subreports.

3. The. rpt Report file

The first step in applying a Report to your application is to use Crystal Report Designer to create a Report. But if you already have some ready-made samples, you can use them now.

4. The Data Source

The way the. rpt file obtains data depends on the method you choose. You can choose to create a Crystal Report to obtain data without writing any code manually. You can also choose to bind your dataset and import it to the Report file.

5. Crystal Report Viewer

Crystal Report Viewer is a container that can be inserted into a page (. net is often called a control ).

Iii. Report Data Access Execution Mode

1. Pull Model

In the PULL model, the driver connects to the database and pulls in the data as needed. When using this model, the connection to the database and the SQL commands executed to obtain data are both processed by Crystal Reports, and developers do not need to write code. If you do not need to write any special code at runtime, use the PULL model.

2. Push Model

On the contrary, the pushing model requires developers to write code to connect to the database, execute SQL commands to create a record set or dataset that matches the fields in the report, and pass the object to the report. This method allows you to place the connection share in the application and filter the data before Crystal Reports receives the data.

Iv. Report Type

Crystal Report Designer can be a Report independent of the solution, but also a Report contained in the solution.

1. stronugly-typed Report:

When a Report is added to the solution, the Report becomes a Strongly-typed Report. In this case, you can directly create a report instance (which can reduce some code) and hide it. Of course, you can click "show all files" in Solution Explorer to display it.

2. Un-Typed Report:

A Report that is not included in the plan is a Un-Typed Report. In this case, you must create a ''report document'' object for the Crystal Report Engine and manually load the Report.

V. layout of the Crystal Report designer

First, add a Crystal report file that publishes data to Windows or Web forms to a project in Visual Studio. NET:

 

After the report is successfully added, open the report:

 

You can see the complete layout of the designer.

1. Field Resource Manager:

List all fields in the report, such as the database fields, parameter fields, and formula fields used. You can modify and delete a Field object here.

2. Main Report window:

Displays the Main Report in the report window. For reports that contain subreports, there is a main report window and a subreport for each deepening (by double-clicking) has

Subreport window. You can right-click any blank position in the report window to start the report shortcut menu.

3. main toolbar of the crystal report:

Including record selection, classification, and Text object formatting icons. You can move or change the size of the entire toolbar.

4. toolbar for inserting a crystal report:

You can insert icons for summary fields, groups, subreports, charts, and images. You can also click "insert" in the Crystal Report toolbar ".

Vi. specific example of Crystal Report

The examples in this section are divided into two parts: Crystal Report development in Windows applications and Crystal Report development in Web applications. In addition, the PULL model and push model examples are introduced in two environments.

The software environment used in this example is Microsoft Visual Studio 2005 and Microsoft SQL Server 2005. Data example: SERVER: cotton-B Database Name: lhomocysteine database table: ProjectStage

Data Table Structure:

 

Data:

 

The main function is to count the number of workers in the project phase.

1,How to design a report file template.

1) Add a result set DataSet1.xsd and add a table.

 

2) Add a report file rpt first.

 

3) Use report experts to select "ADO" from "project data. NET dataset ", insert the" ProjectStage "table, and select the report from the field selector.

 

4) Select the field basis for grouping

 

5) Select the displayed chart and topic information

 

The final result is as follows.

 

2Development of Crystal Report in Windows Applications

2.1Demo of pulling model pull model

To add a condition parameter to an SQL statement in the Crystal Report in PULL mode, use {? Parameter Name.

Example: "SELECT ProjectID, Manhours FROM ProjectStage Where ProjectID = {? Parm} "parm is the parameter name.

Private void Form1_Load (object sender, EventArgs e)

{

ReportDocument rpt = new ReportDocument ();

Rpt. Load (Application. StartupPath + "CrystalReport. rpt ");

// This method must be used in SetDatabaseLogon PULL mode to set logon information. Parameters 1: User // name; parameter 2: password; parameter 3: Server; parameter 4: Database Name

Rpt. SetDatabaseLogon ("sa", "123456", "cotton-B", "lhomocysteine ");

// Transmit parameters to the crystal report. Parameter 1: Parameter Name, parameter 2: parameter value;

Rpt. SetParameterValue ("Parm", 1 );

Rpt. SetParameterValue ("Title", "Pull model demo ");

// CrystalReportViewer1 is the crystal report browser.

CrystalReportViewer1.ReportSource = rpt;

}

 

2.2Demo of pushing model

In the push mode, the SQL statement fields in the Dataset that are programmed and assembled must be consistent with the SQL statement fields in the crystal report. Simply put, the Crystal Report in the push mode is a template. After setting the report format in the designer, assemble DataSet to generate the report.

Private void Form1_Load (object sender, EventArgs e)

{

CrystalReport1 report = new CrystalReport1 ();

String sDBConnetction = "Data Source = cotton-B; Initial Catalog = lhomocysteine; Persist Security Info = True; User ID = sa; Password = 123456 ";

DataSet1 ds = new DataSet1 ();

SqlConnection conn = new SqlConnection (sDBConnetction );

SqlDataAdapter adapterProjectStage = new SqlDataAdapter

("Select * from ProjectStage where ProjectID = 2", conn );

AdapterProjectStage. Fill (ds, "ProjectStage ");

Report. SetDataSource (ds );

Report. SetParameterValue ("Title", "Push model demo ");

CrystalReportViewer1.ReportSource = report;

}

 

3, Web application Crystal Report Development

3.1Demo of pulling model pull model

Like the PULL model of the Winform application, you must use {? Parameter Name.

Example: "SELECT ProjectID, Manhours FROM ProjectStage Where ProjectID = {? Parm} "parm is the parameter name.

 

Protected void Test_pullmodel (object sender, EventArgs e)

{

// CrystalReport. rpt is the name of the crystal report file. CrystalReportSource1 is the object of the crystal report data source added to the page from the toolbox.

CrystalReportSource1.ReportDocument. Load (Server. MapPath ("CrystalReport. rpt "));

// This method must be used in SetDatabaseLogon PULL mode to set logon information. Parameters 1: User Name; parameter 2: password; parameter 3: Server; parameter 4: Database Name

CrystalReportSource1.ReportDocument. SetDatabaseLogon ("sa", "123456", "cotton-B", "lhomocysteine ");

// Transmit parameters to the crystal report. Parameter 1: Parameter Name, parameter 2: parameter value;

// CrystalReportSource1.ReportDocument. SetParameterValue ("Title", "Pull model demo ");

CrystalReportSource1.ReportDocument. SetParameterValue ("Parm", 1 );

// Bind the crystal report data source.

CrystalReportSource1.DataBind ();

// CrystalReportViewer1 is the crystal report browser.

CrystalReportViewer1.ReportSource = CrystalReportSource1;

CrystalReportViewer1.DataBind ();

}

 

3.2Demo of pushing model

String sDBConnetction = "Data Source = cotton-B; Initial Catalog = lhomocysteine; Persist Security Info = True; User ID = sa; Password = 123456 ";

DataSet1 ds = new DataSet1 ();

SqlConnection conn = new SqlConnection (sDBConnetction );

SqlDataAdapter adapterProjectStage = new SqlDataAdapter ("select * from ProjectStage where ProjectID = 2", conn );

AdapterProjectStage. Fill (ds, "ProjectStage ");

CrystalReportSource1.ReportDocument. Load (Server. MapPath ("CrystalReport. rpt "));

CrystalReportSource1.ReportDocument. SetDataSource (ds. Tables ["ProjectStage"]);

CrystalReportSource1.DataBind ();

CrystalReportViewer1.ReportSource = CrystalReportSource1;

CrystalReportViewer1.DataBind ();

 

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.