您的位置:首页 > 移动开发 > Objective-C

水晶报表填充.Net Objects数据源

2014-04-23 23:37 375 查看
CrystalReports(水晶报表)是一款商务智能(BI)软件,主要用于设计及产生报表。是业内最专业、功能最强的报表系统。

查看网络资料及课本图书,鲜有介绍通过.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);




}


}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: