Public Class frmEditItems
    Public ItemID As Integer = 0
    Private Sub txtBarcode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBarcode.TextChanged
        'If txtBarcode.Text.Length >= 11 Then
        '    Try
        '        cbo_fill(cboParts, "Parts", "PartsID", "tblparts")
        '        cbo_fill(cboBrand, "Brand", "BrandID", "tblbrand")
        '        cbo_fill(cboSupplier, "Supplier", "SupplierId", "tblsupplier")
        '        'cbo_fill(.cboLocation, "Location", "LocationID", "tbllocation")
        '        'cbo_fill(cboCompSet, "ComputerSet", "CompSetID", "tblcompset")
        '        sql = "SELECT *,i.Description as 'Desc'  FROM `tblbrand` b,`tblitems` i, `tblparts` p, `tbllocation` l,tblcompset c " _
        '        & "WHERE b.`BrandID`=i.`BrandID` AND i.`PartsID`=p.`PartsID` AND i.`LocationID`=l.`LocationID` AND i.CompSetID=c.CompSetID AND Barcode='" & txtBarcode.Text & "'"
        '        reloadtxt(sql)
        '        cboParts.Text = dt.Rows(0).Item("Parts")
        '        cboBrand.Text = dt.Rows(0).Item("Brand")
        '        txtDescription.Text = dt.Rows(0).Item("Desc")
        '        txtPrice.Text = dt.Rows(0).Item("Price")
        '        cboSupplier.Text = dt.Rows(0).Item("Supplier")
        '        '.cboLocation.Text = dt.Rows(0).Item("Location")
        '        'cboCompSet.Text = dt.Rows(0).Item("ComputerSet") 
        '    Catch ex As Exception

        '    End Try

        'End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            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 ItemId = " & ItemID

                sqladd = "No use"

                sqledit = "UPDATE `tblitems` SET `BrandID`='" & cboBrand.SelectedValue & "', `Description`='" & txtDescription.Text & "', `PartsID`=" & cboParts.SelectedValue & ",Price='" & txtPrice.Text & "',Supplier='" & cboSupplier.Text & "' WHERE ItemId=" & ItemID

                save_or_update(sql, sqladd, sqledit, "Item has been updated in the database.", "New Item has been saved in the database.")

                Call btnNew_Click(sender, e)
                'End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


    Private Sub frmEditItems_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        cleartext(Me)
        cbo_fill(cboParts, "Parts", "PartsID", "tblparts")
        cbo_fill(cboBrand, "Brand", "BrandID", "tblbrand")
        cbo_fill(cboSupplier, "Supplier", "SupplierId", "tblsupplier")
        'cbo_fill(cboLocation, "Location", "LocationID", "tbllocation")
        'cbo_fill(cboCompSet, "ComputerSet", "CompSetID", "tblcompset")
    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 cboSupplier_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboSupplier.KeyPress
        e.Handled = True
    End Sub

    Private Sub cboBrand_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboParts.KeyPress, cboBrand.KeyPress
        e.Handled = True
    End Sub
End Class