
Imports System.Data
Imports System.Data.OleDb
Public Class advSr
    Dim dr As OleDbDataReader
    Dim cmd As New OleDbCommand
    Dim gSQL As String
    Private Sub advSr_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(1).Width = 170
            dgvem.Columns(3).HeaderText = "เวลาเข้างานเช้า"
            dgvem.Columns(2).Width = 120
            dgvem.Columns(4).HeaderText = "เวลาออกงานเช้า"
            dgvem.Columns(3).Width = 120
            dgvem.Columns(5).HeaderText = "เวลาออกงานบ่าย"
            dgvem.Columns(6).HeaderText = "เวลาเข้างานOT"
            dgvem.Columns(7).HeaderText = "เวลาออกงานOT"
            dgvem.Columns(8).HeaderText = "รวมจำนวนชั่วโมงทำงาน"
            dgvem.Columns(9).HeaderText = "สถานะ"


        End If
    End Sub
    Private Sub Showdata()
        Dim dt As New DataTable
        gSQL = "Select Employee_ID,Employee_name,TimeW_Date,TimeW_in1,TimeW_out1,TimeW_out2,TimeW_inOT1,TimeW_outOT2,TimeW_qty,TimeW_statas From Timework 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 txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
        Dim dt As New DataTable
        gSQL = "Select Employee_ID,Employee_name,TimeW_Date,TimeW_in1,TimeW_out1,TimeW_out2,TimeW_inOT1,TimeW_outOT2,TimeW_qty,TimeW_statas From Timework 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 load_data()
        Dim checkboxcol As New DataGridViewCheckBoxColumn
        checkboxcol.Width = 40
        checkboxcol.Name = "checkboxcol"
        checkboxcol.HeaderText = ""
        dgvem.Columns.Insert(0, checkboxcol)
    End Sub

    'Private Sub Button1_Click(sender As Object, e As EventArgs)
    '    Dim i As Integer = 0
    '    For i = 0 To dgvem.RowCount - 1
    '        dgvem.Rows(i).Cells(0).Value = True
    '    Next
    'End Sub

    'Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    '    Dim i As Integer = 0
    '    For i = 0 To dgvem.RowCount - 1

    '        Const dgvem.Rows(i).Cells(0).Value = True Then dgvem.datasourse = 1

    '    Next
    '    Dim sum As Integer
    '    sum = dgvem.DataSource = True
    '    TextBox1.Text = sum
    'End Sub

    'Private Sub dgvem_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvem.CellMouseDoubleClick
    '    If e.RowIndex >= 0 Then
    '        salary.eno.Text = dgvem.Rows(e.RowIndex).Cells(0).Value
    '        salary.ename.Text = dgvem.Rows(e.RowIndex).Cells(1).Value
    '        salary.esalary.Text = dgvem.Rows(e.RowIndex).Cells(2).Value
    '        salary.esoi.Text = dgvem.Rows(e.RowIndex).Cells(3).Value
    '        Me.Close()
    '    End If
    'End Sub
End Class