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数据源的更多相关文章

  1. MS SQL自定义函数IsPositiveInteger MS SQL自定义函数IsNumeric 水晶报表使用IEnumerable<T>数据源

    MS SQL自定义函数IsPositiveInteger   判断字符串是否为正整数,0开始的的数字不算. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...

  2. 水晶报表使用IEnumerable<T>数据源

    这篇我们学习水晶报表,报表呈现的数据源是IEnumerable<T>.比如下面的数据: using System; using System.Collections.Generic; us ...

  3. WinForm中使用CrystalReport水晶报表——基础,分组统计,自定义数据源

    开篇 本篇文章主要是帮助刚开始接触CrystalReport报表的新手提供一个循序渐进的教程.该教程主要分为三个部分1)CrystalReport的基本使用方法:2)使用CrystalReport对数 ...

  4. c# 水晶报表的设计(非常的基础)

    最近在公司实习,由于公司需要用到的一种叫做水晶报表的神奇的东东,老大就叫我们学习学习.怕自己以后忘了,也为了以后阅读方便,将其记录下来. 使用工具:vs2008 基本方法一.使用水晶报表的推模式 步骤 ...

  5. 水晶报表(web)表格信息展示

    一.环境安装 开发工具使用VS2010+SAP Crystal Reports13_0+.NETformwork4.0 因为vs2010已经不再集成水晶报表,所以需要我们去找合适的版本下载http:/ ...

  6. asp.net实现通用水晶报表

    此片博文是在你有一定水晶报表基础的前提下参阅的:如果对于水晶报表的基础知识比较薄弱建议先去了解下水晶报表: 因为项目需要,研究了下水晶报表.说实在,这个组件很强大,但是用起来也很麻烦.刚开始使用遇到了 ...

  7. 水晶报表初体验(Visual Studio 2010)

    安装水晶报表后如下使用: 配置rpt文件,如图 前台(Asp.net页面): <%@ Register Assembly="CrystalDecisions.Web, Version= ...

  8. 水晶报表连接Oracle做数据报表笔记

    首先,新建一个水晶报表的文件,这个时候要给这个报表文件绑定一个oracle数据源, 选择右侧菜单的这个东西,选择“数据库专家”,打开之后是这么一个界面: 选择建立新连接: 这个地方最关键,也是我为什么 ...

  9. 用C#代码控制水晶报表中的对象

    在C#代码中调用水晶报表的各个对象:字段对象:FieldObject obj=(FieldObject)oRpt.ReportDefinition.ReportObjects["FieldO ...

随机推荐

  1. SQL与SQL Server

    SQL--关系数据库的国际标准语言. SQL Server--著名的数据库管理系统.其他著名的数据库管理系统还有Oracle.Sybase等,它们都实现了SQL语言.   在SQL中,完成所有核心功能 ...

  2. Python两个变量的值进行交换的方法

    Python两个变量的值进行交换的方法 使用第三方变量: '''这是第一种赋值方法,采用第三方变量''' c = a a = b b = c 使用两个变量: '''使用两个变量''' a = a+b ...

  3. 记:青岛理工ACM交流赛筹备工作总结篇

    这几天筹备青岛理工ACM交流赛的过程中遇到了不少问题也涨了不少经验.对非常多事也有了和曾经不一样的看法, ​一直在想事后把这几天的流水帐记一遍,一直没空直到今天考完C++才坐下来開始动笔.将这几天的忙 ...

  4. python在linux的报错集锦

    1. 报错提示 /usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 ...

  5. eclipse mavenWeb项目真正实现热部署(修改java代码和页面文件不用重启tomcat)

            1.前言 首先,本文创作灵感源于博客园园作者signheart,特此鸣谢!原文链接见文末推荐: 百度都搜破了,全网讲的都是如何将maven项目部署到tomcat上,对于热部署的认知,真 ...

  6. 【Linux】条件判断eq、ne、gt、lt、ge、le

    整数比较: -eq(equal) 相等 -ne(inequality) 不相等 -gt(greater than) 大于 -lt(less than) 小于 -ge(greater equal) 大于 ...

  7. 转载:mysql添加用户、删除用户、授权、修改密码

    mysql添加用户.删除用户.授权.修改密码等 MySql中添加用户,新建数据库,用户授权,删除用户,修改密码1.新建用户. //登录MYSQL @>mysql -u root -p @> ...

  8. 使用PHP做移动端 api接口开发方法(适用于TP框架)

    1. [代码]使用TP框架时 放在common文件夹下文件名就叫function.php ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...

  9. 工欲善其事,必先利其器 软件工具开发关键词 protractor自动化测试工具 RegexBuddy正则 CodeSmith,LightSwitch:代码生成 CheatEngine:玩游戏修改内存值必备神器 ApkIDE:Android反编译工具 Reflector:反编译dll动态链接库

    工欲善其事,必先利其器 本文版权归翟士丹(Stan Zhai)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利. 原文地址:http ...

  10. linux c学习笔记----线程创建与终止

    进程原语 线程原语 描述 fork pthread_create 创建新的控制流 exit pthread_exit 从现有的控制流中退出 waitpid pthread_join 从控制流中得到退出 ...