此示例说明如何使用代码中的 Business Objects 集合创建 告。
此示例说明如何使用代码中的 Business Objects 集合创建 告。Business Objects 是一个对象类数据,数据可以用不同的结构呈现:表格、列表、数组等。该FillBusinessObject()方法创建并填充数据集合:
private ArrayList list = null;private void FillBusinessObject(){list = new ArrayList();list.Add(new BusinessEntity("name1", "alias1"));list.Add(new BusinessEntity("name2", "alias2"));list.Add(new BusinessEntity("name3", "alias3"));}
数据已创建,现在您需要显示它。首先,您应该在字典中创建一个新的 表和数据结构,将数据从 Business Object 传输到字典:
private void PrintDataGrid(DataGrid sender){StiReport report = new StiReport();report.ScriptLanguage = StiReportLanguageType.CSharp;// Add data to datastorereport.RegData("MyList", list);// Fill dictionaryreport.Dictionary.Synchronize();StiPage page = report.Pages.Items[0];...
然后您需要将组件添加到 告模板中。您应该创建带 Header、Data 和 Footer。这些带用于放置带有文本或对业务对象字段的引用的文本框:
...// Create HeaderBandStiHeaderBand headerBand = new StiHeaderBand();headerBand.Name = "HeaderBand";page.Components.Add(headerBand);// Create DatabandStiDataBand dataBand = new StiDataBand();dataBand.DataSourceName = "MyList";dataBand.Height = 0.5f;dataBand.Name = "DataBand";page.Components.Add(dataBand);StiDataSource dataSource = report.Dictionary.DataSources[0];// Create textsDouble pos = 0;Double columnWidth = StiAlignValue.AlignToMinGrid(page.Width / dataSource.Columns.Count, 0.1, true);int nameIndex = 1;foreach (StiDataColumn column in dataSource.Columns){if (column.Name == "_ID" || column.Name == "_Current") continue;// Create text on headerStiText headerText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f));headerText.Text.Value = column.Name;headerText.HorAlignment = StiTextHorAlignment.Center;headerText.Name = "HeaderText" + nameIndex.ToString();headerText.Brush = new StiSolidBrush(Color.MediumSeaGreen);headerText.Border.Side = StiBorderSides.All;headerBand.Components.Add(headerText);// Create text on Data BandStiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f));dataText.Text.Value = "{MyList." + column.Name + "}";dataText.Name = "DataText" + nameIndex.ToString();dataText.Border.Side = StiBorderSides.All;dataBand.Components.Add(dataText);pos += columnWidth;nameIndex ++;}// Create FooterBandStiFooterBand footerBand = new StiFooterBand();footerBand.Height = 0.5f;footerBand.Name = "FooterBand";page.Components.Add(footerBand);// Create text on footerStiText footerText = new StiText(new RectangleD(0, 0, page.Width, 0.5f));footerText.Text.Value = "Count - {Count()}";footerText.HorAlignment = StiTextHorAlignment.Right;footerText.Name = "FooterText";footerText.Brush = new StiSolidBrush(Color.LightGreen);footerBand.Components.Add(footerText);...
在此之后,您可以呈现 告并将其显示在查看器中(或调用 告设计器):
...// Render without progress barreport.Render(false);report.Show();// For checking created report you can uncomment this line//report.Design();}
在下面的屏幕截图中,您可以看到示例代码的结果:

Aspose、E-iceblue、FastReport、Stimulsoft等文档/ 表图表类开发工具享超低折扣,如有需要可直接联系在线客服。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!