Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

19.16 Mobile Devices

Printing for Mobile Devices

Mobile devices are becoming prevalent in our corporate lives and personal lives. With the faster data connections available and better browser interfaces, more and more people are becoming reliant on them as a primary source of information. In the corporate world, executives want timely business data and sales people want instant access to their latest sales figures. It’s no surprise that Crystal Reports has a means of getting data to your users’ mobile devices.

The Report Parts Viewer in Crystal Reports is designed for mobile devices and portals with a very limited viewing area. It only prints individual report objects and confines them to a limited report size. As the user clicks on data within the page, it drills-down into more data. You, the report designer, use hyperlinks to specify which report part is displayed next.

Having the user click on the report objects and link to other report parts is similar to how you navigate a typical report with drill down capabilities. The difference with report parts is that the resulting data is kept to a minimum and you control the “navigation path” the user follows.

Let’s see how this works by building a web page that uses the report parts viewer and looking at the output. We’re going to take the sample report, Group.rpt, that is installed with Visual Studio and display it with the report parts viewer.

First, create a new web site. Once you’re in design mode, go to the Solution Explorer and right click on the web-site name. Select the menu option Add Existing Item.

Navigate to the Crystal Reports sample directory, “Featured Examples”, and select the report Group.rpt. The report should be in this directory:

C:\Program Files\Microsoft Visual Studio 9.0\Crystal Reports\Samples\En\Reports\Feature Examples

Double-click on the report to open it in design mode. This report is grouped by the Country field. Within each country are listed the customers and last year sales. For the report parts viewer, we’ll show the countries on the first page and let the user drill down to see sales detail for each customer.

The first thing we need to do is tell Crystal Reports which report object it should show on the first page of the report. This will be the Country field in the group header.

Right-click on the group header field (the country name) and select copy. Next, select the menu options Crystal Reports > Report > Report Options. This opens the Report Options dialog box.

At the bottom is the section titled Initial Report Part Settings. This is where you tell Crystal Reports which report object should be shown on the opening page. Click the Paste Link button and it copies the name of the group header field to the Object Name property. This is shown in Figure 19-12.





Figure 19-12. Assigning the initial report part settings.

Click the OK button to save your changes and close the dialog box.

The next step is to tell Crystal Reports what to do when the user clicks on the country name. If there were multiple groups, you might want the user to drill-down through each group. In this example, we’ll just have it show the detail sales records.

Right-click on the Group Header #1 report object again and select Format Object. This opens the Format Editor dialog box. Click on the Hyperlink tab.

To display the detail records, click on the Report Part Drilldown radio button. The bottom of the dialog boxes changes to show the fields that you can select for displaying on the report.

Click the Details node to expand it. Then select the fields Field4 (customer name) and Field14 (last year’s sales) and add them to the Fields To Display list on the right. This is shown in Figure 19-13.





Figure 19-13. Specifying the detail records to show.

At this point, the report is ready to be displayed in a report parts viewer. We just need to add the viewer to the default web page and we’ll be ready to go!

Open the web page Default.aspx in design mode and drag and drop the CrystalReportPartsViewer control onto the form. Use the SmartLinks button (in the top-right corner of the control) to open a new Report Source and specify the Group.rpt report. Click the OK button when you are finished.

Run the report and you should see a small version of the report appear on the web page. This is shown in Figure 19-14.





Figure 19-14. The report parts web page.

Notice at the bottom of the page that the previous and next buttons are already on the page and they are positioned in such a way that they will still be displayed on a mobile device.

You can click on one of the countries to drill down into the sales information. This is shown in Figure 19-15.





Figure 19-15. The detail records of the report parts viewer.

You can see from this example how easy it is to convert your reports into a format that is formatted for viewing on a PDA or portal site.