使用ActiveReports创建动态区段报表 - 范文中心

使用ActiveReports创建动态区段报表

01/30

报表控件ActiveReports的最新7版本提供了更多更广泛的API,让Visual Basic和C#开发者可以完整掌控报表流程引擎,以适应各种复杂报表开发的需求。

它主要提供的事件和属性类型有:

数据检索

数据转换

布局

渲染

完善的API意味着开发人员实现在运行时创建报表,一般的报表工具都将报表设计和报表分开运行扯淡,而ActiveReports却可以通过API实现运行时的报表创建,让一些报表的一些动态功能能够实现。接下来就以如何创建动态区段报表为例,说一下灵活运用API的方法。首先看一下最终创建报表的效果:

简单的说一下创建步骤:

创建一个报表实例

动态的添加区段和控件

修改报表区段和控件的相关细节

给报表指派设置数据源

将报表绑定到数据源

下段代码就能完成所有步骤:

private void Form1_Load(object sender, EventArgs e)

{

rpt = new SectionReport();

//Adding Page Header/Footer sections

rpt.Sections.InsertPageHF();

rpt.Sections[0].BackColor = Color.LightGray;

//Adding Detail section

rpt.Sections.Insert(1, new Detail());

rpt.Sections[1].BackColor = Color.PeachPuff;

rpt.Sections[1].Height = 1.5f;

//Adding label to display first column's name

GrapeCity.ActiveReports.SectionReportModel.Label lblCategoryID = new GrapeCity.ActiveReports.SectionReportModel.Label();

lblCategoryID.Location = new PointF(0, 0.05F);

lblCategoryID.Text = "Category ID";

lblCategoryID.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center;

lblCategoryID.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold);

rpt.Sections[0].Controls.Add(lblCategoryID);

//Adding label to display second column's name

GrapeCity.ActiveReports.SectionReportModel.Label lblCategoryName = new GrapeCity.ActiveReports.SectionReportModel.Label();

lblCategoryName.Location = new PointF(1.459f, 0.05f);

lblCategoryName.Size = new SizeF(1.094f,0.2f);

lblCategoryName.Text = "Category Name";

lblCategoryName.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold);

rpt.Sections[0].Controls.Add(lblCategoryName);

//Adding label to display third column's name

GrapeCity.ActiveReports.SectionReportModel.Label lblDescription = new GrapeCity.ActiveReports.SectionReportModel.Label();

lblDescription.Location = new PointF(3.114f, 0.05f);

lblDescription.Text = "Description";

lblDescription.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold);

rpt.Sections[0].Controls.Add(lblDescription);

//Adding label to display fourth column's name

GrapeCity.ActiveReports.SectionReportModel.Label lblPicture = new GrapeCity.ActiveReports.SectionReportModel.Label();

lblPicture.Location = new PointF(5.219f, 0.05f);

lblPicture.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center;

lblPicture.Text = "Picture";

lblPicture.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold);

rpt.Sections[0].Controls.Add(lblPicture);

//Adding Textbox to display first column's records

GrapeCity.ActiveReports.SectionReportModel.TextBox txtCategoryID = new GrapeCity.ActiveReports.SectionReportModel.TextBox();

txtCategoryID.Location = new PointF(0,0);

txtCategoryID.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center;

rpt.Sections[1].Controls.Add(txtCategoryID);

//Adding Textbox to display second column's records

GrapeCity.ActiveReports.SectionReportModel.TextBox txtCategoryName = new GrapeCity.ActiveReports.SectionReportModel.TextBox();

txtCategoryName.Location = new PointF(1.459f,0);

rpt.Sections[1].Controls.Add(txtCategoryName);

//Adding Textbox to display third column's records

GrapeCity.ActiveReports.SectionReportModel.TextBox txtDescription = new GrapeCity.ActiveReports.SectionReportModel.TextBox();

txtDescription.Location = new PointF(3.114f,0);

rpt.Sections[1].Controls.Add(txtDescription);

//Adding Picture control to display image

GrapeCity.ActiveReports.SectionReportModel.Picture picture = new Picture();

picture.Location = new PointF(5.219f,0);

rpt.Sections[1].Controls.Add(picture);

// Setting report's data source

conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\stduser\Documents\ComponentOne Samples\ActiveReports Developer 7\Data\NWIND.mdb;Persist Security Info=False");

System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("SELECT * FROM Categories", conn);

conn.Open();

reader = cmd.ExecuteReader();

rpt.DataSource = reader;

// Assigning DataField properties of controls in the detail section

txtCategoryID.DataField = "CategoryID";

txtCategoryName.DataField = "CategoryName";

txtDescription.DataField = "Description";

picture.DataField = "Picture";

reader.Close();

conn.Close();

}


相关内容

  • 地质信息技术
    第六章 地质信息技术 前 言 当前,在加拿大.澳大利亚等西方主要矿业大国,矿业软件是矿山生产过程中必不可少的重要工具,特别是在地质数据分析.提高矿山生产与管理效率等方面发挥了巨大作用.当前国外比较著名的商业矿业软件有Surpac .Micr ...
  • 造价师考试计价时间日期汇总
    P14 含税营业额=税前造价+应纳税额=税前造价+税前造价×综合税率=税前造价×(1+综合税率) 综合税率为:(1)纳税地点在市区的,3.48%:(2)县城.镇,3.41%:(3)农村,3.28% P13 应纳营业税=(计税营业额)含税营业 ...
  • 电脑文件格式大全
    386 Windows虚拟设备驱动程序 CDX 复合索引文件 ABC ASCII编码格式文件 CFG 配置文件,包含系统设备和环境信息 ACM 音频压缩管理驱动程序 CGM Paint Shop Pro映象文件 ACT 文档向导 CHK 被 ...
  • 铁路运输进款及运输收入管理规定
    [时效性]:已失效 [发文字号]:铁道部令第13号 [颁布日期]:2003-11-26 [生效日期]:2004-01-01 [效力级别]:部门规章 [颁布机构]:铁道部(已撤销) 目录 * 1 href="#heading_1&q ...
  • 基准地价调整有关事项说明
    附件1 基准地价调整有关事项说明 一.本次调整的基准地价覆盖范围包括蓬江区.江海区和新会区全域,总面积为1818平方公里. 二.本次基准地价同时采用网格点价.区段价.级别价和商业路线价的形式予以表示,并以土地级别图.商业路线价图及文字说明予 ...
  • 交通运输概论简答题
    交通运输概论复习题 1.铁路线路平面.纵断面.横断面的概念. 线路中心线:是指距外轨二分之一轨距的铅垂线AB 与路肩水平线CD 的交点O 的纵向连线 线路平面:线路中心线在水平面上的投影. 线路纵断面 :线路中心线纵向展直后在铅垂面上的投影 ...
  • 国土资源部地质灾害危险性评估技术要求
    地质灾害危险性评估技术要求(试行) 1.范围 1.1本技术要求规定了地质灾害危险性评估的原则.不同阶段地质灾害危险性评估的内容.要求.方法和程序. 1.2本技术要求适用于在全国地质灾害易发区内进行各类建设工程时的地质灾害危险性评估以及在全国 ...
  • 人员管理系统
    人员管理系统 系 统 方 案 北京XXXX 研究所 目录 第一章:设计概述 .................................................................................. ...
  • 城轨供电系统课程设计报告
    城市轨道交通供电系统课程设计报告 专 业:电气工程及其自动化 班 级: 电气 1001 姓 名: XXXXXX 学 号: 201009028 指导教师: XXXXXX 兰州交通大学自动化与电气工程学院 2013 年7月 12日 1 设计原始 ...
  • 党总支.党支部管理员工作职责
    党总支政工员职责 一.负责区段内党工团及廉政建设工作,组织支部会议.工会及团组织活动: 二.负责组织开展区段内各单位职工的精神文明创建工作,并对管理处的相关工作进行有效支持: 三.负责对区段内各单位的厂务公开和民主生活开展情况进行指导和监督 ...