Private Function PrintCertificate(ByVal lngCertificateID As Long) As Boolean
Dim myReport As New ReportDocument
Dim myDS As New Data.DataSet
Dim myDataSet As New dsCertificate
Dim myDataTable As Data.DataTable
Dim params(0) As SqlClient.SqlParameter
Dim strReportPath As String
Dim margins As PageMargins
Try
params(0) = New SqlClient.SqlParameter("@CertificateID", lngCertificateID)
'First update the Date Printed field of the certificate
SqlHelper.ExecuteScalar(General.ConnectionString, CommandType.StoredProcedure, "op_Certficate_Print", params)
myDataTable = SqlHelper.ExecuteDataset(General.ConnectionString, CommandType.StoredProcedure, "op_Certificate_Info", params).Tables(0).Copy
myDataSet.Tables.Add(myDataTable)
If Not General.ReportPath.Substring(General.ReportPath.Length - 1) = "\" Then
strReportPath = General.ReportPath.ToString & "\"
Else
strReportPath = General.ReportPath.ToString
End If
If General.CertificateReportName Is Nothing Then
MessageBox.Show("You must set the certificate report to print.", "Report Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Hand)
Dim frmPrinterOptions As New frmSetDefaultPrinter
frmPrinterOptions.ShowDialog()
Else
If General.CertificateReportName.Substring(General.CertificateReportName.Length - 4) = ".rpt" Then
strReportPath = strReportPath & General.CertificateReportName
Else
strReportPath = strReportPath & General.CertificateReportName & ".rpt"
End If
If Not IO.File.Exists(strReportPath) Then
MessageBox.Show("The file " & strReportPath & " does not exist. Please contact technical support.", "File Does Not Exist", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
myReport.Load(strReportPath)
myReport.SetDataSource(myDataSet.Tables(0))
myReport.PrintOptions.PrinterName = General.CertPrinter
' Get the PageMargins structure and set the
' margins for the report.
margins = myReport.PrintOptions.PageMargins
margins.topMargin = General.CertificateTopMargin
margins.bottomMargin = General.CertificateBottomMargin
margins.leftMargin = General.CertificateLeftMargin
margins.rightMargin = General.CertificateRightMargin
' Apply the page margins.
myReport.PrintOptions.ApplyPageMargins(margins)
If General.CertificateLandscape = True Then
myReport.PrintOptions.PaperOrientation = PaperOrientation.Landscape
Else
myReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait
End If
myReport.PrintToPrinter(1, True, 1, 1)
End If
Return True
Catch ex As Exception
MessageBox.Show("btnPrint_Click - " & ex.Message & vbCr & ex.GetType.ToString)
End Try
End Function