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)
{
	var report = new StiReport();
	report.RegData("EmployeeIEnumerable", CreateBusinessObjectsIEnumerable.GetEmployees());
	report.Load("Reports/BusinessObjects_IEnumerable.mrt");
	report.ShowWithWpf();
}

private void btPreviewITypedList_Click(object sender, System.EventArgs e)
{
	var report = new StiReport();
	report.RegData("EmployeeITypedList", CreateBusinessObjectsITypedList.GetEmployees());
	report.Load("Reports/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", "Nicholas@company1.com");
	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", "Margaret@company1.com");
	emp.Phones.Add(new Phone("(206) 555-4546"));
	emp.Phones.Add(new Phone("(206) 555-0110"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(storeDepartment, "Janet", "Janet@company1.com");
	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", "Laura@company1.com");
	emp.Phones.Add(new Phone("(206) 555-0022"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Mark", "Mark@company1.com");
	emp.Phones.Add(new Phone("(206) 555-9980"));
	emp.Phones.Add(new Phone("(206) 555-5567"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Michael", "Michael@company1.com");
	emp.Phones.Add(new Phone("(206) 555-5642"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Thomas", "Thomas@company1.com");
	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", "Nicholas@company1.com");
	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", "Margaret@company1.com");
	emp.Phones.Add(new Phone("(206) 555-4546"));
	emp.Phones.Add(new Phone("(206) 555-0110"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(storeDepartment, "Janet", "Janet@company1.com");
	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", "Laura@company1.com");
	emp.Phones.Add(new Phone("(206) 555-0022"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Mark", "Mark@company1.com");
	emp.Phones.Add(new Phone("(206) 555-9980"));
	emp.Phones.Add(new Phone("(206) 555-5567"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Michael", "Michael@company1.com");
	emp.Phones.Add(new Phone("(206) 555-5642"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Thomas", "Thomas@company1.com");
	emp.Phones.Add(new Phone("(206) 555-8949"));
	employees.Add(emp);
	
	return employees;
}

На скриншоте ниже Вы можете увидеть результат выполнения данного кода:

Using Business Objects in the Report

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.