In Visual Studio. NET using Crystal (upper) Cashcho (translation)

Source: Internet
Author: User
Tags contains client visual studio
Visual in the Visual Studio. NET used in Crystal ( on )



From www.aspfree.com
Translated by Cash (world seventh)
Cashcao@msn.com



Before we started this little research on how to use Crystal Reports on vs.net, my friends and I were very confused about how to apply it to our web apps. After one weeks, after some effort (looking for "how-to" on the web), we have some small tips for adding simple reports to the ASP.net program.



This article contains some summaries of the methods needed to apply crystal to your. NET Web application, and through these step-by-step demonstrations, the errors you will encounter (as we have encountered) will be minimized. In order to use this article more effectively, readers should have the basic knowledge of database connection in asp.net and are using vs.net development. Please note that we have only tested the following code with the Beta2 version.



This article includes the following:

(1) Introduction;

(2) His experiment-use an existing crystal file in the. aspx page;

(3) Crystal Demo-use pull Model;

(4) Crystal demo-use push Model;

(5) The output of the paper to other formats.



There are all kinds of crystal, and here we are using specifically for. NET design "Crystal for Visual Studio. NET". It is a rich programming model that can manipulate its properties and methods. If you use Vs.net to develop your program, you don't need to install any additional software because it's already included in the vs.net.



Advantages
Use the crystal for Visual Studio. NET's main benefits are:

--Rapid Development Report
--can be extended to complex reports with associated charts
--can interact with other controls in this Web Form
--the ability to output it into a commonly used. pdf,.doc,.xls,.html,.rtf format



Overall structure

Show this two-story crystal:



Client:

The client only needs to use the browser to get the reports that are loaded on the. aspx page.



Server side:



-Crystal Engine (CREngine.dll)

Together with other tasks (such as merging data with report files, outputting data to different formats, and so on), Crystal report Engine can transfer your Crystal report to simple, straightforward HTML in the. aspx page.



-Crystal Designer (CRDesigner.dll)

Use the Crystal Report Designer to make reports from scratch, you can design headings, insert data, formulas, tables, secondary reports, and more.



-The. rpt File

The first step in applying a report to your Web application is to use the Crystal Report Designer to create reports. You already have some ready-made samples on your computer and you can use it now.



-The Data Source

The way in which the. rpt file gets data depends on the method you choose. You can choose to make the Crystal report to get the data without having to write any code manually, or you can choose to bind your dataset and pass it into the file. We'll see a different application later.



-Crystal The Viewer Web Form control (CRWebFormViewer.dll)

Crystal the viewer is a Web Form control that can be inserted into an. aspx page. It can be understood as a container that contains reports.



Note: In the complex implementation process, the report server and the network server can be on different servers, in which case the network server will request the report server. The Crystal will be executed as a Web service.

Execution Mode



Any of the following methods can be used to obtain crystal data.



Pull model (pull models)

In the pull model, the driver connects to the database and pulls the data in as needed. When using this model, the connection to the database and the SQL commands executed to get the data are handled by the Crystal Reports itself, without the need for the developer to write code. If you do not need to write any special code at run time, use the pull model.

Push model (push models)



Instead, the push model requires developers to write code to connect to the database, execute SQL commands to create a recordset 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 into your application and filter the data before Crystal Reports receives the data.



Report Type

In addition to reports that are independent of the programme, Crystal Report Designer can also load reports that are included in the scenario.



-strongly-typed:

When you add a report to a scenario, it becomes a strongly-typed report. In this case, you can create a report instance directly (you can reduce some code) and hide it. You can, of course, click Show All files in Solution Explorer to display it.



-un-typed:

A report that is not included in the scenario is un-typed. In this case, you must create a ' report Document ' object for Crystal Reports engine and manually load the statement into it.



Other things you should know.



Although crystal the zooming, page navigation, and so on, it has no built-in printing options. You must use the browser's print options to do so.



Crystal for Visual Studio. NET unregistered version has only the first 30 features available. Save option will not be available after this. In order to use the full functionality, you have to pay for it.



The default installation only provides five-user licenses, and to support more users, additional licenses must be purchased from the www.crystaldecisions.com.



his experiment-in . aspx page to use an existing Crystal file



Now let's take a look at how to apply a crystal file to your Web form.



(1) Drag a "Crystal" Viewer from tool box onto your. aspx page.









(2) Open the Properties window for this control.

(3) on the "Data Binding" property on the click [...] The Data Binding window pops up.

(4) from the left to select "" ".

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

"C:\Program Files\Microsoft Visual Studio.net\crystal reports\samples\reports\general Business\world Sales Report.rpt "

Remember to include quotes and click OK.









Note: This ' world Sales report.rpt ' file is installed as part of the vs.net. If you specify a different path to install vs.net, please modify it yourself.



(Translator Note: C # users enter the following string: "C:\\Program Files\\Microsoft Visual Studio.net\\crystal Reports\\samples\\reports\\general Business\\world Sales report.rpt ")



After a short period of time loading, you will see a simple preview.



The steps above actually insert the following code on your. aspx page:

<%@ Register tagprefix= "cr" Namespace= "Crystaldecisions.web" assembly= "Crystaldecisions.web"%>

And in the <form> section

<cr:crystalreportviewer

Id= "CrystalReportViewer1"

runat= "Server"

Width= "350px" height= "50px"

Reportsource= ' <%# ' C:\Program Files\Microsoft Visual Studio.net\crystal Reports\samples\reports\general World Sales report.rpt "%> ' >

</CR:CrystalReportViewer>



(6) Invoke the DataBind method to edit the 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, build and run. Now you have a page that contains the crystal file.





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.