Public Class frmaddItemQuantity

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim res As Boolean
            Dim totalprice As Double
            If txtBarcode.Text = "" Or txtDescription.Text = "" Then
                MsgBox("Fields are required.", MsgBoxStyle.Exclamation)
            Else
                'sql = "SELECT * FROM `tblitems` " & _
                '    " WHERE `PartsID`=" & cboParts.SelectedValue & " AND `LocationID`=" & cboLocation.SelectedValue & " AND `CompSetID`=" & cboCompSet.SelectedValue & ""
                'reloadtxt(sql)

                'If dt.Rows.Count > 0 Then
                '    MsgBox(cboParts.Text & " is already exist in the computer ", MsgBoxStyle.Exclamation)
                'Else


                sql = "Select * From tblitems WHERE Barcode = '" & txtBarcode.Text & "'"
                reloadtxt(sql)

                With dt.Rows(0)

                    totalprice = Double.Parse(.Item("Price")) * Double.Parse(txtQty.Text)

                    sqladd = "INSERT INTO `tblitemsummary` (`ItemID`, `Barcode`, `Description`, `RecievedQuantity`,`Price`,`TotalPrice`, `DateRecieved`) " &
                        " VALUES ('" & .Item("ItemID") & "'," & .Item("Barcode") & ",'" & .Item("Description") & "','" & txtQty.Text & "','" & .Item("Price") & "','" & totalprice & "',Now())"
                    res = create(sqladd)

                    If res = True Then
                        sqledit = "UPDATE `tblitems` SET  `Quantity`=`Quantity` + '" & txtQty.Text & "', `OnhandQty`=`OnhandQty` + '" & txtQty.Text & "' WHERE Barcode='" & txtBarcode.Text & "'"
                        updates(sqledit)

                        MsgBox("Item quantity has been updated in the database.")
                    End If
                End With

                'End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub txtItemId_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtItemId.TextChanged
        Try
            sql = "SELECT *,i.Description as 'Desc'  FROM `tblbrand` b,`tblitems` i, `tblparts` p " _
                 & "WHERE b.`BrandID`=i.`BrandID` AND i.`PartsID`=p.`PartsID` AND ItemID = " & txtItemId.Text
            reloadtxt(sql)

            With dt.Rows(0)
                txtBarcode.Text = .Item("Barcode")
                txtDescription.Text = .Item("Desc")
                txtParts.Text = .Item("Parts")
                txtBrand.Text = .Item("Brand")
                txtSupplier.Text = .Item("Supplier")
                txtprice.Text = .Item("Price")

            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub frmaddItemQuantity_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class