or
' Generate the reportsMe.Cursor = Cursors.WaitCursor' Initialize print settingsDim printerSettings As New System.Drawing.Printing.PrinterSettingsDim printerController As New System.Drawing.Printing.StandardPrintControllerDim reportSource As New InstanceReportSourceDim reportProcessor As New ReportProcessorreportProcessor.PrintController = printerController' Create the report book to add reportsDim reportBook As New ReportBookreportBook.DocumentName = "Credit Vouchers"' Print the report headerprinterSettings.Duplex = Printing.Duplex.SimplexDim rptHeader As New CreditVoucherReportLibrary.ReportTitlereportBook.Reports.Add(rptHeader)Dim c As Integer = 0Dim firstCV As String = ""Dim lastCV As String = ""Dim cn As New SqlConnection(My.Settings.OMSConnectionString)Using cn cn.Open() ' Get the list of voucher numbers to print Dim cmd As SqlCommand = New SqlCommand("Accounts_Payable.get_Credit_Vouchers_Lot_list", cn) cmd.CommandType = CommandType.StoredProcedure IIf(CreditVoucherTextBox.Text = "", Nothing, CreditVoucherTextBox.Text) cmd.Parameters.AddWithValue("@Year", YearComboBox.SelectedItem) cmd.Parameters.AddWithValue("@Month", PeriodComboBox.SelectedItem) cmd.Parameters.AddWithValue("@Payment_Number_Code", IIf(CreditVoucherTextBox.Text = "", Nothing, CreditVoucherTextBox.Text)) Try Dim r As SqlDataReader = cmd.ExecuteReader If r.HasRows Then While r.Read Dim rptVoucherStatement As New CreditVoucherReportLibrary.CV_Statement Dim rptVoucher As New CreditVoucherReportLibrary.CreditVoucher ' Print Credit Voucher Statement rptVoucherStatement.ReportParameters("YearPeriod").Value = YearComboBox.SelectedItem rptVoucherStatement.ReportParameters("MonthPeriod").Value = PeriodComboBox.SelectedItem rptVoucherStatement.ReportParameters("PaymentNumber").Value = Trim(r(0)) printerSettings.Duplex = Printing.Duplex.Horizontal ' Add the voucher statement to the report book Try reportBook.Reports.Add(rptVoucherStatement) Catch ex As Exception End Try ' Print Credit Voucher c += 1 rptVoucher.ReportParameters("YearPeriod").Value = YearComboBox.SelectedItem rptVoucher.ReportParameters("MonthPeriod").Value = PeriodComboBox.SelectedItem rptVoucher.ReportParameters("PaymentNumber").Value = Trim(r(0)) rptVoucher.ReportParameters("LastUpdatedBy").Value = "System" rptVoucher.ReportParameters("IsReprint").Value = False If c = 1 Then firstCV = Trim(r(0)) Else lastCV = Trim(r(0)) End If printerSettings.Duplex = Printing.Duplex.Simplex ' Add the voucher to the report book Try reportBook.Reports.Add(rptVoucher) Catch ex As Exception End Try End While End If Catch ex As Exception End TryEnd Using' Print the summary pageDim rptSummary As New CreditVoucherReportLibrary.CV_Summary_ReportTry Dim range As String = "" If c = 1 Then range = firstCV Else range = firstCV & " - " & lastCV End If rptSummary.ReportParameters("YearPeriod").Value = YearComboBox.SelectedItem rptSummary.ReportParameters("MonthPeriod").Value = PeriodComboBox.SelectedItem rptSummary.ReportParameters("PaymentNumber").Value = IIf(CreditVoucherTextBox.Text = "", Nothing, CreditVoucherTextBox.Text) rptSummary.ReportParameters("RangeOfVouchers").Value = range rptSummary.ReportParameters("NumberOfVouchers").Value = c printerSettings.Duplex = Printing.Duplex.Horizontal ' Add the summary to the report book reportBook.Reports.Add(rptSummary)Catch ex As ExceptionEnd Try' Print the report bookIf PrintPreviewCheckBox.Checked Then Dim dlg As New CreditVoucherPrintPreviewForm dlg.reportBook = reportBook dlg.ShowDialog()Else reportSource.ReportDocument = reportBook reportProcessor.PrintReport(reportSource, printerSettings)End If