如何在 Crystal 报告中打印主副本、客户副本和副本
How to print main, customer and duplicate copy in Crystal Report
如何打印第一次主副本
第二次客户复制
第三次或更多次重复复制
我的要求如下图:
在你的代码中
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load("<report name>")
rpt.SetDataSource(your datasource)
For reportType As Integer = 1 To 3
rpt.SetParameterValue("paramReportType", reportType)
' show your report in a dialog window
ShowReport(rpt)
Next
Public Sub ShowReport(ByRef oRpt As Object)
Using frm As New ReportViewer
With frm
.Icon = frmMain.Icon
.Report = oRpt
.ShowDialog()
End With
End Using
End Sub
ReportViewer 表单内部(带有 1 个名为 crv 的 CrystalReportViewer 控件)
Public Class ReportViewer
Dim oReport As Object
Public WriteOnly Property Report() As Object
Set(ByVal value As Object)
oReport = value
End Set
End Property
Private Sub ReportViewer_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Me.Cursor = Cursors.WaitCursor
crv.ReportSource = oRpt
Catch ex As Exception
Msgbox(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
End Class
在您的报表中,创建一个名为 paramReportType 且类型为 Number 的参数值。
然后,同样在您的报告中,创建一个公式字段(我使用的是 Basic 语法)
select case {?paramReportType}
case 1
formula = "Main Copy"
case 2
formula = "Customer Copy"
case 3
formula = "Duplicate Copy"
end select
然后将公式字段添加到报表中,而不是文本对象。
VB代码
首先导入
Imports System.Web.UI.WebControls
Public Sub ShowReport(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal filterstring As String, ByVal CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer)
Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim myTable As Table
For Each myTable In MyReport.Database.Tables
myLogonInfo = myTable.LogOnInfo
'myLogonInfo.ConnectionInfo.ServerName = Application.StartupPath & "\" & "data.mdb"
myLogonInfo.ConnectionInfo.ServerName = My.Settings.RptserverPath.ToString
myLogonInfo.ConnectionInfo.DatabaseName = My.Settings.Database.ToString
myLogonInfo.ConnectionInfo.UserID = My.Settings.DBUser.ToString
myLogonInfo.ConnectionInfo.Password = My.Settings.DBPass.ToString
myTable.ApplyLogOnInfo(myLogonInfo)
Next myTable
End Sub
Private Sub SimpleButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton4.Click
For reportType As Integer = 1 To 3
Dim MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New RecipeWithOutCostingSheet
MyReport.SetParameterValue("paramReportType", reportType)
PrintReport(MyReport, filterstring, CrystalReportViewer1, PrintDialog1)
Next
End Sub
Crystal 报表公式创建 公式名称paramReportType
Select {?paramReportType}
Case 1 :
"Main Copy"
Case 2 :
"Customer Copy"
Default :
"Duplicate Copy"
写上你的举报地点。
如何打印第一次主副本
第二次客户复制
第三次或更多次重复复制
我的要求如下图:
在你的代码中
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load("<report name>")
rpt.SetDataSource(your datasource)
For reportType As Integer = 1 To 3
rpt.SetParameterValue("paramReportType", reportType)
' show your report in a dialog window
ShowReport(rpt)
Next
Public Sub ShowReport(ByRef oRpt As Object)
Using frm As New ReportViewer
With frm
.Icon = frmMain.Icon
.Report = oRpt
.ShowDialog()
End With
End Using
End Sub
ReportViewer 表单内部(带有 1 个名为 crv 的 CrystalReportViewer 控件)
Public Class ReportViewer
Dim oReport As Object
Public WriteOnly Property Report() As Object
Set(ByVal value As Object)
oReport = value
End Set
End Property
Private Sub ReportViewer_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Me.Cursor = Cursors.WaitCursor
crv.ReportSource = oRpt
Catch ex As Exception
Msgbox(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
End Class
在您的报表中,创建一个名为 paramReportType 且类型为 Number 的参数值。
然后,同样在您的报告中,创建一个公式字段(我使用的是 Basic 语法)
select case {?paramReportType}
case 1
formula = "Main Copy"
case 2
formula = "Customer Copy"
case 3
formula = "Duplicate Copy"
end select
然后将公式字段添加到报表中,而不是文本对象。
VB代码
首先导入
Imports System.Web.UI.WebControls
Public Sub ShowReport(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal filterstring As String, ByVal CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer)
Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim myTable As Table
For Each myTable In MyReport.Database.Tables
myLogonInfo = myTable.LogOnInfo
'myLogonInfo.ConnectionInfo.ServerName = Application.StartupPath & "\" & "data.mdb"
myLogonInfo.ConnectionInfo.ServerName = My.Settings.RptserverPath.ToString
myLogonInfo.ConnectionInfo.DatabaseName = My.Settings.Database.ToString
myLogonInfo.ConnectionInfo.UserID = My.Settings.DBUser.ToString
myLogonInfo.ConnectionInfo.Password = My.Settings.DBPass.ToString
myTable.ApplyLogOnInfo(myLogonInfo)
Next myTable
End Sub
Private Sub SimpleButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton4.Click
For reportType As Integer = 1 To 3
Dim MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New RecipeWithOutCostingSheet
MyReport.SetParameterValue("paramReportType", reportType)
PrintReport(MyReport, filterstring, CrystalReportViewer1, PrintDialog1)
Next
End Sub
Crystal 报表公式创建 公式名称paramReportType
Select {?paramReportType}
Case 1 :
"Main Copy"
Case 2 :
"Customer Copy"
Default :
"Duplicate Copy"
写上你的举报地点。