Skip to Content
0
Former Member
Apr 22, 2009 at 03:01 PM

Export to PDF through button press

34 Views

Hi, i have a few intranet sites which print out invoices, credit notes and so on and so forth. They all work great. The user taps an invoice or credit note number in and it generates the report on the crystal report viewer. Great. Now i've been asked if i can bypass the viewer and just enter a invoice number and when they press the button, it will instantly create a pdf for that invoice. So it's kind of cutting out a process. My current code is this and it works fine. How can i alter it by either having the facility to view it on the crystal report viewer and for a Crystal Report to be generated or for me to add a new button which will create the PDF relating to the Invoice number pressed. Please help!

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Net.Mail
Imports System.Net.Mail.Attachment
Partial Class Default2
    Inherits System.Web.UI.Page
    Dim cryRpt As New ReportDocument
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Documents and Settings\xxxxxxxx.xxxxxxxxxxx\My Documents\Visual Studio 2005\WebSites\Invoices\CrystalReport3.rpt")
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue
        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("InvoiceNo")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
        CrystalReportViewer1.ReportSource = cryRpt
        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        myConnectionInfo.DatabaseName = "xxx"
        myConnectionInfo.UserID = "xxxxxxxxx"
        myConnectionInfo.Password = "xxxxxxxx"
        myConnectionInfo.ServerName = "x.x.x.x"
        SetDBLogonForReport(myConnectionInfo)
        CrystalReportViewer1.RefreshReport()
    End Sub
    Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)
        Dim myTableLogOnInfos As TableLogOnInfos = CrystalReportViewer1.LogOnInfo
        For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos
            myTableLogOnInfo.ConnectionInfo = myConnectionInfo
        Next
    End Sub
End Class