Option Strict Off
Public Class 人員資料表
    ReadOnly ds As New DataSet
    Private Sub 讀取人員資料表()
        人員清單_dgv.DataSource = Nothing : ds.Clear()
        人員清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        人員清單_dgv.ColumnHeadersHeight = 25 : 人員清單_dgv.AllowUserToAddRows = False
        If 在職_ch.Checked = True Then : SQL2 = " WHERE IsLockedOut = 0 " : ElseIf 離職1_ch.Checked = True Then : SQL2 = " WHERE IsLockedOut = 1 " : Else : SQL2 = "" : End If
        SQL_人員資料()
        da.Fill(ds) : 人員清單_dgv.DataSource = ds.Tables(0) : conn.Close()
        人員清單_dgv.Columns(0).FillWeight = 50 : 人員清單_dgv.Columns(1).FillWeight = 50 : 人員清單_dgv.Columns(2).FillWeight = 50 : 人員清單_dgv.Columns(3).FillWeight = 80
        人員清單_dgv.Columns(4).FillWeight = 50 : 人員清單_dgv.Columns(5).FillWeight = 70 : 人員清單_dgv.Columns(6).FillWeight = 100 : 人員清單_dgv.Columns(7).FillWeight = 100
        人員清單_dgv.Columns(8).FillWeight = 70 : 人員清單_dgv.Columns(9).FillWeight = 70 : 人員清單_dgv.Columns(10).FillWeight = 130 : 人員清單_dgv.Columns(11).FillWeight = 130
        人員清單_dgv.Columns(12).FillWeight = 50 : 人員清單_dgv.Columns(13).FillWeight = 50 : 人員清單_dgv.Columns(14).FillWeight = 50 : 人員清單_dgv.Columns(15).FillWeight = 70
        人員清單_dgv.Columns(16).FillWeight = 80 : 人員清單_dgv.Columns(17).FillWeight = 130 : 人員清單_dgv.Columns(18).FillWeight = 100
    End Sub
    Private Sub 人員資料表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = GRAMS_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        讀取人員資料表()
    End Sub
    Private Sub 人員清單_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 人員清單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            UID_tb.Text = 人員清單_dgv("UID", e.RowIndex).Value.ToString : DIN_tb.Text = 人員清單_dgv("DIN", e.RowIndex).Value.ToString
            PIN_tb.Text = 人員清單_dgv("PIN", e.RowIndex).Value.ToString : UserName_tb.Text = 人員清單_dgv("UserName", e.RowIndex).Value.ToString
            Sex_tb.Text = 人員清單_dgv("Sex", e.RowIndex).Value.ToString : Password_tb.Text = 人員清單_dgv("Password", e.RowIndex).Value.ToString
            PasswordQuestion_tb.Text = 人員清單_dgv("PasswordQuestion", e.RowIndex).Value.ToString : PasswordAnswer_tb.Text = 人員清單_dgv("PasswordAnswer", e.RowIndex).Value.ToString
            已核准_ch.Checked = 人員清單_dgv("IsApproved", e.RowIndex).Value.ToString : 離職_ch.Checked = 人員清單_dgv("IsLockedOut", e.RowIndex).Value.ToString
            CreateDate_tb.Text = 人員清單_dgv("CreateDate", e.RowIndex).Value.ToString : LastLoginDate_tb.Text = 人員清單_dgv("LastLoginDate", e.RowIndex).Value.ToString
            DeptId_tb.Text = 人員清單_dgv("DeptId", e.RowIndex).Value.ToString : AttId_tb.Text = 人員清單_dgv("AttId", e.RowIndex).Value.ToString
            RuleId_tb.Text = 人員清單_dgv("RuleId", e.RowIndex).Value.ToString : WeekendId_tb.Text = 人員清單_dgv("WeekendId", e.RowIndex).Value.ToString
            LastUpdatedUID_tb.Text = 人員清單_dgv("LastUpdatedUID", e.RowIndex).Value.ToString : LastUpdatedDate_tb.Text = 人員清單_dgv("LastUpdatedDate", e.RowIndex).Value.ToString
            Comment_tb.Text = 人員清單_dgv("Comment", e.RowIndex).Value.ToString

            CreateDate_tb.Text = CreateDate_tb.Text.Replace(" 上午 ", " ").Replace(" 下午 ", " ")
            LastLoginDate_tb.Text = LastLoginDate_tb.Text.Replace(" 上午 ", " ").Replace(" 下午 ", " ")
            LastUpdatedDate_tb.Text = LastUpdatedDate_tb.Text.Replace(" 上午 ", " ").Replace(" 下午 ", " ")
        End If
    End Sub
    Private Sub 重讀_bt_Click(sender As Object, e As EventArgs) Handles 重讀_bt.Click
        讀取人員資料表()
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If UID_tb.Text = "" Then : Else : PA = DIN_tb.Text
            PA17 = PIN_tb.Text : PA1 = UserName_tb.Text : PA2 = Sex_tb.Text : PA3 = Password_tb.Text : PA4 = PasswordQuestion_tb.Text : PA5 = PasswordAnswer_tb.Text
            PA6 = 已核准_ch.Checked : PA7 = 離職_ch.Checked : PA8 = CreateDate_tb.Text : PA9 = LastLoginDate_tb.Text : PA10 = DeptId_tb.Text : PA11 = AttId_tb.Text
            PA12 = RuleId_tb.Text : PA13 = WeekendId_tb.Text : PA14 = LastUpdatedUID_tb.Text : PA15 = LastUpdatedDate_tb.Text : PA16 = Comment_tb.Text
            SQL_人員修改() : 讀取人員資料表()
        End If
    End Sub
    Private Sub 新增_tb_Click(sender As Object, e As EventArgs) Handles 新增_tb.Click
        If UID_tb.Text = "" Then : Else : PA = DIN_tb.Text : PA18 = UID_tb.Text
            PA17 = PIN_tb.Text : PA1 = UserName_tb.Text : PA2 = Sex_tb.Text : PA3 = Password_tb.Text : PA4 = PasswordQuestion_tb.Text : PA5 = PasswordAnswer_tb.Text
            PA6 = 已核准_ch.Checked : PA7 = 離職_ch.Checked : PA8 = CreateDate_tb.Text : PA9 = LastLoginDate_tb.Text : PA10 = DeptId_tb.Text : PA11 = AttId_tb.Text
            PA12 = RuleId_tb.Text : PA13 = WeekendId_tb.Text : PA14 = LastUpdatedUID_tb.Text : PA15 = LastUpdatedDate_tb.Text : PA16 = Comment_tb.Text
            SQL_人員資料確認() : If dr.Read Then : MsgBox("該號碼已有人員使用!!") : Else : SQL_人員新增() : 讀取人員資料表() : End If
        End If
    End Sub
    Private Sub 在職_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 在職_ch.Click
        在職_ch.Checked = True : 離職1_ch.Checked = False : 全部_ch.Checked = False : 讀取人員資料表()
    End Sub
    Private Sub 離職1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 離職1_ch.Click
        在職_ch.Checked = False : 離職1_ch.Checked = True : 全部_ch.Checked = False : 讀取人員資料表()
    End Sub
    Private Sub 全部_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 全部_ch.Click
        在職_ch.Checked = False : 離職1_ch.Checked = False : 全部_ch.Checked = True : 讀取人員資料表()
    End Sub
    Private Sub UID_tb_TextChanged(sender As Object, e As EventArgs) Handles UID_tb.TextChanged
        If UID_tb.Text <> "" Then
            If IsNumeric(CInt(UID_tb.Text)) Then
                DIN_tb.Text = CInt(UID_tb.Text) + 2 : PIN_tb.Text = CInt(UID_tb.Text) + 2
            End If
        End If
    End Sub
End Class
