Stimulsoft Simple Tabular Report using Business Objects

Andrew-Savin

Member
Joined
Feb 1, 2008
Messages
15
Programming Experience
5-10
<p>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.</p>

<p>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.</p>

<p>The data for this sample report will come from the <A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en">
Northwind sample database</a> provided by Microsoft.</p>

<p>The demo version of Stimulsoft reporting tools can be downloaded from the website
<A href="http://stimulsoft.com/ReportsNetDownloads.aspx">http://stimulsoft.com/ReportsNetDownloads.aspx.</a></p>

<p><img width=993 height=429 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/1.png"></p>

<p align="center"> <h1 align="center"><b>Steps are required in order to create a simple tabular report using Business Objects</b></h1></p>

<a href="#1. Add an ADO.NET data model to your project"><b>1. Add an ADO.NET data model to your project</b></a>
<br>
<a href="#2. Generate Entity Model for Northwind database"><b>2. Generate Entity Model for Northwind database</b></a>
<br>
<a href="#3. Register Business Objects with Report Desinger"><b>3. Register Business Objects with Report Desinger</b></a>
<br>
<a href="#4. Design new report using Business Objects"><b>4. Design new report using Business Objects</b></a>
<br>
<a href="#5. Run new report using Business Objects"><b>5. Run new report using Business Objects</b></a>
<br>
<br>
<br>
<a name="1. Add an ADO.NET data model to your project"><b><span style='color:blue'>1. Add an ADO.NET data model to your project</span></b></p>
• Make sure you targeting .NET Framework version 3.5 SP1 or higher
<br>
• Right-click on the project name in Solution Explorer
<br>
• Select Add and then select New Item
<br>
• Select the ADO.NET Entity Date Model
<br>
• Type the name of the model file, for this tutorial it is going to be Northwind.edmx
<br>
• Click on the Add button
<p><img width=392 height=473 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/2.png"></p>
<p><img width=688 height=424 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/3.png"></p>
<a name="2. Generate Entity Model for Northwind database"><b><span style='color:blue'>2. Generate Entity Model for Northwind database</span></b></p>
• Select Generate from database and click Next
<br>
• Choose the connection string for northwind or build our own connection string using instructions given on <A href="http://www.connectionstrings.com">http://www.connectionstrings.com</a>
<br>
• Select all database objects that you want to report on. For the sake of this tutorial we are going to select only the tables.
<br>
• Type the namespace of the ADO.net entity model as NorthwindModel or any other namespace or our choice and click on Finish.
<br>
• Visual studio will now scan the database schema and generate all required Entity model classes and definitions.
<br>
• Browse the Entity model to see various entities that are created.
<br>
• We will be using Customers entity to list all customers in our report.
<p><img width=540 height=489 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/4.png"></p>
<p><img width=539 height=489 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/5.png"></p>
<p><img width=924 height=883 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/6.png"></p>
<a name="3. Register Business Objects with Report Desinger"><b><span style='color:blue'>3. Register Business Objects with Report Desinger</span></b></p>
• Create a new form in your project
<br>
• Make sure you have added the reference to required stimulsoft.net dlls by right-clicking on the project and selecting add reference.
<br>
• Add a button called Design Report and another button called Run Report.
<br>
• Create an event handler for design report button.
<br>
• 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 <A href="http://msdn.microsoft.com/en-us/library/bb738636.aspx">http://msdn.microsoft.com/en-us/library/bb738636.aspx</a> )
<br>
• 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)
<br>
• Register the list of customers with the report object.
<br>
• Call the Design function of the report object to launch the designer.
<p><img width=469 height=438 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/7.png"></p>
<p><img width=277 height=143 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/8.png"></p>
   using Stimulsoft.Report;<br>
  /// <summary> <br>
   /// Event Handler for Design Report button <br>
   /// </summary> <br>
   private void Design_Click(object sender, EventArgs e) <br>
   { <br>
    // Get Report Object <br>
    StiReport report = GetReport(); <br>
    // Launch Report Deginer for the report <br>
    report.Design(); <br>
   } <br>
<br>
   /// <summary> <br>
   /// This function Loads report definition from a fixed location <br>
   /// and registers all Business Objects in the report definition <br>
   /// </summary> <br>
   /// <returns> <br>
   /// StiReport object for the report <br>
   /// </returns> <br>
   private StiReport GetReport() <br>
   { <br>
    // Create a new object of StiReport Class<br>
    StiReport report = new StiReport();<br>
<br>
   // Load the report definition file from C:\MyReport.mrt if the file exists <br>
   // This tutorial assumes you have are storing the report definition in a fixed location <br>
   // If the file does not exists then Designer will allow you to save the your newly created report in the location <br>
   if (File.Exists("C:\\MyReport.mrt")) <br>
   { <br>
    report.Load("C:\\MyReport.mrt"); <br>
<br>
   // Get of List of all customers from database using ADO.net Enity data model <br>
   NorthWindEntities nw = new NorthWindEntities(); <br>
   List<Customers> customers = nw.Customers.ToList(); <br>
   nw.Dispose(); <br>
<br>
   // Register Business Objects for Customers in the report <br>
   report.RegBusinessObject("Northwind", "Customers", customers); <br>
<br>
   // Return report to calling function <br>
   return report; <br>
   } <br>

<a name="4. Design new report using Business Objects"><b><span style='color:blue'>4. Design new report using Business Objects</span></b></p>
• On run the project by pressing F5 on your keyboard or click on Start Debugging button in Visual Studio
<br>
• Click on Design Report button to show the Stimulsoft report designer
<br>
• Brower to Dictionary and Expand Business Objects
<br>
• Northwind is shown here because we specified category of Customers while registering business objects using RegBusinessObject function
<br>
• Expand Northwind to see customers and expand customers to see all the fields that belong to customers
<br>
• Drag Customers and drop into the report layout to add customers table to the design
<br>
• Select all the fields that you want to show in the report
<br>
• Click on Preview tab to see the report preview
<br>
• Click on Save Report icon save to C:\MyReport.mrt
<br>
• Close the report designer
<p><img width=312 height=467 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/9.png"></p>
<p><img width=721 height=571 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/10.png"></p>
<p><img width=716 height=232 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/11.png"></p>
<p><img width=718 height=465 src="http://stimulsoft.com/Articles/TabularReportUsingBusinessObjects/images/12.png"></p>
<a name="5. Run new report using Business Objects"><b><span style='color:blue'>5. Run new report using Business Objects</span></b></p>
• Add a event handler for Run Report button
<br>
• 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 Query Expression Syntax Examples: Filtering(LINQ to Entities) )
<br>
• 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)
<br>
• Register the list of customers with the report object.
<br>
• Call the Show function of the report object to launch the report viewer.
<br>
<br>
<br>
   using Stimulsoft.Report; <br>
   /// <summary> <br>
   /// Event Handler for Run Report button <br>
   /// </summary> <br>
   private void btnRun_Click(object sender, EventArgs e) <br>
   { <br>
     // Get Report Object <br>
     StiReport report = GetReport(); <br>
     // Show report to user <br>
     report.Show(); <br>
   } <br>
<br>
   /// <summary> <br>
   /// This function Loads report definition from a fixed location <br>
   /// and registers all Business Objects in the report definition <br>
   /// </summary> <br>
   /// <returns> <br>
   /// StiReport object for the report <br>
   /// </returns> <br>
   private StiReport GetReport() <br>
   { <br>
     // Create a new object of StiReport Class <br>
     StiReport report = new StiReport(); <br>
<br>
     // Load the report definition file from C:\MyReport.mrt if the file exists <br>
     // This tutorial assumes you have are storing the report definition in a fixed location <br>
     // If the file does not exists then Designer will allow you to save the your newly created report in the location <br>
     if (File.Exists("C:\\MyReport.mrt")) <br>
     { <br>
     report.Load("C:\\MyReport.mrt"); <br>
     } <br>
<br>
     // Get of List of all customers from database using ADO.net Enity data model <br>
     NorthWindEntities nw = new NorthWindEntities(); <br>
     List<Customers> customers = nw.Customers.ToList(); <br>
     nw.Dispose(); <br>
<br>
     // Register Business Objects for Customers in the report <br>
     report.RegBusinessObject("Northwind", "Customers", customers); <br>
<br>
     // Return report to calling function <br>
     return report; <br>
   }
<br>
<br>
<br>
<br>
The author of the article is Chirag Nirmal and his linkedin profile is
<a href="http://www.linkedin.com/in/chiragn">http://www.linkedin.com/in/chiragn</a>
 
Back
Top