Use Crystal Report in Visual Studio .NET (on)

zhaozj2021-02-17  48

Use Crystal Report in Visual Studio .NET (on)

From www.aspfree.comTranslated by Cash (Tianxia Seventh) Cashcao@msn.com

Beginning this about how to use Crystal Reports on VS.NET, I and my friends are very puzzled with my friends to apply it to our web program. After a week, after some efforts (find "How-to" documents online), we have some small techniques that will join the simple report to the ASP.NET program.

This article contains some summary of the method you need to apply Crystal Report to your .NET web application, through these steps, progress, you will encounter the mistake (as we have encountered) will be reduced to minimally. In order to use this article more efficiently, the reader should have basic knowledge of database connections in ASP.NET and is developing vs.net. Please note that we only use the Beta2 version to test the following code.

This article includes the following:

(1 Introduction;

(2) Cow Knife Try - Use an existing Crystal Report file in the .aspx page;

(3) Crystal Report Demo - Using Pull Model;

(4) Crystal Report Demo - Using Push Model;

(5) Output the Report file to other formats.

There are a variety of Crystal Report, where we use "Crystal Report for Visual Studio .NET" designed for .NET. It is a RICH Programming Model to operate its Properties and Methods. If you develop your program with vs.net, you don't need to install any additional software because it is included in the vs.net.

Advantages The main benefits of using Crystal Report for Visual Studio .NET are:

- Rapid Development Reports - Extension To complex reports with related charts - can interact with other controls in this web form - capable of outputting it commonly used. Pdf, .doc, .xls ,. HTML, .RTF and other formats

The overall structure

Show this Crystal Report with two-layer structure needs:

Client:

The client only needs to use a browser to get a report on the .aspx page.

Service-Terminal:

- Crystal Report Engine (Crengune.dll)

Together with other tasks (such as merged data with report files, the data is output to different formats, etc.), Crystal Report Engine can turn your Crystal Report into a concise HTML in the .aspx page.

- Crystal Report Designer (CRDesigner.dll)

Use Crystal Report Designer to create a report from scratch, you can design a title, insert data, formula, table, subprogramment, etc.

- The.RPT Report File

Applying a report to the first step in your web application is to create a report using Crystal Report Designer. In your computer already has some ready-made samples, you can use it now.

- The data source

The way the .rpt file acquisition data depends on the method you choose. You can choose to make Crystal Report to get data without hand writing any code, or you can choose to bind your DataSet and pass it into the report file. We will see different applications later.

- Crystal Report Viewer Web Form Control (CRWEBFORMVIEWER.DLL) Crystal Report Viewer is a Web Form Control that can be inserted into .aspx. It can be understood as a container containing a report.

Note: In complex implementation, report servers and web servers can be on different servers, in which case the web server will ask report servers. Crystal Report will be executed as a Web Service.

Execution mode

Crystal Report data can be obtained in any of the following methods.

Pull Model

In the scaffold, the driver will connect to the database and "pull" "to" "" "as needed. When using this model, the SQL commands that are connected to the database and the SQL commands executed in order to obtain data are also processed by the Crystal Reports itself, and the developer is required to write code. Use the pull model if you do not need to write any special code at runtime.

Push model (push model)

Instead, the push model requires the developer to write code to connect to the database, execute the SQL command to create a recordset or data set that matches the fields in the report, and passes the object to the report. This method allows you to share the connection into the application and filter data before Crystal Reports receives data.

Report type

In addition to the statement of the scheme, Crystal Report Designer can also load reports included in the scenario.

- Strongly-typed report:

When a report is added in the scenario, the report becomes a strongly-type. In this case, you can create a report instance (you can reduce several code), you can hide it. Of course, you can display it in "Show All Files" in Solution Explorer.

- UN-TYPED REPORT:

Reports that are not included in the scenario is Un-type. In this case, a Crystal Report Engine's 'Report Document' object must be created and the report is manually loaded.

In addition, what else you should know:

Although the Crystal Report Viewer control has built-in Zooming, Page Navigation, etc., it does not have built-in print options. You must use the browser's print option.

Crystal Report for Visual Studio .NET The unregistered version is available for only the top 30 features. Save Option will not be used here. In order to use all the features, you have to pay for it.

The default installation only provides five users licenses. To support more users, you must purchase additional licenses to www.crystaldecisions.com.

Cow Knife Try - Use an existing Crystal Report file in .aspx page

Let us now look at how to apply a Crystal Report file to your web form.

(1) Drag a "Crystal Report Viewer" from Tool Box to your .aspx page.

(2) Open this Control's properties window.

(3) Click [...] to pop up the Data Binding window on the "Data Binding" property.

(4) Select "Report Source" from the left.

(5) Select "Custom Binding Expression" and enter the following statement in the list below:

"C: / Program Files / Microsoft Visual Studio.Net/crystal Reports / Samples / Reports / General Business / World Sales Report.rpt" Remember to include quotes, point OK.

Note: This 'World Sales Report.rpt' file is made as part of the VS.NET is installed. If you specify a different path to install vs.net, please modify it.

(Translator Note: C # users Enter the following string: "C: // Program Files // Microsoft Visual Studio.Net//crystal report // Samples // Reports // General Business // World Sales Report.rpt")

After a short time, you will see a simple preview.

The above steps are actually inserted into the following code on your .aspx page:

<% @ Register tagprefix = "cr" namespace = "crystaldecisions.web" assembly = "crystaldecisions.web"%>

And in

ID = "CrystalReportViewer1"

Runat = "server"

Width = "350px" Height = "50px"

ReportSource = '<% # "C: / Program Files / Microsoft Visual Studio.Net/crystal Reports / Samples / Reports / General Business / World Sales Report.rpt"%> ">

(6) Call the DATABIND method, edit Page Load Event in the Code Behind file

Private sub page_load (byval sender as system.object, byval e as system.EventArgs)

DataBind ()

End Sub

(7). Save, generate and run. Now you already have a page containing the Crystal Report file.

转载请注明原文地址:https://www.9cbs.com/read-28488.html

New Post(0)