Public Class frmsupplier
    Dim supplierid = 0
    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        If txtSupplier.Text = "" Then
            MsgBox("Field is required.", MsgBoxStyle.Exclamation)
        Else
            sql = "Select * From tblparts WHERE PartsID = " & supplierid

            sqladd = "INSERT INTO `tblsupplier` (`Supplier`,Company ) VALUES ('" & txtSupplier.Text & "','" & txtCompany.Text & "' )"

            sqledit = "UPDATE `tblsupplier` SET `Supplier`='" & txtSupplier.Text & "',`Company`='" & txtCompany.Text & "' WHERE SupplierId=" & supplierid


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

            Call frmsupplier_Load(sender, e)

        End If
    End Sub

    Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
        supplierid = 0
        txtSupplier.Clear()
        txtCompany.Clear()
        sql = "Select SupplierId,`Supplier`,Company  From tblsupplier"
        reloadDtg(sql, dtglist)
    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        sql = "Select SupplierId,`Supplier`,Company  From tblsupplier WHERE Supplier Like '%" & txtSearch.Text & "%'"
        reloadDtg(sql, dtglist)
    End Sub

    Private Sub frmsupplier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call btnnew_Click(sender, e)
    End Sub

    Private Sub dtglist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtglist.Click
        Try
            With dtglist
                supplierid = .CurrentRow.Cells(0).Value
                txtSupplier.Text = .CurrentRow.Cells(1).Value
                txtCompany.Text = .CurrentRow.Cells(2).Value
            End With
        Catch ex As Exception

        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
End Class