pull、push模式的Report应用

     Public  crReportDocument  As  CrystalDecisions.CrystalReports.Engine.ReportDocument    ' '/表表的名称
     Public  crExportOptions  As  CrystalDecisions.Shared.ExportOptions
    
Protected   WithEvents  CrystalReportViewer1  As  CrystalDecisions.Web.CrystalReportViewer
    
Public  crDiskFileDestinationOptions  As  CrystalDecisions.Shared.DiskFileDestinationOptions

    
Private   Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
'在此处放置初始化页的用户代码
        '''Pull 模式
        Me.DataBind()
    
End Sub


    
Private   Sub 打印_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打印.Click

        
If Me.DropDownList1.SelectedValue <> "Portable Document (PDF)" Then
            Exportxls()
        
Else
            Exporpdf()
        
End If

    
End Sub

    
Function Exportxls()
        crReportDocument 
= New ReportCustomers

        crDiskFileDestinationOptions 
= New CrystalDecisions.Shared.DiskFileDestinationOptions
        crDiskFileDestinationOptions.DiskFileName 
= "d: empexported.xls"

        crExportOptions 
= crReportDocument.ExportOptions
        crExportOptions.DestinationOptions 
= crDiskFileDestinationOptions
        crExportOptions.ExportDestinationType 
= CrystalDecisions.[Shared].ExportDestinationType.DiskFile
        crExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.Excel
        crReportDocument.Export()

    
End Function


    
Function Exporpdf()
        crReportDocument 
= New ReportCustomers

        crDiskFileDestinationOptions 
= New CrystalDecisions.Shared.DiskFileDestinationOptions
        
Select Case (DropDownList1.SelectedItem.Text)

            
Case "Portable Document (PDF)"
                crDiskFileDestinationOptions.DiskFileName 
= "d: empexported.pdf"
                crReportDocument.ExportOptions.ExportDestinationType 
= CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                crReportDocument.ExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
                crReportDocument.ExportOptions.DestinationOptions 
= crDiskFileDestinationOptions
                crReportDocument.Export()

            
Case "Rich Text (RTF)"
                crExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.RichText
                crDiskFileDestinationOptions.DiskFileName 
= "d:demo.rtf"

            
Case "MS Word (DOC)"
                crExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.WordForWindows
                crDiskFileDestinationOptions.DiskFileName 
= "d:demo.doc"

            
Case "MS Excel (XLS)"
                crExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.Excel
                crDiskFileDestinationOptions.DiskFileName 
= "d:demo.xls"
        
End Select

    
End Function
 
      Public  myReport  As   New  CrystalDecisions.CrystalReports.Engine.ReportDocument    ' '/表表的名称

    
Private   Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
'在此处放置初始化页的用户代码
        BindReport()
    
End Sub


  
Sub BindReport()

        
Dim myConnection As New SqlClient.SqlConnection

        myConnection.ConnectionString 
= "workstation id=""ATDG-IS-2000"";packet size=4096;user id=sa;data source=""ATDG-IS-20" & _
        
"00"";persist security info=False;initial catalog=Northwind;password=sa"

        
Dim MyCommand As New SqlClient.SqlCommand

        MyCommand.Connection 
= myConnection

        MyCommand.CommandText 
= "Select * from Customers"

        MyCommand.CommandType 
= CommandType.Text

        
Dim MyDA As New SqlClient.SqlDataAdapter

        MyDA.SelectCommand 
= MyCommand

        
Dim myDS As New DatasetCustomers

        
'这就是我们在设计模式上使用的DataSet 

        MyDA.Fill(myDS, 
"Customers")

        
'你不得不使用与你前面DataSet相同名字。 

        
Dim oRpt As New pusReportCustomers

        
' 水晶报表绑定 

        oRpt.SetDataSource(myDS)
        
' 设定水晶报表的ReportSource 

        CrystalReportViewer1.ReportSource 
= oRpt

    
End Sub

    
Private   Sub 导出_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 导出.Click


        
Dim DiskOpts As New CrystalDecisions.Shared.DiskFileDestinationOptions
        myReport.ExportOptions.ExportDestinationType 
= CrystalDecisions.Shared.ExportDestinationType.DiskFile
        
Select Case (DropDownList1.SelectedItem.Text)

            
Case "Rich Text (RTF)"
                myReport.ExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.RichText
                DiskOpts.DiskFileName 
= "d:demo.rtf"

            
Case "Portable Document (PDF)"
                myReport.ExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
                DiskOpts.DiskFileName 
= "d:demo.pdf"

            
Case "MS Word (DOC)"
                myReport.ExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.WordForWindows
                DiskOpts.DiskFileName 
= "d:demo.doc"

            
Case "MS Excel (XLS)"
                myReport.ExportOptions.ExportFormatType 
= CrystalDecisions.Shared.ExportFormatType.Excel
                DiskOpts.DiskFileName 
= "d:demo.xls"
        
End Select
        myReport.ExportOptions.DestinationOptions 
= DiskOpts
        myReport.Export()


    
End Sub


    
Private   Sub 打印_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打印.Click

    
End Sub

你可能感兴趣的:(pull、push模式的Report应用)