hello, hopefully someone could help me with my issue. this is a point of sale software and it is a touch screen. the issue im having is that when i tap the drawer open button on the screen the cash drawer is not popping open, instead it prints a small receipt with the drawercode that i have stored on the database. however if i embed the drawer code into the sourcecode like this : DrawerCode = Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25) it pops open the drawer perfectly but the issue remains that not everyone who uses the point of sale software is also using the exact make and model of hardware which is why i decided to store drawer codes in the database.
Code:
Sub OpenCashDrawer()
Try
con = New SqlConnection(cs)
con.Open()
cmd = con.CreateCommand()
cmd.CommandText = "SELECT RTRIM(CashDrawer) from POSPrinterSetting where CashDrawer='Enabled'"
rdr = cmd.ExecuteReader()
If Not rdr.Read() Then
frmCustomDialog11.ShowDialog()
Exit Sub
End If
If (rdr IsNot Nothing) Then
rdr.Close()
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
'Modify DrawerCode to your receipt printer open drawer code
con = New SqlConnection(cs)
con.Open()
cmd = con.CreateCommand()
cmd.CommandText = "SELECT RTRIM(CDCode) from POSPrinterSetting where CashDrawer='Enabled' and TillID=@d1"
cmd.Parameters.AddWithValue("@d1", lblTillID.Text)
rdr = cmd.ExecuteReader()
If rdr.Read() Then
DrawerCode = rdr(0).ToString
End If
If (rdr IsNot Nothing) Then
rdr.Close()
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
'Modify PrinterName to your receipt printer name
con = New SqlConnection(cs)
con.Open()
cmd = con.CreateCommand()
cmd.CommandText = "SELECT RTRIM(PrinterName) from POSPrinterSetting where TillID=@d1 and IsEnabled='Yes'"
cmd.Parameters.AddWithValue("@d1", lblTillID.Text)
rdr = cmd.ExecuteReader()
If rdr.Read() Then
s4 = rdr.GetValue(0)
End If
If (rdr IsNot Nothing) Then
rdr.Close()
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
Dim PrinterName As String = s4
RawPrinter.PrintRaw(PrinterName, DrawerCode)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub