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, XPS and many 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 you how to create a Master Detail 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 at: http://www.stimulsoft.com/en/downloads

Stimulsoft reporting tools

Steps are required in order to create a Master Detail 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 Designer
4. Design new report using Business Objects
5. Associate Customers to child orders
6. Add Master and Detail tables to the report layout
7. Run new report using Business Objects


1. Add an ADO.NET data model to your project

  • Make sure you are targeting .NET Framework version 3.5 SP1 or higher;
  • Right-click on project name in Solution Explorer;
  • Select Add and then select New Item;
  • Select ADO.NET Entity Date Model;
  • Type the name of the model file, for this tutorial it is going to be Northwind.edmx;
  • Click on Add button.

Add an ADO.NET data model to your project
Add an ADO.NET data model to your project

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

Generate Entity Model for Northwind database
Generate Entity Model for Northwind database
Generate Entity Model for Northwind database

3. Register Business Objects with Report Desinger

  • Create a new form in your project;
  • Make sure you have added the reference to required Stimulsoft Reports.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 the Design Report button;
  • Add some code to get a list of customers and list of orders from those 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);
  • The Entity Data Model shows that Customers has a property classes Orders, it also shows there are 1 to many relationship between customers and orders;
  • Create a 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 and list of orders with the report object;
  • Stimulsoft report designer scans the definition of customer and determines that it has child orders, this will be very helpful while designing the report;
  • Call the Design function of the report object to launch the designer.

Register Business Objects with Report Desinger
Register Business Objects with Report Desinger
using Stimulsoft.Report

///
/// Event Handler for Design Report button
///
private void Design_Click(object sender, EventArgs e)
{
	// Get Report Object
	StiReport report = GetReport();
	// Launch Report Deginer for the report
	report.Design();
}

///
/// This function Loads report definition from a fixed location
/// and registers all Business Objects in the report definition
///

///
/// 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 and List of all orders from database using ADO.net Enity data model
	NorthWindEntities nw = new NorthWindEntities();
	List customers = nw.Customers.ToList();
	List orders = nw.Orders.ToList();
	nw.Dispose();
	// Register Business Objects for Customers and Orders in the report
	report.RegBusinessObject("Northwind", "Customers", customers);
	report.RegBusinessObject("Northwind", "Orders", orders);
	// 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 orders;
  • Expand Customers to see all the fields that belong to customers;
  • Expand Orders to see all the fields that belong to orders.

Design new report using Business Objects

5. Associate Customers to child orders

  • In order to associate Customer to their child orders we need to show orders under customers;
  • Right click on Customers and select New Business Object;
  • Select Child of Business Object;
  • Select Orders from the list of children of Customers;
  • Make any changes alias of orders or to columns inside Orders or add new calculated columns;
  • Click Ok to continue.

Associate Customers to child orders
Associate Customers to child orders
Associate Customers to child orders

6. Add Master and Detail tables to report layout

  • 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;
  • Drag Orders under customers and drop into the report layout to add orders table to the design;
  • Select all the fields that you want to show in the report;
  • Report designer automatically shows details grouped by master;
  • Change background color of Customers to differentiate it from details;
  • Click on Preview tab to see the report preview;
  • Click on Save Report icon save to 'C:\MyReport.mrt';
  • Close the report designer.

Add Master and Detail tables to report layout
Add Master and Detail tables to report layout
Add Master and Detail tables to report layout
Add Master and Detail tables to report layout
Add Master and Detail tables to report layout
Add Master and Detail tables to report layout

7. Run new report using Business Objects

  • Add a event handler for Run Report button;
  • 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);
  • Add code to get a list of customers and list of orders from those 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);
  • The Entity Data Model shows that's Customers has a property classes Orders, it also shows there are a 1 to many relationship between customers and orders;
  • 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 and list of orders with the report object;
  • Call the Show function of the report object to launch the report viewer.
using Stimulsoft.Report;

///
/// Event Handler for Run Report button
///
private void btnRun_Click(object sender, EventArgs e)
{
	// Get Report Object
	StiReport report = GetReport();
	// Show report to user
	report.Show();
}

///
/// This function Loads report definition from a fixed location
/// and registers all Business Objects in the report definition
///

///
/// 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 and List of all orders from database using ADO.net Enity data model
	NorthWindEntities nw = new NorthWindEntities();
	List customers = nw.Customers.ToList();
	List orders = nw.Orders.ToList();
	nw.Dispose();
	
	// Register Business Objects for Customers and Orders in the report
	report.RegBusinessObject("Northwind", "Customers", customers);
	report.RegBusinessObject("Northwind", "Orders", orders);
	
	// Return report to calling function
	return report;
}
By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.