Imports System.Data.OleDb

Public Class frmAdminProduct

    Private Sub btnAdd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd1.Click
        txtProductCategory.Focus()
        txtProductCategory.Text = ""
        txtProductName.Text = ""
        txtProductQuantity.Text = ""


        conn = New OleDbConnection(cn)
        'autonum 
        Dim cmd As New OleDbCommand("Select ProductCode from ProductInfo", conn)
        conn.Open()
        dr = cmd.ExecuteReader
        While dr.Read()
            txtProductNo.Text = dr(0)
        End While
        txtProductNo.Text = Val(txtProductNo.Text) + 1
        dr.Close()
        conn.Close()
        '   btnSave.Enabled = True

        txtProductCategory.Enabled = True
        txtProductName.Enabled = True
        txtProductQuantity.Enabled = True
    End Sub

    Private Sub btnSave1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave1.Click
        'Save Database

        If txtProductCategory.Text = "" Then
            MsgBox("Select Product Category")
            txtProductCategory.Focus()

        ElseIf txtProductName.Text = "" Then
            MsgBox("Please enter Product Name")
            txtProductName.Focus()

        ElseIf txtProductQuantity.Text = "" Then
            MsgBox("Please enter Product Quantity")
            txtProductQuantity.Focus()


        Else
            conn = New OleDbConnection(cn)
            Try
                conn.Open()
                str = "Insert into ProductInfo values ('" & txtProductNo.Text & "','" & txtProductCategory.Text & "' ,'" & txtProductName.Text & "' ,'" & txtProductQuantity.Text & "')"
                cmd = New OleDbCommand(str, conn)
                cmd.ExecuteNonQuery()
                MsgBox("Record Saved Successfully!")

                txtProductCategory.Focus()
                txtProductCategory.Text = ""
                txtProductName.Text = ""
                txtProductQuantity.Text = ""


                txtProductNo.Enabled = False
                txtProductCategory.Enabled = False
                txtProductName.Enabled = False
                txtProductQuantity.Enabled = False

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

    Private Sub frmAdminProduct_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtProductNo.Enabled = False
        txtProductCategory.Enabled = False
        txtProductName.Enabled = False
        txtProductQuantity.Enabled = False
    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