Я пишу программу с сенсорным экраном, которая вставляет регистрацию транспортного средства в базу данных mysql, и мне нужно распечатать квитанцию для клиента с подробной информацией о ней. Когда я пытаюсь распечатать квитанцию, я не могу определить строку ошибки. Когда я нажимаю кнопку «Да», появляется сообщение «Ошибки принтера. Обратитесь в службу поддержки»
Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
'Printing function
Dim sqlConn As MySqlConnection
Dim cmd As New MySqlCommand
Dim SQLUser, SQLPassword, strSQL, strID, strSiteName, strSiteID As String
strSiteID = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\White List Touch Screen\", "siteid", "")
strSiteName = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\White List Touch Screen\", "sitename", "")
SQLUser = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\White List Touch Screen\", "sqluser", "")
SQLPassword = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\White List Touch Screen\", "sqlpwd", "")
sqlConn = New MySqlConnection("Data Source=localhost;Persist Security Info=True;uid = root; pwd=java; database=exemption")
strSQL = "SELECT TOP(1) id FROM tblVRM ORDER BY id DESC"
sqlConn.Open()
cmd = New MySqlCommand(strSQL, sqlConn)
strID = cmd.ExecuteScalar
sqlConn.Close()
Dim strVRM, FullDate, DateOnly As String
strVRM = txtVRM.Text
FullDate = CStr(Date.Now)
DateOnly = FullDate.Substring(0, 10)
'Font to use for the variable strVRM
Dim VRMFont As New Font("Arial", 14)
Dim ValidForFont As New Font("Arial", 11)
'For printing each line, the first number is the horizontal alignment, second is for verticle alignment
args.Graphics.DrawString("WHITE LIST RECEIPT FOR:", New Font(Me.Font, FontStyle.Regular), Brushes.Black, 10, 5)
args.Graphics.DrawString(strSiteID & ", " & strSiteName, New Font(Me.Font, FontStyle.Bold), Brushes.Black, 10, 20)
args.Graphics.DrawString("VALID ONLY FOR: " & DateOnly, New Font(ValidForFont, FontStyle.Bold), Brushes.Black, 28, 50)
args.Graphics.DrawString("FOR VEHICLE REGISTRATION: ", New Font(Me.Font, FontStyle.Regular), Brushes.Black, 10, 80)
args.Graphics.DrawString(strVRM, New Font(VRMFont, FontStyle.Bold), Brushes.Black, 183, 74)
args.Graphics.DrawString("RECEIPT No: " & strID, New Font(Me.Font, FontStyle.Bold), Brushes.Black, 10, 95)
args.Graphics.DrawString("VALID FROM: " & Date.Now, New Font(Me.Font, FontStyle.Bold), Brushes.Black, 10, 110)
End Sub
Private Sub btnYes_Click(sender As System.Object, e As System.EventArgs) Handles btnYes.Click
'Call the print function
Try
Dim i As Integer = 0
Do While i < 2
Dim Print As New Printing.PrintDocument
Dim Printer As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\White List Touch Screen\", "printer", "")
Print.PrinterSettings.PrinterName = Printer
AddHandler Print.PrintPage, AddressOf Me.PrintPageHandler
Print.Print()
RemoveHandler Print.PrintPage, AddressOf Me.PrintPageHandler
pnlResult.Visible = True
pnlKeyboard.Visible = True
i = i + 4
Loop
Catch
MessageBox.Show("Printer Errors. Please contact Support")
Exit Sub
End Try
End Sub