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