水晶报表填充.Net Objects数据源
2014-04-23 23:37
375 查看
CrystalReports(水晶报表)是一款商务智能(BI)软件,主要用于设计及产生报表。是业内最专业、功能最强的报表系统。
查看网络资料及课本图书,鲜有介绍通过.NETObjects作为数据源填充水晶报表的示例。本文将通过两个简单的示例演示水晶报表填充.NetObjects数据源的过程。
示例一:打印学生信息(一个.NETObjects数据源的填充)
示例效果:
Student.cs
将其编译后,即可通过数据库专家将其作为数据源导入到字段资源管理器。
绘制报表样式并插入数据库字段:
在Default.aspx页面拖入CrystalReportViewer控件:
Default.aspx.cs
示例二:打印学生成绩(多个.NETObjects数据源的填充)
示例效果:
Subject.cs
主报表:(CrSupReport.rpt)
子报表:(CrSubReport.rpt)
Default2.aspx
Default2.aspx.cs
查看网络资料及课本图书,鲜有介绍通过.NETObjects作为数据源填充水晶报表的示例。本文将通过两个简单的示例演示水晶报表填充.NetObjects数据源的过程。
示例一:打印学生信息(一个.NETObjects数据源的填充)
示例效果:
Student.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Web;
namespaceCrystalReportsDemo
{
publicclassStudent
{
publicStudent(stringstudentNo,stringstudentName,stringsex,intage)
{
this.StudentNo=studentNo;
this.StudentName=studentName;
this.Sex=sex;
this.Age=age;
}
publicstringStudentNo
{set;get;}
publicstringStudentName
{set;get;}
publicstringSex
{get;privateset;}
publicintAge
{get;privateset;}
}
}
将其编译后,即可通过数据库专家将其作为数据源导入到字段资源管理器。
绘制报表样式并插入数据库字段:
在Default.aspx页面拖入CrystalReportViewer控件:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Default.aspx.cs"Inherits="CrystalReportsDemo._Default"%>
<%@Registerassembly="CrystalDecisions.Web,Version=13.0.2000.0,Culture=neutral,PublicKeyToken=692fbea5521e1304"namespace="CrystalDecisions.Web"tagprefix="CR"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<CR:CrystalReportViewerID="crvReport"runat="server"AutoDataBind="true"/>
</div>
</form>
</body>
</html>
Default.aspx.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
namespaceCrystalReportsDemo
{
publicpartialclass_Default:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
FillReport();
}
privatevoidFillReport()
{
List<Student>studentList=newList<Student>();
studentList.Add(newStudent("200901001","学生一","男",23));
studentList.Add(newStudent("200901002","学生二","男",24));
studentList.Add(newStudent("200901003","学生三","女",22));
studentList.Add(newStudent("200901004","学生四","男",23));
studentList.Add(newStudent("200901005","学生五","女",25));
studentList.Add(newStudent("200901006","学生六","男",23));
CrStudentsstudentsReport=newCrStudents();
studentsReport.SetDataSource(studentList);
crvReport.ReportSource=studentsReport;
}
}
}
示例二:打印学生成绩(多个.NETObjects数据源的填充)
示例效果:
Subject.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Web;
namespaceCrystalReportsDemo
{
publicclassSubject
{
publicSubject(stringsubjectName,stringsubjectType,doubleresult,stringcomment)
{
this.SubjectName=subjectName;
this.SubjectType=subjectType;
this.Result=result;
this.Comment=comment;
}
publicstringSubjectName
{set;get;}
publicstringSubjectType
{set;get;}
publicdoubleResult
{set;get;}
publicstringComment
{set;get;}
}
}
主报表:(CrSupReport.rpt)
子报表:(CrSubReport.rpt)
Default2.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Default2.aspx.cs"Inherits="CrystalReportsDemo.Default2"%>
<%@RegisterAssembly="CrystalDecisions.Web,Version=13.0.2000.0,Culture=neutral,PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web"TagPrefix="CR"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<CR:CrystalReportViewerID="crvReport2"runat="server"AutoDataBind="true"/>
</div>
</form>
</body>
</html>
Default2.aspx.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingCrystalDecisions.CrystalReports.Engine;
namespaceCrystalReportsDemo
{
publicpartialclassDefault2:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
FillReport();
}
privatevoidFillReport()
{
List<Student>studentList=newList<Student>();
studentList.Add(newStudent("200901001","学生一","男",23));
ReportDocumentsupReport=newCrSupReport();
supReport.SetDataSource(studentList);
crvReport2.ReportSource=supReport;
List<Subject>subjectList=newList<Subject>();
subjectList.Add(newSubject("语文","文科",90,"评语"));
subjectList.Add(newSubject("数学","理科",90,"评语"));
subjectList.Add(newSubject("工程学","工科",80,"评语"));
subjectList.Add(newSubject("现代医学","医学",90,"评语"));
ReportDocumentsubReport=supReport.Subreports["CrSubReport"];
subReport.SetDataSource(subjectList);
}
}
}
相关文章推荐
- 在Winform中,获取DataGrid当前选定行对应的数据
- Scott Mitchell 的ASP.NET 2.0数据教程之三十二:: 数据控件的嵌套
- liferay数据类型持久化
- Sqlserver2005与Sqlserver Compact的数据订阅与发布
- SQLServer 2005 海量数据解决方案 分区表
- ACCESS中按日期统计数据
- Hibernate查询视图数据
- 两种实现数据交换的宏定义
- JVM基础概念总结:数据类型、堆与栈
- Shell数据对象(一):数据对象如何工作
- 多年一直想完善的自由行政审批流程组件【2002年PHP,2008年.NET,2010年完善数据设计、代码实现】
- CMCC.IN开放数据接口开发指南
- Access java jdbc连接 insert插入的数据 中文乱码解决方案!!!
- AIDL 2 之 传递复杂数据的AIDL服务
- 说说数据类型转换帮助类
- Hibernate数据查询
- 数据是一种信仰 (转载)
- SQL Server里面导出SQL脚本(表数据的insert语句)
- [asp.net]网站数据安全之验证码
- Struts2 返回JSON数据方法(二)使用JSONObject