Introduction
This article presents a tool for generation of reports that was developed in the last five months. The tool has been created in C# and works in .NET Framework 2.0. For a long time, I used the ReportBuilder with Delphi. Then, I migrated to Visual Studio and C# as I felt a certain difficulty working with the tools for generation of reports. At that time, I decided to build my own tool. The result of my work is shown in this article. The creator supports several types of data - DataSet
, ArrayList
, and DataTable
. I could still add new types, but this seems to be enough to implement the IDataReport
interface.
Using the Code
Drawing of the layout of the Document Principal modules, which is also the module that absorbed the most development time, was the module for drawing the report layout. In the Designer's module, it is possible to create title pages, titles, to shape the layout and size of the page, as well as do groupings. All this can be observed in the following three figures.
Figure 1 - Title, Header, Summary
Figure 2 - Visualization of the Report. First page
Figure 3 - Visualization of the Report. Next page
Code to load the Module of Drawing of the report is as follows:
using KReport;
public static void Main () {
DataSet dsDados = new DataSet ();
ds.ReadXML (' Teste.xml ');
KReport.Engine.Report rpt = new KReport.Engine.Report();
rpt.FileName = 'C:\Report.xml ';
rpt.Load ();
rpt.AddSource (dsdados);
rpt.ShowDesigner ();
}
Code to load the form of visualization of the report is as follows:
using KReport;
public static void Main () {
DataSet dsDados = new DataSet ();
ds.ReadXML (" Teste.xml ");
KReport.Engine.Report rpt = new KReport.Engine.Report();
rpt.FileName = " Report.xml ";
rpt.Load ();
rpt.AddSource (dsdados);
rpt.Show ();
}
Code to load and print the report is as follows:
public static void Main () {
DataSet dsDados = new DataSet ();
ds.ReadXML (" Teste.xml ");
KReport.Engine.Report rpt = new KReport.Engine.Report();
rpt.FileName = " Report.xml ";
rpt.Load ();
rpt.AddSource (dsdados);
rpt.Print ();
}
Code using a list of objects is as follows:
public static void Main () {
ArrayList source;
Persistencia.StartSession ();
source = Persistencia.GetListObject (typeof (Credito), " status = 0 ");
Persistencia.EndSession ();
KReport.Engine.Report rpt = new KReport.Engine.Report();
rpt.FileName = " Report.xml ";
rpt.Load ();
rpt.AddSource (source);
rpt.Print ();
}
History
- 22nd February, 2008 -- Original version posted
- 26th February, 2008 -- Download added