使用Crystal Reports在Visual Studio 2005(C#.NET Windows应用程序) [英] Using Crystal Reports in Visual Studio 2005 (C# .NET Windows App)

查看:142
本文介绍了使用Crystal Reports在Visual Studio 2005(C#.NET Windows应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建立一个C#.NET Windows应用程序的报告。我有一个SQL Server 2005数据库,Visual Studio 2005和我与创建存储过程和数据集相当确定。

I need to create reports in a C# .NET Windows app. I've got an SQL Server 2005 database, Visual Studio 2005 and am quite OK with creating stored procedures and datasets.

有人能请点我在正确的方向,用于创建报告?我好像不能做出来。一些例子将是一个良好的开端,还是一个简单的操作方法教程......什么真正的好一点比MSDN文档解释了。

Can someone please point me in the right direction for creating reports? I just can't seem work it out. Some examples would be a good start, or a simple How-to tutorial... anything really that is a bit better explained than the MSDN docs.

我使用在CrystalDecisions.Windows.Forms.CrystalReportViewer控件来显示报告,我相信这是正确的。

I'm using the CrystalDecisions.Windows.Forms.CrystalReportViewer control to display the reports, I presume this is correct.

如果我即将踏上一个漫长而复杂的旅程,有什么最简单的方法来创建和也可以打印显示的报告吗?

If I'm about to embark on a long and complex journey, what's the simplest way to create and display reports that can also be printed?

推荐答案

我已成功地完成这项工作了。

I have managed to make this work now.

简要概述

它的工作原理有一个'数据类',这仅仅是一个包含变量,没有代码的常规的C#类。这则实例化和填充数据,然后放在一个ArrayList中。 ArrayList的绑定到报表查看器,该报告的名称一起加载。在报表设计器'.NET对象'的使用,而不是与数据库进行通信。

It works by having a 'data class' which is just a regular C# class containing variables and no code. This is then instantiated and filled with data and then placed inside an ArrayList. The ArrayList is bound to the report viewer, along with the name of the report to load. In the report designer '.Net Objects' are used, rather than communicating with the database.

说明

我创建了一个类来保存数据,我的报告。这个类是从数据库中检索人工手动的数据填补了我。如何你这并不重要,但这里有一个例子:

I created a class to hold the data for my report. This class is manually filled by me by manually retrieving data from the database. How you do this doesn't matter, but here's an example:

DataSet ds = GeneratePickingNoteDataSet(id);
foreach (DataRow row in ds.Tables[0].Rows) {
    CPickingNoteData pickingNoteData = new CPickingNoteData();

    pickingNoteData.delivery_date = (DateTime)row["delivery_date"];
    pickingNoteData.cust_po = (int)row["CustomerPONumber"];
    pickingNoteData.address = row["CustomerAddress"].ToString();
    // ... and so on ...

    rptData.Add(pickingNoteData);
}



该类然后把一个ArrayList中。 ArrayList中的每个元素对应于完成的报表一行row。

The class is then put inside an ArrayList. Each element in the arraylist corresponds to one 'row' in the finished report.

在列表中的第一个元素还可以容纳报告标题数据,并在最后一个元素列表中可容纳的报告脚注数据。因为这是一个ArrayList,正常的数组访问可以被用来针对他们:

The first element in the list can also hold the report header data, and the last element in the list can hold the report footer data. And because this is an ArrayList, normal Array access can be used to get at them:

((CPickingNoteData)rptData[0]).header_date = DateTime.Now;
((CPickingNoteData)rptData[rptData.Count-1]).footer_serial = GenerateSerialNumber();



一旦你有一个ArrayList充分的数据,将其绑定到你的报表查看器这样的,其中rptData 的类型为ArrayList的

Once you have an arraylist full of data, bind it to your report viewer like this, where 'rptData' is of type 'ArrayList'

ReportDocument reportDoc = new ReportDocument();
reportDoc.Load(reportPath);
reportDoc.SetDataSource(rptData);
crystalReportViewer.ReportSource = reportDoc;

现在,你需要将你的数据类绑定到报告本身。你这样做设计师里面:

Now you will need to bind your data class to the report itself. You do this inside the designer:


  1. 打开字段资源管理器选项卡(这可能是查看菜单下),然后右键单击数据库字段

  2. 点击项目数据

  3. 单击上'.NET对象'

  4. 向下滚动列表找到你的
    数据类(如果它不存在,
    编译应用程序)

  5. 按>>,然后确定

  6. 现在,您可以拖动类成员
    到报表,并安排他们为
    你想要的。

  1. Open the Field Explorer tab (which might be under the 'View' menu), and right-click "Database Fields"
  2. Click on 'Project Data'
  3. Click on '.NET Objects'
  4. Scroll down the list to find your data class (if it isn't there, compile your application)
  5. Press '>>' and then OK
  6. You can now drag the class members onto the report and arrange them as you want.

这篇关于使用Crystal Reports在Visual Studio 2005(C#.NET Windows应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆