水晶报表填充.Net Objects数据源
Crystal Reports(水晶报表)是一款商务智能(BI)软件,主要用于设计及产生报表。是业内最专业、功能最强的报表系统。
查看网络资料及课本图书,鲜有介绍通过.NET Objects作为数据源填充水晶报表的示例。本文将通过两个简单的示例演示水晶报表填充.Net Objects数据源的过程。
示例一:打印学生信息(一个.NET Objects数据源的填充)
示例效果:

Student.cs
using System;
using System.Collections.Generic;
using System.Web;
namespace CrystalReportsDemo
{
public class Student
{
public Student(string studentNo,string studentName,string sex,int age)
{
this.StudentNo = studentNo;
this.StudentName = studentName;
this.Sex = sex;
this.Age = age;
}
public string StudentNo
{ set; get; }
public string StudentName
{ set; get; }
public string Sex
{ get; private set; }
public int Age
{ get; private set; }
}
}
将其编译后,即可通过数据库专家将其作为数据源导入到字段资源管理器。

绘制报表样式并插入数据库字段:

在Default.aspx页面拖入CrystalReportViewer控件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CrystalReportsDemo._Default" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="crvReport" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CrystalReportsDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillReport();
}
private void FillReport()
{
List<Student> studentList = new List<Student>();
studentList.Add(new Student("200901001", "学生一", "男", 23));
studentList.Add(new Student("200901002", "学生二", "男", 24));
studentList.Add(new Student("200901003", "学生三", "女", 22));
studentList.Add(new Student("200901004", "学生四", "男", 23));
studentList.Add(new Student("200901005", "学生五", "女", 25));
studentList.Add(new Student("200901006", "学生六", "男", 23));
CrStudents studentsReport = new CrStudents();
studentsReport.SetDataSource(studentList);
crvReport.ReportSource = studentsReport;
}
}
}
示例二:打印学生成绩(多个.NET Objects数据源的填充)
示例效果:

Subject.cs
using System;
using System.Collections.Generic;
using System.Web;
namespace CrystalReportsDemo
{
public class Subject
{
public Subject(string subjectName,string subjectType,double result,string comment)
{
this.SubjectName = subjectName;
this.SubjectType = subjectType;
this.Result = result;
this.Comment = comment;
}
public string SubjectName
{ set; get; }
public string SubjectType
{ set; get; }
public double Result
{ set; get; }
public string Comment
{ set; get; }
}
}
主报表:(CrSupReport.rpt)

子报表:(CrSubReport.rpt)

Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="CrystalReportsDemo.Default2" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="crvReport2" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
</html>
Default2.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalReportsDemo
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillReport();
}
private void FillReport()
{
List<Student> studentList = new List<Student>();
studentList.Add(new Student("200901001", "学生一", "男", 23));
ReportDocument supReport = new CrSupReport();
supReport.SetDataSource(studentList);
crvReport2.ReportSource = supReport;
List<Subject> subjectList = new List<Subject>();
subjectList.Add(new Subject("语文","文科",90,"评语"));
subjectList.Add(new Subject("数学", "理科", 90, "评语"));
subjectList.Add(new Subject("工程学", "工科", 80, "评语"));
subjectList.Add(new Subject("现代医学", "医学", 90, "评语"));
ReportDocument subReport = supReport.Subreports["CrSubReport"];
subReport.SetDataSource(subjectList);
}
}
}
水晶报表填充.Net Objects数据源的更多相关文章
- MS SQL自定义函数IsPositiveInteger MS SQL自定义函数IsNumeric 水晶报表使用IEnumerable<T>数据源
MS SQL自定义函数IsPositiveInteger 判断字符串是否为正整数,0开始的的数字不算. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...
- 水晶报表使用IEnumerable<T>数据源
这篇我们学习水晶报表,报表呈现的数据源是IEnumerable<T>.比如下面的数据: using System; using System.Collections.Generic; us ...
- WinForm中使用CrystalReport水晶报表——基础,分组统计,自定义数据源
开篇 本篇文章主要是帮助刚开始接触CrystalReport报表的新手提供一个循序渐进的教程.该教程主要分为三个部分1)CrystalReport的基本使用方法:2)使用CrystalReport对数 ...
- c# 水晶报表的设计(非常的基础)
最近在公司实习,由于公司需要用到的一种叫做水晶报表的神奇的东东,老大就叫我们学习学习.怕自己以后忘了,也为了以后阅读方便,将其记录下来. 使用工具:vs2008 基本方法一.使用水晶报表的推模式 步骤 ...
- 水晶报表(web)表格信息展示
一.环境安装 开发工具使用VS2010+SAP Crystal Reports13_0+.NETformwork4.0 因为vs2010已经不再集成水晶报表,所以需要我们去找合适的版本下载http:/ ...
- asp.net实现通用水晶报表
此片博文是在你有一定水晶报表基础的前提下参阅的:如果对于水晶报表的基础知识比较薄弱建议先去了解下水晶报表: 因为项目需要,研究了下水晶报表.说实在,这个组件很强大,但是用起来也很麻烦.刚开始使用遇到了 ...
- 水晶报表初体验(Visual Studio 2010)
安装水晶报表后如下使用: 配置rpt文件,如图 前台(Asp.net页面): <%@ Register Assembly="CrystalDecisions.Web, Version= ...
- 水晶报表连接Oracle做数据报表笔记
首先,新建一个水晶报表的文件,这个时候要给这个报表文件绑定一个oracle数据源, 选择右侧菜单的这个东西,选择“数据库专家”,打开之后是这么一个界面: 选择建立新连接: 这个地方最关键,也是我为什么 ...
- 用C#代码控制水晶报表中的对象
在C#代码中调用水晶报表的各个对象:字段对象:FieldObject obj=(FieldObject)oRpt.ReportDefinition.ReportObjects["FieldO ...
随机推荐
- Windows系统Ionic安装教程/Ionic环境配置
原文链接:http://blog.csdn.net/superjunjin/article/details/43412017 参考文章 Cordova 3.x 基础(1) -- 环境搭建(Window ...
- 教你轻松计算AOE网关键路径
认识AOE网 有向图中,用顶点表示活动,用有向边表示活动之间开始的先后顺序,则称这种有向图为AOV网络:AOV网络可以反应任务完成的先后顺序(拓扑排序). 在AOV网的边上加上权值表示完成该活动所需的 ...
- app_offline.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DT ...
- angularjs中templateUrl的路径问题
angularjs中templateUrl的路径问题 templateUrl的相对路径是现对于app主页面的,因为template使用js来加载的.
- Payment相关逻辑
payment相关逻辑 付款有手动付款和计划程序自动付款两种,照例先列出涉及到的概念 付款方式 - PaymentTypes - 现金,支票,信用卡,等等 记账类型 - Ledger_AccTrans ...
- 一次dns缓存引发的慘案
时间2015年的某个周六凌晨5点,公司官方的QQ群实用户反馈官网打不开了,但有的用户反馈能够打开.客服爬起来自己用电脑试了一下没有问题,就给客户反馈说.可能是自己网络的问题,请过会在试试.早点8点,越 ...
- 【C#】Excel导出合并行和列并动态加载行与列
简单的Excel导出比较好做,只要设置表头,循环在表格中赋值添加数据即可,但是如果表头是不固定的,并且个数是不确定的,这就需要根据查询出数据的特点来添加导出了. 导出效果图: 如上图所示,商品的个数是 ...
- Kinect2.0获取关节姿态(Joint Orientation)
Bones Hierarchy 骨骼层次结构从SpineBase作为根节点开始,一直延伸到肢体末端(头.指尖.脚): 层级结构如下图所示: 通过IBody::GetJointOrientations函 ...
- 简单的BSON OID生成实现
简单的OID生成测试实现,只是简单的用用,切勿用于生产环境. /* 应该使用大端序的,这里没有做转换 * ObjectId是12-byte BSON类型,其结构为: * * 4-byte 值为Unix ...
- spark rdd Transformation和Action 剖析
1.看到 这篇总结的这么好, 就悄悄的转过来,供学习 wordcount.toDebugString查看RDD的继承链条 所以广义的讲,对任何函数进行某一项操作都可以认为是一个算子,甚至包括求幂次,开 ...