question

ClaudeLarocque-5662 avatar image
0 Votes"
ClaudeLarocque-5662 asked XingyuZhao-MSFT commented

Barcode and adding a row in datagridview

Why when I scan barcode with my USB scanner the first barcode generate an unwanted row in my datagridview, but the second scan generate the right product.

I attach a pdf files for this challenging question.

a) I have a form named FrmBilling on which a combobox named BarcodesCBX received the scan for my USB scanner.
b) The possible barcodes are all into this field as you will see on my pdf files.
c) I take my scanner and scan any barcode, the row is added to my datagridview named OrderLinesDGV but that row shows the products information belonging to the first barcode in that combobox, then, if I scan the same barcode a second time I get the right product.

So everytime I scan a product, my application send the product information of the first barcode in the list, I scan the same barcode again and then the right product information is added in my datagridview.

I know someone must have encounter a similar behavior, I hope :)

Claude from Quebec, Canada
My first language being French please forgive the mistakes I do...132437-question-for-barcode-scans.pdf


dotnet-visual-basic
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ClaudeLarocque-5662
I have some questions to confirm with you.
Does the code work well if you don't use the scanner?

when I scan barcode with my USB scanner the first barcode generate an unwanted row in my datagridview

Whether the data of first row in the combobox is additionally included in the result of the first scan?
How does your USB scanner scan the barcode?

0 Votes 0 ·

Yes, if I choose any barcode from the combobox manually everything works well, what I don't understand is the first scan is the first barcode of that combobox but if I scan the same barcode a second time, then, the right product information comes up.

Thanks for taking the time to help solve that mystery :)

Claude

0 Votes 0 ·
XingyuZhao-MSFT avatar image XingyuZhao-MSFT ClaudeLarocque-5662 ·

Hi @ClaudeLarocque-5662 ,
In order to help others analyze the question, Could you provide more details about your USB scanner?

0 Votes 0 ·
ClaudeLarocque-5662 avatar image
1 Vote"
ClaudeLarocque-5662 answered XingyuZhao-MSFT commented

Thanks for helping me and in return I am posting the solution if somebody like me is looking to make the barcode works (Retrieve product information, update SQL database and the order lines in the datagridview)

Hope that help
Claude

     Private Sub BarcodeTB_TextChanged(sender As Object, e As EventArgs) Handles BarcodeTB.TextChanged
         Me.UpdateDGV.Select()
         Me.BarcodeTextTB.Select()
     End Sub
    
     Private Sub BarcodeTextTB_KeyDown(sender As Object, e As KeyEventArgs) Handles BarcodeTextTB.KeyDown
         If e.KeyValue = Keys.Enter Then
             LblBarcode.Text = BarcodeTextTB.Text
             BarcodeTextTB.Clear()
         End If
     End Sub
    
     Private Sub LblBarcode_TextChanged(sender As Object, e As EventArgs) Handles LblBarcode.TextChanged
         BarcodeTB.Text = LblBarcode.Text
     End Sub
    
     Private Sub UpdateDGV_Enter(sender As Object, e As EventArgs) Handles UpdateDGV.Enter
         UpdateOrderLinesDGVWithBarcode()
     End Sub
    
    
     Private Sub UpdateOrderLinesDGVWithBarcode()
         Try
             'CLEAR EXISTING RECORD
             If SQL.DBDS IsNot Nothing Then
                 SQL.DBDS.Clear()
             End If
             Me.QtyTB.Text = 1
             SQL.RunQuery("SELECT * FROM Warehouse.ProductsBarcodesEAN13 Where BarcodeEAN13 = '" & BarcodeTB.Text & "' ")
             If SQL.DBDS.Tables(0).Rows(0).Item(0) >= 1 Then
                 Me.InvoicedQuantityTB.Text = 0
                 Me.BackOrderYesNoCB.Checked = False
                 Me.BackorderQuantityTB.Text = 0
                 Me.UnitPriceTB.Text = SQL.DBDS.Tables(0).Rows(0).Item("SellingPrice1")
                 Me.ExtendedPriceTB.Text = QtyTB.Text * UnitPriceTB.Text
                 Me.DiscountRateTB.Text = SQL.DBDS.Tables(0).Rows(0).Item("DiscountRate")
                 Me.DiscountAmountTB.Text = Math.Round(QtyTB.Text * UnitPriceTB.Text) * DiscountRateTB.Text / 100
                 Me.LineTotalTB.Text = QtyTB.Text * UnitPriceTB.Text - DiscountAmountTB.Text
                 Me.DeliveryDateExpectedTB.Text = Now()
                 SQL.AddParam("@OrderNo", Me.OrderNoSelectedTB.Text)
                 SQL.AddParam("@ProductID", SQL.DBDS.Tables(0).Rows(0).Item("ProductID"))
                 SQL.AddParam("@ProductName", SQL.DBDS.Tables(0).Rows(0).Item("ProductName"))
                 SQL.AddParam("@Quantity", QtyTB.Text)
                 SQL.AddParam("@UnitPrice", SQL.DBDS.Tables(0).Rows(0).Item("SellingPrice1"))
                 SQL.AddParam("@ExtendedPrice", Me.QtyTB.Text * Me.UnitPriceTB.Text)
                 SQL.AddParam("@DiscountRate", SQL.DBDS.Tables(0).Rows(0).Item("DiscountRate"))
                 SQL.AddParam("@DiscountAmount", Me.DiscountAmountTB.Text)
                 SQL.AddParam("@InvoicedQuantity", Me.InvoicedQuantityTB.Text)
                 SQL.AddParam("@BackOrderYesNo", Me.BackOrderYesNoCB.Checked)
                 SQL.AddParam("@BackorderQuantity", Me.BackorderQuantityTB.Text)
                 SQL.AddParam("@LineTotal", Me.QtyTB.Text * Me.UnitPriceTB.Text - DiscountAmountTB.Text)
                 SQL.AddParam("@DeliveryDate", Me.DeliveryDateExpectedTB.Text)
                 SQL.ExecQuery("INSERT INTO Sales.OrderLines(OrderNo,ProductID,ProductName,Quantity,UnitPrice,ExtendedPrice,DiscountRate,DiscountAmount,InvoicedQuantity,BackOrderYesNo, " &
                               "BackOrderQuantity,LineTotal,DeliveryDate) " &
                               "VALUES (@OrderNo,@ProductID,@ProductName,@Quantity,@UnitPrice,@ExtendedPrice,@DiscountRate,@DiscountAmount,@InvoicedQuantity,@BackOrderYesNo, " &
                               "@BackorderQuantity,@LineTotal,@DeliveryDate) ", True)
                 RecordsCounted()
                     Me.QtyTB.Text = 1
    
                     'Scroll to the last row.
                     Me.OrderLinesDGV.FirstDisplayedScrollingRowIndex = Me.OrderLinesDGV.RowCount - 1
                     Me.OrderLineIDTB.Text = Me.OrderLinesDGV.RowCount
                     'Select the last row.
                     Me.OrderLinesDGV.Rows(Me.OrderLinesDGV.RowCount - 1).Selected = True
                 End If
             If SQL.HasException(True) Then Exit Sub
         Catch ex As Exception
             MsgBox(ex.Message)
             System.IO.File.AppendAllText("C:\ACRegister\Documents\log.txt", ex.ToString & vbNewLine & vbNewLine)
         End Try
     End Sub


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ClaudeLarocque-5662 ,
I'm glad to hear that your problem has been solved.
In order to help people who encounter similar problems find the solution quickly, you can consider clicking "Accept Answer".

0 Votes 0 ·
ClaudeLarocque-5662 avatar image
0 Votes"
ClaudeLarocque-5662 answered

Sure, the scanner is an Eclipse ES-250A, and I have to mentioned here that when I scan into a notepad or any other software like Excel, Access or Word, everything works fine. Below I scanned 4 articles in notepad

6819716
18163780036
16716990036
062338929613

My problem is not the scanner but here are the specifications and the user manual links:

This the specification for the Eclipse ES-250A
https://www.eclipse-pos.com/downloads/fiches/es250a-eng.jpg

This is the barcode scanner user manual for the Eclipse ES-250A
https://www.eclipse-pos.com/downloads/drivers/Eclipse_ES-250A_v6.6.2.pdf

I think my problem is easier then the barcode scanner, for example, if I scan any barcode the first time, it works fine but in my BarcodeCBX, the code stays in there, if I manually remove the data into the BarcodeCBX.text then I can scan another one and it works fine.

So my problem is how to empty completely my combobox after the scan, I tried the SendKeys.Send("{BACKSPACE}") it didn't work, so I am trying other solution, if you have any, please help me!

Claude

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.