
Imports System.Data
Imports System.Data.OleDb
Public Class leaSR
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub SleaSR_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(1).Width = 200
            dgvem.Columns(2).HeaderText = "แผนก"
            dgvem.Columns(2).Width = 120

        End If
    End Sub
    Private Sub Showdata()
        Dim dt As New DataTable
        gSQL = "Select Employee_ID,Employee_name,TypeEm_ID From Employeee Where Employee_name"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gSQL
            .Connection = cnn
            dr = .ExecuteReader
            If dr.HasRows Then
                dt.Load(dr)
                dgvem.DataSource = dt
                dgvem.Columns(0).HeaderText = "รหัสพนักงาน"
                dgvem.Columns(1).HeaderText = "ชื่อพนักงาน"
                dgvem.Columns(1).Width = 200
                dgvem.Columns(2).HeaderText = "แผนก"
                dgvem.Columns(2).Width = 120
            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,TypeEm_ID From Employeee 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
            Leavee.tEno.Text = dgvem.Rows(e.RowIndex).Cells(0).Value
            Leavee.tEname.Text = dgvem.Rows(e.RowIndex).Cells(1).Value
            Me.Close()
        End If
    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        Leavee.Show()
        Me.Close()
    End Sub
End Class