Imports System.Data.OleDb
Public Class frmAdminCustomer

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

    End Sub

    Private Sub frmAdminCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      
        txtAge.MaxLength = 2 '// set max. allowed characters.


        txtCustomerNo.Enabled = False
        txtLastName.Enabled = False
        txtFirstName.Enabled = False
        txtLastName.Enabled = False
        txtMiddleName.Enabled = False
        txtAge.Enabled = False
        txtAddress.Enabled = False
        txtContactNo.Enabled = False
        cmbGender.Enabled = False
        cmbCategory.Enabled = False



    End Sub

    Private Sub btnAdd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd1.Click
        txtLastName.Focus()
        txtLastName.Text = ""
        txtFirstName.Text = ""
        txtMiddleName.Text = ""
        txtAge.Text = ""
        txtAddress.Text = ""
        txtAge.Text = ""
        txtContactNo.Text = ""
        cmbGender.Text = ""
        cmbCategory.Text = ""

        conn = New OleDbConnection(cn)
        'autonum 
        Dim cmd As New OleDbCommand("Select CustomerNo from CustomerInfo", conn)
        conn.Open()
        dr = cmd.ExecuteReader
        While dr.Read()
            txtCustomerNo.Text = dr(0)
        End While
        txtCustomerNo.Text = Val(txtCustomerNo.Text) + 1
        dr.Close()
        conn.Close()
        '   btnSave.Enabled = True
     
        txtLastName.Enabled = True
        txtFirstName.Enabled = True
        txtMiddleName.Enabled = True
        txtAge.Enabled = True
        txtAddress.Enabled = True
        txtContactNo.Enabled = True
        cmbGender.Enabled = True
        cmbCategory.Enabled = True
    End Sub

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

        If txtLastName.Text = "" Then
            MsgBox("Please enter Last Name")
            txtLastName.Focus()

        ElseIf txtFirstName.Text = "" Then
            MsgBox("Please enter First Name")
            txtFirstName.Focus()

        ElseIf txtMiddleName.Text = "" Then
            MsgBox("Please enter Middle Name")
            txtMiddleName.Focus()

        ElseIf txtAddress.Text = "" Then
            MsgBox("Please enter  Address")
            txtAddress.Focus()

        ElseIf txtAge.Text = "" Then
            MsgBox("Please enter  Age")
            txtAge.Focus()

        ElseIf DateTimePicker1.Text = "" Then
            MsgBox("Please enter  Birthday")
            DateTimePicker1.Focus()

        ElseIf cmbGender.Text = "" Then
            MsgBox("Please enter  Gender")
            cmbGender.Focus()

        ElseIf txtContactNo.Text = "" Then
            MsgBox("Please enter your Contact Number")
            txtContactNo.Focus()

        Else
            conn = New OleDbConnection(cn)
            Try
                conn.Open()
                str = "Insert into CustomerInfo values ('" & txtCustomerNo.Text & "','" & cmbCategory.Text & "' ,'" & txtLastName.Text & "' ,'" & txtFirstName.Text & "','" & txtMiddleName.Text & "','" & txtAddress.Text & "', '" & DateTimePicker1.Text & "','" & txtAge.Text & "','" & cmbGender.Text & "', '" & txtContactNo.Text & "')"
                cmd = New OleDbCommand(str, conn)
                cmd.ExecuteNonQuery()
                MsgBox("Record Saved Successfully!")

                txtLastName.Focus()
                txtCustomerNo.Text = ""
                txtLastName.Text = ""
                txtFirstName.Text = ""
                txtMiddleName.Text = ""
                txtAge.Text = ""
                txtAddress.Text = ""
                txtAge.Text = ""
                txtContactNo.Text = ""
                cmbGender.Text = ""
                cmbCategory.Text = ""

                txtCustomerNo.Enabled = False
                txtLastName.Enabled = False
                txtFirstName.Enabled = False
                txtMiddleName.Enabled = False
                txtAge.Enabled = False
                txtAddress.Enabled = False
                txtContactNo.Enabled = False
                cmbGender.Enabled = False
                cmbCategory.Enabled = False
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            conn.Close()
        End If
    End Sub

    Private Sub txtCustomerName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLastName.KeyPress
        Dim c As Char = e.KeyChar
        If Char.IsNumber(c) Then
            e.Handled = True
        End If
    End Sub
    Private Sub cmbGender_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cmbGender.KeyPress
        Dim c As Char = e.KeyChar
        If Char.IsNumber(c) Then
            e.Handled = True
        End If
    End Sub
    Private Sub txtAge_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAge.KeyPress
        Dim i As Char = e.KeyChar
        If Char.IsLetter(i) Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtContactNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtContactNo.KeyPress
        Dim i As Char = e.KeyChar
        If Char.IsLetter(i) Then
            e.Handled = True
        End If
    End Sub

    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click

    End Sub
End Class