Using Business Objects in the Report

This example shows how to create a report with the Business Objects collection. Business Objects is an object class data with which the data can be presented in different structures: tables, lists, arrays, etc. To use the Bisiness Objects you can use the RegBusinessObject() method of the report object:

private void btDesign_Click(object sender, RoutedEventArgs e)
{
var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
"UsingBusinessObjects.SimpleList.mrt");

StiReport report = new StiReport();
report.Load(stream);

stream.Close();
stream.Dispose();
stream = null;
report.CalculationMode = StiCalculationMode.Interpretation;
report.RegBusinessObject("Data", "Data", new Data());

report.Design();
}

private void btPreview_Click(object sender, RoutedEventArgs e)
{
var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
"UsingBusinessObjects.SimpleList.mrt");

StiReport report = new StiReport();
report.Load(stream);

stream.Close();
stream.Dispose();
stream = null;

report.CalculationMode = StiCalculationMode.Interpretation;
report.RegBusinessObject("Data", "Data", new Data());
report.Render();

report.Show();
}


The Data() object contains the data structure and the data rows required for the report:

public class Data
{
private List<CategoriesItem> categoriesItems = new List<CategoriesItem>();
public List<CategoriesItem> Categories
{
get
{
return categoriesItems;
}
set
{
categoriesItems = value;
}
}

public class CategoriesItem
{
private List<ProductsItem> products;
public List<ProductsItem> Products
{
get
{
return products;
}
set
{
products = value;
}
}

private System.Int32? categoryID;
public System.Int32? CategoryID
{
get
{
return categoryID;
}
set
{
categoryID = value;
}
}

...


In the screenshot below you can see the result of the sample code.

Using Business Objects in the Report