Imports System.IO
Public Class 加班審核
    ReadOnly ds1 As New DataSet
    Private Sub Set_加班明細()
        月清單_DGV.DataSource = Nothing : ds1.Clear()
        月清單_DGV.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月清單_DGV.ColumnHeadersHeight = 40
        月清單_DGV.AllowUserToAddRows = False
        SQL_加班申請明細()
        da.Fill(ds1) : 月清單_DGV.DataSource = ds1.Tables(0) : conn.Close()

        月清單_DGV.Columns(1).Visible = False
        月清單_DGV.Columns(0).FillWeight = 60 : 月清單_DGV.Columns(2).FillWeight = 90 : 月清單_DGV.Columns(3).FillWeight = 60 : 月清單_DGV.Columns(4).Visible = False
        月清單_DGV.Columns(5).FillWeight = 100 : 月清單_DGV.Columns(6).FillWeight = 200 : 月清單_DGV.Columns(7).FillWeight = 80 : 月清單_DGV.Columns(8).FillWeight = 90
        月清單_DGV.Columns(9).FillWeight = 80 : 月清單_DGV.Columns(10).FillWeight = 90 : 月清單_DGV.Columns(11).Visible = False : 月清單_DGV.Columns(12).Visible = False
        月清單_DGV.Columns(13).Visible = False
        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
            End If
        Next
    End Sub
    Private Sub 加班審核_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = YS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        審核人_tb.Text = gUserName : 請假類別_cb.SelectedIndex = 0
        Set_加班明細()
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : YS_ERP_SYS.Timer1.Enabled = False : YS_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : YS_ERP_SYS.Timer1.Enabled = False : YS_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 介面關閉_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        MyModule1.虛擬桌面開啟()
    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
            特假日期_tb.Text = 月清單_DGV("日期", e.RowIndex).Value.ToString : 審核人1_tb.Text = 月清單_DGV("核准人1", e.RowIndex).Value.ToString
            事由_tb.Text = 月清單_DGV("事由紀錄", e.RowIndex).Value.ToString : 審核人2_tb.Text = 月清單_DGV("核准人2", e.RowIndex).Value.ToString
            DTP1_tb.Text = 月清單_DGV("核准日期1", e.RowIndex).Value.ToString : DTP2_tb.Text = 月清單_DGV("核准日期2", e.RowIndex).Value.ToString
            審核人1_tb.Text = gUserName : 審核人2_tb.Text = gUserName
            '------------驗貨報告讀取--------------------------------------------------------------------------------------------
            If 月清單_DGV("圖片資料庫", e.RowIndex).Value.ToString <> "" And 月清單_DGV("圖片編號", e.RowIndex).Value.ToString <> "" Then
                圖片庫 = 月清單_DGV("圖片資料庫", e.RowIndex).Value.ToString : SQL_連線字串_圖片資料庫() : PA2 = 月清單_DGV("圖片編號", e.RowIndex).Value.ToString
                SQL_加班圖() : PictureBox1.Image = Nothing
                While dr.Read() = True
                    Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
                    Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream)
                End While : conn.Close() : PictureBox1.SizeMode = 4
            Else
                PictureBox1.Image = Nothing
            End If
        End If
    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
            End If
        Next
    End Sub
    Private Sub 加班核准_bt_Click(sender As Object, e As EventArgs) Handles 加班核准_bt.Click
        If 特假日期_tb.Text = "" Then
            MsgBox("日期不能為空白")
        Else
            If 審核人1_tb.Text <> "" And 審核人2_tb.Text = "" Then
                PA = "申請中" : PA1 = Format(Today(), "yyyy/MM/dd") : PA2 = ""
            ElseIf 審核人1_tb.Text <> "" And 審核人2_tb.Text <> "" Then
                PA = "已核准" : PA1 = DTP1_tb.Text : PA2 = Format(Today(), "yyyy/MM/dd")
            End If
            SQL_加班審核核准() : Set_加班明細() : MsgBox("審核完成")
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 加班未准_bt.Click
        If 特假日期_tb.Text = "" Then
            MsgBox("日期不能為空白")
        Else
            SQL_加班審核未准() : Set_加班明細() : MsgBox("審核完成")
        End If
    End Sub
    Private Sub 默認核准_bt_Click(sender As Object, e As EventArgs) Handles 默認核准_bt.Click
        If 特假日期_tb.Text = "" Then
            MsgBox("日期不能為空白")
        Else
            審核人1_tb.Text = "自動核准" : 審核人2_tb.Text = "自動核准"
            PA = "已核准" : PA1 = Format(Today(), "yyyy/MM/dd") : PA2 = Format(Today(), "yyyy/MM/dd")
            SQL_加班審核核准() : Set_加班明細() : MsgBox("審核完成")
        End If
    End Sub
    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        圖片傳遞 = PictureBox1.Image : 圖片放大視窗.ShowDialog()
    End Sub
End Class