此示例显示如何使用Business Objects集合创建报表。Business Objects是一个对象类数据,使用它可以以不同的结构呈现数据:表,列表,数组等。要使用Bisiness对象,您可以使用报表对象的RegBusinessObject()方法:
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();}
Data()对象包含报表所需的数据结构和数据行:
public class Data{ private ListcategoriesItems = new List (); public List Categories { get { return categoriesItems; } set { categoriesItems = value; } } public class CategoriesItem { private List products; public List Products { get { return products; } set { products = value; } } private System.Int32? categoryID; public System.Int32? CategoryID { get { return categoryID; } set { categoryID = value; } } ...
下面的屏幕截图中,您可以看到示例代码的结果。