or
' Generate the reports
Me
.Cursor = Cursors.WaitCursor
' Initialize print settings
Dim
printerSettings
As
New
System.Drawing.Printing.PrinterSettings
Dim
printerController
As
New
System.Drawing.Printing.StandardPrintController
Dim
reportSource
As
New
InstanceReportSource
Dim
reportProcessor
As
New
ReportProcessor
reportProcessor.PrintController = printerController
' Create the report book to add reports
Dim
reportBook
As
New
ReportBook
reportBook.DocumentName =
"Credit Vouchers"
' Print the report header
printerSettings.Duplex = Printing.Duplex.Simplex
Dim
rptHeader
As
New
CreditVoucherReportLibrary.ReportTitle
reportBook.Reports.Add(rptHeader)
Dim
c
As
Integer
= 0
Dim
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
Try
End
Using
' Print the summary page
Dim
rptSummary
As
New
CreditVoucherReportLibrary.CV_Summary_Report
Try
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
Exception
End
Try
' Print the report book
If
PrintPreviewCheckBox.Checked
Then
Dim
dlg
As
New
CreditVoucherPrintPreviewForm
dlg.reportBook = reportBook
dlg.ShowDialog()
Else
reportSource.ReportDocument = reportBook
reportProcessor.PrintReport(reportSource, printerSettings)
End
If