Imports System.Data.OleDb
Imports System.IO

Public Class EntryFrm

    Dim Dst = New DataSet
    Dim con As New OleDbConnection
    Dim myDA As OleDbDataAdapter

    Private Sub EntryFrm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            OleCn.Close()
            Me.Dispose()

        Catch ex As Exception
        End Try

    End Sub

    Private Sub EntryFrm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        e.SuppressKeyPress = e.Control
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{tab}")
        End If
    End Sub

    Private Sub EntryFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Call serialnogenerate()
            txtName.Focus()
            txtDate.Text = Today
            Me.KeyPreview = True
        Catch ex As Exception
        End Try

    End Sub

     Public Sub serialnogenerate()


        Call SNoNavigation()

        Dim a
        Dim i As Integer
        i = 0

        Try

            i = Dst.Tables("Table1").rows.count - 1
            a = Dst.Tables("Table1").Rows(i)("SerialNo").ToString + 1
            txtSerialNo.Text = a

        Catch ex As Exception
            MsgBox(ex.Message(), MsgBoxStyle.Critical, "Auto Genrate Serial-No Error...")
        End Try


    End Sub


    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Try

            OleCn.Close()
            Me.Close()

        Catch ex As Exception
        End Try
    End Sub
    Private Function SNoExist()
        Dim Str, Str1 As String
        Dim i As Integer
        Str = txtSerialNo.Text
        i = 0
        While i <> Dst.Tables("Table1").rows.count
            Str1 = Dst.Tables("Table1").Rows(i)("SerialNo")
            If Str = Str1 Then
                Return True
            End If
            i += 1
        End While
        Return False
    End Function
    Private Function RequiredEntry() As Boolean
        If txtSerialNo.Text = "" Or txtName.Text = "" Or txtDate.Text = "" Then
            MsgBox("Please enter required (*) information....", MsgBoxStyle.Critical, "Attention...")
            Return True
            Exit Function
        End If
    End Function
    Private Sub SNoNavigation()
        Try
            OleCn.Close()
            con.ConnectionString = "Provider=Microsoft.Ace.oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\BackUp\Printmaker11.Accdb;Persist Security Info=False"
            If con.State - System.Data.ConnectionState.Closed Then
                con.Open()
            End If
            myDA = New OleDbDataAdapter("SELECT * From Table1 order by SerialNo", con)
            myDA.Fill(Dst, "Table1")
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message(), MsgBoxStyle.Critical, "Serial-No Error...")
        End Try
    End Sub

    Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click

        Try
            If RequiredEntry() = True Then
                Return
            End If

            Call SNoNavigation()
            If SNoExist() = True Then
                MsgBox("SERIAL NO : Serial No is already exist. Please choose another one..... ")
                Me.txtSerialNo.Focus()
                Exit Sub
            End If

            Try
                With OleCn
                    If .State <> ConnectionState.Open Then
                        .ConnectionString = StrConnection()
                        .Open()
                    End If
                End With
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

            Try

                Dim sSQL As String = "insert into Table1 (SerialNo,CabinNo,Dat,CustomerName,ID_Proof,Particular) values (@SerialNo,@CabinNo,@Dat,@CustomerName,@ID_Proof,@Particular)"

                Dim cmd As OleDbCommand = New OleDbCommand(sSQL, OleCn)

                'Serial No
                Dim SerialNo As OleDbParameter = New OleDbParameter("@SerialNo", SqlDbType.BigInt)
                SerialNo.Value = txtSerialNo.Text.ToString()
                cmd.Parameters.Add(SerialNo)

                'CabinNo
                Dim CabinNo As OleDbParameter = New OleDbParameter("@CabinNo", SqlDbType.BigInt)
                CabinNo.Value = CBFormState.Text.ToString()
                cmd.Parameters.Add(CabinNo)

                'Date
                Dim Dat As OleDbParameter = New OleDbParameter("@Dat", OleDbType.VarChar, 20)
                Dat.Value = txtDate.Text.ToString()
                cmd.Parameters.Add(Dat)

                'CustomerName
                Dim name As OleDbParameter = New OleDbParameter("@CustomerName", OleDbType.VarChar, 20)
                name.Value = txtName.Text.ToString()
                cmd.Parameters.Add(name)

                'ID_Proof
                Dim ID_Proof As OleDbParameter = New OleDbParameter("@ID_Proof", OleDbType.VarChar, 20)
                ID_Proof.Value = TxtIDProof.Text.ToString()
                cmd.Parameters.Add(ID_Proof)

                'Particular
                Dim Particular As OleDbParameter = New OleDbParameter("@Particular", OleDbType.VarChar, 20)
                Particular.Value = TxtParticular.Text.ToString()
                cmd.Parameters.Add(Particular)


                If cmd.ExecuteNonQuery() Then
                    OleCn.Close()
                    If CBFormState.Text = "1" Then
                        If TimerFrm.TimerCabin1.Enabled = True Then
                            TimerFrm.TxtSnoCabin1.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin1.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else

                            TimerFrm.TxtSnoCabin1.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin1.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin1.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin1.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "2" Then
                        If TimerFrm.TimerCabin2.Enabled = True Then
                            TimerFrm.TxtSnoCabin2.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin2.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin2.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin2.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin2.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin2.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "3" Then
                        If TimerFrm.TimerCabin3.Enabled = True Then
                            TimerFrm.TxtSnoCabin3.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin3.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin3.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin3.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin3.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin3.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "4" Then
                        If TimerFrm.TimerCabin4.Enabled = True Then
                            TimerFrm.TxtSnoCabin4.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin4.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin4.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin4.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin4.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin4.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "5" Then
                        If TimerFrm.TimerCabin5.Enabled = True Then
                            TimerFrm.TxtSnoCabin5.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin5.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin5.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin5.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin5.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin5.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "6" Then
                        If TimerFrm.TimerCabin6.Enabled = True Then
                            TimerFrm.TxtSnoCabin6.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin6.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin6.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin6.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin6.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin6.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "7" Then
                        If TimerFrm.TimerCabin7.Enabled = True Then
                            TimerFrm.TxtSnoCabin7.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin7.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin7.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin7.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin7.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin7.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "8" Then
                        If TimerFrm.TimerCabin8.Enabled = True Then
                            TimerFrm.TxtSnoCabin8.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin8.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin8.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin8.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin8.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin8.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "9" Then
                        If TimerFrm.TimerCabin9.Enabled = True Then
                            TimerFrm.TxtSnoCabin9.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin9.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin9.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin9.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin9.Text = Now.ToLongTimeString.ToString()

                            TimerFrm.TimerCabin9.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "10" Then
                        If TimerFrm.TimerCabin10.Enabled = True Then
                            TimerFrm.TxtSnoCabin10.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin10.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin10.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin10.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin10.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin10.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "11" Then
                        If TimerFrm.TimerCabin11.Enabled = True Then
                            TimerFrm.TxtSnoCabin11.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin11.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin11.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin11.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin11.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin11.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "12" Then
                        If TimerFrm.TimerCabin12.Enabled = True Then
                            TimerFrm.TxtSnoCabin12.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin12.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin12.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin12.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin12.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin12.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "13" Then
                        If TimerFrm.TimerCabin13.Enabled = True Then
                            TimerFrm.TxtSnoCabin13.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin13.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin13.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin13.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin13.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin13.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "14" Then
                        If TimerFrm.TimerCabin14.Enabled = True Then
                            TimerFrm.TxtSnoCabin14.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin14.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin14.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin14.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin14.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin14.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "15" Then
                        If TimerFrm.TimerCabin15.Enabled = True Then
                            TimerFrm.TxtSnoCabin15.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin15.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin15.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin15.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin15.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin15.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "16" Then
                        If TimerFrm.TimerCabin16.Enabled = True Then
                            TimerFrm.TxtSnoCabin16.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin16.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin16.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin16.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin16.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin16.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "17" Then
                        If TimerFrm.TimerCabin17.Enabled = True Then
                            TimerFrm.TxtSnoCabin17.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin17.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin17.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin17.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin17.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin17.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "18" Then
                        If TimerFrm.TimerCabin18.Enabled = True Then
                            TimerFrm.TxtSnoCabin18.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin18.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin18.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin18.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin18.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin18.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "19" Then
                        If TimerFrm.TimerCabin19.Enabled = True Then
                            TimerFrm.TxtSnoCabin19.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin19.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin19.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin19.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin19.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin19.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If
                    If CBFormState.Text = "20" Then
                        If TimerFrm.TimerCabin20.Enabled = True Then
                            TimerFrm.TxtSnoCabin20.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin20.Text = Me.txtName.Text
                            Me.Close()
                            Return
                        Else
                            TimerFrm.TxtSnoCabin20.Text = Me.txtSerialNo.Text
                            TimerFrm.LblNameCabin20.Text = Me.txtName.Text
                            TimerFrm.LblTimeCabin20.Text = Now.ToLongTimeString.ToString()
                            TimerFrm.TimerCabin20.Enabled = True
                            Me.Close()
                        End If
                        Return
                    End If

                Else
                    MsgBox("Record Addition Failed ", MsgBoxStyle.Critical, "Addition Failed")
                    Return
                End If

            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString(), "Data Error")
                '  Exit Sub
            End Try

        Catch ex As Exception
        End Try
    End Sub

    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
        Try
            txtName.Clear()
            TxtIDProof.Clear()
            TxtParticular.Clear()
            Call serialnogenerate()
            txtName.Focus()
            txtDate.Text = Today
        Catch ex As Exception
        End Try
    End Sub

    Private Sub txtSerialNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSerialNo.KeyPress
        Dim NotAllowed As String = "abcdefghijklmnopqrstuvwxyz~`@#$%^&*()_-+={[}]:;'.><?|/\.!"

        'Allowed Numbers Only
        If e.KeyChar <> ControlChars.Back = True Then
            If NotAllowed.IndexOf(e.KeyChar) = -1 = False Then
                e.Handled = True
            End If
        End If
    End Sub

    Private Sub txtName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
        Dim NotAllowed As String = "1234567890~`@#$%^&*()_-+={[}]:;!><?/|\"

        'Allowed Letters only
        If e.KeyChar <> ControlChars.Back = True Then
            If NotAllowed.IndexOf(e.KeyChar) = -1 = False Then
                e.Handled = True
            End If
        End If
    End Sub
End Class