Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
81
Добавлен:
11.05.2015
Размер:
2.11 Mб
Скачать

The first line of code creates an instance of the MyDataSource object in your application, much like you might create an instance of an ADO Recordset object. The second line of code added uses the SetDataSource method inside the Crystal Designer Component library to dynamically change the source of data used by your report.

If you designed your report using an ADO, DAO, or RDO data source, or by using a Data Definition file, then your report uses the Active Data Driver to access the report data at runtime. Since the Active Data Driver also supports data sources that expose the Crystal Data Source interface, you can easily assign the MyDataSource object to your report.

Crystal Data Source Projects

Now that you have seen the extensive power of the Crystal Data Source interface implemented inside a Visual Basic class, you can begin to consider the extensive possibilities for its use. Many computer based operations produce continuous streams of data in real-time. In your own work, you may encounter needs for gathering data from process control systems, data acquisition applications, or computer-based instrumentation.

In these kinds of applications, data is usually gathered and stored for later analysis. Systems running in realtime, however, may need real-time monitoring and reporting. With objects that implement the Crystal Data Source interface, you can gather and move through data as it is generated, then produce up to the instant analysis through reports.

Programmer’s building n-tier applications that operate across a network may often find themselves designing business objects and other business rules components. By implementing the Crystal Data Source interface in business object components, you can design reports that produce real-time information about data traveling across the network. Even Microsoft Transaction Server components can implement a fully functional ActiveX data source for reporting. Crystal Data Source takes your applications from runtime to real time.

Grid Controls and the Crystal Report Engine

This topic is only supported by the Professional Edition of Seagate Crystal Reports.

In Seagate Crystal Reports, a Crystal ActiveX Control can be bound directly to a Visual Basic Data Control. Using the Visual Basic Data Control with the Crystal ActiveX Control offers the following benefits:

Generating reports in Visual Basic programs is made even easier and does not require an existing .RPT file.

A powerful feature of Visual Basic is ad-hoc queries that are run by executing SQL statements in the RecordSource property of the Data Control. By directly binding a Crystal Custom Control to a Data Control, users can now create reports of dynaset data which are the results of such ad-hoc queries.

Visual Basic Solutions

139

The following topics are discussed in this section:

Bound Report Driver and Bound Report Files, Page 140

Crystal ActiveX Control Properties, Page 140

Creating a Bound Report using the Crystal ActiveX Control, Page 141

Creating a Formatted Bound Report, Page 142

Creating a Formatted Bound Report at Runtime, Page 142

Sample Application, Page 143

Bound Report Driver and Bound Report Files

When using Seagate Crystal Reports to generate reports from database files of a particular file format (for example, Paradox file format), you need to have the appropriate report driver (i.e., PDBPDX.DLL) to retrieve data from the databases. Similarly, when you generate reports by binding to a Visual Basic Data Control, a Bound Report Driver (PDBBND.DLL) is used to retrieve data from the Data Control. Make sure PDBBND.DLL is in your \WINDOWS\SYSTEM directory or search paths, along with other database drivers.

Crystal ActiveX Control Properties

Several properties are added to the Crystal Custom Control in order to support bound reports. These new properties are described below.

Custom

This property allows you to create bound .RPT files at Visual Basic design time and is not available at runtime. After a bound .RPT file is created, programmers can then use Seagate Crystal Reports to customize the report layout or even link the bound data to other database tables.

DataSource (Data Control)

This property can be read/write at design time and runtime. This property is ignored if the ReportSource property is 0 (Report files). To generate bound reports, set this property to the Data Control you want to retrieve data from. The Data Control must already be on the form before this property can be set.

BoundReportFooter (Boolean)

This property can be read/write both at design-time and runtime. This property is ignored if the ReportSource property is 0 (Report files). Default is False and the bound reports generated will not have page numbers printed. If set to True, page numbers will be printed at the bottom of a page.

Visual Basic Solutions

140

BoundReportHeading (string expression)

This property can be read/write both at design time and runtime. This property is ignored if the ReportSource property is 0 (Report files). It specifies the report title at the beginning of a bound report. If it is blank, no report title will be printed.

ReportSource (numeric expression)

This property can be read/write both at design time and runtime. The allowed values are:

0 - Report files

1 - Bound TrueDBGrid Control

3 - All Data Control Fields

The default value is 0 - Report files, and the ReportFileName property must be assigned to an existing report path name (.RPT). This is equivalent to when the new bound report features were not available and all reports were generated from existing .RPT files.

When set to 1 or 3, the ReportFileName property will be ignored and no .RPT file is needed. Reports will be created using data retrieved from Data Control. The reports generated directly from the Data Control are identical to the reports generated from the respective bound .RPT files created using the (Custom) property described above.

Creating a Bound Report using the Crystal ActiveX Control

1Add the following controls to your Visual Basic form:

2On the Data Control:

3Set the DatabaseName property to the name of the database being reported on.

4Set the RecordSource property (this can be a database table or a SQL query statement).

5On the Crystal ActiveX Control:

6Set the DataSource property to the Data Control (for example, Data1).

7Set the ReportSource to 3 - All Data Control Fields.

8On the Command Button, add the following code for the Click event:

Private Sub Command1_Click() CrystalReport1.Action = 1

End Sub

Run the application, click the command button, and the Crystal ActiveX Control will retrieve data from the Data Control and create the report. The report will appear as a simple columnar report. There are no runtime properties to control any report formatting. However, this can be accomplished at design-time by editing the report designed by the ActiveX control (a report template) in Seagate Crystal Reports.

Visual Basic Solutions

141

Creating a Formatted Bound Report

1Add the Data control, ActiveX control, and a command button to your form.

2On the Data control, set the DatabaseName property and the RecordSource property as you did in the previous example.

3On the ActiveX control:

Set the DataSource property to the Data Control (i.e., Data1).

Set the ReportSource property to 3 - All Data Control Fields.

Open the Custom property and select the Data-Bound Report Tab.

Click the Save Report As button and enter a name for the report.

4Open the report template in Seagate Crystal Reports and apply any formatting that you want including spacing between columns, font size, colors, grouping, and totaling. Save the report template again when finished.

5In your Visual Basic application, set the following properties for the ActiveX control:

Set the ReportSource to 0 - Report File.

Set the ReportFileName to the .RPT file that you saved (include the complete path of the file).

6On the command button, add the following code to the Click event:

Private Sub Command1_Click()

CrystalReport1.Action = 1

End Sub

Now, the application will create the report at runtime with the formatting you have applied.

Creating a Formatted Bound Report at Runtime

The following steps describe an alternative method of creating formatted bound reports:

1Create your Visual Basic application as in the first example above.

2Set the ActiveX Control to print to a preview window, and run the application.

3Click the Export button in the preview window, and export the report to a disk file in .RPT format.

4Once the report has been exported, you can open it up in Seagate Crystal Reports.

5Perform all formatting changes that you want and save the report.

6Return to the Visual Basic application and stop it if it is still running.

7On the ActiveX Control:

8Set the ReportSource to 0 - Report File.

9Set the ReportFileName to the .RPT file that you created.

10Run the Visual Basic application and you will be able to see your bound report with the formatting changes you've made.

Visual Basic Solutions

142

Соседние файлы в папке crystal