Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

248 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

Table 11-2 Buttons in the Toolbar of the Windows Forms Viewer Control

(continued)

Buttons

Description

Go to Page

A user can click on the Go to Page button to view a specified page.

Close Current View

A user can click on the Close Current View button to close the

 

current view. This button is active only for Subreport or groups.

Print Report

Refresh Report

Export Report

Toggle Group Tree

Zoom

Search Text

A user can click on the Print Report button to print the data in a

report.

 

L

 

 

 

A user can click on the Refresh Report button to refresh the data in

a report.

 

Y

 

M

 

A user can click on the Export Report button to save the report as

A

 

 

a Word documentF(.doc), an Acrobat file (.pdf), an Excel spread-

sheet (.xls), or a rich text format (.rtf) file.

T

 

 

 

user can click on the Toggle Group Tree button to display or

hide the Field Explorer window.

EA user can click on the Zoom button to increase or decrease the

zoom percentage of a report.The user can select the zoom percentage from the drop-down list.

A user can click on the Search Text button to find the specified data in a report.

The following section discusses creating a Windows Forms Viewer control to display a crystal report.

Creating the Windows Forms Viewer Control

As discussed earlier, a Windows Forms Viewer control is used to host and display a crystal report. Perform the following steps to create a Windows Forms Viewer control.

1.In the Solution Explorer window, right-click on the project name, Customer Maintenance Project.

Team-Fly®

CRYSTAL REPORTS

Chapter 11

249

 

 

 

 

2.In the displayed list , point to Add and click on the Add New Item option.

The Add New Item dialog box is displayed.

3.In the Templates: pane, select the Windows Form option.

4.In the Name: text box, type the name of the form as ConsumableForm and click on the Open button.

Visual Studio .NET creates a new form for you.

From the Windows Forms toolbox, drag the CrystalReportViewer and Button controls to the form.

TIP

In the Windows Forms toolbox, a Windows Forms Viewer control is called CrystalReportViewer.

Resize the CrystalReportViewer control to occupy maximum area on the form. Figure 11-4 shows ConsumableForm with the Cr ystalReportViewer control.

FIGURE 11-4 ConsumableForm with the CrystalReportViewer control

250 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

As you can see, the CrystalReportViewer control is empty. To host and display the report in the CrystalReportViewer control, you need to associate the control with ConsumablesReport.rpt. To do so, perform the following steps:

1.Select the CrystalReportViewer control to make it active.

2.In the Properties window, change the value of the ReportSource property of the CrystalReportViewer control.

The ReportSource property enables you to associate the CrystalReportViewer control with the required crystal report.

3.Click on the down arrow button of the ReportSource property.

4.From the drop-down list, select the Browse option.

The Browse option enables you to browse for the location of the ConsumablesReport.rpt report.

After associating the report with the CrystalReportViewer control, you can test the report by clicking on the F5 key or by selecting the Start command on the Debug menu.

When you run the project and click on the Monthly Consumable Report radio button in the Reports form, the ConsumableForm form is displayed. Figure 11-5 shows the Reports form with the Monthly Consumable Report radio button.

FIGURE 11-5 Reports form

The ConsumableForm form now contains the Consumable Report that you have created. Figure 11-6 shows the Consumable Report as seen at run time.

CRYSTAL REPORTS

Chapter 11

251

 

 

 

 

FIGURE 11-6 Consumable Report at run time

To enable a user to return to the Reports form after viewing the report, you can make the Exit button functional. To do so, add the following code to the Click event of the Exit button.

private void btnExit_Click(object sender, System.EventArgs e)

{

Reports newForm = new Reports(); newForm.Show();

this.Hide();

}

After creating the Monthly Consumable report, you can similarly create the Monthly Customer Visit, Monthly Balancing and Alignment, and Monthly Worker reports.

Creating the Monthly

Customer Visit Report

The Monthly Customer Visit report is created to track the number of visits of a customer in a particular month. The procedure for creating the Monthly Customer

252 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

Visit report is similar to the one you used to create the Monthly Consumable report. However, while creating the Monthly Customer Visit report, you need to make a few changes, such as changes in the table name, field names, Group By: field, and so on.

Similar to the Monthly Consumable report, you can use Standard Report Expert to create the Monthly Customer Visit report.However, if you want, you can select any other expert.The following list will discuss the changes that you need to make while creating the Monthly Customer Visit report.

1.In the Data tab of Standard Report Expert, select the tblCustomer and tblJobDetails tables to display data from both these tables. After clicking on the Next button, the Links tab is displayed.

The Links tab displays the link between the tblCustomer and tblJobDe-

tails tables. By default, the common field name, CarNo, is selected as the link. However, if required, you can clear the link by clicking on the Clear Links button and then create a new link by dragging the field name from one table to another. Figure 11-7 displays the Links tab of Standard Report Expert.

FIGURE 11-7 The Links tab of Standard Report Expert

CRYSTAL REPORTS

Chapter 11

253

 

 

 

 

2. In the Fields tab, select the CarNo, Name, Address, and Make fields from the tblCustomer table. From the tblJobDetails table, select the JobDate option.

3.In the Group By: list, select the CarNo and then the JobDate fields.

4.In the Title: text box of the Style tab, type the title of the report as Customer Visit Report and select any style from the Style: list.

Figure 11-8 displays the Monthly Customer Visit report as created by the Crystal Report Gallery.

FIGURE 11-8 Monthly Customer Visit report in the design view

After creating the crystal report, you can create a new form, CustomerVisitForm, and include a CrystalReportViewer control to display the report. Figure 11-9 shows the Monthly Customer Visit report as seen at run time.

254 Project 1 CREATING A CUSTOMER MAINTENANCE PROJECT

FIGURE 11-9 Monthly Customer Visit report at run time

Creating the Monthly Balancing

and Alignment Report

The Monthly Balancing and Alignment report is created to track the number of balancing and alignment jobs performed by a worker in a month. You can create the Monthly Balancing and Alignment report by using the Crystal Report Gallery as discussed in the previous sections. Figure 11-10 displays the report as created by the Cr ystal Report Gallery.

CRYSTAL REPORTS

Chapter 11

255

 

 

 

 

FIGURE 11-10 Monthly Balancing and Alignment report in the design view

You can make changes to the layout of the Monthly Balancing and Alignment report in the design view. However, to display the report at run time, you need to create a new form, AlignmentForm, and then include a CrystalReportViewer control. Figure 11-11 shows the Monthly Balancing and Alignment report at run time.

FIGURE 11-11 Monthly Balancing and Alignment report at run time