如何在Crystal Report中打印主要副本,客户副本和副本

时间:2015-12-06 11:45:48

标签: vb.net crystal-reports crystal-reports-xi

如何首次打印主副本
第二次客户副本
第三次或更多次重复复制

我的要求如下图所示:

Main Copy, Customer Copy, Duplicate Copy

2 个答案:

答案 0 :(得分:0)

在您的代码中

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。

然后,在报告中,创建一个公式字段(我使用的是基本语法)

select case {?paramReportType}
case 1
    formula = "Main Copy"
case 2
    formula = "Customer Copy"
case 3
    formula = "Duplicate Copy"
end select

然后将公式字段添加到报表中,而不是Text对象。

答案 1 :(得分:0)

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

水晶报表公式创建公式名称 paramReportType

Select {?paramReportType}
Case  1 :
    "Main Copy"
Case  2 :
    "Customer Copy"
Default :
    "Duplicate Copy"

点击您的报告位置。