Stimulsoft reporting provides a set of powerful reporting tools for Microsoft Visual Studio .net 2008 and 2010;
these tools are available for windows forms as well as web forms. They provide many useful features such as an easy
to use report designer and native support for exporting to PDF, Word, Excel and various other formats. Stimulsoft
reporting now supports binding to any .net class; this feature is called business objects in the report designer.
Crystal Report and Microsoft reports are great for day to day reporting, but if you need to create reports with
cross-tabs and drill down, Ajax, support for barcodes and connecting to more than one report source at the same time,
then Stimulsoft reporting is a very good solution. They also have a feature where end users can create their own reports
for Adhoc reporting. All these features make Stimulsoft reports a good choice for business intelligence reporting.
In this tutorial I will show to create a simple tabular report using the Business Objects (.net classes). Show how
to create an ADO.NET data model, register entities as business objects with stimulsoft report designer and design a
tabular report and save the report definition file to run the newly created report.
The data for this sample report will come from the
Northwind sample database provided by Microsoft.
The demo version of Stimulsoft reporting tools can be downloaded from the website
http://stimulsoft.com/ReportsNetDownloads.aspx.
Steps are required in order to create a simple tabular report using Business Objects
1. Add an ADO.NET data model to your project
2. Generate Entity Model for Northwind database
3. Register Business Objects with Report Desinger
4. Design new report using Business Objects
5. Run new report using Business Objects
1. Add an ADO.NET data model to your project
• Make sure you targeting .NET Framework version 3.5 SP1 or higher
• Right-click on the project name in Solution Explorer
• Select Add and then select New Item
• Select the ADO.NET Entity Date Model
• Type the name of the model file, for this tutorial it is going to be Northwind.edmx
• Click on the Add button
2. Generate Entity Model for Northwind database
• Select Generate from database and click Next
• Choose the connection string for northwind or build our own connection string using instructions given on http://www.connectionstrings.com
• Select all database objects that you want to report on. For the sake of this tutorial we are going to select only the tables.
• Type the namespace of the ADO.net entity model as NorthwindModel or any other namespace or our choice and click on Finish.
• Visual studio will now scan the database schema and generate all required Entity model classes and definitions.
• Browse the Entity model to see various entities that are created.
• We will be using Customers entity to list all customers in our report.
3. Register Business Objects with Report Desinger
• Create a new form in your project
• Make sure you have added the reference to required stimulsoft.net dlls by right-clicking on the project and selecting add reference.
• Add a button called Design Report and another button called Run Report.
• Create an event handler for design report button.
• Add a code to get a list of customers using Northwind entity model (For simplicity we are getting list of all customers, in practice you would be
using LINQ to form a query by following tutorials provided Microsoft at http://msdn.microsoft.com/en-us/library/bb738636.aspx )
• Create new a StiReport object and load the report definition from “C:\MyReport.mrt” if the file exists (For this tutorial we have fixed the location of report file for simplicity)
• Register the list of customers with the report object.
• Call the Design function of the report object to launch the designer.
using Stimulsoft.Report;
/// <summary>
/// Event Handler for Design Report button
/// </summary>
private void Design_Click(object sender, EventArgs e)
{
// Get Report Object
StiReport report = GetReport();
// Launch Report Deginer for the report
report.Design();
}
/// <summary>
/// This function Loads report definition from a fixed location
/// and registers all Business Objects in the report definition
/// </summary>
///
/// StiReport object for the report
///
private StiReport GetReport()
{
// Create a new object of StiReport Class
StiReport report = new StiReport();
// Load the report definition file from C:\MyReport.mrt if the file exists
// This tutorial assumes you have are storing the report definition in a fixed location
// If the file does not exists then Designer will allow you to save the your newly created report in the location
if (File.Exists("C:\\MyReport.mrt"))
{
report.Load("C:\\MyReport.mrt");
// Get of List of all customers from database using ADO.net Enity data model
NorthWindEntities nw = new NorthWindEntities();
List
nw.Dispose();
// Register Business Objects for Customers in the report
report.RegBusinessObject("Northwind", "Customers", customers);
// Return report to calling function
return report;
}
4. Design new report using Business Objects
• On run the project by pressing F5 on your keyboard or click on Start Debugging button in Visual Studio
• Click on Design Report button to show the Stimulsoft report designer
• Brower to Dictionary and Expand Business Objects
• Northwind is shown here because we specified category of Customers while registering business objects using RegBusinessObject function
• Expand Northwind to see customers and expand customers to see all the fields that belong to customers
• Drag Customers and drop into the report layout to add customers table to the design
• Select all the fields that you want to show in the report
• Click on Preview tab to see the report preview
• Click on Save Report icon save to C:\MyReport.mrt
• Close the report designer
5. Run new report using Business Objects
• Add a event handler for Run Report button
• Add code to get a list of customers using Northwind entity model (For simplicity we are getting list of all customer, in practice you would be using LINQ to form a query by following tutorials provided Microsoft at http://msdn.microsoft.com/en-us/library/bb738636.aspx )
• Create new StiReport object and load the report definition from “C:\MyReport.mrt” if the file exists (For this tutorial we have fixed the location of report file for simplicity)
• Register the list of customers with the report object.
• Call the Show function of the report object to launch the report viewer.
using Stimulsoft.Report;
/// <summary>
/// Event Handler for Run Report button
/// </summary>
private void btnRun_Click(object sender, EventArgs e)
{
// Get Report Object
StiReport report = GetReport();
// Show report to user
report.Show();
}
/// <summary>
/// This function Loads report definition from a fixed location
/// and registers all Business Objects in the report definition
/// </summary>
///
/// StiReport object for the report
///
private StiReport GetReport()
{
// Create a new object of StiReport Class
StiReport report = new StiReport();
// Load the report definition file from C:\MyReport.mrt if the file exists
// This tutorial assumes you have are storing the report definition in a fixed location
// If the file does not exists then Designer will allow you to save the your newly created report in the location
if (File.Exists("C:\\MyReport.mrt"))
{
report.Load("C:\\MyReport.mrt");
}
// Get of List of all customers from database using ADO.net Enity data model
NorthWindEntities nw = new NorthWindEntities();
List
nw.Dispose();
// Register Business Objects for Customers in the report
report.RegBusinessObject("Northwind", "Customers", customers);
// Return report to calling function
return report;
}
The author of the article is Chirag Nirmal and his linkedin profile is
http://www.linkedin.com/in/chiragn
1 comment:
It would be fantastic if you could fix the images so we could actually see what is going on. They all give me a 404.
Post a Comment