You are on page 1of 27

Chapter 6.

ActiveReports
A reference of ActiveReports for .NET 2.0 Documentation

Lương Xuân Phú IT Faculty, Vinh University

Contents
    

Introduction ActiveReports Designer ActiveReports Viewer Group Data in a Report ActiveReports Events

Slide 2

Introduction

ActiveReports for .NET is a fully-integrated product which combines the features of the Visual Studio programming languages with user-friendly controls to provide a powerful report designer. ActiveReports for .NET Standard Edition supports the following features:
  

Full integration with the .NET environment Familiar user interface Use with C# and VB.NET
Slide 3

ActiveReports Designer
 

Open a Visual Studio project Add an ActiveReport to your project
 

Click on Project -> Add Windows Form Item. Select ActiveReports File and rename the file. Click Add to add the report to your project.

Once the report is added, you will see the report design surface.

Slide 4

ActiveReports Designer

Report structure

A report section contains a group of controls that are processed and printed at the same time as a single unit. ActiveReports defines the following section types:
   


Report Header Report Footer Page Header Page Footer Detail Group Header/Footer
Slide 5

ActiveReports Designer

Report structure

Report Header: A report can have one report header section that prints at the beginning of the report. Report Footer: A report can have one report footer section that prints at the end of the report. Note: Right-click in the report design surface, select Insert, and click on Report Header/Footer.

Slide 6

ActiveReports Designer

Report structure

Page Header: Used to print column headers, page numbers, page titles, or any information that needs to be printed once at the top of each page. Page Footer: Used to print page totals, page numbers or any other information that needs to be printed once at the bottom of each page. Detail: This section is the body of the report that prints once for each record in the data source.
Slide 7

ActiveReports Designer

Report structure

Group Header/Footer: A report can consist of single or multiple nested groups, with each group having its own header and footer sections. The header section is inserted and printed immediately before the detail section. The footer section is inserted and printed immediately after the detail section. Note: Right-click in the the report design surface, select Insert, and click on Group Header/Footer.
Slide 8

ActiveReports Designer

Toolbox

The ActiveReports toolbox displays a variety of controls available for use in ActiveReports. The items available from the toolbox change depending on the designer currently in use. Pointer: Allows you to select controls or sections of the report Label: Allows you to insert a new static label control

Slide 9

ActiveReports Designer

Toolbox

 

Textbox: Allows you to insert a text box, bound to a database field or unbound. Picture: Allows you to insert an image, loaded from a file. Line: Allows you to insert a line control. Barcode:Allows you to insert an ActiveReports Barcode control.

Slide 10

ActiveReports Designer

Add controls to contain data
 

Add Textboxes Set the DataField property to the Field being used.

Binding report to a DataSource

ActiveReports allows much flexibility in binding reports to various kinds of data sources:
  

Using a DataTable Using a DataSet Using a DataView

Slide 11

ActiveReports Designer

Binding report to a DataSource

To use a DataTable, set the reports DataSource property to the DataTable being used.

myReport.DataSource = myTable;

To use a data set, set the reports DataSource property to the DataSet being used and the reports DataMember property to the table from which the reports data is derived.
 

myReport.DataSource = myDataSet; myReport.DataMember = “….”;
Slide 12

ActiveReports Viewer

Used to preview a report output

 

Add a new “Windows Form” to your project and rename it rptPreview form. Click on the ActiveReports viewer control in the appropriate toolbox and drag it onto rptPreview. Set the viewer control's Dock property to Fill. To write the code to call ActiveReport File
  

myReport rpt = new myReport(); this.viewer1.Document = rpt.Document; rpt.Run();
Slide 13

ActiveReports Viewer

Adds a constructor to call a ActiveReport file
DataTable myTable)

public myPreview(DataDynamics.ActiveReports.ActiveReport rpt, { InitializeComponent(); rpt.DataSource = myTable; viewer1.Document = rpt.Document; rpt.Run(true); }

Call ActiveReport Viewer from a form
  

myReport rpt = new myReport(); Preview myPreview = new Preview(rpt,myTable) myPreview.Show();
Slide 14

Group data in a Report

In ActiveReports, a report can consist of single or multiple nested groups, with each group having its own header and footer sections. The header section is inserted and printed immediately before the Detail section. The footer section is inserted and printed immediately after the Detail section.
Slide 15

Group data in a Report

To group data in a report

Right-click in the Detail section of the report design surface, select Insert, and click on Group Header/Footer. This will insert a new group header/footer section into your report. In the Properties window for the group header, change the DataField property to the field on which you want your data grouped. Change the name of the group header to reflect the field on which data is being grouped.
Slide 16

ActiveReports Events

Single Firing Events: The following events are all of the events that fire only once during a report's processing. These events fire at the beginning and at the end of the report processing cycle:
  

ReportStart DataInitialize ReportEnd

Slide 17

ActiveReports Events

ReportStart

This event fires before the DataInitialize event. Use this event to initialize any objects or variables needed while running a report. Also use this event to set any Subreport control objects to a new instance of the report assigned to the Subreport control. Do not add items dynamically to a report once this event has finished.

Slide 18

ActiveReports Events

DataInitialize

This event fires after ReportStart. Use it to add custom fields to the report's Fields collection. Custom fields can be added to a bound report (one that uses a Data Control to connect and retrieve records) or an unbound report (one that does not depend on a data control to get its records). In a bound report the dataset is opened and the dataset fields are added to the custom fields collection, then the DataInitialize event is fired so new custom fields can be added.
Slide 19

ActiveReports Events

ReportEnd

This event fires after the report finishes processing. Use this event to close or free any objects that you were using while running a report in unbound mode, or to display information or messages to the end user. This event can also be used to export reports.

Slide 20

ActiveReports Events

Multiple Firing Events: The following ActiveReports events fire multiple times during a report's processing:
  

FetchData PageStart PageEnd

Slide 21

ActiveReports Events
 

FetchData: This event fires every time a new record is processed. PageStart: This event fires before a page is rendered. Use this event to initialize any variables needed for each page when running an unbound report. PageEnd: This event fires after each page in the report is rendered. Use this event to update any variables needed for each page when running an unbound report.
Slide 22

ActiveReports Events

Section Events: In a report, regardless of the type or content of the various sections, there are three events for each section: Format, BeforePrint and AfterPrint. Out of the three events, the Format event generally is used the most often, followed by the BeforePrint event and, in rare circumstances, the AfterPrint event.

Slide 23

ActiveReports Events

Format Events

This event fires after the data is loaded and bound to the controls contained in a section, but before the section is rendered to a page. The format event is the only event where the section's height may be changed. This section may be used to set or change the properties of any controls or load subreport controls with subreports.

Slide 24

ActiveReports Events

Format Event

If the CanGrow or CanShrink property of any control contained with a section, or the section itself, is set to true, all of the growing and shrinking of controls contained in this section, and the section itself, takes place in the Format event. Because of this, information about a control or a section's height cannot be obtained in this event.

Slide 25

ActiveReports Events

BeforePrint Event

This event fires before the section is rendered to the page. The growing and shrinking of the section and all controls contained in a section have already taken place by the time this event fires. Use this section to resize any controls if needed.

Slide 26

ActiveReports Events

BeforePrint Event

Since all controls and section growth have already taken place by the time this event fires, this event may be used to get an accurate height of the section, or, if needed, any controls contained in it. Any controls in the BeforePrint event may be resized but not the height of the section itself.

AfterPrint Event

This event fires after the section is rendered to the page.
Slide 27