ASP.NET(VB.NET)网页中输出水晶报表


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            '1.创建报表文件
            Dim myReport As ReportDocument = New ReportDocument()
            '2.取到报表文件的物理路径
            Dim reportPath As String = Server.MapPath("~/RES/secCheckReport.rpt")
            '3.加载报表文件
            myReport.Load(reportPath)
            ''准备报表数据源
            Dim dtScdPrint As DataTable = SecCheckDec.dtScd
            '4自定义报表头部所需要的参数
            Dim vOpeAgtName As String = ""
            Dim vAwbAgtName As String = ""
            Dim vAwbNo As String = ""
            Dim vDate As String = ""
            Dim vQualification As String = ""
            If dtScdPrint.Rows.Count > 0 Then ''打印时只能打印指定运单号的安检申报清单,故取第一条记录获取其中的信息
                Dim rowScd As DataRow = dtScdPrint.Rows(0)
                vOpeAgtName = SafeString(rowScd.Item("HANDLEAGTNAME"), "")
                vAwbAgtName = SafeString(rowScd.Item("OWNERAGTNAME"), "")
                vAwbNo = rowScd.Item("AWBPFX") + "-" + rowScd.Item("AWBNUM")
                vDate = DateTime.Now.ToString("yyyy-MM-dd")
                vQualification = ""
            End If
            '5将定义好的报表头参数传入报表
            '5.1定义ParameterFields
            Dim paramfields As ParameterFields = New ParameterFields()

            '5.2设置在报表中,将要接受参数字段的名称
            Dim pfHash As Hashtable = New Hashtable
            pfHash.Add("strOpeAgtName", vOpeAgtName)
            pfHash.Add("strAwbAgtName", vAwbAgtName)
            pfHash.Add("strAwbNo", vAwbNo)
            pfHash.Add("strDate", vDate)
            pfHash.Add("strQualification", vQualification)
            For Each item As System.Collections.DictionaryEntry In pfHash
                Dim paramfield As ParameterField = New ParameterField()
                Dim p_arg As ParameterDiscreteValue = New ParameterDiscreteValue()
                paramfield.ParameterFieldName = item.Key.ToString()
                p_arg.Value = item.Value.ToString()
                paramfield.CurrentValues.Add(p_arg)
                paramfields.Add(paramfield)
            Next

            '6.将参数集合绑定到报表浏览控件
            Me.CrystalReportViewer1.ParameterFieldInfo = paramfields
            '7.为报表设置新的数据源
            myReport.SetDataSource(SecCheckDec.dtScd)
            '8.将创建你的新的报表文档绑定
            Me.CrystalReportViewer1.ReportSource = myReport
            Me.CrystalReportViewer1.DataBind()

        Catch ex As Exception
            Call (New CargoException("", ex)).AppendToLog()
        End Try
    End Sub
End Class

posted on 2013-09-11 13:48  麦克斯韦科思  阅读(286)  评论(0编辑  收藏  举报