The Baker's Dozen: 13 Productivity Tips for Crystal Reports Redux : Page 3
This article is a redux, or "Version 2.0" of the Baker's Dozen article on Crystal Reports that ran in the January/February 2005 issue of CoDe Magazine. The article updates some of the classes, covers some new features in Crystal Reports XI, and demonstrates techniques to help developers get the most out of Crystal Reports.
by Kevin S. Goff
Feb 5, 2007
Page 3 of 6
Tip 3: Building a Reusable Library for Common Reporting Tasks
I've incorporated a handful of reports into my application and find that I'm repeating common tasks for setting the report's data source, previewing, printing, and exporting the reports. I'd like to build and use a generic set of classes to handle all of these tasks every time.
Figure 10: The Crystal Reports tools project from the Common Ground Framework.
In my original Crystal Reports article, I presented a project called ccCrystalTools that contained some reusable functionality for previewing and printing reports. I've modified and enhanced the library since then. The library provides functionality for many common reporting tasks. The main benefit is that you don't have to repeat code for using the Crystal Reports object model.
Figure 10 shows the Visual Studio 2005 project for the library, now called CGS.CrystalReportsTools. The library consists of the following:
ccCrystalManager: a class that contains the core functionality for pushing datasets into reports, as well as previewing, printing, and exporting reports. Table 1 and Table 2 list the public methods and properties for this class.
Table 1: Public methods for ccCrystalManager parameters are in bold.
DataSet, Report object
Pushes the DataSet into a Report object, and returns the report object
ccReportInfo Header/Footer object, report object
Pushes a ccReportInfo header/footer object into a report object
Report object, title string
Launches a preview screen for a report object, and displays a preview screen title.
Report object, title string, Dataset
Combines PushReportData and the first overload of PreviewReport
Prints the report object, using print properties described in Table 2
Report object, filename, ExportType object
Exports a report object to the filename, as a format described in the ExportType object (valid options are PDF, Word, and Excel)
Report object, filename, ExportType object, start page, end page
Performs same task as the first overload, but only for a specific page range
Table 2: Public properties for ccCrystalManager.
Name of printer to use
Number of copies
Sets flag to print all pages
Sets flag to print page range
If printing page range, the starting page number
If printing page range, the ending page number
Sets flag to collate printed copies
Public enumeration, items are PDF, MSWord, and MSExcel