文档彩票走势图>>Stimulsoft Reports.WinForms教程-2019>>【Stimulsoft Reports.WinForms教程】在报表中使用Business Objects
【Stimulsoft Reports.WinForms教程】在报表中使用Business Objects
【下载Stimulsoft Reports.Ultimate最新版本】
此示例显示如何使用Business Objects集合创建报表。Business Objects:一个对象类数据,使用它可以以不同的结构呈现数据:表,列表,数组等。此示例使用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模型,为了填充数据,使用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模型,为了填充数据,使用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; }
示例代码的结果如下图所示: