如何以编程方式生成 Crystal Reports 的多个副本(详细信息部分)? [英] How can I programmatically produce multiple copies of Crystal Reports (Details Section)?

查看:24
本文介绍了如何以编程方式生成 Crystal Reports 的多个副本(详细信息部分)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,它要求用户输入数字,并根据输入执行 SQL 查询,然后获取结果以填充 Crystal Reports 页面.以下是搜索数据库并填写报告的代码:(为简单起见,我删除了很多不会为问题增加价值的查询字符串,水晶报表字段也是如此)

I have a web page that asks the user for an input number and based on the input, an SQL query is executed and the results is then fetched to fill a Crystal Reports page. Here is the code that searches the database and fills the report: (For simplicity, I removed a lot of query string that does not add value to the question, same goes for Crystal Reports fields)

Dim sql As String = ""
sql = " SELECT * from table1 where input_id = '" & INPUT_NUMBER & "'"

Dim ds As DataSet = getTable(sql)
Dim orpt As New CrystalReport3
CrystalReportViewer1.ReportSource = orpt
orpt.DataDefinition.FormulaFields("fldMaterialID").Text = """" & ds.Tables(0).Rows(0).Item("MATERIAL_ID").ToString & """"
orpt.DataDefinition.FormulaFields("fldMaterialID2").Text = """" & ds.Tables(0).Rows(0).Item("MATERIAL_ID").ToString & """"
orpt.DataDefinition.FormulaFields("fldBar").Text = """" & ds.Tables(0).Rows(0).Item("MATERIAL_ID_BAR_CODE").ToString & """"
orpt.Refresh()

我试图允许用户查看报告的多个副本.我已经试过了:

I am trying to allow the user to view multiple copies of the report. I already tried:

 orpt.PrintToPrinter(2, False, 0, 1)

但这没有用.我进行了搜索,但我得到的所有解决方案都与带有已保存查询的 Crystal Reports 相关,这对我来说不是一个选择.

But that did not work. I searched, but all the solutions I got were related to Crystal Reports with Saved Queries which is not an option for me.

推荐答案

我终于做到了.

对于那些想知道如何做,或者想获得更好的 StackOverFlow.com 体验的人,我很高兴分享解决方案.

For those who would like to know how, or for a better StackOverFlow.com experience, I am glad to share the solution.

在阅读了这篇很棒的文章后,我被受到解决方案的启发,并能够通过

After reading this great article, I was inspired by the solution and was able to accomplish the desired result by

1-用包含相同列数的ADO数据集替换FormulaFields为此,我在 VS.2008 中创建了一个新的 DataSet,并将其命名为 adoDataSet.然后将所有需要的列名添加到其中(此时没有链接到实际数据,因为数据将在以后动态拉取.这就像数据模板一样).默认情况下,所有列都是 String 类型的,但对我来说没问题.

1-Replacing the FormulaFields with an ADO dataset containing the same number of columns I did that by creating a new DataSet in VS.2008 and named it adoDataSet. Then added all required column names to it (No linking to the actual data at this point as the data will be pulled dynamically later. This is just like a template for the data only). By default, all columns will be String typed, but that okay for my case.

3- 在 Crystal Reports 中,我使用 DataBase Expert 将提到的数据集拉入报表,并用 adoDataSet 中的列替换公式字段的位置

3- In Crystal Reports, I used DataBase Expert to pull the mentioned dataset into the report and replaced the locations of the formula fields with the columns from the adoDataSet

4- 然后在我的代码中用数据填充公式字段,我只是调用了相同的函数,该函数接受 SQL 查询并返回一个普通的 OracleClient 数据集(因此它可能会根据需要返回多行)

4- Then in my code to populate the formulafields with data, I just called the same function that takes an SQL query and returns a normal OracleClient data set (so it might return multiple rows as desired)

5- 但是,此数据集不能直接用于 Crystal Reports,因此必须先将其转换为与之前创建的 adoDataSet 相同的类型.所以一个简单的 TryCast 为我做到了.

5- This dataset however can not be used directly with Crystal Reports, so it must be first converted to the same type of the adoDataSet created earlier. so a simple TryCast did that for me.

Dim sql As String = ""
sql = " SELECT * from table1 where input_id = '" & INPUT_NUMBER & "'"

Dim ds As DataSet = getTable(sql)
Dim orpt As New CrystalReport3
CrystalReportViewer1.ReportSource = orpt
dim ds1 as New adoDataSet
ds1 = TryCast(ds,adoDataSet)   ' ds is based on OracleClient data set
                        ' while adoDataSet is the one CrystalReports likes to use
orpt.SetDataSource(ds1)

从那里我能够生成任意数量的副本,因为我拥有数据,并且可以使数据出现任意多次.

from there I was able to generate as much copies as I wanted because I own the data, and can cause the data to appear as many times as I like.

这篇关于如何以编程方式生成 Crystal Reports 的多个副本(详细信息部分)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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