0% found this document useful (0 votes)
59 views16 pages

Generation in C#: MIS 21 - Introduction To Applications Development

The document discusses how to manually generate reports in C# by using a ReportClass to set properties like the title, fonts, and data source, and then displaying the report in a PrintPreviewDialog. It covers creating an instance of ReportClass, assigning values to properties to customize the report design, and using methods to pass header and data values and generate the report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views16 pages

Generation in C#: MIS 21 - Introduction To Applications Development

The document discusses how to manually generate reports in C# by using a ReportClass to set properties like the title, fonts, and data source, and then displaying the report in a PrintPreviewDialog. It covers creating an instance of ReportClass, assigning values to properties to customize the report design, and using methods to pass header and data values and generate the report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Report

Generation in C#
MIS 21 – Introduction to Applications Development
Management Reporting
 The regular provision of information to decision-
makers within an organization to support them in
their work
 Can have graphs, text and tables
 Can be generated regularly (e.g. weekly, monthly)
or ad hoc
 Adding reporting features in a program saves the
user time and effort in preparing the report
Example of a Report
Creating Reports in C#
 Can be done by
 Using ReportViewer (for Visual Studio Standard
Edition)
 Using third-party software (e.g. CrystalReports)
 Manually draw the report using System.Drawing
and System.Drawing.Printing
 Forour version of C#, we will manually
create our reports
Manually Creating Reports
 Advantages
 Free
 Flexible and customizable
 Disadvantages
 Complicated
 Each text and graphic needs to be drawn
 Takes time to program
 Solution
 Use third-party libraries
Generating a Report
 using ReportLibrary;
 Create an instance of ReportClass
 Assign
values to the Properties of the
ReportClass (e.g. report.ReportTitle)
 Createa PrintPreviewDialog and
associate the report to it
Sample Report Code
ReportClass report = new ReportClass();
report.SetReportSource(headers, data);
report.ReportTitle = "Sample Report";
report.ReportLogo = Image.FromFile("company_logo.jpg");
report.TitleFont = new Font("Arial", 24, FontStyle.Bold);
report.TitleFontColor = Brushes.Green;
report.ShowTableGrid = false;
report.ShowTotals = false;
report.IsLandscape = false;

PrintPreviewDialog printPreview = new PrintPreviewDialog();


printPreview.Document = report.ReportDocument;
printPreview.ShowDialog();
Sample Report Code
ReportClass report = new ReportClass();
report.SetReportSource(headers, data);
report.ReportTitle = "Sample Report";
report.ReportLogo = Image.FromFile("company_logo.jpg");
report.TitleFont = new Font("Arial", 24, FontStyle.Bold);
report.TitleFontColor = Brushes.Green;
report.ShowTableGrid = false; Create a ReportClass
report.ShowTotals = false; and assign the
report.IsLandscape = false; Properties

PrintPreviewDialog printPreview = new PrintPreviewDialog();


printPreview.Document = report.ReportDocument;
printPreview.ShowDialog();
Important Properties
 ReportTitle – title of the report
 ReportLogo– image of the logo of the
company using the report
Passing Data to the Report
 Use the method SetDataSource()
 Takes 2 arguments
 string[] headers
 Column headers of the report
 List<object[]> data
 Data to be displayed in the report
Sample Report Code
ReportClass report = new ReportClass();
report.SetReportSource(headers, data);
report.ReportTitle = "Sample Report";
report.ReportLogo = Image.FromFile("company_logo.jpg");
report.TitleFont = new Font("Arial", 24, FontStyle.Bold);
report.TitleFontColor = Brushes.Green;
report.ShowTableGrid = false; Create a ReportClass
report.ShowTotals = false; and assign the
report.IsLandscape = false; Properties
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = report.ReportDocument;
printPreview.ShowDialog();
Sample Report Code
ReportClass report = new ReportClass();
report.SetReportSource(headers, data);
report.ReportTitle = "Sample Report";
report.ReportLogo = Image.FromFile("company_logo.jpg");
report.TitleFont = new Font("Arial", 24, FontStyle.Bold);
report.TitleFontColor = Brushes.Green;
report.ShowTableGrid = false; Puts the report in a
report.ShowTotals = false; PrintPreviewDialog and
report.IsLandscape = false; opens the dialog

PrintPreviewDialog printPreview = new PrintPreviewDialog();


printPreview.Document = report.ReportDocument;
printPreview.ShowDialog();
More Properties: Fonts and Colors
 The font family, size, style and color can be
changed
 Applies to the title, table header and body
of the report

report.TitleFont = new Font("Arial", 24, FontStyle.Bold);


report.TitleFontColor = Brushes.Green;
More Properties: Alignment
 Alignment can also be changed
 StringAlignment.Near (Left)
 StringAlignment.Center
 StringAlignment.Far (Right)

 Applies to the report title, table header


titles and numeric texts
More Properties: Boolean Flags
 IsLandscape – orientation of the report
 ShowTableGrid – shows borders of table
 ShowTotals – adds a total row at the end of
table and sums the numeric columns
 ShowTitleFirstPageOnly – displays title at
the first page only
More Properties: Height and Width
 Height and width auto-adjusts by
default
 Appliesto the logo, title, table header,
ad table rows
 Uses integers

You might also like