Imports System.Data
Imports System.Data.OleDb
Public Class la
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub la_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call connectdatabase()
        Call SetGrid()
        Call Showdata()
    End Sub
    Private Sub SetGrid()
        If dgvem.RowCount > 0 Then
            dgvem.Columns(0).HeaderText = "รหัสพนักงาน"
            dgvem.Columns(1).HeaderText = "ชื่อพนักงาน"
            dgvem.Columns(2).HeaderText = "วันที่เบิก"
            dgvem.Columns(3).HeaderText = "จำนวนเงินที่เบิก"

        End If
    End Sub
    Private Sub Showdata()
        Dim dt As New DataTable
        gSQL = "Select Employee_ID,Employee_name,Leave_Date,TypeLe_ID From Leave"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gSQL
            .Connection = cnn
            dr = .ExecuteReader
            If dr.HasRows Then
                dt.Load(dr)
                dgvem.DataSource = dt
                SetGrid()
            End If
            dr.Close()
        End With
    End Sub
    Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
        Dim dt As New DataTable
        gSQL = "Select Employee_ID,Employee_name,Leave_Date,TypeLe_ID From Leave Where Employee_name  Like '%" & txtSearch.Text & "%'"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gSQL
            .Connection = cnn
            dr = .ExecuteReader
            If dr.HasRows Then
                dt.Load(dr)
                dgvem.DataSource = dt
                SetGrid()
            End If
            dr.Close()
        End With

        'Dim dt As New DataTable
        'gSQL = "Select Employee_ID,Employee_name,AdPaym_Date,AdPaym_Net From AdvancePayment Where Employee_name  Like '%" & txtSearch.Text & "%'"
        'With cmd
        '    .CommandType = CommandType.Text
        '    .CommandText = gSQL
        '    .Connection = cnn
        '    dr = .ExecuteReader
        '    If dr.HasRows Then
        '        dt.Load(dr)
        '        dgvem.DataSource = dt
        '        SetGrid()
        '    End If
        '    dr.Close()
        'End With
    End Sub
    'Private Sub dgvem_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvem.CellMouseDoubleClick
    '    If e.RowIndex >= 0 Then

    '        Me.Close()
    '    End If
    'End Sub
End Class
