Skip to main content Skip to footer

.NET Reporting Solutions in ComponentOne Studio Enterprise

Applies To:

Studio Enterprise (.Net 1.x)

Author:

John Juback

Published On:

9/2/2005

ComponentOne Studio Enterprise is a comprehensive and integrated framework for developing cutting-edge, enterprise-style .NET, ASP.NET, and .NET Compact Framework applications. Although it is perhaps best known for its award-winning grid components (FlexGrid for .NET, True DBGrid for .NET, and WebGrid for ASP.NET), it also includes several components that greatly simplify the task of adding reporting capabilities to .NET applications:

C1Report Designer

A standalone application used to create XML report definition files.

C1Report

A non-visual component that hosts report definition files created with the C1Report Designer.

C1PrintPreview

A visual component that renders reports on the screen and provides commands for navigation, panning, zooming, and printing.

C1PrintDocument

A document creation engine that supports styles, tables, page setup, and rendering methods.

C1WebReport

An ASP.NET wrapper for the C1Report control, with support for server-side caching.

C1Pdf

A non-visual component for creating Adobe PDF documents, programmatically similar to the .NET Graphics class.

Typically, a developer uses the C1Report Designer application to create report definitions, which are saved as XML files. Report definition files contain one or more reports. They can be created from scratch or imported from Microsoft Access or Crystal Reports. The C1Report Designer provides a visual editing surface for report definitions, including a Wizard for creating new reports. If you are familiar with the report designer in Microsoft Access, you will find the C1Report Designer very easy to use.

C1Report Designer

Alternatively, you can create report definitions in code, either by using the object model to add groups and fields or by writing a custom XML file.

Every report contains at least five sections:

Detail

This section contains fields that are rendered once for each record in the source recordset.

Header

The report header section is rendered at the beginning of the report.

Footer

The report footer section is rendered at the end of the report.

Page Header

The page header section is rendered at the top of every page (except optionally for pages that contain the report header).

Page Footer

The page footer section is rendered at the bottom of every page (except optionally for pages that contain the report footer).

In addition to these five sections, there are two additional sections for each group: a group header and a group footer. For example, a report with three grouping levels will have eleven sections.

Groups make reports easier to read by visually separating like-valued records and displaying introductory and summary data. Group breaks are based on a grouping expression, which usually equates to one or more recordset fields but can be as complex as you like.

Group headers and footers can contain calculated fields for computing aggregate functions such as Sum, Min, Max, Avg, etc. The aggregates are evaluated within the context of each group, making it easy to implement subtotals and averages for nested groups or the entire report.

Groups are also used for sorting the data, even if you don't plan to display the group header and footer sections.

The C1Report component is used to host report definitions, which can be loaded at either design time or run time. Report definitions loaded at design time are embedded within the application, in which case you need not distribute the XML report definition file with your application.

By default, the C1Report component will use the data source specified in the C1Report Designer. However, you can write code to specify a different data source at run time, or to authenticate the user before rendering the report.

The C1Report component can render reports directly to a printer, into a C1PrintPreview control, or as HTML and PDF files that can be published on the Web.

To print a report directly to the printer, use the C1Report.Document property, which returns a standard PrintDocument object that exposes printer and page settings as well as a Print method. For example, the following code opens a print dialog and prints the report:

// load report definition  
c1Report1.Load(reportFile, reportName);  

// get PrintDocument object  
PrintDocument doc = c1Report1.Document;  

// show a PrintDialog so user can customize the printing  
PrintDialog pd = new PrintDialog();  

// use PrinterSettings in report document  
pd.PrinterSettings = doc.PrinterSettings;  

// show the dialog and print the report  
if (pd.ShowDialog() == DialogResult.OK)  
    doc.Print();  

// cleanup and release PrintDialog resources  
pd.Dispose();

You can also use the C1Report.Document property to preview the report by assigning it to the Document property of a C1PrintPreview control, which will display the report and allow the user to browse, zoom, or print it. For example:

// load report definition  
c1Report1.Load(reportFile, reportName);  

// preview the document  
c1PrintPreview1.Document = c1Report1.Document;

The C1PrintPreview control includes an optional navigation bar for displaying page thumbnails and group outlines; a toolbar for page layout, printing, navigation, and search commands; and a status bar with zoom factor and page counter controls.

C1PrintPreview Control

The C1Report component also provides a RenderToFile method for exporting reports to a variety of file formats, including HTML, RTF, PDF, TIFF, XLS, and plain text. The following example saves a report as an Adobe PDF file:

// load report definition  
c1Report1.Load(reportFile, reportName);  

// export to PDF  
c1Report1.RenderToFile(outFile   ".pdf", FileFormatEnum.PDF);

For ASP.NET applications, the C1WebReport control hosts the C1Report component and streams HTML or PDF reports to the client machine. It uses the same report definition files created by the C1Report Designer.

C1WebReport also supports server-side caching. Whenever the control needs to generate a report, it looks in its cache first. If the report is found there, it is retrieved, decompressed, and sent to the client. This is a very efficient process, much faster than regenerating the report. If the report is not found in the cache, it is generated, compressed, stored in the cache, and then sent to the client.

As an alternative to Microsoft Access-style banded reports, the C1PrintDocument component provides a rich object-oriented framework for advanced document formatting and processing. Its features include multi-column pages, rich text formatting options, tables (including nested tables), automatic column and page breaks, and PDF export. Instead of rendering a report definition created with the C1Report Designer, C1PrintDocument exposes an object model for rendering content in code, either by drawing objects directly at specific positions on a page, or in the block flow, where column and page breaks are handled automatically when there is not enough space to accommodate the drawing object.

C1PrintDocument integrates seamlessly with C1PrintPreview, and also recognizes C1-printable controls. For example, multi-page controls such as C1TrueDBGrid and C1FlexGrid use the C1PrintDocument component internally to print their contents.

As an alternative to exporting a C1Report-based document to a PDF file, you can use the C1Pdf component to create PDF files directly. C1Pdf supports most of the advanced features included in the PDF specification, including security, compression, outlining, hyperlinking, and attachments.

But the main feature of C1Pdf is ease of use. The commands provided for adding content to documents are similar to the ones available in the .NET Graphics class. If you know how to display text and graphics in .NET, you already know how to use the C1Pdf component.

For some projects, you may want to give your end-users the ability to customize existing reports or create new ones after your application has been deployed. However, you cannot redistribute the C1Report Designer application as per the licensing agreement for ComponentOne Studio Enterprise. Fortunately, there is a separate product, Reports for .NET Designer Edition, which includes the following:

  • C1ReportDesigner, a Windows Forms control that provides the ability to design and edit report definitions for use with the C1Report and C1WebReport controls.
  • Full source code for the C1Report Designer application, which uses the C1ReportDesigner control extensively.
  • Royalty-free distribution of the C1ReportDesigner control with your application.

You can use the source code for the C1Report Designer as a starting point for your own designer, or you can incorporate the C1ReportDesigner control into an existing application. Either way, your end-users gain control over the format and content of their reports without having to master a complex report writer.

The ComponentOne reporting layer offers a number of advantages for .NET developers:

  • It imports existing report definitions from both Crystal Reports and Microsoft Access.
  • It integrates natively with the ComponentOne data layer, but can also consume any ADO.NET data source.
  • It is platform-neutral. Report definitions can be consumed by both WinForms and WebForms applications.
  • It makes deployment easier by allowing report definitions to be embedded within applications.
  • It includes a powerful object model (C1PrintDocument) that can be used to programmatically render free-form reports.
  • Source code for the C1Report Designer is also available.

For more information, or to download a free 30-day trial version of ComponentOne Studio Enterprise, visit the link below:

Download evaluation

If you prefer, you can download one or more of the following individual products:

  • Studio for WinForms
  • Studio for ASP.NET
  • Reports for .NET Designer Edition

MESCIUS inc.

comments powered by Disqus