Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

The Baker's Dozen: 13 Productivity Tips for Crystal Reports and .NET : Page 4

These 13 tips show you how to build tools to address common reporting requirements for your business using Crystal Reports with .NET.


advertisement
Tip 4: Exporting Reports
Crystal Reports supports export of reports to different output formats. You can use the RunReport method in ccCrystalManager to export simply by passing PDF, WORD, or EXCEL as a parameter, and providing the name of the output file as an additional parameter:

oCrystal.RunReport(DsMyData, oReport, "", "PDF","MyPDF.PDF");

Crystal Report's export capabilities have improved dramatically over the years. The export to Word and Excel feature retains a very high percentage of the report's format, and the export to PDF is even better. As PDF has become a popular means of distributing output electronically, this makes the export capability even more attractive in an enterprise environment.

Tip 5: Multiple Levels of Detail (Subreports)
Crystal Reports allows you to produce reports with multiple levels of detail. A simple but demonstrative example is shown in Figure 7, an Employee Report that displays two different levels of detail: weekly hours and employee notes.

 
Figure 7: Establishing subreport links is easy with this dialog box.
As with the first report you created, you need to define the necessary schema in the Visual Studio .NET dataset designer. For this example, you need four datatables: the standard company header table, a parent employee ID/Name table, and two related child tables (on the employee ID) for weekly hours worked and employee notes.

Create the report and specify the XML schema definition as the data source. Note that after supplying the XML schema, you should verify the visual links between related datatables by clicking Database...Database Expert...Links.

You need to perform some additional tasks to produce the multiple levels of detail. First, you need to insert a group on the Employee ID from the Employee table. This is done by specifying the Insert...Group column as the key.

Next, you need to insert two subreport definitions for hours worked and notes. These subreports will be linked by employee ID so that only the related rows for hours and notes will display for each employee. This is done by doing the following:

  • Click Insert...SubReport.
  • Specify a unique name for each subreport (SubReportHours and SubReportNotes) and then click Report Wizard.
  • Identify the data table(s) to be used in each subreport (the datatable for employee hours and the datatable for employee notes).
  • Go into each subreport and drag the necessary columns from the field explorer.
  • Finally (and most importantly), go back to the main report, right-click on the subreport placeholder, and select Change Subreport Links. This ensures that hours and notes are only displayed for the group definition (employeeid). Select EmployeeID from the list of columns (see Figure 7).
After saving the report, you can add it to your Visual Studio .NET project and then run the report using the same command you used in the first report:

RPT_EmployeeSubReport oReport = new RPT_EmployeeSubReport(); ccCrystalTools.ccCrystalManager oCrystal = new ccCrystalTools.ccCrystalManager(); oCrystal.RunReport(DsEmployeeList, oReport, "Employee Listing", "PREVIEW");

Note that you don't need to specify any of the subreports when you generate the Employee Report with RunReport. This function automatically searches the report object for any subreport definitions, and performs the necessary calls to SetDataSource based on the dataset you provided to the function.

Earlier I covered the internal method SetData, which scans through a report's database object and matches up datatables to the dataset that you provide. RunReport actually makes up to two sets of calls to SetData: one for the main report object and a second for any subreports:



foreach(ReportDocument oSubReport in oReport.Subreports) this.SetData(DsReportData,oSubReport);

So again, you never need to worry about matching up subreport names based on how you designed them: RunReport takes care of it for you!



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date