Stimulsoft reporting provides built in components that allow the developer to programmatically export their reports to a wide variety of document formats. In my experience the user requirement is usually to have an export button on the webpage or a windows forms that does the job for the user. Exporting by code behind is also usually required for batch processes where reports scheduled to be emailed to users or saved to a network drive or they may also be uploaded to sharepoint/ftp server. Below is the list of formats that we support natively by Stimulsoft reporting. There is no need to use third party or COM components.

In this tutorial I will show to create a simple table report, show it on a web page and show an Export to PDF button on a webpage that allows the user to download the PDF. For doing that I need a way to call the export function of the report or report viewer in the code behind.

The demo version of Stimulsoft reporting tools can be downloaded from the website: http://www.stimulsoft.com/en/downloads
The following steps are required in order to create a cross-tab report and export it to PDF, Word, Excel and other formats.


1. Supported Export Formats
2. Supported Export Settings
3. Add report to your web page
4. Add a new connection to the report
5. Add a Data Source to the report
6. Add Table and Page Header to the report
7. Add report to your web page
8. Page load event
9. Export Report on Export button click


1. Supported Export Formats
  • PDF (Adobe Portable Document Format);
  • Microsoft XPS (XML Paper Specification);
  • HTML (HyperText Markup Language);
  • MHT;
  • Text;
  • Rich Text;
  • Microsoft Word 2007;
  • OpenDocument Writer;
  • Microsoft Excel;
  • Microsoft Excel XML;
  • OpenDocument Calc;
  • CSV (Comma-separated values);
  • dBase DBF (DataBase File);
  • XML (Extensible Markup Language);
  • BMP (Bitmap);
  • GIF (Graphics Interchange Format);
  • JPEG (Joint Photographic Experts Group);
  • PCX (Pacific Exchange);
  • PNG (Portable Network Graphics);
  • TIFF (Tagged Image File Format);
  • Windows Metafile.


2. Supported Export Settings

Stimulsoft Reports has built-in support for exporting to a file on the disk using the ExportDocument function of the StiReport object. The reporting framework also has the StiReportResponse class for exporting the report directly to the http response so users can download reports as files in a web application. When exporting to the http response it also provides export options listed below.

1) openDialog flag:
If this flag is set to true, it will force the user to download the file before opening and if the flag is set to false, it will allow the browse to open the application required to show the report. For example, if the export format is PDF and the show dialog flag is set to false, the browser will open Adobe Reader in the browse if it installed on the client computer and if the show dialog flag is set to true, the browser will prompt the user to download the report as file even if Adobe Reader viewer is installed on the client computer.

Example:
//set the StiReport report object
StiReport oSR = stiBooksReport.GetReport();
// Export report to pdf and force user to download the file
StiReportResponse.ResponseAsPdf(this, oSR, false);
// Export report to pdf and open Adobe Reader if available
StiReportResponse.ResponseAsPdf(this, oSR);
In the screen shot below, openDialog is set to false so the PDF opens in the embedded Acrobat Reader.

PDF opens in the embedded Acrobat Reader
In the screen shot below openDialog is set to true, so use is asked to Open, Save or Cancel depending on the browser.

Open, Save or Cancel depending on the browser
2) StiPagesRanges
If the programmer wants to define which pages of the report should be exported, they have the option of passing an object of the StiPagesRange class as a parameter to the export function. With the stiPagesRange programmers can export only one page or give page ranges to be exported.

Example:
//set the StiReport report object
StiReport oSR = stiBooksReport.GetReport();
// Export page 1
StiPagesRange oSPR = new StiPagesRange(1);
// Export report to pdf and open the file in browser
StiReportResponse.ResponseAsPdf(this, oSR, false, oSPR);

//set the StiReport report object
StiReport oSR = stiBooksReport.GetReport();
// Export pages 1 to 10
StiPagesRange oSPR = new StiPagesRange("1-10");
// Export report to pdf and open the file in browser
StiReportResponse.ResponseAsPdf(this, oSR, false, oSPR);
3) StiPdfExportSettings
This parameter allows the programmer to set advanced export settings listed below;
a) Compression flag – Enable/Disable compression of the PDF;
b) Creator string – Set the name of the creator;
c) Image Quality – Sets the image quality;
d) Image Resolution – Sets the image resolution;
e) Allow embedded fonts – Allow embedded fonts in the PDF;
f) Keywords – Keywords;
g) Password – Pdf security password;
h) Digital Certificates – Enable/Disable local digital signatures and certificates;
i) Page Range – Page range to be exported.

4) StiExcelExportSettings
This parameter can be used when exporting reports to Excel. The following advanced properties can be set;
a) ExportDataOnly – Export only data without formatting and images;
b) ExportEachPageToSheet – Export each report page to a new excel worksheet;
c) ExportObjectFormatting – Export the formatting for text, pictures and other objects;
d) ExportPageBreaks – Export page breaks for printing of sheets;
e) ImageQuality – Sets the image quality;
f) ImageResolution – Sets the image resolution;
g) PageRange – Page range to be exported;
h) UseOnePageHeaderAndFooter – Use only one page header and footer for the entire sheet;

In the screenshot below, Export Data only is set to false.

Export Data only is set to false
Export Data only is set to true

Export Data only is set to true

3. Add report to your web page

  • Drag and Drop StiWebReport from the toolbox to your webpage;
  • Click on the arrow on the top right corner of StiWebReport1 to show StiWebReport Tasks;
  • Click on Design Report to open the report Designer.

Add report to your web page

4. Add a new connection to the report

  • Find the Dictionary on the right side of the report designer;
  • Click on the New Item Icon and select New Connection;
  • Select SQL Connection and click OK;
  • Type the connection string for the MS Access Books database;
  • Click test to confirm that the connection string is correct.

Add a new connection to the report
Add a new connection to the report

5. Add a Data Source to the report

  • Click on the New Item icon the Dictionary pane and select New Data Source;
  • Select Data from SQL Connection and Click Ok;
  • Type the name of the query in the Name field as Sales;
  • Type the SQL query in the Query Text Field;
  • Click on Retrieve Columns to confirm that you have all the required columns;
  • Click Ok to see the Sales Datasource in the Dictionary Pane;
  • The following query has been used in the report;
  • Give a name to the data source so that it can used later.
Select * from Books
Add a Data Source to the report
Add a Data Source to the report

6. Add Table and Page Header to the report

  • Click on the AllBooks data source and drag it to the report;
  • Click on the Text tool on the toolbar and click on the Page Header to insert a label;
  • Format label to your requirements, this label will shown as the page header for each report.

Add Table and Page Header to the report

7. Add report to your web page

  • Design the report using the Report Designer and save the report file to a know location;
  • Drag and Drop StiWebReport from the toolbox to your webpage;
  • Click on the arrow on the top right corner of StiWebReport1 to show StiWebReport Tasks;
  • Click on Open Report from File;
  • Browse to the report file and click Open; the report is now loaded as a string in the aspx markup itself;
  • Add buttons for Export to PDF (ShowDialog is false), Export to PDF, Export to Word and Export to Excel.

Add report to your web page

8. Page load event

  • Get the report object from StiWebReport and set the report viewer source on page load event;
  • Assign report to the StiWebViewer to render and show the report.
protected void Page_Load(object sender, EventArgs e)
{
	// ignore the page request if images are beign loaded for report viewer
	if (stiRepViewerBooks.IsImageRequest) return;
	if (!IsPostBack)
	{
		//set the StiReport report object when page loads for the first time
		stiRepViewerBooks.Report = stiBooksReport.GetReport();
	}
}
9. Export Report on Export button click

  • Set the event handler for each export button to btnExport_Click;
  • Call StiReportResponse export functions based the sender object;
  • Export can be done by pressing one of the export buttons and the customer can see save dialog or not. It depends on ShowDialog parameter of the ResponseAsPdf method.
protected void btnExport_Click(object sender, EventArgs e)
{
	StiReport oSR = stiBooksReport.GetReport(); //set the StiReport report object
	oSR.Render(false);
	
	if (sender == btnExportPdfShowDialogIsfalse)
		StiReportResponse.ResponseAsPdf(this, oSR, false); // Export report as PDF with showDialog false
	if (sender == btnExportPdf)
		StiReportResponse.ResponseAsPdf(this, oSR); // Export report as PDF with showDialog true
	if (sender == btnExportWord)
		StiReportResponse.ResponseAsRtf(this, oSR); // Export report as a Word document
	if (sender == btnExportExcel)
		StiReportResponse.ResponseAsXls(this, oSR); // Export report as an Excel Sheet
}
Stimulsoft reporting provides a set of powerful reporting tools Microsoft Visual Studio .net 2005 and 2008; 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. 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 bar codes 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 cross tab report, show it on a web page and allow users to export the report to word, excel and pdf without writing a single line of code.

The data for this sample report will come from the AdventureWork sample database provided by Microsoft.

The demo version of Stimulsoft reporting tools can be downloaded from the website: http://www.stimulsoft.com/en/downloads

The following steps are required in order to create a cross tab and export it to PDF, Word, Excel and other formats


1. Add report to your web page
2. Add a new connection to the report
3. Add a Data Source to the report
4. Add a Cross-Tab to the report
5. Load the Report from file
6. Export the report to PDF


1. Add report to your web page

  • Drag and Drop StiWebReport from the toolbox to your webpage;
  • Click on the arrow on the top right corner of StiWebReport1 to show StiWebReport Tasks;
  • Click on Design Report to open the report Designer.

Add report to your web page

2. Add a new connection to the report

  • Find the Dictionary on the right side of the report designer;
  • Click on the New Item Icon and select New Connection;
  • Select Sql Connection and click OK;
  • Type the connection string for the AdventureWorks database;
  • Click test to confirm that the connection string is correct.

Add a new connection to the report
Add a new connection to the report

3. Add a Data Source to the report

  • Click on the New Item icon the Dictionary pane and select New Data Source;
  • Select Data from Sql Connection and Click Ok;
  • Type the name of the query in the Name field as Sales;
  • Type the SQL query in the Query Text Field;
  • Click on Retrieve Columns to confirm that you have all the required columns;
  • Click Ok to see the Sales Datasource in the Dictionary Pane;
  • The following query has been used in the report.
SELECT
,[SalesOrderID]
,[RevisionNumber]
,[OrderDate]
,[DueDate]
,[ShipDate]
,[Status]
,[OnlineOrderFlag]
,[SalesOrderNumber]
,[PurchaseOrderNumber]
,[AccountNumber]
,[CustomerID]
,[ContactID]
,[SalesPersonID]
,st Name
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[CreditCardID]
,[CreditCardApprovalCode]
,[CurrencyRateID]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[Comment]
FROM [AdventureWorks].[Sales].[SalesOrderHeader] soh
Inner join [AdventureWorks].[Sales].[SalesTerritory] st on soh.TerritoryID = st.TerritoryID
Add a Data Source to the report
Add a Data Source to the report

4. Add a Cross-Tab to the report

  • Click on Cross Bands icon on the right toolbar and select Cross-Tab;
  • Draw the cross tab onto the report;
  • The Cross-Tab Designer window will appear;
  • Select Sales in the Datasource dropdown;
  • Add OrderDate in the Columns list and change the display value property and value property to {Format("{0:yyyy}", Sales.OrderDate)} in order to show only the order year;
  • Add Name to the Rows list and TotalDue in the Summary Field;
  • Click OK to save the changes;
  • Press F5 to preview the report;
  • This report now shows the total amounts due by sales territory and year, it also gives a total of each row and column;
  • Save the report as Sales.mrt and close the report designer.

Add a Cross-Tab to the report
Add a Cross-Tab to the report
Add a Cross-Tab to the report
Add a Cross-Tab to the report

5. Load the Report from file

  • Click on the right arrow on the StiWebReport1 object on the aspx page and select Open report from file
  • Browse to the location where you saved the report as an .mrt file.
  • Show report in the report viewer
  • Drag and Drop a StiWebViewer object to the page where Stiwebreport1 object already exists.
  • Add the following code to the page load event of the page.
protected void Page_Load(object sender, EventArgs e)
{
	if (StiWebViewer1.IsImageRequest) return;
	if (!Page.IsPostBack)
	{
		Stimulsoft.Report.StiReport oRep = StiWebReport1.GetReport();
		StiWebViewer1.Report = oRep;
	}
}
  • The first line is required as part of the stireports framework;
  • The second if statement is used to load the report only once when the page load occurs and the 2 lines in the if statement set the report source of the report viewer;
  • Press F5 to view the report as a web report.

Load the Report from file
Load the Report from file

6. Export the report to PDF

  • Click on the save and select Adobe Pdf;
  • Users can export the report to a wide variety of formats shown below;
  • No coding or external library is required to export.

Export the report to PDF
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://www.stimulsoft.com/en/downloads

Stimulsoft reporting tools
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 Designer
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.

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

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

3. Register Business Objects with Report Designer

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

Register Business Objects with Report Designer
Register Business Objects with Report Designer
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 Designer 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 from database using ADO.net Enity data model
	NorthWindEntities nw = new NorthWindEntities();
	List customers = nw.Customers.ToList();
	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;
  • Browser 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.

Design new report using Business Objects
Design new report using Business Objects
Design new report using Business Objects
Design new report using Business Objects

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 d:\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;

///
/// 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 from database using ADO.net Enity data model
	NorthWindEntities nw = new NorthWindEntities();
	List customers = nw.Customers.ToList();
	nw.Dispose();
	
	// Register Business Objects for Customers in the report
	report.RegBusinessObject("Northwind", "Customers", customers);
	
	// Return report to calling function
	return report;
}
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;
}
Stimulsoft reporting provides a tool that checks your reports for problems which you may miss. This tool is unique to Stimulsoft and can be a very helpful feature for quality control. Users can run checks for warnings, compilation errors, recommendations and even advice. In many cases the report checker can show you a preview of the report with the problem area highlighted and also provides ways to fix the issues in the report definition file.

In this tutorial I will show you how to create shipping label report in Stimulsoft Reports.Wpf and check it in Report Checker.Wpf and fix the errors, warnings and recommendations.

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://www.stimulsoft.com/en/downloads

Stimulsoft reporting tools
Steps are required in order to create a simple report:


1. Add a connection to your report
2. Add required data sources to report
3. Add Orders to the report
4. Fix report in Report Checker


1. Add a data source to your report

  • Open Stimulsoft Reports.Wpf Designer from start menu, the WPF designer is big improvement of the windows forms designer and looks very similar to the office 2010 interface;
  • Select Dictionary Tab in the right pane;
  • Select New Item and click on New Connection;
  • The new connection wizard gives you various options for different types of connections, namely SQL connection, OleDB connection, XML data and ODBC connection;
  • Select SQL connection for this tutorial;
  • Give the connection any name that represents the database. For our example I will name it Northwind;
  • Click on Build button to create a connection string or paste it into the connection string text area. You can also create your own connection string using instructions given on http://www.connectionstrings.com;
  • Click on the test button to make sure that the connection string works.

Add a data source to your report
Add a data source to your report
Add a data source to your report
Add a data source to your report

2. Add required data sources to report

  • Right-click on the newly created Northwind connection and select New Data Source;
  • Select Northwind and click OK;
  • Stimulsoft reports will display all data objects that are available for reporting;
  • For our example we will selected Orders and Order details tables and click OK;
  • Orders and Order Details tables as now available under Northwind connection.

Add required data sources to report
Add required data sources to report

3. Add Orders to the report

  • Find Data Band in Toolbox on Left side of report designer;
  • Drag and drop the data band from toolbox into the report to create a new data band. When prompted for data source selection just click ok;
  • Move your mouse to top right corner of data and to see various small buttons, click on the left most to select data source;
  • Select orders to assign orders as the data source of the data band;
  • Drag and Drop Text object into the Header to display Orders header;
  • We will use HTML formatting to display Orders in Bold. Type <B>Orders</B> to display it in Bold;
  • Drag and Drop Order Date, Ship Name, Ship Address, Ship City, Region, Country and Postal Code to the Data Band;
  • This report will help users print shipping labels so we will need to a bar code also;
  • Drag and Drop the bar code object into the data band;
  • Right click on the barcode and select properties;
  • Find the Code Property and click on ... button on right most corner of the property;
  • Drag and Drop the Order.Freight property into the text edit, this tells the report designer to generate barcodes based on value of freight;
  • Click on the preview tab to see how the report looks with real data;
  • Save the file as Order.mrt as a known location.

Add Orders to the report
Add Orders to the report
Add Orders to the report
Add Orders to the report
Add Orders to the report
Add Orders to the report

4. Fix report in Report Checker

  • Open report checker from start menu;
  • Click on the Open button and browse to Orders.mtr and click on Open;
  • Report Checker will scan Order.mrt and display its findings;
  • We can see that there are 2 warnings;
  • The first warning shows as one of the components in the report is outside the page;
  • To view which component is outside the page, simple move your move over to the magnifying glass to see a preview;
  • We can clearly see that the bar code is highlighted in Red and is outside the page;
  • I don't need to go back to the report designer to fix, I can simply click on Move to page or To Print Area to fix this;
  • Now I can go back to the report designer to see that the bar code has been moved inside the margin;
  • The second warning shows that AllowHtmlTags property is set to False;
  • Move your move over the magnifying glass to see that Orders header is highlighted;
  • To fix this error simply click on the On button;
  • When we go back to report designer we can see that the ugly <B> tags are gone and Orders text is displayed in bold;
  • Now we can go to preview tab to see the final result.

Fix report in Report Checker
Fix report in Report Checker
Fix report in Report Checker