Quickly master CrystalReport for .NET

xiaoxiao2021-03-06  46

Reports in almost all applications are the problem of the headache of the programmer. In the .NET environment contains a powerful report tool: Crystal Report. It can interact with the database, make a variety of beautiful reports and analysis charts (the following article will be more detailed). In fact, this article today is the courseware of the lecture for a company for a few more time. After the revision, I hope that some programmers who can develop reports in the .NET environment. Since our company is an e-government system, serious "Chinese statement" is huge, so I encapsulated a report control for the company, and realize the entry, deletion, display, printing of the data in the report document. If you have friends foresee similar problems, I am happy to communicate with you and learn together. E-mail: Billzhangmingming@sina.com Started in 1993, Crystal Report is part of the Visual Studio suite. At present, it has actually become a report standard in Visual Studio.NET, which is a leading position in the field of Windows report, which promotes the future development of Web reports. The latest Visual Studio.net is integrated with Crystal Report9.0 in an integrated development environment (IDE), enhances the development of Visual Studio.NET, and Crystal Report provides developers with as much API.

Crystal Report for .NET Function Introduction By using Crystal Report's report handling features and to your database applications, applications and web developers can save development time to meet the needs of users. Crystal Report supports most popular development languages ​​that can be easily added to any application. Whether it is the site administrator in the IT industry, or the financial industry, the database administrator of the telecommunications industry, Crystal Report is a powerful tool that helps everyone analyzes and analyzes the data. Specifically, the functionality of Crystal Report has the following: ** Comprehensive Database Access: Crystal Report includes more than 35 data source drivers, you can access an XML, enterprise, and relational databases. ** Widely Design Format and Design: Through Crystal Report, users can convert databases to high interactive content. You can choose from more than 100-middle format options, including parameters, mapping, crosstabs, and hyperlinks to strengthen the impact of the report. ** Powerful chart design features: Crystal Report can include colorful, easy-to-read charts in the report (providing very rich report types, such as bar chart, line diagram, area map, pie chart, dry special map, Stock illustration, etc.). ** Flexible Application Integration Technology: Crystal Report With flexible Java, COM, and .NET SDK, as well as embedded Report Application Server, you can closely integrate reports to the enterprise web application. By using Crystal Report's "zero" client browser control, you can provide a rich report interaction, create and modify features for the final end support. ** Powerful Report Export: All reports of Crystal Reprort can export a variety of different formats: including XML, PDF, HTML, and Microsoft Excel. Crystal Report Designer Layout ** Field Explorer: List all fields, such as: Used database fields, parameters, formula fields, and more. You can modify and delete field objects here. ** Main News window: It is used to display the main report in the Reports window. For reports containing sub-reports, there is a sub-report window with a primary report window and a sub-report for each deepening (by double click). You can start the report shortcut menu by right-clicking on any blank position of the report window. ** Crystal Report Main Toolbar: Includes Record Selection, Classification, and Text Object Format Icon. You can move or change the size of the entire toolbar. ** Crystal Report Insert Toolbar: You can insert the icon for the summary field, group, sub-report, charts, and images. You can also click the Mouse in the Crystal Report toolbar to select "Insert". Specific examples of Crystal Report ** Crystal Report Viewer Crystal Report Viewer is a Windows Form Control for Windows Applications in Visual Studio .NET. Similar to his Windows Form Control, adding a Windows Form Viewer to drag crystal report viewer control from the Visual Studio.Net toolbox to Windows Form Design attempt. Then specify the crystal report in the Crystal Report Viewer. *** A Demo that creates a report using Crysatl Report Viewer: To add Windows Form View to a Windows Form in a Visual Basic or C # item, do the following: Open Toolbox and drag a CrystalReportViewer to the form on.

Adjust the Windows Form View to the desired size and move it to the desired location by dragging operation. When running the application, the report will be displayed in the viewer. Like any other control in Toolbox, if you want to add code to the Windows Form Viewer Control, double-click the control to display the Code view. Next, bind the report to the Windows Forms Viewer. Specific About this Demo, I wrote a very detailed article on how to operate on Wiki, I suggest you go to see. ** ReportDocument Object Description: The top level of the Crystal Reports object model is the ReportDocument object. ReportDocument contains all properties and methods needed to interface and custom reports. You can use its LOAD method to open a report file or assign a strong type of report. To use ReportDocument, you must first reference the CrystalDecisions.crystalReports.Engine namespace (found in CrystalDecisions.crystalReports.Engine.dll). This reference is automatically added if you have insert reports into your application. *** A specific use of the ReportDocument object to create a dynamically loaded report: Add reference to CrystalDecisions.crystalReports.Engine to open Form1.cs in the code editor. Add a Button on Form1 form, add the following namespaces to Form1.cs: using CrystalDecisions.CrystalReports.Engine; create a report object, as Form1 () in public ReportDocument variable:. Public ReportDocument oRpt = null; the function button1_Click ( In the use of the "Report Document" object, bind the object to the Windows Form Viewer: Private Void Button1_Click (Object Sender, System.EventArgs E) {RPT = New ReportDocument (); rpt.load ("..////Myreport.rpt"); CrystalReportViewer1.Reportsource = rpt;} ** Use DataSet to create a master from Demo: In the report, there are many tables that are the master-slave structure, such as: order With order details, each order is a record in a "order" table, and the details are multiple records in another "order detail" table, and the two tables are associated with a field "Order ID". This report can be implemented using its packet function, which will be specifically described below. Add a "CrystalReportViewer" control on from1.cs. In the Solution Explorer, right click on the project, point to Add, select "Dataset", click OK.

In the Server Resource Administrator, add a connection, this example uses the sample database Xtreme.mdb in Crystal Report for .NET, the default installation directory in "F: Program Files / Microsoft Visual Studio.Net/Crystal Reports / Under Samples / Database / CHS, click OK. Drag the "Order" table and "Order Detail" table to "Dataset". Create a Crystal Report file, named "MyReport". Use the report expert to select "ADO.NET Dataset" in Project Data, insert "Order" and "Order Detail" table, select to be on the field selector The data field shown on the report. There are two fields that must be ({customer. Customer ID} and {product details. Product ID}). Select the group based on "Order" table in the Group tab. Click Finish. Return to Form1.cs to encode. In the beginning of the namespace of Form1, enter: use system.data.oledb; start local input: private myreport report = null; in form1_load () Enter: report = new myreport (); dataset1 dataset = new DataSet1 (); oledbconnection conn = new oledbconnection ("provider = microsoft.jet.Oledb.4.0; data source = f: // visual studio.net//crystal report // Samples // Database // CHS // xtreme.mdb "); OleDbDataAdapter oleAdapter = new OleDbDataAdapter (" SELECT * FROM orders ", conn); oleAdapter.Fill (dataSet," orders "); OleDbDataAdapter oleDetailsAdapter = new OleDbDataAdapter (" SELECT * FROM order details ", conn); oleDetailsAdapter.Fill (Dataset, "order details"); Report.SetDataSource (Dataset); CrystalReportViewer1.ReportSource = Report; generates two objects of the two OLEDBDataAdapter classes and uses the filling fill method to get the data acquisition data. ** Chart: Crystal Reports allows you to include complex, colorful charts in the report. Drawing charts are not only a method of representing data, but also an analysis tool. Users can deepen on the graphics or graphics to get details. You can draw charts according to the following: Summary and Small Field Details, Formulas and Run Summer Field Cross - Table Summary ** How to Insert Chart in Report: Right-click in Report Designer, point to "Insert", and click "chart". In the Types tab, select the chart type. If you want the Chart Experts to use the default options on the Coordinate axis and Options tab, select Auto Set Chart Options. Click the Data tab. In the Location area, specify the frequency that the chart appears in the report, and then click "Header" or "Footer" to specify the location of the chart. In the "layout" area, choose the chart layout.

In the "Data" area, specify the database field to be used as the condition. If the Coordinate axis and Options tabs appear, you can customize some chart properties, such as shaft scale, illustration, and data points. Click the Text tab. Accept the default header information or add the new title to the chart. Click the "OK" button. ** Using the formula formula Overview: In many cases, the data required to report to exist in the database table field. For example: To prepare a list of orders, the appropriate field should be placed in the table. However, sometimes you need to place the data in any data field in the report. In this case, you need to create a formula. For example: To calculate the number of days required to handle each order, you need a formula that can be determine the number of ordered date and shipping date. This formula can be easily created using Crystal Report. Create and edit formulas using the Formula Editor. This dialog box appears when the existing formula field or create a new formula field by right-clicking on the Formula field in Field Explorer. This dialog will appear after named the formula. ** Subrport: The sub-report is the report in the report. Use a sub-report, you can blew the mouth, ū 砗 砗 ⒌ ⒌ 霰 霰 霰 碇? Tedan pregnancy  鞅 薹   拥 氖   蛘咴 蛘咴 诘ジ? BR> Different views showing the same data in the report. The process of creating sub-reports is similar to the process of creating a regular report. The word report has the most characteristics of the report, including his own record selection conditions. The only difference between the subfamily report is that the sub-reports: * is inserted into the primary report as an object, which cannot be independent (but can save the sub-report as the main report). * You can place it within any section of the report, and the entire sub-report will print in this section. Another sub-report cannot be included in the sub-report. ** How to create a specific steps for sub-reports: Right-click in Report Designer, point to "Insert", click Sub Report. Drag the sub-report object to the report. Select a report in the project, another existing report, or create a new report to the child report. Select "Display Substall as needed" to enable data on the sub-reports when needed. Otherwise, all sub-report data will appear together with the report. Note The use of the report will increase the performance of the report containing sub-reports as needed. If you need to link the sub-report to the data in the primary report, click the "Link" tab. Select from the "Available Field" list to use the field to use as the link field in the main (included) report. Use the Field Link section (only if the link field is selected) Set the link for each link field: Select the field you want to link to the primary report from the Sub-Branch Parameters Use of Use. Select the data check box and select a field from the adjacent drop-down list to organize sub-report data based on a specific field (this is equivalent to quickly using "Select Experts"). If you do not specify a field here, the sub-report will use the structure of the main report. Click the "OK" button.

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

New Post(0)