文檔首頁>>Stimulsoft Reports.WinForms教程-2019>>【Stimulsoft Reports.WinForms教程】在報表中使用Business Objects
【Stimulsoft Reports.WinForms教程】在報表中使用Business Objects
【下載Stimulsoft Reports.Ultimate最新版本】
此示例顯示如何使用Business Objects集合創(chuàng)建報表。Business Objects:一個對象類數(shù)據(jù),使用它可以以不同的結(jié)構(gòu)呈現(xiàn)數(shù)據(jù):表,列表,數(shù)組等。此示例使用Business Objects的兩個變體:IEnumerable和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.Show(); } private void btPreviewITypedList_Click(object sender, System.EventArgs e) { StiReport report = new StiReport(); report.RegData("EmployeeITypedList", CreateBusinessObjectsITypedList.GetEmployees()); report.Load("..\\BusinessObjects_ITypedList.mrt"); report.Show(); }
作為IEnumerable對象使用EmployeeIEnumerable模型,為了填充數(shù)據(jù),使用CreateBusinessObjectsIEnumerable類的GetEmployees()方法:
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; }
作為ITypedList對象使用EmployeeITypedList模型,為了填充數(shù)據(jù),使用CreateBusinessObjectsITypedList類的GetEmployees()方法:
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; }
示例代碼的結(jié)果如下圖所示: