Creating Reports in Visual Studio .NET

To assist Visual Studio .NET developers in designing reports, Crystal Reports for Visual Studio .NET provides a collection of Report Experts, extremely similar to the Report Creation Wizards (covered in Hour 4, "Using the Default Report Wizards") available in Crystal Reports 9. The Report Experts will guide the Visual Studio .NET developer through the creation of a variety of reports while handling the details of how the report is created. The available Report Experts create several types of reports, including standard, form letter, form, cross-tab, sub-report, mail label, and drill-down reports, shown in Figure A.1. Figure A.2 displays the Standard Report Creation Expert dialog.

Figure A.1. The Crystal Reports Gallery dialog allows Visual Studio .NET developers to access a variety of Report Creation Experts.

graphics/afig01.jpg

Figure A.2. The Standard Report Expert is perhaps the most common expert used to create reports.

graphics/afig02.jpg

Crystal Reports for Visual Studio .NET is composed of several components. Once a report is set up, either manually or by using one of the Report Experts, developers use the Crystal Reports Designer in Visual Studio .NET to modify, add, and format objects and fields, as well as to format the report layout and manipulate the report design, as shown in Figure A.3. The designer then generates .rpt files. (.rpt is the file extension for a Crystal Report.) Within the Visual Studio environment, these .rpt files are processed by the Crystal Reports engine, which delivers the report output to one of two Crystal Report viewers a Windows Forms viewer control or a Web Forms viewer control depending on the type of application the developer specifies. The report viewer then presents the formatted report information to the business user of the application.

Figure A.3. The Crystal Reports for Visual Studio .NET design environment.

graphics/afig03.jpg

Using Crystal Reports in Web Applications

A developer, using Crystal Reports for Visual Studio .NET, can integrate highly interactive reports into a Web page. Dynamic Web applications are made possible through ASP .NET technology integrated into Visual Studio .NET. Crystal Reports for Visual Studio .NET provides a Web Forms Report Viewer, which is a Web Form (HTML files with embedded Web Controls and code files that contain event-handling logic) that hosts the report. When a client (end business user) accesses such a Web form, the event handler can update and format information in a Crystal Report and send the updated report to the business user of the application.[7]

[7] Developer Zone, Hot Downloads (Crystal Reports for Visual Studio .NET Walkthroughs). http://www.crystaldecisions.com/products/dev_zone

One of the walkthroughs available on the Crystal Decision's Web site instructs Visual Studio .NET developers how to enable Web page interactivity and how to use ASP .NET and its controls. In this walkthrough, the business user of the application accesses information about countries by first entering a country name into a text box, and then submits the information. The country name is passed to the Web forms viewer control and the report is updated.

Using Crystal Reports with Web Services

Using Crystal Reports for Visual Studio .NET, any Crystal Report created in C# can be published as an "XML Report Web Service" as shown in Figure A.4. A Web service provides methods that are accessible over the Internet to any application, independent of programming language or platform. As an example, an XML Report Web Service could be an excellent mechanism with which business partners could access specific report information. Visual Studio .NET generates a DLL file (dynamic link library) that contains the report and an XML file when a Crystal Report is published as an XML Report Web service. Both files are published to a Web server so that a client machine (business user) can access the report. An XML-based SOAP message passes the data to and from the Web service. When a developer uses Visual Studio .NET to create and publish the Web service, the developer can associate the Web service to either a Windows or a Web application to display the data returned from the Web service.

Figure A.4. Crystal Reports can be published as a Web Service within the Visual Studio .NET design environment.

graphics/afig04.jpg

One of the great things about using a report as a Web service is that it allows companies to exchange corporate information without passing the actual data. Rather than opening up your database to a partner, you can build a report off it and have the report exposed as a Web service. The report is still executed at the host company, alleviating any security issues, but the partner consuming the report can benefit from the insight it provides.

Again, Crystal Decisions provides a good example, via a walkthrough, of the steps necessary to familiarize developers with implementing a report as a Web service.

To truly understand the value and implementation of a Crystal Report Web service, it's useful to consider a common scenario. Let's assume that company A has a large regional distributor network and needs to share sales information with these distributors on a regular basis and has built a sales report used internally to understand this information. Company A would like to use this same report to serve external audiences. The following example provides an illustration of how company A can build an XML report Web services application to enable business partners to access relevant information:

  1. Click New Project on the Start page.

  2. Select Visual Basic Projects and then ASP.NET Web Service.

  3. Click OK. Provide a new project name, and then click OK. Visual Studio .NET will open up your new project.

  4. Right-click on the "name" of your new project.

  5. Select Add and then Add New Item.

  6. Select Crystal Report from the menu.

  7. Either select an existing Crystal Report or create a new Crystal Report.

  8. Assuming that you select an existing report, select the World Sales Report.

  9. Right-click on the report you just added and select Publish as Web Service.

  10. Select Build and then Build Solution.

Company B (business partner of company A) builds a C# Windows application within Visual Studio .NET that consumes the XML report Web service created by company A:

  1. Right-click on Solution and select Add and then Add new project.

  2. This time, select Visual C# Projects and then Windows Application.

  3. IMPORTANT Set this project as your Startup Project by right-clicking on the name of this new application and selecting Set as Startup Project.

  4. Copy the location of the new Crystal Report .asmx file created earlier by clicking on it and selecting Copy.

  5. In the new project, select References and then Add Web Reference.

  6. Paste the location of the item copied in step 4 into the top Address box and click Enter.

  7. When the page comes up, select Add Reference a new Web Reference should be visible in the Solution Explorer.

  8. Go to the toolbox and drag the Windows CrystalReportsViewer.

  9. Select Dock from the Properties area.

  10. Double-click on the form and view the code.

  11. Locate InitializeComponent(); and space down two spaces.

  12. Enter this line of code: crystalReportViewer1.ReportSource = new localhost.<NAME OF CRYSTAL WEB SERVICE>();.

  13. Select Save All, Build, Build Solution, Debug, and then Start without Debugging.

  14. The application will build and display after 20 seconds.

  15. The resulting report even supports drill-down, export, and printing capabilities.



Sams Teach Yourself Crystal Reports 9 in 24 Hours
Sams Teach Yourself Crystal Reports 9 in 24 Hours
ISBN: B003D7JUVW
EAN: N/A
Year: 2005
Pages: 230

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net