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. This example uses two variants of Business Objects - IEnumerable and ITypedList:

private void btPreviewIEnumerable_Click(object sender, System.EventArgs e)
{
StiReport report = new StiReport();
report.RegData("EmployeeIEnumerable", CreateBusinessObjectsIEnumerable.GetEmployees());
report.Load("..\\BusinessObjects_IEnumerable.mrt");
report.ShowWithWpf();
}

private void btPreviewITypedList_Click(object sender, System.EventArgs e)
{
StiReport report = new StiReport();
report.RegData("EmployeeITypedList", CreateBusinessObjectsITypedList.GetEmployees());
report.Load("..\\BusinessObjects_ITypedList.mrt");
report.ShowWithWpf();
}


As the IEnumerable object, the EmployeeIEnumerable model is used. To populate data, the GetEmployees() method of the CreateBusinessObjectsIEnumerable class is used:

public static EmployeeIEnumerableCollection GetEmployees()
{
EmployeeIEnumerableCollection employees = new EmployeeIEnumerableCollection();
Company company = new Company("Company1");
Department storeDepartment = new Department(company, "Store Department");
Department salesDepartment = new Department(company, "Sales Department");

EmployeeIEnumerable emp = new EmployeeIEnumerable(storeDepartment, "Nicholas", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-9857"));
emp.Phones.Add(new Phone("(206) 555-6546"));
emp.Phones.Add(new Phone("(206) 555-7651"));
employees.Add(emp);

emp = new EmployeeIEnumerable(storeDepartment, "Margaret", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-4546"));
emp.Phones.Add(new Phone("(206) 555-0110"));
employees.Add(emp);

emp = new EmployeeIEnumerable(storeDepartment, "Janet", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-5462"));
emp.Phones.Add(new Phone("(206) 555-8400"));
emp.Phones.Add(new Phone("(206) 555-9842"));
employees.Add(emp);

emp = new EmployeeIEnumerable(salesDepartment, "Laura", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-0022"));
employees.Add(emp);

emp = new EmployeeIEnumerable(salesDepartment, "Mark", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-9980"));
emp.Phones.Add(new Phone("(206) 555-5567"));
employees.Add(emp);

emp = new EmployeeIEnumerable(salesDepartment, "Michael", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-5642"));
employees.Add(emp);

emp = new EmployeeIEnumerable(salesDepartment, "Thomas", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-8949"));
employees.Add(emp);

return employees;
}


As ITypedList object, the EmployeeITypedList model is used. To populate data, the GetEmployees() method of the CreateBusinessObjectsITypedList class is used:

public static EmployeeITypedListCollection GetEmployees()
{
EmployeeITypedListCollection employees = new EmployeeITypedListCollection();
Company company = new Company("Company1");
Department storeDepartment = new Department(company, "Store Department");
Department salesDepartment = new Department(company, "Sales Department");

EmployeeITypedList emp = new EmployeeITypedList(storeDepartment, "Nicholas", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-9857"));
emp.Phones.Add(new Phone("(206) 555-6546"));
emp.Phones.Add(new Phone("(206) 555-7651"));
employees.Add(emp);

emp = new EmployeeITypedList(storeDepartment, "Margaret", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-4546"));
emp.Phones.Add(new Phone("(206) 555-0110"));
employees.Add(emp);

emp = new EmployeeITypedList(storeDepartment, "Janet", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-5462"));
emp.Phones.Add(new Phone("(206) 555-8400"));
emp.Phones.Add(new Phone("(206) 555-9842"));
employees.Add(emp);

emp = new EmployeeITypedList(salesDepartment, "Laura", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-0022"));
employees.Add(emp);

emp = new EmployeeITypedList(salesDepartment, "Mark", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-9980"));
emp.Phones.Add(new Phone("(206) 555-5567"));
employees.Add(emp);

emp = new EmployeeITypedList(salesDepartment, "Michael", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-5642"));
employees.Add(emp);

emp = new EmployeeITypedList(salesDepartment, "Thomas", "This email address is being protected from spambots. You need JavaScript enabled to view it.");
emp.Phones.Add(new Phone("(206) 555-8949"));
employees.Add(emp);

return employees;
}


Also, you can see the article Creating a Report Using Business Object in Runtime. In the screenshot below you can see the results of the sample code.

Using Business Objects