Search
Tutorial 6: Creating and Printing Reports

This tutorial demonstrates how to setup and preview an event report in MindFusion.Scheduling.

1. Create the report

To create a report, simply instantiate from the Report class.

C#  Copy Code

Report report = new Report();

Visual Basic  Copy Code

Dim report As new Report()

2. Setting-up the report columns

Report columns are created by calling the CreateColumn method on the report object. Once created the column's properties can be customized as needed, then the columns are added to the report by calling the Add method of the ReportColumnCollection returned by the Columns property. The following code illustrates how to create three columns containing the header text, the start date and the end date of items respectively and how to add them to the report created in step 1.

C#  Copy Code

ReportColumn column = null;

// Create the first column
column = report.CreateColumn();
column.Property = "HeaderText";
column.Width = 100;
report.Columns.Add(column);

// Create the second column
column = report.CreateColumn();
column.Property = "StartTime";
column.Width = 50;
report.Columns.Add(column);

// Create the third column
column = report.CreateColumn();
column.Property = "EndTime";
column.Width = 50;
report.Columns.Add(column);

Visual Basic  Copy Code

Dim column As ReportColumn = Nothing

' Create the first column
column = report.CreateColumn()
column.Property = "HeaderText"
column.Width = 100
report.Columns.Add(column)

' Create the second column
column = report.CreateColumn()
column.Property = "StartTime"
column.Width = 50
report.Columns.Add(column)

' Create the third column
column = report.CreateColumn()
column.Property = "EndTime"
column.Width = 50
report.Columns.Add(column)

We make the first column twice as wide as the other columns.

3. Associate the report with a schedule

It is very important to associate the report with the schedule, which would provide the items for the report. If the report does not have an assigned schedule by the time its Preview or Print methods are invoked, the invocation would raise an exception. You associate a schedule with the report by assigning the schedule instance to the Schedule property of the report. The code below assumes that the variable schedule identifies a valid Schedule instance.

C#  Copy Code

report.Schedule = schedule;

Visual Basic  Copy Code

report.Schedule = schedule

4. Setup report options

You can customize various aspects of the report by modifying the properties of the ReportOptions object, accessed through the Report.Options property. In this particular case we will make the width of the columns in the report to resize to automatically fill the width of one page.

C#  Copy Code

report.Options.AbsoluteColumnWidth = false;

Visual Basic  Copy Code

report.Options.AbsoluteColumnWidth = False

5. Print / Preview the report

The report is printed or previewed by calling the Print or Preview methods respectively. Both methods accept two .NET DateTime instances, which specify the time range of the items included in the report. If you do NOT have infinite recurrences in the report it is safe to specify DateTime.MinValue and DateTime.MaxValue for those parameters to ensure that all items will get included in the report.

C#  Copy Code

report.Preview(DateTime.MinValue, DateTime.MaxValue);

Visual Basic  Copy Code

report.Preview(DateTime.MinValue, DateTime.MaxValue)

Here is how our report would look like.