|
-
Apr 20th, 2021, 06:32 PM
#1
Thread Starter
New Member
help with cash drawer kick open with stored drawer codes in database
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
Last edited by iced8out; Apr 20th, 2021 at 06:42 PM.
Reason: add more detail
-
Apr 20th, 2021, 08:02 PM
#2
Re: help with cash drawer kick open with stored drawer codes in database
First things first, don't use a data reader. If you're retrieving a single value from a database then call ExecuteScalar, not ExecuteReader.
As for the issue, I'm wondering whether it has something to do with the text encoding. I would suggest that you retrieve that data from the database and then compare it to your hard-coded value. The next step depends on whether they are equal or not.
-
Apr 21st, 2021, 02:41 AM
#3
Thread Starter
New Member
Re: help with cash drawer kick open with stored drawer codes in database
thanks jmcilhinney for your reply. i went ahead changed it to ExecuteScalar as you suggested. i also compared the code thats prints on the receipt and its exactly as the hard-coded value. yet when i hard code with the same exact drawer code value in to the source code its kicks the drawer instantly without issue. what could you suggest i do to have it kick open the drawer with the drawer code value coming from the database. thank u
-
Apr 21st, 2021, 02:54 AM
#4
Re: help with cash drawer kick open with stored drawer codes in database
They're obviously not the same or using them would produce the same result. How did you compare them? Did you just look at them? the fact that two things look the same is not proof that they are the same. Did you actually use code to compare the two Strings for equality? Did you compare each Char in the Strings?
-
Apr 21st, 2021, 02:59 AM
#5
Thread Starter
New Member
Re: help with cash drawer kick open with stored drawer codes in database
i copied and pasted the code stored in the database and pasted it into the source and it worked. now when i did it the other way where the value comes from the database its prints a receipt with the exact drawer code but doesnt kick open the drawer.
-
Apr 21st, 2021, 03:36 AM
#6
Re: help with cash drawer kick open with stored drawer codes in database
That's not what I said to do. If you're not going to listen when the help you asked for is provided then I'll waste no more time providing it.
-
Apr 21st, 2021, 05:57 AM
#7
Re: help with cash drawer kick open with stored drawer codes in database
 Originally Posted by iced8out
i copied and pasted the code stored in the database and pasted it into the source and it worked. now when i did it the other way where the value comes from the database its prints a receipt with the exact drawer code but doesnt kick open the drawer.
try compare again with code
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Dim str1 As String = "TestString"
'Dim str2 As String = "teststring"
Dim str1 As String = "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)"
Dim str2 As String = "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25) "
If String.Compare(str1, str2, StringComparison.Ordinal) = 0 Then
MessageBox.Show("Are Equal")
Else
MessageBox.Show("Are Not Equal")
End If
End Sub
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Apr 21st, 2021, 07:36 AM
#8
Re: help with cash drawer kick open with stored drawer codes in database
 Originally Posted by iced8out
i copied and pasted the code stored in the database and pasted it into the source and it worked. now when i did it the other way where the value comes from the database its prints a receipt with the exact drawer code but doesnt kick open the drawer.
Wait... do you literally have "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)" in the database? If so, that's your problem. That's not what should be there. What you should have in the database is the characters that are returned by that code, not the code itself.\
-tg
-
Apr 21st, 2021, 01:11 PM
#9
Thread Starter
New Member
Re: help with cash drawer kick open with stored drawer codes in database
 Originally Posted by ChrisE
try compare again with code
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Dim str1 As String = "TestString"
'Dim str2 As String = "teststring"
Dim str1 As String = "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)"
Dim str2 As String = "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25) "
If String.Compare(str1, str2, StringComparison.Ordinal) = 0 Then
MessageBox.Show("Are Equal")
Else
MessageBox.Show("Are Not Equal")
End If
End Sub
hi chris thank you for your reply, i ran your code and i got the message that " not equal"
-
Apr 21st, 2021, 01:19 PM
#10
Thread Starter
New Member
Re: help with cash drawer kick open with stored drawer codes in database
 Originally Posted by techgnome
Wait... do you literally have "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)" in the database? If so, that's your problem. That's not what should be there. What you should have in the database is the characters that are returned by that code, not the code itself.\
-tg
hi techgnome, thank you for your reply. yes i have the code literally "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)" in the database because i dont how to store it in the database any other way. if you could give me a better way to do it i would be greatly appreciate it. ive tried removing the "chr" and putting it in like this : (27)(7)(11)(55)(25) but same result, ive tried also : Chr(27) Chr(7) Chr(11) Chr(55) Chr(25) but also no luck.
-
Apr 21st, 2021, 01:57 PM
#11
Re: help with cash drawer kick open with stored drawer codes in database
 Originally Posted by iced8out
hi techgnome, thank you for your reply. yes i have the code literally "Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)" in the database because i dont how to store it in the database any other way. if you could give me a better way to do it i would be greatly appreciate it. ive tried removing the "chr" and putting it in like this : (27)(7)(11)(55)(25) but same result, ive tried also : Chr(27) Chr(7) Chr(11) Chr(55) Chr(25) but also no luck.
Imagine your password to a website is 200, should the system accept a password of "Two Hundred"? That should demonstrate why what you are trying isn't going to work.
I'm not motivated enough to fire up my box that has SQL on it to try it, but I'm going to assume that storing the non-printable low ascii characters as-is won't work.
If this were me, I'd probably store it as:
in SQL, retrieve it in VB, split it into an array, and then use Chr() on the array values to build the string. That being said, there's likely more elegant ways to do it than that.
-
Apr 21st, 2021, 07:18 PM
#12
Re: help with cash drawer kick open with stored drawer codes in database
Good grief! What Chr does is create a Char value from an ASCII code and your code here:
vb.net Code:
DrawerCode = Chr(27) & Chr(7) & Chr(11) & Chr(55) & Chr(25)
creates a String containing those characters. It's that String that you should be saving to the database. I'm sure that you're quite capable of working out how to save a String to a database. Alternatively, you could convert the String to a Byte array using Encoding.ASCII.GetBytes and then store that as binary data in the database, calling Encoding.ASCII.GetString in your application. That extra step seems a bit pointless though.
-
Apr 23rd, 2021, 05:03 PM
#13
Re: help with cash drawer kick open with stored drawer codes in database
 Originally Posted by iced8out
hi chris thank you for your reply, i ran your code and i got the message that " not equal"
Chr(80) = “P”
But
“Chr(80)” <> “P”
Why??? Check the quotation marks. Anything contained within double quotation marks is a String literal
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|