Imports System.Data.OleDb
Imports System.IO
Public Class FrmFilter

    Private Sub FrmFilter_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 FrmFilter_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 FrmFilter_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.SearchCategory.SelectedItem = "Serial No"
    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged

        Try
            If Me.SearchCategory.Text = "" Then
                MsgBox("First You Should Select The Search Category !!!", MsgBoxStyle.Critical, "Attention...")
                Return
            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
                If SearchCategory.Text = "Serial No" Then
                    Dim dap As OleDbDataAdapter = New OleDbDataAdapter("Select * From Table1 where SerialNo like '" & Me.txtSearch.Text & "%' ", OleCn)
                    Dim ds As DataSet = New DataSet
                    dap.Fill(ds, "table1")
                    MainFrm.PrintmakerGridView.DataSource = ds.Tables(0)
                    Me.LblRecord.Text = Me.BindingContext(ds, "table1").Position + 1 & " of " & Me.BindingContext(ds, "table1").Count
                    Return
                End If

                If SearchCategory.Text = "Cabin No" Then
                    Dim dap As OleDbDataAdapter = New OleDbDataAdapter("Select * From Table1 where CabinNo like '" & Me.txtSearch.Text & "%' ", OleCn)
                    Dim ds As DataSet = New DataSet
                    dap.Fill(ds, "table1")
                    MainFrm.PrintmakerGridView.DataSource = ds.Tables(0)
                    Me.LblRecord.Text = Me.BindingContext(ds, "table1").Position + 1 & " of " & Me.BindingContext(ds, "table1").Count
                    Return
                End If

                If SearchCategory.Text = "Name" Then
                    Dim dap As OleDbDataAdapter = New OleDbDataAdapter("Select * From Table1 where CustomerName like '" & Me.txtSearch.Text & "%' ", OleCn)
                    Dim ds As DataSet = New DataSet
                    dap.Fill(ds, "table1")
                    MainFrm.PrintmakerGridView.DataSource = ds.Tables(0)
                    Me.LblRecord.Text = Me.BindingContext(ds, "table1").Position + 1 & " of " & Me.BindingContext(ds, "table1").Count
                    Return
                End If

                If SearchCategory.Text = "Date" Then
                    Dim dap As OleDbDataAdapter = New OleDbDataAdapter("Select * From Table1 where Dat like '" & Me.txtSearch.Text & "%' ", OleCn)
                    Dim ds As DataSet = New DataSet
                    dap.Fill(ds, "table1")
                    MainFrm.PrintmakerGridView.DataSource = ds.Tables(0)
                    Me.LblRecord.Text = Me.BindingContext(ds, "table1").Position + 1 & " of " & Me.BindingContext(ds, "table1").Count
                    Return
                End If

            Catch ex As Exception
                MsgBox(ex.Message(), MsgBoxStyle.Critical, "Fillter Error...")
            Finally
                OleCn.Close()
            End Try

        Catch ex As Exception
        End Try
    End Sub
End Class