Public Class 國定假日設定
    ReadOnly ds, ds1 As New DataSet
    Private Sub 讀取人員資料表()
        人員_dgv.DataSource = Nothing : ds.Clear()
        人員_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        人員_dgv.ColumnHeadersHeight = 25
        人員_dgv.AllowUserToAddRows = False
        SQL_國定假日設定_人員()
        da.Fill(ds) : 人員_dgv.DataSource = ds.Tables(0) : conn.Close()
        人員_dgv.Columns(0).FillWeight = 70 : 人員_dgv.Columns(1).FillWeight = 80 : 人員_dgv.Columns(2).FillWeight = 100
        For i As Integer = 0 To 人員_dgv.Rows.Count - 1
            人員_dgv.Rows(i).Cells("No.").Value = i + 1
        Next
    End Sub
    Private Sub Set_考勤明細()
        月清單_DGV.DataSource = Nothing : ds1.Clear()
        月清單_DGV.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月清單_DGV.ColumnHeadersHeight = 40
        月清單_DGV.AllowUserToAddRows = False
        PA = 員工編號_tb.Text : PA1 = 年份_cb.Text : PA2 = 月份_cb.Text : SQL_國定假日設定_月份考勤()
        da.Fill(ds1) : 月清單_DGV.DataSource = ds1.Tables(0) : conn.Close()

        月清單_DGV.Columns(0).FillWeight = 80 : 月清單_DGV.Columns(1).FillWeight = 50 : 月清單_DGV.Columns(2).FillWeight = 90 : 月清單_DGV.Columns(3).FillWeight = 150
        月清單_DGV.Columns(4).FillWeight = 75 : 月清單_DGV.Columns(5).FillWeight = 70 : 月清單_DGV.Columns(6).FillWeight = 80
        For I As Integer = 0 To 月清單_DGV.Rows.Count - 1
            If 月清單_DGV.Rows(I).Cells("星期").Value.ToString = "星期六" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 月清單_DGV.Rows(I).Cells("星期").Value.ToString = "星期日" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 月清單_DGV.Rows(I).Cells("請假類別").Value.ToString = "國定假日" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 月清單_DGV.Rows(I).Cells("請假類別").Value.ToString <> "" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightYellow
            End If
        Next
    End Sub
    Private Sub 年份_下拉表單資料載入()
        SQL_考勤明細表_年份_下拉()
        年份_cb.Items.Clear()
        While (dr.Read()) : 年份_cb.Items.Add(dr("年份")) : End While
        conn.Close()
    End Sub
    Private Sub 國定假日設定_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        年份_下拉表單資料載入()
        年份_cb.Text = Year(Today) : 月份_cb.SelectedIndex = Month(Today) - 1 : 請假類別_cb.SelectedIndex = 0
    End Sub
    Private Sub 月清單_DGV_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月清單_DGV.RowPostPaint
        For I As Integer = 0 To 月清單_DGV.Rows.Count - 1
            If 月清單_DGV.Rows(I).Cells("星期").Value.ToString = "星期六" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 月清單_DGV.Rows(I).Cells("星期").Value.ToString = "星期日" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 月清單_DGV.Rows(I).Cells("請假類別").Value.ToString = "國定假日" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 月清單_DGV.Rows(I).Cells("請假類別").Value.ToString <> "" Then : 月清單_DGV.Rows(I).DefaultCellStyle.BackColor = Color.LightYellow
            End If
        Next
    End Sub
    Private Sub 人員_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 人員_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            員工編號_tb.Text = 人員_dgv("編號", e.RowIndex).Value.ToString : 申請人_tb.Text = 人員_dgv("姓名", e.RowIndex).Value.ToString
            Set_考勤明細()
        End If
    End Sub
    Private Sub 月清單_DGV_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 月清單_DGV.CellClick
        If e.RowIndex = -1 Then : Else
            請假日期_tb.Text = 月清單_DGV("日期", e.RowIndex).Value.ToString
            請假類別_cb.Text = 月清單_DGV("請假類別", e.RowIndex).Value.ToString
            TextBox5.Text = 月清單_DGV("事由", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 月份_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月份_cb.SelectedIndexChanged
        PA1 = 年份_cb.Text : PA2 = 月份_cb.Text : 讀取人員資料表() : If 申請人_tb.Text <> "" Then : Set_考勤明細() : End If
    End Sub
    Private Sub 年份_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 年份_cb.SelectedIndexChanged
        If 月份_cb.Text <> "" Then : PA1 = 年份_cb.Text : PA2 = 月份_cb.Text : 讀取人員資料表() : If 申請人_tb.Text <> "" Then : Set_考勤明細() : End If : End If
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Format(Today(), "yyyy/MM/dd")
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If 申請人_tb.Text = "" Or 請假日期_tb.Text = "" Or TextBox5.Text = "" Or 請假類別_cb.Text = "" Then
            MsgBox("請檢查資料是否有填選完畢")
        Else
            For I As Integer = 0 To 人員_dgv.Rows.Count - 1
                資料數 = 31 : MyModule1.進度條()
                PA = 人員_dgv("編號", I).Value.ToString : PA1 = 請假日期_tb.Text
                SQL_國定假日設定_查詢()
                If dr.Read() Then
                    conn.Close()
                Else
                    PA = 人員_dgv("編號", I).Value.ToString : SQL_國定假日申請() : conn.Close()
                    Set_日期格式轉換()
                    SQL_國定假日核准() : conn.Close()
                End If
            Next : GRAMS_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
            Set_考勤明細()
            MsgBox("核准完成")
        End If
    End Sub
End Class