ir, roc

ci riar.


IP ilA'.

tn lac

Z'JI P1.1

Current Page No: 1 |Total Page No: 1 + |Zoom Factor: Page Width

Figure 2-1

ODBC [lata Source Adminístralos H]^

User DSN System DSN File DSN | Drivers Tracing | Correction Pooling j About System Data SQUtce.s:

Name Driver Add...

Crystal R epository M icrosoft Access D river (x. mdbi R emove

Xtreme S ample Dalabase 2003 Microsoft Access D river (x.mdb'


An GDEC.-System data source stores'information about how to connect to the indicated data provider A System data source is visible to all users on this machine, including NT Serviced.

GK j Cancel Help

Figure 2-2

Select the System DSN tab and click the Add button. This displays a list of drivers for which you want to set up a data source. We are using a Microsoft Access database, so select Microsoft Access Driver (.mdb) and then use the next window to locate the database and give it a name (Xtreme Sample Database 2003), finally selecting OK to finish.

Planning Your Report Design

Before we actually get into the technical report design, we need to spend a little time planning our report to alleviate some of the problems we might face later when we actually sit down and develop the report. Often developers will create reports that they think the user will want, using all of the latest features, bells, and whistles, only to find that the end user would be happy with a simpler report that was easier to read and understand.

Another problem is that a developer will often sit down and crack open the Report Designer without really knowing what the end product will look like or considering how the end user will use what has been created. What is called for is a bit of planning before we jump right into the technical aspect of designing reports. By planning our report before we get started, we can deliver a report that meets the users' needs and expectations.

If you already have a report design methodology and it works for you, please have a read over this section anyway; you may find a different way of doing things or be able to incorporate some small part of it into what you already do. In any case, there are a number of reports associated with this section available in the downloadable code for this chapter. Feel free to modify these reports for your own use.

In a very basic report design methodology, there are four steps to planning a new report:

□ Gather report requirements

□ Perform technical review

□ Develop report prototype

□ Design report

In most applications, reports are usually tied to a specific function or area of an application. For example, if you have created an application that is used for entering telephone sales orders from customers, chances are there will be a suite of reports tied to that function, showing sales summaries, order totals, and so on. The best way to determine what these reports should look like is to actually ask the people who will be using them on a daily basis.

If you are working in a large organization, you will probably have a business analyst who will interview the users, gather their requirements, and then communicate these requirements back to you. If you are in a smaller organization or, if like the rest of us, you are forced to take on a number of roles, you may gather these requirements yourself.

In either case, end-user interviews are the key to targeting a report's content. Organize the interviews with the actual end users (not their supervisors, personal assistants, or others), and ask them to bring along examples of reports they currently use or would like to use. This is your chance to find out what information they need to better perform their job. Be careful when interviewing, as users will sometimes come up with an arm-length wish list for reports they would like to see.

In the interview, the user should be able to tell you how the report is used and what decisions are made based on this information. If they can't tell you either of these things, either you are interviewing the wrong person or they really don't need the information they have asked for.

Once you have interviewed the end users, you should have a pretty good idea of what reports are required and how they will be used. From this point, there are many different ways of documenting the user's requirements (such as user requirements statements or use cases), but the most straightforward method is to create a formal Report Requirements document.

A Report Requirements document will outline what information needs to appear in the report, how the report is used (is it interactive or run in a batch?), and the general look and feel of the report. You may also create a mock-up of the report or a rough sketch of what it will look like. With your report requirements in hand, the next step in our method is to perform a technical review of the report's definition.

A good place to start with a technical review is to determine the data source for this report. Most likely the data source will be a relational database, but the data could also reside in spreadsheets, text files, OLAP (Online Analytical Processing) data structures, and even nonrelational data sources (like Exchange or Outlook folders). Once you have found the data source, you will need to dig a little deeper to determine the exact tables and views that can provide the data required. You may need to develop additional views or stored procedures to consolidate the data prior to developing a report (for speed and ease of use and reuse), and these will need to be documented, as well. Again, all of this information is added to your Report Requirements document.

For the next step of the technical review, you will need to investigate whether the design of the report is feasible. The user may request twenty columns when the page will fit only seven landscape, or they may have based the design on an existing report or spreadsheet created by hand. Once you are more experienced working with Crystal Reports, you will begin to understand how the tool works and the kind of output that can be achieved. In the meantime, browse through some of the sample reports that ship with the product to get a feel for the types of reports Crystal can produce.

Once you have completed the technical review, you understand where the data for the report resides, and you are comfortable that Crystal Reports .NET can deliver the required format, it is time to create a report prototype from your notes and preliminary sketches. This prototype can be created using Word, Excel, Visio, and other programs, but it should closely match the report's final layout and design. Again, another important check is to make sure that the layout and design you want can be created with the features and functionality that Crystal Reports .NET has available.

A good way to determine whether Crystal Reports .NET can deliver a particular format for data is to find a sample report that shows the data presented in the method you want to use. You also could create a small proof-of-concept report with sample data to test the design.

The prototype, combined with a formal Report Requirements document, will clearly communicate what the report should look like when it is finished. It also helps gain user acceptance for the design, as they can see what the finished product will look like even before you have opened the Report Designer. If you are working in a large team, this documentation will communicate the requirements to other report developers so you don't actually have to brief them on every single report that needs to be developed.

If you are working as a business analyst, application developer, and report developer all-in-one, it can also help you keep on track with the user's requirements and make gaining user acceptance that much easier. Once signed-off by the client, the Report Requirements is a contract, so should it turn out that the report designed isn't what the client wanted, you can point to this document and their signature on it!

Finally, with the documentation and prototype in hand, it is time to sit down, open the Report Designer, and design your report.

Creating a Crystal Report

In the next few pages, we are going to walk through the steps to create a customer listing report in an existing Windows application using the Standard Expert. You can open the solution and project that is available in the code download for this example (located by default at C:\Crystal.NET2 003\ Chapter02\chapter2.sln) or create your own.

When creating a report from scratch within Crystal Reports .NET, you have a number of experts that can be used to guide you through the report development process. In this section, we will look at how to use one of these experts to get started. Once you have finished working through the expert, you will have a report you can further develop using the integrated designer. Over time, as the interface becomes familiar, you may choose to start with a blank report and build it up piece-by-piece, but most developers use the expert at least to get them started.

To begin, create a new Visual Basic .NET project by opening Visual Studio .NET 2003 and selecting New Project. Select Windows Application from the dialog, call the project CustomerListing, and put it in the folder C:\Crystal.NET2003\Chapter02.

Adding a Report to Your Application

Adding a new report to your application is as simple as selecting Project ^ Add New Item and selecting Crystal Report from the list of available templates. Enter customerlisting.rpt into the name field and then click Open to insert the new report into your application. A separate tab will now appear for the report and allow you to use the integrated Report Designer to create your report, but before you can do this you will see the Crystal Report Gallery window, shown in Figure 2-3.

Figure 2-3

If you haven't registered Crystal Reports .NET, you will receive a nag screen asking you to register the product. This registration is specific to Crystal Reports and is required to be able to distribute your applications to other users. You can use the Registration Wizard that appears to register via the Internet, e-mail, fax, or mail and will receive a registration key that will eliminate the nag screen and allow you to distribute your application.

The first decision you will need to make about your report is to select how it will be created. In this instance, we are actually going to use one of the report experts to walk us through the report design, but there are other options as well, as shown in the following table.



Using the Report Expert

There are a number of different report experts available to walk you step-by-step through creating a report. This is the most popular method even for experienced report developers, as it provides a starting point for further report development.

As a Blank Report

This option is for experienced developers who are familiar with the Report Designer and want to build a report up piece by piece. This is often a good way to produce a report that is leaner and has fewer overheads built into it. When this is selected, the experts aren't available.

From an Existing Report

If you have an existing report that will serve as the basis for the report you wish to create, you can use this method to import your existing report. Again, when this is selected the experts aren't available.

Using a Report Expert

If you decide to use a report expert, there are seven different experts to choose from. All of the experts share some steps in common; in all of them you will be prompted for the data source for your report, for example, as well as for what fields will appear.

As we go through this chapter, we will be looking at all of the major steps involved in creating a report using the experts, but for now here is an overview of the different types of experts available:

□ Standard — The Standard Expert is used most often and is the most generic. You can use the Standard Expert to create a column-based reportthat includes features such as grouping, sorting, and summaries. This expert has the ability to add charts, apply a number of predefined styles, filter records, and it also includes advanced analysis features like TopN, BottomN (for example, the top 10 or bottom 10 reports).

□ Form Letter — By combining text objects and database fields, Crystal Reports .NET can be used to create form letters and statements. This expert guides you through creating a report and placing database fields and text within that report.

□ Form—To support reports that are designed for a specific paper form, Crystal Reports .NET can use a scanned form or graphic as a guide for your report. Using the Form Expert, you will be able to underlay an image behind your report to correctly place fields on the form. From that point, you can either leave the image in place and print the form and fields on blank paper or delete the image and print the report directly onto your forms.

□ Cross-Tab—Cross-tabs within Crystal Reports .NET look similar to a spreadsheet, with columns and rows of summarized data. Using the Cross-Tab Expert, you can create a report that will feature a cross-tab object in the report header.

□ Subreport — Subreports are reports that are inserted into a main report. Subreports can be unrelated to the main report or you can pass parameters between the main report and subreports to determine the content to display.

□ Mail Label — Crystal Reports .NET supports multi-column reports, and this functionality makes mailing labels possible. It includes a number of mailing labels predefined for common label stock from Avery and other suppliers (but only in Letter sizes), or you can create your own custom label size using this expert.

□ Drill Down—The concept behind drill-down is that you display a summary in your report and users can drill-down into the summary to see the details that make it up.

For this chapter we will look at the Standard Expert, so click OK with Standard selected in the listbox in the Crystal Report Gallery window.

Selecting Your Data Source

The first step in any of the experts is to select your data source. There are seven different types of data sources we can use as the basis of our report, as shown in Figure 2-4.

Figure 2-4

Which of these data sources you select as the basis of your report will depend on your own particular needs and the data sources available to you.

Data Source


Project Data

Crystal Reports .NET can leverage the ADO .NET Framework and report directly from datasets that appear in your application. For more information on how Crystal Reports .NET can be used with ADO .NET data, please see Chapter 7, "Working with .NET Data."

Data Source



This folder is for data sources that can be accessed through OLE DB, including SQL Server, Oracle, and Microsoft Jet 3.51/4.00-accessible data sources (Access, Excel, Paradox, Dbase, and so on).


This folder is for data sources that can be accessed through an ODBC-compliant driver (which is just about every other data source). In addition to reporting from tables, views, stored procedures, and so on, Crystal Reports .NET will also allow you to enter an SQL command to serve as the basis for your report.

Database Files

This folder includes a number of file-type database formats, including Access, Excel, XML, and Crystal Field Definition files (TTX), used with previous versions of Crystal Reports and bound reporting.

More Data Sources

These include reporting directly from XML files, Access/Excel through DAO, and Crystal Field Definition Files (TTX).

When reporting from an ADO .NET data source, the underlying XML file (with the .XSD extension) is used to determine the details of the dataset, such as fields or lengths. Because this XML contains only the definition of the data and not the data itself, you won't be able to browse data from within the Report Designer when using this data source.

To select the table we are going to use in our customer listing report, double-click the node for ODBC (RDO), which will open the dialog shown in Figure 2-5.

Select the Xtreme Sample Database 2003 and click Finish. This data source should now appear in the Data tab of the Standard Report Expert, shown in Figure 2-6.

Figure 2-6

Click the plus icon next to Tables, locate the Customer table, and double-click it to insert this table into your report.

Multiple Tables

If you select multiple tables to appear in your report, a new tab will appear for Links, allowing you to specify how these tables or views are joined together. By default, Crystal Reports .NET will attempt to make these links for you, based on the primary keys, field lengths, and names. You can clear the links that have been provided by clicking the Clear Links button on the right-hand side of the Links dialog (or by highlighting each link and clicking the delete button), and you can redraw them by dragging one field on top of another.

By default, Crystal Reports .NET will join these tables with an Equal join, but you can change the join type by right-clicking on top of the link and selecting Link Options. If you have added a second table, delete it now because we will use only a single table in this example; to do this click the Data tab, select the second table you added from the Tables in Report column, and finally click the Delete Table button.

Choosing the Fields For Your Report

Now that you have selected the data source for your report, the next step in the Standard Expert is to select the fields that will appear in your report. To move on to this step, you can either click the Fields tab at the top of the expert or use the Next button at the bottom of the dialog.

To select a field, highlight the field and then use the arrows to move it from the left-hand list to the right, as shown in Figure 2-7. The fields will be listed using the notation TableName.FieldName, and if you are unsure of a field's contents or type, you can use the Browse Data button to browse the contents of the field. There is also a Find Field button for finding a particular field in long field lists, or you can click anywhere within the table and just start typing the name of the field; Crystal Reports will jump directly to the field.

Figure 2-7

When you look at your report's design a little later, the fields you have selected here will be inserted into the report's detail section and a separate line will be printed for each record in the dataset. You can change the order these fields are inserted by using the up and down arrows at the top right corner of the dialog. They are inserted from left to right on your report, starting from the top of the list of fields that appear here.

For this report, we are inserting:

□ Customer.Customer Name

□ Customer.Contact Last Name

□ Customer.Contact Title

□ Customer.Phone

With each field, a corresponding field heading will be added to your report and placed in the page header. You can use the textbox marked Column Heading to change the default heading (usually the field name), or you can edit the headings later in the Report Designer.

Having selected the data source for your report and these five fields, you could click the Finish button to begin working with your report in the Report Designer, but we are going to push on and have a look at grouping and sorting the data.

Grouping and Sorting

After you have selected the fields that will appear on your report, you can choose which fields will be used for sorting and grouping. Click the Group tab and use the same concept as before—moving the field from the left-hand list to the right to select it for grouping.

This dialog can be confusing, as developers will select a group field and then preview their report, only to find that the data are sorted, but no group has been inserted. In order to create groups of records, you must specify a field in the dialog shown in Figure 2-8 and in the next dialog we discuss (the Total tab) and then select some summary to appear for each group.

Figure 2-8

The fields we are selecting for the grouping in our report are:

□ Customer.Country

□ Customer.Region

□ Customer.City

You can change the order of the fields you have selected by using the up and down arrows in the upper right corner of the dialog and then selecting a sort order from the drop-down list below.

Getting Started with Crystal Reports .NET

There are four options available for sort order including:

Sort Order



For ordering the data from A-Z, 1-9, and so on.


For ordering the data from Z-A, 9-1, and so on.


If your dataset is already sorted, this option will leave the data in its original sort order.


Used for creating your own custom groups and setting some criteria. Any records that meet the criteria would belong to the specified group.

If you select in a specified order, a second drop-down list and other items appear in the window, as shown in Figure 2-9.

Was this article helpful?

0 0

Post a comment