| |
Microsoft Visual Studio.NET: Crystal Reports
This is a brief article about VS.NET's new addition: Crystal Reports.
Benefits of Crystal Reports
Use the programming language of your choice and access the Crystal Report Designer from any project. Crystal Reports for Visual Studio .NET provides two report viewers with which you can view your report in your application: use the Web Forms Viewer for Web applications and the Windows Forms Viewer for Windows applications. Once you choose your development framework, Crystal Reports provides you with the report viewer appropriate to both your application and your development language. These report viewers are also customizable in that you can change the appearance and the available options of the toolbar. Initialize properties of the Web Forms Viewer and the Windows Forms Viewer at design time. Or, set up your Web Forms Viewer or Windows Forms Viewer to interact with other controls at runtime. With runtime customization, users can view different reports, or change the format, data selection, or export options of an existing report. The Report Object Model exposed by the Report Engine allows you to add code to the source file of the Windows Forms page to enable the Windows Forms Viewer control to interact with other controls in the same page. For example, the Windows Forms control can interact with a button or combo box to provide users with export and report formatting options.
Designing a Report
In the Crystal Report Designer, you first select the data source that your report will reference. You can use more than one data source in a report. Next, you choose the database tables you want to use in the report. Crystal Reports can automatically link the tables, or you can specify how you want the tables linked. Database tables are linked so records from one database match related records from another. The Crystal Report Designer uses a drag-and-drop approach similar to Visual Studio .NET — you drag a report object onto the Designer (such as a database field or text object) and use the Property window or shortcut menu to format the object. Some report objects that you can add to your report and format according to your needs include:
Database fields Formula fields Parameter fields Group Name fields Running Total fields Summary fields Charts Subreports
The Crystal Report Designer is divided into report sections, such as section headers, footers, and details. You drag objects onto a report section. The data that appears in the finished report is contingent upon your design choices. In particular, report data varies depending on the sections into which you choose to insert particular report objects. For example, if you insert a chart object in the Report Header section, the chart will appear only once at the beginning of the report and will summarize the data contained in the report. Alternatively, if a chart object is added to the Group Header section, a separate chart will appear at the beginning of each group of data and will summarize the data relating only to that group.
Using Crystal Reports in Projects you create
A report added to a Visual Basic or C# project is a "strongly-typed" report. A report source file, containing a report class specific to this report, is automatically created for it. This report class has ReportClass as its base class. For more information on the ReportClass class, please refer to the derived class ReportDocument . The report source file also shows sections of the Crystal report. These sections should not be modified. The report source file has the extension .cs for a Visual C# project, and .vb for a Visual Basic project. This file is normally hidden. You can click the Show All Files icon to list it (e.g., under CrystalReport1.rpt) in the Solution Explorer.
To add a new Crystal report to a project
In the Solution Explorer, right-click the project name, point to Add and select Add New Item from the shortcut menu. (Alternatively, highlight the project name in the Solution Explorer; from the Project menu in the Visual Studio Standard Toolbar, select Add New Item.) In the Add New Item dialog box, select Crystal Report from the Templates pane. Alternatively, expand the folder tree in the Categories pane, highlight Utility, and select Crystal Report from the Templates pane. Enter a report name with an .rpt extension in the Name field. Or, accept the default report file name, CrystalReport1.rpt, if it exists. Click Open to invoke the Crystal Report Designer that helps you create and design the new report.
To add an existing Crystal report to a project
In the Solution Explorer, right-click the project name and point to Add and select Add Existing Item from the shortcut menu. In the Add Existing Item dialog box, select All Files under Files of type. Specify the location and name of the report you are adding.
|
|