Option Explicit On
Imports System.IO
Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
Imports Microsoft.Office.Interop.Excel.Constants
Imports Microsoft.Office.Interop.Excel.XlBordersIndex
Imports Microsoft.Office.Interop.Excel.XlLineStyle
Imports Microsoft.Office.Interop.Excel.XlBorderWeight
Imports Microsoft.Office.Interop.Excel.XlThemeFont
Imports Microsoft.Office.Interop.Excel.XlThemeColor
Imports Microsoft.Office.Interop.Excel.XlWindowState
Imports Microsoft.Office.Interop.Excel.XlPageOrientation
Imports Microsoft.Office.Interop.Excel
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Public Class 人員薪資
    Dim 對話框(17) As String
    Dim 間隔1, 時長, 總時, GN1, 之前選擇 As Integer
    Dim 時段(6), 計算(6), X1, AUTO時, AUTO舊1, AUTO舊2 As String
    Dim 本周周一 As Date
    Dim xlApp As Application
    Dim xlBook As Workbook
    Dim xlSheet As Worksheet
    Private Function IsVerticalScrollBarVisible(dgv As DataGridView) As Boolean
        Return dgv.FirstDisplayedScrollingRowIndex > 0 OrElse dgv.DisplayedRowCount(False) < dgv.Rows.Count
    End Function
    Private Sub 語言轉換讀取()
        If 系統語言 = "繁體中文" Then : 語言 = "CH" : ElseIf 系統語言 = "English" Then : 語言 = "EN" : ElseIf 系統語言 = "Indonesian" Then : 語言 = "IN" : End If
        對話框(16) = 系統語言字典("H609-141-" & 語言) : 對話框(17) = 系統語言字典("H609-142-" & 語言) : 表頭(0) = 系統語言字典("H601-103-" & 語言)
        表頭(1) = 系統語言字典("H602-104-" & 語言) : 表頭(2) = 系統語言字典("H609-107-" & 語言) : 表頭(3) = 系統語言字典("H609-108-" & 語言)
        表頭(4) = 系統語言字典("H609-109-" & 語言) : 表頭(5) = 系統語言字典("H609-110-" & 語言) : 表頭(6) = 系統語言字典("H609-111-" & 語言)
        表頭(7) = 系統語言字典("H609-112-" & 語言) : 表頭(8) = 系統語言字典("H609-113-" & 語言) : 表頭(9) = 系統語言字典("H609-114-" & 語言)
        表頭(10) = 系統語言字典("H609-115-" & 語言) : 表頭(11) = 系統語言字典("H609-116-" & 語言) : 表頭(12) = 系統語言字典("H609-117-" & 語言)
        表頭(13) = 系統語言字典("H609-118-" & 語言) : 表頭(14) = 系統語言字典("H609-119-" & 語言) : 表頭(15) = 系統語言字典("H609-120-" & 語言)
        表頭(16) = 系統語言字典("H609-123-" & 語言) : 表頭(17) = 系統語言字典("H609-124-" & 語言) : 表頭(18) = 系統語言字典("H609-128-" & 語言)
        表頭(19) = 系統語言字典("H601-108-" & 語言) : 表頭(20) = 系統語言字典("H609-129-" & 語言) : 表頭(21) = 系統語言字典("H609-125-" & 語言)
        表頭(22) = 系統語言字典("H607-103-" & 語言) : 表頭(23) = 系統語言字典("H609-130-" & 語言) : 表頭(24) = 系統語言字典("H609-131-" & 語言)
        表頭(25) = 系統語言字典("H609-132-" & 語言) : 表頭(26) = 系統語言字典("H611-105-" & 語言) : 表頭(27) = 系統語言字典("H611-106-" & 語言)
        表頭(28) = 系統語言字典("H611-107-" & 語言) : 表頭(29) = 系統語言字典("H611-108-" & 語言) : 工人_ch.Text = 系統語言字典("G000-159-" & 語言)
        對話框(0) = 系統語言字典("H611-100-" & 語言) : 對話框(1) = 系統語言字典("H611-101-" & 語言) : 對話框(2) = 系統語言字典("H611-102-" & 語言)
        對話框(3) = 系統語言字典("H611-103-" & 語言) : 對話框(4) = 系統語言字典("H611-104-" & 語言) : 表頭(30) = 系統語言字典("H611-109-" & 語言)
        DA1_bt.Text = 系統語言字典("H611-111-" & 語言) : DA2_bt.Text = 系統語言字典("H611-112-" & 語言) : DA3_bt.Text = 系統語言字典("H611-113-" & 語言)
        群組輸入_ch.Text = 系統語言字典("H611-114-" & 語言) : 群組選擇_ch.Text = 系統語言字典("H611-115-" & 語言) : 考勤表_bt.Text = 系統語言字典("H611-116-" & 語言)
        薪資表_bt.Text = 系統語言字典("H611-117-" & 語言) : Label11.Text = 系統語言字典("H611-118-" & 語言) : Label1.Text = 系統語言字典("H611-119-" & 語言)
        Label7.Text = 系統語言字典("H609-124-" & 語言) : Label8.Text = 系統語言字典("H611-120-" & 語言)
        表頭(64) = 系統語言字典("H611-122-" & 語言) : 表頭(31) = 系統語言字典("H611-123-" & 語言) : 表頭(32) = 系統語言字典("H611-124-" & 語言)
        表頭(33) = 系統語言字典("H611-125-" & 語言) : 表頭(34) = 系統語言字典("H611-126-" & 語言) : 表頭(35) = 系統語言字典("H611-127-" & 語言)
        表頭(36) = 系統語言字典("H611-128-" & 語言) : 表頭(37) = 系統語言字典("H611-129-" & 語言) : 表頭(38) = 系統語言字典("H611-130-" & 語言)
        表頭(39) = 系統語言字典("H611-131-" & 語言) : 表頭(40) = 系統語言字典("H611-132-" & 語言) : 表頭(41) = 系統語言字典("H611-133-" & 語言)
        表頭(42) = 系統語言字典("H611-134-" & 語言) : 表頭(43) = 系統語言字典("H611-135-" & 語言) : 表頭(44) = 系統語言字典("H611-136-" & 語言)
        表頭(45) = 系統語言字典("H611-137-" & 語言) : 表頭(46) = 系統語言字典("H611-138-" & 語言) : 表頭(47) = 系統語言字典("H611-139-" & 語言)
        表頭(48) = 系統語言字典("H611-140-" & 語言) : 表頭(49) = 系統語言字典("H611-141-" & 語言) : 表頭(50) = 系統語言字典("H611-142-" & 語言)
        表頭(51) = 系統語言字典("H611-143-" & 語言) : 表頭(52) = 系統語言字典("H611-144-" & 語言) : 表頭(53) = 系統語言字典("H611-145-" & 語言)
        表頭(54) = 系統語言字典("H611-146-" & 語言) : 表頭(55) = 系統語言字典("H611-147-" & 語言) : 表頭(56) = 系統語言字典("H611-148-" & 語言)
        表頭(57) = 系統語言字典("H611-149-" & 語言) : 表頭(58) = 系統語言字典("H611-150-" & 語言) : 表頭(59) = 系統語言字典("H611-151-" & 語言)
        表頭(60) = 系統語言字典("H611-152-" & 語言) : 表頭(61) = 系統語言字典("H611-153-" & 語言) : 表頭(62) = 系統語言字典("H611-154-" & 語言)
        表頭(63) = 系統語言字典("H611-155-" & 語言)
    End Sub
    Private Sub Set_使用者清單()
        Set_總清單() : Set_虛擬表() : Dim ds1, ds2 As New DataSet
        清單1_dgv.DataSource = Nothing : ds1.Clear()
        清單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單1_dgv.ColumnHeadersHeight = 45 : 清單1_dgv.AllowUserToAddRows = False : 清單1_dgv.RowTemplate.Height = 35
        合計_dgv.DataSource = Nothing : ds2.Clear()
        合計_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        合計_dgv.ColumnHeadersHeight = 45 : 合計_dgv.AllowUserToAddRows = False : 合計_dgv.RowTemplate.Height = 35
        合計_dgv.ColumnHeadersVisible = False

        If 群組1_cb.Text = "HARIAN GROUP" Then
            SQL5 = " AND [HX-PGS-MSN].dbo.人員資料表.部門名稱 LIKE 'HARIAN GROUP'"
            SQL4 = "[HX-PGS-MSN].dbo.人員資料表.員工代碼"
        Else
            SQL5 = " AND [HX-PGS-MSN].dbo.人員資料表.部門名稱 NOT LIKE 'HARIAN GROUP'"
            SQL4 = "[HX-PGS-MSN].dbo.人員資料表.部門名稱,使用者權限管理表.姓名"
        End If
        PA25 = 地區_cb.SelectedIndex : SQL3 = "" : PA14 = 級別_cb.Text : PA19 = 群組_cb.Text
        SQL_人員薪資表1() : da.Fill(ds1) : 清單1_dgv.DataSource = ds1.Tables(0) : conn.Close()
        SQL_人員薪資表2() : da.Fill(ds2) : 合計_dgv.DataSource = ds2.Tables(0) : conn.Close() : PA25 = ""

        清單1_dgv.Columns("Save.").FillWeight = 40 : 清單1_dgv.Columns(12).Visible = True : 清單1_dgv.Columns(50).Visible = False : 清單1_dgv.Columns(0).FillWeight = 120
        清單1_dgv.Columns(4).FillWeight = 25
        合計_dgv.Columns("Save.").FillWeight = 40 : 合計_dgv.Columns(12).Visible = True : 合計_dgv.Columns(50).Visible = False : 合計_dgv.Columns(0).FillWeight = 120
        合計_dgv.Columns(4).FillWeight = 25

        For i As Integer = 2 To 14 : 清單1_dgv.Columns(i).Visible = False : Next : For i As Integer = 29 To 48 : 清單1_dgv.Columns(i).Visible = False : Next
        For i As Integer = 15 To 28 : 清單1_dgv.Columns(i).FillWeight = 60 : Next : For i As Integer = 29 To 34 : 清單1_dgv.Columns(i).FillWeight = 60 : Next
        For i As Integer = 35 To 48 : 清單1_dgv.Columns(i).FillWeight = 40 : Next : 清單1_dgv.Columns(12).Visible = True : 清單1_dgv.Columns(4).Visible = True
        For i As Integer = 1 To 50 : 清單1_dgv.Columns(i).ReadOnly = True : Next
        If 群組選擇_ch.Checked = True Then : 清單1_dgv.Columns(0).ReadOnly = True : Else : 清單1_dgv.Columns(0).ReadOnly = False : End If
        清單1_dgv.Columns(12).ReadOnly = False

        For i As Integer = 2 To 14 : 合計_dgv.Columns(i).Visible = False : Next : For i As Integer = 29 To 48 : 合計_dgv.Columns(i).Visible = False : Next
        For i As Integer = 15 To 28 : 合計_dgv.Columns(i).FillWeight = 60 : Next : For i As Integer = 29 To 34 : 合計_dgv.Columns(i).FillWeight = 60 : Next
        For i As Integer = 35 To 48 : 合計_dgv.Columns(i).FillWeight = 40 : Next : 合計_dgv.Columns(12).Visible = True : 合計_dgv.Columns(4).Visible = True
        For i As Integer = 1 To 50 : 合計_dgv.Columns(i).ReadOnly = True : Next
        If 群組選擇_ch.Checked = True Then : 合計_dgv.Columns(0).ReadOnly = True : Else : 合計_dgv.Columns(0).ReadOnly = False : End If
        合計_dgv.Columns(12).ReadOnly = False

        清單1_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 清單1_dgv.Columns(13).DefaultCellStyle.Format = "#,##0"
        For i As Integer = 4 To 11
            清單1_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            清單1_dgv.Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Next
        For i As Integer = 12 To 48
            清單1_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            清單1_dgv.Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Next
        If 深色風格 = False Then
            清單1_dgv.Columns(15).DefaultCellStyle.ForeColor = Color.Red : 清單1_dgv.Columns(16).DefaultCellStyle.ForeColor = Color.Red
            清單1_dgv.Columns(17).DefaultCellStyle.ForeColor = Color.Blue : 清單1_dgv.Columns(18).DefaultCellStyle.ForeColor = Color.Blue
            清單1_dgv.Columns(19).DefaultCellStyle.ForeColor = Color.Green : 清單1_dgv.Columns(20).DefaultCellStyle.ForeColor = Color.Green
            清單1_dgv.Columns(21).DefaultCellStyle.ForeColor = Color.Coral : 清單1_dgv.Columns(22).DefaultCellStyle.ForeColor = Color.Coral
            清單1_dgv.Columns(23).DefaultCellStyle.ForeColor = Color.Cyan : 清單1_dgv.Columns(24).DefaultCellStyle.ForeColor = Color.Cyan
            清單1_dgv.Columns(25).DefaultCellStyle.ForeColor = Color.Salmon : 清單1_dgv.Columns(26).DefaultCellStyle.ForeColor = Color.Salmon
            清單1_dgv.Columns(27).DefaultCellStyle.ForeColor = Color.SlateGray : 清單1_dgv.Columns(28).DefaultCellStyle.ForeColor = Color.SlateGray

            清單1_dgv.Columns(29).DefaultCellStyle.ForeColor = Color.Red : 清單1_dgv.Columns(30).DefaultCellStyle.ForeColor = Color.Red
            清單1_dgv.Columns(31).DefaultCellStyle.ForeColor = Color.Blue : 清單1_dgv.Columns(32).DefaultCellStyle.ForeColor = Color.Blue
            清單1_dgv.Columns(33).DefaultCellStyle.ForeColor = Color.Green : 清單1_dgv.Columns(34).DefaultCellStyle.ForeColor = Color.Green
            清單1_dgv.Columns(35).DefaultCellStyle.ForeColor = Color.Coral : 清單1_dgv.Columns(36).DefaultCellStyle.ForeColor = Color.Coral
            清單1_dgv.Columns(37).DefaultCellStyle.ForeColor = Color.Cyan : 清單1_dgv.Columns(38).DefaultCellStyle.ForeColor = Color.Cyan
            清單1_dgv.Columns(39).DefaultCellStyle.ForeColor = Color.Salmon : 清單1_dgv.Columns(40).DefaultCellStyle.ForeColor = Color.Salmon
            清單1_dgv.Columns(41).DefaultCellStyle.ForeColor = Color.SlateGray : 清單1_dgv.Columns(42).DefaultCellStyle.ForeColor = Color.SlateGray
            清單1_dgv.Columns(43).DefaultCellStyle.ForeColor = Color.Red : 清單1_dgv.Columns(44).DefaultCellStyle.ForeColor = Color.Red
            清單1_dgv.Columns(45).DefaultCellStyle.ForeColor = Color.Blue : 清單1_dgv.Columns(46).DefaultCellStyle.ForeColor = Color.Blue
            清單1_dgv.Columns(47).DefaultCellStyle.ForeColor = Color.Green : 清單1_dgv.Columns(48).DefaultCellStyle.ForeColor = Color.Green
        Else
            清單1_dgv.Columns(15).DefaultCellStyle.ForeColor = Color.LightPink : 清單1_dgv.Columns(16).DefaultCellStyle.ForeColor = Color.LightPink
            清單1_dgv.Columns(17).DefaultCellStyle.ForeColor = Color.LightBlue : 清單1_dgv.Columns(18).DefaultCellStyle.ForeColor = Color.LightBlue
            清單1_dgv.Columns(19).DefaultCellStyle.ForeColor = Color.LightGreen : 清單1_dgv.Columns(20).DefaultCellStyle.ForeColor = Color.LightGreen
            清單1_dgv.Columns(21).DefaultCellStyle.ForeColor = Color.LightCoral : 清單1_dgv.Columns(22).DefaultCellStyle.ForeColor = Color.LightCoral
            清單1_dgv.Columns(23).DefaultCellStyle.ForeColor = Color.LightCyan : 清單1_dgv.Columns(24).DefaultCellStyle.ForeColor = Color.LightCyan
            清單1_dgv.Columns(25).DefaultCellStyle.ForeColor = Color.LightSalmon : 清單1_dgv.Columns(26).DefaultCellStyle.ForeColor = Color.LightSalmon
            清單1_dgv.Columns(27).DefaultCellStyle.ForeColor = Color.LightSlateGray : 清單1_dgv.Columns(28).DefaultCellStyle.ForeColor = Color.LightSlateGray

            清單1_dgv.Columns(29).DefaultCellStyle.ForeColor = Color.LightPink : 清單1_dgv.Columns(30).DefaultCellStyle.ForeColor = Color.LightPink
            清單1_dgv.Columns(31).DefaultCellStyle.ForeColor = Color.LightBlue : 清單1_dgv.Columns(32).DefaultCellStyle.ForeColor = Color.LightBlue
            清單1_dgv.Columns(33).DefaultCellStyle.ForeColor = Color.LightGreen : 清單1_dgv.Columns(34).DefaultCellStyle.ForeColor = Color.LightGreen
            清單1_dgv.Columns(35).DefaultCellStyle.ForeColor = Color.LightCoral : 清單1_dgv.Columns(36).DefaultCellStyle.ForeColor = Color.LightCoral
            清單1_dgv.Columns(37).DefaultCellStyle.ForeColor = Color.LightCyan : 清單1_dgv.Columns(38).DefaultCellStyle.ForeColor = Color.LightCyan
            清單1_dgv.Columns(39).DefaultCellStyle.ForeColor = Color.LightSalmon : 清單1_dgv.Columns(40).DefaultCellStyle.ForeColor = Color.LightSalmon
            清單1_dgv.Columns(41).DefaultCellStyle.ForeColor = Color.LightSlateGray : 清單1_dgv.Columns(42).DefaultCellStyle.ForeColor = Color.LightSlateGray
            清單1_dgv.Columns(43).DefaultCellStyle.ForeColor = Color.LightPink : 清單1_dgv.Columns(44).DefaultCellStyle.ForeColor = Color.LightPink
            清單1_dgv.Columns(45).DefaultCellStyle.ForeColor = Color.LightBlue : 清單1_dgv.Columns(46).DefaultCellStyle.ForeColor = Color.LightBlue
            清單1_dgv.Columns(47).DefaultCellStyle.ForeColor = Color.LightGreen : 清單1_dgv.Columns(48).DefaultCellStyle.ForeColor = Color.LightGreen
        End If : 清單1_dgv.EditMode = DataGridViewEditMode.EditOnEnter

        合計_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 合計_dgv.Columns(13).DefaultCellStyle.Format = "#,##0"
        For i As Integer = 4 To 11
            合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            合計_dgv.Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Next
        For i As Integer = 12 To 48
            合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            合計_dgv.Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        Next
        If 深色風格 = False Then
            合計_dgv.Columns(15).DefaultCellStyle.ForeColor = Color.Red : 合計_dgv.Columns(16).DefaultCellStyle.ForeColor = Color.Red
            合計_dgv.Columns(17).DefaultCellStyle.ForeColor = Color.Blue : 合計_dgv.Columns(18).DefaultCellStyle.ForeColor = Color.Blue
            合計_dgv.Columns(19).DefaultCellStyle.ForeColor = Color.Green : 合計_dgv.Columns(20).DefaultCellStyle.ForeColor = Color.Green
            合計_dgv.Columns(21).DefaultCellStyle.ForeColor = Color.Coral : 合計_dgv.Columns(22).DefaultCellStyle.ForeColor = Color.Coral
            合計_dgv.Columns(23).DefaultCellStyle.ForeColor = Color.Cyan : 合計_dgv.Columns(24).DefaultCellStyle.ForeColor = Color.Cyan
            合計_dgv.Columns(25).DefaultCellStyle.ForeColor = Color.Salmon : 合計_dgv.Columns(26).DefaultCellStyle.ForeColor = Color.Salmon
            合計_dgv.Columns(27).DefaultCellStyle.ForeColor = Color.SlateGray : 合計_dgv.Columns(28).DefaultCellStyle.ForeColor = Color.SlateGray

            合計_dgv.Columns(29).DefaultCellStyle.ForeColor = Color.Red : 合計_dgv.Columns(30).DefaultCellStyle.ForeColor = Color.Red
            合計_dgv.Columns(31).DefaultCellStyle.ForeColor = Color.Blue : 合計_dgv.Columns(32).DefaultCellStyle.ForeColor = Color.Blue
            合計_dgv.Columns(33).DefaultCellStyle.ForeColor = Color.Green : 合計_dgv.Columns(34).DefaultCellStyle.ForeColor = Color.Green
            合計_dgv.Columns(35).DefaultCellStyle.ForeColor = Color.Coral : 合計_dgv.Columns(36).DefaultCellStyle.ForeColor = Color.Coral
            合計_dgv.Columns(37).DefaultCellStyle.ForeColor = Color.Cyan : 合計_dgv.Columns(38).DefaultCellStyle.ForeColor = Color.Cyan
            合計_dgv.Columns(39).DefaultCellStyle.ForeColor = Color.Salmon : 合計_dgv.Columns(40).DefaultCellStyle.ForeColor = Color.Salmon
            合計_dgv.Columns(41).DefaultCellStyle.ForeColor = Color.SlateGray : 合計_dgv.Columns(42).DefaultCellStyle.ForeColor = Color.SlateGray
            合計_dgv.Columns(43).DefaultCellStyle.ForeColor = Color.Red : 合計_dgv.Columns(44).DefaultCellStyle.ForeColor = Color.Red
            合計_dgv.Columns(45).DefaultCellStyle.ForeColor = Color.Blue : 合計_dgv.Columns(46).DefaultCellStyle.ForeColor = Color.Blue
            合計_dgv.Columns(47).DefaultCellStyle.ForeColor = Color.Green : 合計_dgv.Columns(48).DefaultCellStyle.ForeColor = Color.Green
        Else
            合計_dgv.Columns(15).DefaultCellStyle.ForeColor = Color.LightPink : 合計_dgv.Columns(16).DefaultCellStyle.ForeColor = Color.LightPink
            合計_dgv.Columns(17).DefaultCellStyle.ForeColor = Color.LightBlue : 合計_dgv.Columns(18).DefaultCellStyle.ForeColor = Color.LightBlue
            合計_dgv.Columns(19).DefaultCellStyle.ForeColor = Color.LightGreen : 合計_dgv.Columns(20).DefaultCellStyle.ForeColor = Color.LightGreen
            合計_dgv.Columns(21).DefaultCellStyle.ForeColor = Color.LightCoral : 合計_dgv.Columns(22).DefaultCellStyle.ForeColor = Color.LightCoral
            合計_dgv.Columns(23).DefaultCellStyle.ForeColor = Color.LightCyan : 合計_dgv.Columns(24).DefaultCellStyle.ForeColor = Color.LightCyan
            合計_dgv.Columns(25).DefaultCellStyle.ForeColor = Color.LightSalmon : 合計_dgv.Columns(26).DefaultCellStyle.ForeColor = Color.LightSalmon
            合計_dgv.Columns(27).DefaultCellStyle.ForeColor = Color.LightSlateGray : 合計_dgv.Columns(28).DefaultCellStyle.ForeColor = Color.LightSlateGray

            合計_dgv.Columns(29).DefaultCellStyle.ForeColor = Color.LightPink : 合計_dgv.Columns(30).DefaultCellStyle.ForeColor = Color.LightPink
            合計_dgv.Columns(31).DefaultCellStyle.ForeColor = Color.LightBlue : 合計_dgv.Columns(32).DefaultCellStyle.ForeColor = Color.LightBlue
            合計_dgv.Columns(33).DefaultCellStyle.ForeColor = Color.LightGreen : 合計_dgv.Columns(34).DefaultCellStyle.ForeColor = Color.LightGreen
            合計_dgv.Columns(35).DefaultCellStyle.ForeColor = Color.LightCoral : 合計_dgv.Columns(36).DefaultCellStyle.ForeColor = Color.LightCoral
            合計_dgv.Columns(37).DefaultCellStyle.ForeColor = Color.LightCyan : 合計_dgv.Columns(38).DefaultCellStyle.ForeColor = Color.LightCyan
            合計_dgv.Columns(39).DefaultCellStyle.ForeColor = Color.LightSalmon : 合計_dgv.Columns(40).DefaultCellStyle.ForeColor = Color.LightSalmon
            合計_dgv.Columns(41).DefaultCellStyle.ForeColor = Color.LightSlateGray : 合計_dgv.Columns(42).DefaultCellStyle.ForeColor = Color.LightSlateGray
            合計_dgv.Columns(43).DefaultCellStyle.ForeColor = Color.LightPink : 合計_dgv.Columns(44).DefaultCellStyle.ForeColor = Color.LightPink
            合計_dgv.Columns(45).DefaultCellStyle.ForeColor = Color.LightBlue : 合計_dgv.Columns(46).DefaultCellStyle.ForeColor = Color.LightBlue
            合計_dgv.Columns(47).DefaultCellStyle.ForeColor = Color.LightGreen : 合計_dgv.Columns(48).DefaultCellStyle.ForeColor = Color.LightGreen
        End If : 合計_dgv.EditMode = DataGridViewEditMode.EditOnEnter

        Dim mycol1 As DataGridViewImageColumn = 清單1_dgv.Columns("Save.") : mycol1.ImageLayout = DataGridViewImageCellLayout.Zoom
        For I As Integer = 0 To 清單1_dgv.Rows.Count - 1
            清單1_dgv.Rows(I).Cells("Save.").Value = My.Resources.SAVER
        Next
        '-------------------------合計DGV變形----------------------------------------------------------------------------------------------------------------------
        If IsVerticalScrollBarVisible(清單1_dgv) Then : 合計_dgv.Size = New Size(清單1_dgv.Size.Width - 17, 合計_dgv.Size.Height)
        Else : 合計_dgv.Size = New Size(清單1_dgv.Size.Width, 合計_dgv.Size.Height) : End If

        合計_dgv.Rows(0).Cells(0).Value = "" : 合計_dgv.Rows(0).Cells(1).Value = "" : 合計_dgv.Rows(0).Cells(4).Value = "" : 合計_dgv.Rows(0).Cells(12).Value = "0"
        合計_dgv.Rows(0).Cells(13).Value = "0" : 合計_dgv.Rows(0).Cells(15).Value = "" : 合計_dgv.Rows(0).Cells(16).Value = "" : 合計_dgv.Rows(0).Cells(17).Value = ""
        合計_dgv.Rows(0).Cells(18).Value = "" : 合計_dgv.Rows(0).Cells(19).Value = "" : 合計_dgv.Rows(0).Cells(20).Value = "" : 合計_dgv.Rows(0).Cells(21).Value = ""
        合計_dgv.Rows(0).Cells(22).Value = "" : 合計_dgv.Rows(0).Cells(23).Value = "" : 合計_dgv.Rows(0).Cells(24).Value = "" : 合計_dgv.Rows(0).Cells(25).Value = ""
        合計_dgv.Rows(0).Cells(26).Value = "" : 合計_dgv.Rows(0).Cells(27).Value = "" : 合計_dgv.Rows(0).Cells(28).Value = "" : 合計_dgv.Rows(0).Cells(29).Value = "0"
        合計_dgv.Rows(0).Cells(30).Value = "0" : 合計_dgv.Rows(0).Cells(31).Value = "" : 合計_dgv.Rows(0).Cells(32).Value = "" : 合計_dgv.Rows(0).Cells(33).Value = "0"
        合計_dgv.Rows(0).Cells(34).Value = "0" : 合計_dgv.Rows(0).Cells(35).Value = "0" : 合計_dgv.Rows(0).Cells(36).Value = "0" : 合計_dgv.Rows(0).Cells(37).Value = "0"
        合計_dgv.Rows(0).Cells(38).Value = "0" : 合計_dgv.Rows(0).Cells(39).Value = "0" : 合計_dgv.Rows(0).Cells(40).Value = "0" : 合計_dgv.Rows(0).Cells(41).Value = "0"
        合計_dgv.Rows(0).Cells(42).Value = "0" : 合計_dgv.Rows(0).Cells(43).Value = "0" : 合計_dgv.Rows(0).Cells(44).Value = "0" : 合計_dgv.Rows(0).Cells(45).Value = "0"
        合計_dgv.Rows(0).Cells(46).Value = "0" : 合計_dgv.Rows(0).Cells(47).Value = "0" : 合計_dgv.Rows(0).Cells(48).Value = "0"
        合計_dgv.Rows(0).Cells("Save.").Value = My.Resources.NULL1

        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            '-------------------------實際考勤--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(0).Value.ToString <> "" Then : 清單1_dgv.Rows(i).Cells(0).Value = 清單1_dgv.Rows(i).Cells(0).Value.ToString.ToUpper : End If
            If 清單1_dgv.Rows(i).Cells(1).Value.ToString <> "" Then : 清單1_dgv.Rows(i).Cells(1).Value = 清單1_dgv.Rows(i).Cells(1).Value.ToString.ToUpper : End If
            '-------------------------清空資料取得預設值--------------------------------------------------------------------------------------------------------------------
            For FF As Integer = 15 To 48 : 清單1_dgv.Rows(i).Cells(FF).Value = "" : Next
            '-------------------------計算週考勤表--------------------------------------------------------------------------------------------------------------------
            For II As Integer = 0 To 總清單_dgv.Rows.Count - 1
                If 清單1_dgv.Rows(i).Cells("ID卡號").Value.ToString = 總清單_dgv.Rows(II).Cells("ID卡號").Value.ToString Then
                    '-------------------------計算星期一--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星1_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星1_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(15).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(16).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(15).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(16).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(15).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(16).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                    '-------------------------計算星期二--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星2_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星2_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(17).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(18).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(17).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(18).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(17).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(18).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                    '-------------------------計算星期三--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星3_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星3_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(19).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(20).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(19).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(20).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(19).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(20).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                    '-------------------------計算星期四--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星4_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星4_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(21).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(22).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(21).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(22).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(21).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(22).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                    '-------------------------計算星期五--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星5_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星5_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(23).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(24).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(23).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(24).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(23).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(24).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                    '-------------------------計算星期六--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星6_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星6_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(25).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(26).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(25).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(26).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(25).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(26).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                    '-------------------------計算星期日--------------------------------------------------------------------------------------------------------------------
                    If 月份2_cb.Text = Strings.Mid(星7_bt.Text, 6, 2) Then
                        If 總清單_dgv.Rows(II).Cells(表頭(3)).Value.ToString = 星7_bt.Text Then
                            If 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString = "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(27).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(28).Value = 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString = "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString = "" Then
                                清單1_dgv.Rows(i).Cells(27).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(28).Value = 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString
                            ElseIf 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(5)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(6)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(7)).Value.ToString <> "" And
                               總清單_dgv.Rows(II).Cells(表頭(8)).Value.ToString <> "" And 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString <> "" Then
                                清單1_dgv.Rows(i).Cells(27).Value = 總清單_dgv.Rows(II).Cells(表頭(4)).Value.ToString
                                清單1_dgv.Rows(i).Cells(28).Value = 總清單_dgv.Rows(II).Cells(表頭(9)).Value.ToString
                            End If
                        End If
                    End If
                End If
            Next
            '-------------------------虛擬考勤--------------------------------------------------------------------------------------------------------------------
            For ii As Integer = 0 To 虛擬表_dgv.Rows.Count - 1
                If 清單1_dgv.Rows(i).Cells(50).Value.ToString = 虛擬表_dgv.Rows(ii).Cells(0).Value.ToString Then
                    If 月份2_cb.Text = Strings.Mid(星1_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(15).Value = 虛擬表_dgv.Rows(ii).Cells(1).Value.ToString : 清單1_dgv.Rows(i).Cells(16).Value = 虛擬表_dgv.Rows(ii).Cells(2).Value.ToString
                    End If
                    If 月份2_cb.Text = Strings.Mid(星2_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(17).Value = 虛擬表_dgv.Rows(ii).Cells(3).Value.ToString : 清單1_dgv.Rows(i).Cells(18).Value = 虛擬表_dgv.Rows(ii).Cells(4).Value.ToString
                    End If
                    If 月份2_cb.Text = Strings.Mid(星3_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(19).Value = 虛擬表_dgv.Rows(ii).Cells(5).Value.ToString : 清單1_dgv.Rows(i).Cells(20).Value = 虛擬表_dgv.Rows(ii).Cells(6).Value.ToString
                    End If
                    If 月份2_cb.Text = Strings.Mid(星4_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(21).Value = 虛擬表_dgv.Rows(ii).Cells(7).Value.ToString : 清單1_dgv.Rows(i).Cells(22).Value = 虛擬表_dgv.Rows(ii).Cells(8).Value.ToString
                    End If
                    If 月份2_cb.Text = Strings.Mid(星5_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(23).Value = 虛擬表_dgv.Rows(ii).Cells(9).Value.ToString : 清單1_dgv.Rows(i).Cells(24).Value = 虛擬表_dgv.Rows(ii).Cells(10).Value.ToString
                    End If
                    If 月份2_cb.Text = Strings.Mid(星6_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(25).Value = 虛擬表_dgv.Rows(ii).Cells(11).Value.ToString : 清單1_dgv.Rows(i).Cells(26).Value = 虛擬表_dgv.Rows(ii).Cells(12).Value.ToString
                    End If
                    If 月份2_cb.Text = Strings.Mid(星7_bt.Text, 6, 2) Then
                        清單1_dgv.Rows(i).Cells(27).Value = 虛擬表_dgv.Rows(ii).Cells(13).Value.ToString : 清單1_dgv.Rows(i).Cells(28).Value = 虛擬表_dgv.Rows(ii).Cells(14).Value.ToString
                    End If
                End If
            Next
        Next : AUTO時段() : 表頭變形1()
        If 群組1_cb.Text = "HARIAN GROUP" Or 群組1_cb.Text = "" Then
            PA25 = 年份2_cb.Text : PA26 = 月份2_cb.Text : PA27 = Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd")
            If 群組1_cb.Text = "HARIAN GROUP" Then : PA30 = "1" : Else : PA30 = "0" : End If
            PA28 = 合計_dgv.Rows(0).Cells(4).Value.ToString : PA29 = 合計_dgv.Rows(0).Cells(13).Value.ToString
            SQL_工人薪資彙總報表_查詢()
            If dr.Read Then : SQL_工人薪資彙總報表_修改() : Else : SQL_工人薪資彙總報表_新增() : End If
        End If : PA25 = "" : PA26 = "" : PA27 = "" : PA28 = "" : PA29 = "" : PA30 = ""
    End Sub
    Private Sub 表頭變形1()
        Dim NNS, 位置(50), X軸1 As Integer
        For Each column As DataGridViewColumn In 清單1_dgv.Columns
            If column.Index >= 0 Then
                Dim currentWidth As Integer = column.Width
                位置(NNS) = currentWidth
            End If
            If NNS = 15 Or NNS = 16 Or NNS = 17 Or NNS = 18 Or NNS = 19 Or NNS = 20 Or NNS = 21 Or NNS = 22 Or NNS = 23 Or NNS = 24 Or NNS = 25 Or NNS = 26 Or NNS = 27 Or NNS = 28 Or
               NNS = 35 Or NNS = 36 Or NNS = 37 Or NNS = 38 Or NNS = 39 Or NNS = 40 Or NNS = 41 Or NNS = 42 Or NNS = 43 Or NNS = 44 Or NNS = 45 Or NNS = 46 Or NNS = 47 Or NNS = 48 Then
                column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter
            End If : NNS += 1
        Next
        X軸1 = 清單1_dgv.Location.X + 位置(0) + 位置(1) + 位置(4) + 位置(12) + 7
        星1_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星1_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(15) + 位置(16) : 星2_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星2_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(17) + 位置(18) : 星3_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星3_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(19) + 位置(20) : 星4_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星4_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(21) + 位置(22) : 星5_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星5_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(23) + 位置(24) : 星6_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星6_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(25) + 位置(26) : 星7_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星7_bt.Size = New Size(位置(15) + 位置(16) - 2, 星1_bt.Size.Height)
    End Sub
    Private Sub 表頭變形2()
        Dim NNS, 位置(50), X軸1 As Integer
        For Each column As DataGridViewColumn In 清單1_dgv.Columns
            If column.Index >= 0 Then
                Dim currentWidth As Integer = column.Width
                位置(NNS) = currentWidth
            End If
            If NNS = 15 Or NNS = 16 Or NNS = 17 Or NNS = 18 Or NNS = 19 Or NNS = 20 Or NNS = 21 Or NNS = 22 Or NNS = 23 Or NNS = 24 Or NNS = 25 Or NNS = 26 Or NNS = 27 Or NNS = 28 Or
               NNS = 35 Or NNS = 36 Or NNS = 37 Or NNS = 38 Or NNS = 39 Or NNS = 40 Or NNS = 41 Or NNS = 42 Or NNS = 43 Or NNS = 44 Or NNS = 45 Or NNS = 46 Or NNS = 47 Or NNS = 48 Then
                column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter
            End If : NNS += 1
        Next
        X軸1 = 清單1_dgv.Location.X + 位置(0) + 位置(1) + 位置(4) + 位置(13) + 位置(29) + 位置(30) + 位置(31) + 位置(32) + 位置(33) + 位置(34) + 7
        星1_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星1_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(35) + 位置(36) : 星2_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星2_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(37) + 位置(38) : 星3_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星3_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(39) + 位置(40) : 星4_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星4_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(41) + 位置(42) : 星5_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星5_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(43) + 位置(44) : 星6_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星6_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
        X軸1 = X軸1 + 位置(45) + 位置(46) : 星7_bt.Location = New System.Drawing.Point(X軸1, 星1_bt.Location.Y) : 星7_bt.Size = New Size(位置(35) + 位置(36) - 2, 星1_bt.Size.Height)
    End Sub
    Private Sub Set_虛擬表()
        Dim ds1 As New DataSet
        虛擬表_dgv.DataSource = Nothing : ds1.Clear()
        虛擬表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        虛擬表_dgv.ColumnHeadersHeight = 25 : 虛擬表_dgv.AllowUserToAddRows = False : 虛擬表_dgv.RowTemplate.Height = 25

        PA25 = 星1_bt.Text : SQL_考勤虛擬表() : PA25 = ""
        da.Fill(ds1) : 虛擬表_dgv.DataSource = ds1.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_總清單()
        Dim ds1 As New DataSet
        總清單_dgv.DataSource = Nothing : ds1.Clear()
        總清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        總清單_dgv.ColumnHeadersHeight = 25 : 總清單_dgv.AllowUserToAddRows = False : 總清單_dgv.RowTemplate.Height = 25

        PA2 = 年份2_cb.Text : PA3 = 月份2_cb.Text : PA25 = 地區_cb.SelectedIndex : SQL_考勤總明細() : PA25 = ""
        da.Fill(ds1) : 總清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        總清單_dgv.Columns(表頭(17)).FillWeight = 70 : 總清單_dgv.Columns(表頭(18)).FillWeight = 70
        總清單_dgv.Columns("第一").Visible = False : 總清單_dgv.Columns("第二").Visible = False : 總清單_dgv.Columns("第三").Visible = False
        總清單_dgv.Columns("第四").Visible = False : 總清單_dgv.Columns("第五").Visible = False : 總清單_dgv.Columns("第六").Visible = False

        For I As Integer = 4 To 9 : 總清單_dgv.Columns(表頭(I)).Visible = False : Next : 總時 = 0
        For i As Integer = 0 To 總清單_dgv.Rows.Count - 1
            '-------------基本資料準備------------------------------------
            If 工人_ch.Checked = True Then : 總清單_dgv.Rows(i).Cells(表頭(17)).Value = True
            Else : If IsDBNull(總清單_dgv.Rows(i).Cells(表頭(17)).Value) Then : 總清單_dgv.Rows(i).Cells(表頭(17)).Value = False : End If : End If
            If IsDBNull(總清單_dgv.Rows(i).Cells(表頭(18)).Value) Then : 總清單_dgv.Rows(i).Cells(表頭(18)).Value = False : End If
            If 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期一" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(0)
            ElseIf 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期二" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(1)
            ElseIf 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期三" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(2)
            ElseIf 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期四" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(3)
            ElseIf 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期五" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(4)
            ElseIf 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期六" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(5)
            ElseIf 總清單_dgv.Rows(i).Cells("MGB").Value.ToString = "星期日" Then : 總清單_dgv.Rows(i).Cells(表頭(2)).Value = 對話框(6)
            End If
            Dim DFG(6) As String : Dim CV As Integer = 1 : For V As Integer = 0 To 6 : DFG(V) = "" : Next
            If 總清單_dgv.Rows(i).Cells("第一").Value.ToString <> "" Then : DFG(CV) = 總清單_dgv.Rows(i).Cells("第一").Value.ToString : CV += 1 : End If
            If 總清單_dgv.Rows(i).Cells("第二").Value.ToString <> "" Then : DFG(CV) = 總清單_dgv.Rows(i).Cells("第二").Value.ToString : CV += 1 : End If
            If 總清單_dgv.Rows(i).Cells("第三").Value.ToString <> "" Then : DFG(CV) = 總清單_dgv.Rows(i).Cells("第三").Value.ToString : CV += 1 : End If
            If 總清單_dgv.Rows(i).Cells("第四").Value.ToString <> "" Then : DFG(CV) = 總清單_dgv.Rows(i).Cells("第四").Value.ToString : CV += 1 : End If
            If 總清單_dgv.Rows(i).Cells("第五").Value.ToString <> "" Then : DFG(CV) = 總清單_dgv.Rows(i).Cells("第五").Value.ToString : CV += 1 : End If
            If 總清單_dgv.Rows(i).Cells("第六").Value.ToString <> "" Then : DFG(CV) = 總清單_dgv.Rows(i).Cells("第六").Value.ToString : End If

            時段(1) = DFG(1) : 時段(2) = DFG(2)
            時段(3) = DFG(3) : 時段(4) = DFG(4)
            時段(5) = DFG(5) : 時段(6) = DFG(6)
            For II As Integer = 4 To 16 : 總清單_dgv.Rows(i).Cells(表頭(II)).Value = "" : Next
            '-------------時間推移計算------------------------------------
            If 時段(1) = "" And 時段(2) = "" And 時段(3) = "" And 時段(4) = "" And 時段(5) = "" And 時段(6) = "" Then
            ElseIf 時段(1) <> "" And 時段(2) = "" And 時段(3) = "" And 時段(4) = "" And 時段(5) = "" And 時段(6) = "" Then
                X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
            ElseIf 時段(1) <> "" And 時段(2) <> "" And 時段(3) = "" And 時段(4) = "" And 時段(5) = "" And 時段(6) = "" Then
                X1 = 時段(1) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(2) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 665 Then
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(15)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(9)).Value = 時段(2)
                    'X1 = 時段(1) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = X1 : 時段(2) = X1
                    'X1 = 時段(2) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = X1 : 時段(3) = X1
                    'X1 = 時段(3) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = X1 : 時段(4) = X1
                    'X1 = 時段(4) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = X1
                    總清單_dgv.Rows(i).Cells(表頭(11)).Value = "12:00:00" : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = "12:00:00"
                    總清單_dgv.Rows(i).Cells(表頭(12)).Value = "13:00:00" : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = "13:00:00"
                    總清單_dgv.Rows(i).Cells(表頭(13)).Value = "17:00:00" : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = "17:00:00"
                    總清單_dgv.Rows(i).Cells(表頭(14)).Value = "18:00:00" : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = "18:00:00"
                ElseIf 間隔1 >= 325 And 間隔1 < 665 Then
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(2)
                    'X1 = 時段(1) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = X1 : 時段(2) = X1
                    'X1 = 時段(2) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = X1 : 時段(3) = X1
                    總清單_dgv.Rows(i).Cells(表頭(11)).Value = "12:00:00" : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = "12:00:00"
                    總清單_dgv.Rows(i).Cells(表頭(12)).Value = "13:00:00" : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = "13:00:00"
                ElseIf 間隔1 < 325 Then
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(1) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                End If
            ElseIf 時段(1) <> "" And 時段(2) <> "" And 時段(3) <> "" And 時段(4) = "" And 時段(5) = "" And 時段(6) = "" Then
                X1 = 時段(1) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(3) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 665 Then          '---------大於十小時
                    X1 = 時段(1) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(2) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                    If 間隔1 <= 325 Then
                        X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                        X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                        X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(15)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(9)).Value = 時段(3)
                        'X1 = 時段(2) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = X1 : 時段(3) = X1
                        'X1 = 時段(3) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = X1 : 時段(4) = X1
                        'X1 = 時段(4) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = X1
                        總清單_dgv.Rows(i).Cells(表頭(12)).Value = "13:00:00" : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = "13:00:00"
                        總清單_dgv.Rows(i).Cells(表頭(13)).Value = "17:00:00" : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = "17:00:00"
                        總清單_dgv.Rows(i).Cells(表頭(14)).Value = "18:00:00" : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = "18:00:00"
                    ElseIf 間隔1 > 325 Then
                        X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                        X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(15)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(9)).Value = 時段(3)
                        'X1 = 時段(1) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = X1 : 時段(2) = X1
                        'X1 = 時段(2) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = X1 : 時段(3) = X1
                        'X1 = 時段(3) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = X1 : 時段(4) = X1
                        'X1 = 時段(4) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = X1
                        總清單_dgv.Rows(i).Cells(表頭(11)).Value = "12:00:00" : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = "12:00:00"
                        總清單_dgv.Rows(i).Cells(表頭(12)).Value = "13:00:00" : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = "13:00:00"
                        總清單_dgv.Rows(i).Cells(表頭(13)).Value = "17:00:00" : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = "17:00:00"
                        總清單_dgv.Rows(i).Cells(表頭(14)).Value = "18:00:00" : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = "18:00:00"
                    End If
                ElseIf 間隔1 > 325 And 間隔1 < 625 Then
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(3)
                    'X1 = 時段(1) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = X1 : 時段(2) = X1
                    'X1 = 時段(2) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = X1 : 時段(3) = X1
                    總清單_dgv.Rows(i).Cells(表頭(11)).Value = "12:00:00" : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = "12:00:00"
                    總清單_dgv.Rows(i).Cells(表頭(12)).Value = "13:00:00" : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = "13:00:00"
                ElseIf 間隔1 >= 325 Then
                    X1 = 時段(2) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(3) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                    If 間隔1 >= 90 Then
                        X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                        X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                        X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(3)
                        X1 = 時段(2) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = X1
                    Else
                        X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                        X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                        X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1
                    End If
                Else
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                    X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1
                End If
            ElseIf 時段(1) <> "" And 時段(2) <> "" And 時段(3) <> "" And 時段(4) <> "" And 時段(5) = "" And 時段(6) = "" Then
                X1 = 時段(1) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(4) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 665 Then
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                    X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = 時段(3)
                    X1 = 時段(4) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(15)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(9)).Value = 時段(4)
                    'X1 = 時段(3) : Set_時段定點_加四小時() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = X1 : 時段(4) = X1
                    'X1 = 時段(4) : Set_時段定點_加一小時() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = X1
                    總清單_dgv.Rows(i).Cells(表頭(13)).Value = "17:00:00" : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = "17:00:00"
                    總清單_dgv.Rows(i).Cells(表頭(14)).Value = "18:00:00" : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = "18:00:00"
                Else
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                    X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = 時段(3)
                    X1 = 時段(4) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(4)
                End If
            ElseIf 時段(1) <> "" And 時段(2) <> "" And 時段(3) <> "" And 時段(4) <> "" And 時段(5) <> "" And 時段(6) = "" Then
                X1 = 時段(1) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(5) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 665 Then
                    X1 = 時段(4) : Set_時段定點() : 計算(0) = X1 : X1 = 時段(5) : Set_時段定點() : 計算(1) = X1 : 時間比對()
                    If 間隔1 >= 90 Then
                        X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                        X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                        X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = 時段(3)
                        X1 = 時段(4) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(4)
                        X1 = 時段(5) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(15)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(9)).Value = 時段(6)
                        X1 = 時段(5) : Set_時段定點_減一小時() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = X1
                    Else
                        X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                        X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                        X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = 時段(3)
                        X1 = 時段(4) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(4)
                        X1 = 時段(5) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = 時段(5)
                    End If
                Else
                    X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                    X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                    X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = 時段(3)
                    X1 = 時段(4) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(4)
                    X1 = 時段(5) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = 時段(5)
                End If
            ElseIf 時段(1) <> "" And 時段(2) <> "" And 時段(3) <> "" And 時段(4) <> "" And 時段(5) <> "" And 時段(6) <> "" Then
                X1 = 時段(1) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(10)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(4)).Value = 時段(1)
                X1 = 時段(2) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(11)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(5)).Value = 時段(2)
                X1 = 時段(3) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(12)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(6)).Value = 時段(3)
                X1 = 時段(4) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(13)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(7)).Value = 時段(4)
                X1 = 時段(5) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(14)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(8)).Value = 時段(5)
                X1 = 時段(6) : Set_時段定點() : 總清單_dgv.Rows(i).Cells(表頭(15)).Value = X1 : 總清單_dgv.Rows(i).Cells(表頭(9)).Value = 時段(6)
            End If
            '-------------時間彙總計算------------------------------------
            時長 = 0
            If 總清單_dgv.Rows(i).Cells(表頭(10)).Value.ToString <> "" And 總清單_dgv.Rows(i).Cells(表頭(11)).Value.ToString <> "" And
               總清單_dgv.Rows(i).Cells(表頭(12)).Value.ToString = "" And 總清單_dgv.Rows(i).Cells(表頭(13)).Value.ToString = "" And
               總清單_dgv.Rows(i).Cells(表頭(14)).Value.ToString = "" And 總清單_dgv.Rows(i).Cells(表頭(15)).Value.ToString = "" Then
                計算(0) = 總清單_dgv.Rows(i).Cells(表頭(10)).Value.ToString : 計算(1) = 總清單_dgv.Rows(i).Cells(表頭(11)).Value.ToString : 時間比對() : 時長 += (間隔1 / 60)
                If 時長 <= 8 Then : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = "0" & 時長 & " H 00 M" : End If
            ElseIf 總清單_dgv.Rows(i).Cells(表頭(10)).Value.ToString <> "" And 總清單_dgv.Rows(i).Cells(表頭(11)).Value.ToString <> "" And
               總清單_dgv.Rows(i).Cells(表頭(12)).Value.ToString <> "" And 總清單_dgv.Rows(i).Cells(表頭(13)).Value.ToString <> "" And
               總清單_dgv.Rows(i).Cells(表頭(14)).Value.ToString = "" And 總清單_dgv.Rows(i).Cells(表頭(15)).Value.ToString = "" Then
                計算(0) = 總清單_dgv.Rows(i).Cells(表頭(10)).Value.ToString : 計算(1) = 總清單_dgv.Rows(i).Cells(表頭(11)).Value.ToString : 時間比對() : 時長 += (間隔1 / 60)
                計算(0) = 總清單_dgv.Rows(i).Cells(表頭(12)).Value.ToString : 計算(1) = 總清單_dgv.Rows(i).Cells(表頭(13)).Value.ToString : 時間比對() : 時長 += (間隔1 / 60)
                If 時長 <= 8 Then : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = "0" & 時長 & " H 00 M" : Else
                    If 總清單_dgv.Rows(i).Cells(表頭(17)).Value = False Then
                        總清單_dgv.Rows(i).Cells(表頭(16)).Value = "08 H 00 M"
                    Else
                        If 時長 < 10 Then : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = "0" & 時長 & " H 00 M"
                        Else : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = 時長 & " H 00 M" : End If
                    End If
                End If
            ElseIf 總清單_dgv.Rows(i).Cells(表頭(10)).Value.ToString <> "" And 總清單_dgv.Rows(i).Cells(表頭(11)).Value.ToString <> "" And
               總清單_dgv.Rows(i).Cells(表頭(12)).Value.ToString <> "" And 總清單_dgv.Rows(i).Cells(表頭(13)).Value.ToString <> "" And
               總清單_dgv.Rows(i).Cells(表頭(14)).Value.ToString <> "" And 總清單_dgv.Rows(i).Cells(表頭(15)).Value.ToString <> "" Then
                計算(0) = 總清單_dgv.Rows(i).Cells(表頭(10)).Value.ToString : 計算(1) = 總清單_dgv.Rows(i).Cells(表頭(11)).Value.ToString : 時間比對() : 時長 += (間隔1 / 60)
                計算(0) = 總清單_dgv.Rows(i).Cells(表頭(12)).Value.ToString : 計算(1) = 總清單_dgv.Rows(i).Cells(表頭(13)).Value.ToString : 時間比對() : 時長 += (間隔1 / 60)
                計算(0) = 總清單_dgv.Rows(i).Cells(表頭(14)).Value.ToString : 計算(1) = 總清單_dgv.Rows(i).Cells(表頭(15)).Value.ToString : 時間比對() : 時長 += (間隔1 / 60)
                If 時長 <= 8 Then : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = "0" & 時長 & " H 00 M" : Else
                    If 總清單_dgv.Rows(i).Cells(表頭(17)).Value = False Then
                        總清單_dgv.Rows(i).Cells(表頭(16)).Value = "08 H 00 M"
                    Else
                        If 時長 < 10 Then : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = "0" & 時長 & " H 00 M"
                        Else : 總清單_dgv.Rows(i).Cells(表頭(16)).Value = 時長 & " H 00 M" : End If
                    End If
                End If
            End If
        Next : For I As Integer = 10 To 15 : 總清單_dgv.Columns(I).Visible = True : Next
    End Sub
    Private Sub Set_時段定點()
        Dim 時 As String = Strings.Left(X1, 2) : Dim 分 As String = Strings.Mid(X1, 4, 2)
        If (時 = "23" And CInt(分) >= 30) Or (時 = "00" And CInt(分) < 0) Then : X1 = "23:59:59" : ElseIf (時 = "00" And CInt(分) >= 30) Or (時 = "01" And CInt(分) < 30) Then : X1 = "01:00:00"
        ElseIf (時 = "01" And CInt(分) >= 30) Or (時 = "02" And CInt(分) < 30) Then : X1 = "02:00:00" : ElseIf (時 = "02" And CInt(分) >= 30) Or (時 = "03" And CInt(分) < 30) Then : X1 = "03:00:00"
        ElseIf (時 = "03" And CInt(分) >= 30) Or (時 = "04" And CInt(分) < 30) Then : X1 = "04:00:00" : ElseIf (時 = "04" And CInt(分) >= 30) Or (時 = "05" And CInt(分) < 30) Then : X1 = "05:00:00"
        ElseIf (時 = "05" And CInt(分) >= 30) Or (時 = "06" And CInt(分) < 30) Then : X1 = "06:00:00" : ElseIf (時 = "06" And CInt(分) >= 30) Or (時 = "07" And CInt(分) < 30) Then : X1 = "07:00:00"
        ElseIf (時 = "07" And CInt(分) >= 30) Or (時 = "08" And CInt(分) < 30) Then : X1 = "08:00:00" : ElseIf (時 = "08" And CInt(分) >= 30) Or (時 = "09" And CInt(分) < 30) Then : X1 = "09:00:00"
        ElseIf (時 = "09" And CInt(分) >= 30) Or (時 = "10" And CInt(分) < 30) Then : X1 = "10:00:00" : ElseIf (時 = "10" And CInt(分) >= 30) Or (時 = "11" And CInt(分) < 30) Then : X1 = "11:00:00"
        ElseIf (時 = "11" And CInt(分) >= 30) Or (時 = "12" And CInt(分) < 30) Then : X1 = "12:00:00" : ElseIf (時 = "12" And CInt(分) >= 30) Or (時 = "13" And CInt(分) < 30) Then : X1 = "13:00:00"
        ElseIf (時 = "13" And CInt(分) >= 30) Or (時 = "14" And CInt(分) < 30) Then : X1 = "14:00:00" : ElseIf (時 = "14" And CInt(分) >= 30) Or (時 = "15" And CInt(分) < 30) Then : X1 = "15:00:00"
        ElseIf (時 = "15" And CInt(分) >= 30) Or (時 = "16" And CInt(分) < 30) Then : X1 = "16:00:00" : ElseIf (時 = "16" And CInt(分) >= 30) Or (時 = "17" And CInt(分) < 30) Then : X1 = "17:00:00"
        ElseIf (時 = "17" And CInt(分) >= 30) Or (時 = "18" And CInt(分) < 30) Then : X1 = "18:00:00" : ElseIf (時 = "18" And CInt(分) >= 30) Or (時 = "19" And CInt(分) < 30) Then : X1 = "19:00:00"
        ElseIf (時 = "19" And CInt(分) >= 30) Or (時 = "20" And CInt(分) < 30) Then : X1 = "20:00:00" : ElseIf (時 = "20" And CInt(分) >= 30) Or (時 = "21" And CInt(分) < 30) Then : X1 = "21:00:00"
        ElseIf (時 = "21" And CInt(分) >= 30) Or (時 = "22" And CInt(分) < 30) Then : X1 = "22:00:00" : ElseIf (時 = "22" And CInt(分) >= 30) Or (時 = "23" And CInt(分) < 30) Then : X1 = "23:00:00"
        End If
    End Sub
    Private Sub Set_時段定點_減一小時()
        Dim 時 As String = Strings.Left(X1, 2) : Dim 分 As String = Strings.Mid(X1, 4, 2)
        If (時 = "23" And CInt(分) >= 30) Or (時 = "00" And CInt(分) < 30) Then : X1 = "23:00:00" : ElseIf (時 = "00" And CInt(分) >= 30) Or (時 = "01" And CInt(分) < 30) Then : X1 = "00:00:00"
        ElseIf (時 = "01" And CInt(分) >= 30) Or (時 = "02" And CInt(分) < 30) Then : X1 = "01:00:00" : ElseIf (時 = "02" And CInt(分) >= 30) Or (時 = "03" And CInt(分) < 30) Then : X1 = "02:00:00"
        ElseIf (時 = "03" And CInt(分) >= 30) Or (時 = "04" And CInt(分) < 30) Then : X1 = "03:00:00" : ElseIf (時 = "04" And CInt(分) >= 30) Or (時 = "05" And CInt(分) < 30) Then : X1 = "04:00:00"
        ElseIf (時 = "05" And CInt(分) >= 30) Or (時 = "06" And CInt(分) < 30) Then : X1 = "05:00:00" : ElseIf (時 = "06" And CInt(分) >= 30) Or (時 = "07" And CInt(分) < 30) Then : X1 = "06:00:00"
        ElseIf (時 = "07" And CInt(分) >= 30) Or (時 = "08" And CInt(分) < 30) Then : X1 = "07:00:00" : ElseIf (時 = "08" And CInt(分) >= 30) Or (時 = "09" And CInt(分) < 30) Then : X1 = "08:00:00"
        ElseIf (時 = "09" And CInt(分) >= 30) Or (時 = "10" And CInt(分) < 30) Then : X1 = "09:00:00" : ElseIf (時 = "10" And CInt(分) >= 30) Or (時 = "11" And CInt(分) < 30) Then : X1 = "10:00:00"
        ElseIf (時 = "11" And CInt(分) >= 30) Or (時 = "12" And CInt(分) < 30) Then : X1 = "11:00:00" : ElseIf (時 = "12" And CInt(分) >= 30) Or (時 = "13" And CInt(分) < 30) Then : X1 = "12:00:00"
        ElseIf (時 = "13" And CInt(分) >= 30) Or (時 = "14" And CInt(分) < 30) Then : X1 = "13:00:00" : ElseIf (時 = "14" And CInt(分) >= 30) Or (時 = "15" And CInt(分) < 30) Then : X1 = "14:00:00"
        ElseIf (時 = "15" And CInt(分) >= 30) Or (時 = "16" And CInt(分) < 30) Then : X1 = "15:00:00" : ElseIf (時 = "16" And CInt(分) >= 30) Or (時 = "17" And CInt(分) < 30) Then : X1 = "16:00:00"
        ElseIf (時 = "17" And CInt(分) >= 30) Or (時 = "18" And CInt(分) < 30) Then : X1 = "17:00:00" : ElseIf (時 = "18" And CInt(分) >= 30) Or (時 = "19" And CInt(分) < 30) Then : X1 = "18:00:00"
        ElseIf (時 = "19" And CInt(分) >= 30) Or (時 = "20" And CInt(分) < 30) Then : X1 = "19:00:00" : ElseIf (時 = "20" And CInt(分) >= 30) Or (時 = "21" And CInt(分) < 30) Then : X1 = "20:00:00"
        ElseIf (時 = "21" And CInt(分) >= 30) Or (時 = "22" And CInt(分) < 30) Then : X1 = "21:00:00" : ElseIf (時 = "22" And CInt(分) >= 30) Or (時 = "23" And CInt(分) < 30) Then : X1 = "22:00:00"
        End If
    End Sub
    Private Sub Set_時段定點_加一小時()
        Dim 時 As String = Strings.Left(X1, 2) : Dim 分 As String = Strings.Mid(X1, 4, 2)
        If (時 = "23" And CInt(分) >= 30) Or (時 = "00" And CInt(分) < 30) Then : X1 = "01:00:00" : ElseIf (時 = "00" And CInt(分) >= 30) Or (時 = "01" And CInt(分) < 30) Then : X1 = "02:00:00"
        ElseIf (時 = "01" And CInt(分) >= 30) Or (時 = "02" And CInt(分) < 30) Then : X1 = "03:00:00" : ElseIf (時 = "02" And CInt(分) >= 30) Or (時 = "03" And CInt(分) < 30) Then : X1 = "04:00:00"
        ElseIf (時 = "03" And CInt(分) >= 30) Or (時 = "04" And CInt(分) < 30) Then : X1 = "05:00:00" : ElseIf (時 = "04" And CInt(分) >= 30) Or (時 = "05" And CInt(分) < 30) Then : X1 = "06:00:00"
        ElseIf (時 = "05" And CInt(分) >= 30) Or (時 = "06" And CInt(分) < 30) Then : X1 = "07:00:00" : ElseIf (時 = "06" And CInt(分) >= 30) Or (時 = "07" And CInt(分) < 30) Then : X1 = "08:00:00"
        ElseIf (時 = "07" And CInt(分) >= 30) Or (時 = "08" And CInt(分) < 30) Then : X1 = "09:00:00" : ElseIf (時 = "08" And CInt(分) >= 30) Or (時 = "09" And CInt(分) < 30) Then : X1 = "10:00:00"
        ElseIf (時 = "09" And CInt(分) >= 30) Or (時 = "10" And CInt(分) < 30) Then : X1 = "11:00:00" : ElseIf (時 = "10" And CInt(分) >= 30) Or (時 = "11" And CInt(分) < 30) Then : X1 = "12:00:00"
        ElseIf (時 = "11" And CInt(分) >= 30) Or (時 = "12" And CInt(分) < 30) Then : X1 = "13:00:00" : ElseIf (時 = "12" And CInt(分) >= 30) Or (時 = "13" And CInt(分) < 30) Then : X1 = "14:00:00"
        ElseIf (時 = "13" And CInt(分) >= 30) Or (時 = "14" And CInt(分) < 30) Then : X1 = "15:00:00" : ElseIf (時 = "14" And CInt(分) >= 30) Or (時 = "15" And CInt(分) < 30) Then : X1 = "16:00:00"
        ElseIf (時 = "15" And CInt(分) >= 30) Or (時 = "16" And CInt(分) < 30) Then : X1 = "17:00:00" : ElseIf (時 = "16" And CInt(分) >= 30) Or (時 = "17" And CInt(分) < 30) Then : X1 = "18:00:00"
        ElseIf (時 = "17" And CInt(分) >= 30) Or (時 = "18" And CInt(分) < 30) Then : X1 = "19:00:00" : ElseIf (時 = "18" And CInt(分) >= 30) Or (時 = "19" And CInt(分) < 30) Then : X1 = "20:00:00"
        ElseIf (時 = "19" And CInt(分) >= 30) Or (時 = "20" And CInt(分) < 30) Then : X1 = "21:00:00" : ElseIf (時 = "20" And CInt(分) >= 30) Or (時 = "21" And CInt(分) < 30) Then : X1 = "22:00:00"
        ElseIf (時 = "21" And CInt(分) >= 30) Or (時 = "22" And CInt(分) < 30) Then : X1 = "23:00:00" : ElseIf (時 = "22" And CInt(分) >= 30) Or (時 = "23" And CInt(分) < 30) Then : X1 = "24:00:00"
        End If
    End Sub
    Private Sub Set_時段定點_加四小時()
        Dim 時 As String = Strings.Left(X1, 2) : Dim 分 As String = Strings.Mid(X1, 4, 2)
        If (時 = "23" And CInt(分) >= 30) Or (時 = "00" And CInt(分) < 30) Then : X1 = "04:00:00" : ElseIf (時 = "00" And CInt(分) >= 30) Or (時 = "01" And CInt(分) < 30) Then : X1 = "05:00:00"
        ElseIf (時 = "01" And CInt(分) >= 30) Or (時 = "02" And CInt(分) < 30) Then : X1 = "06:00:00" : ElseIf (時 = "02" And CInt(分) >= 30) Or (時 = "03" And CInt(分) < 30) Then : X1 = "07:00:00"
        ElseIf (時 = "03" And CInt(分) >= 30) Or (時 = "04" And CInt(分) < 30) Then : X1 = "08:00:00" : ElseIf (時 = "04" And CInt(分) >= 30) Or (時 = "05" And CInt(分) < 30) Then : X1 = "09:00:00"
        ElseIf (時 = "05" And CInt(分) >= 30) Or (時 = "06" And CInt(分) < 30) Then : X1 = "10:00:00" : ElseIf (時 = "06" And CInt(分) >= 30) Or (時 = "07" And CInt(分) < 30) Then : X1 = "11:00:00"
        ElseIf (時 = "07" And CInt(分) >= 30) Or (時 = "08" And CInt(分) < 30) Then : X1 = "12:00:00" : ElseIf (時 = "08" And CInt(分) >= 30) Or (時 = "09" And CInt(分) < 30) Then : X1 = "13:00:00"
        ElseIf (時 = "09" And CInt(分) >= 30) Or (時 = "10" And CInt(分) < 30) Then : X1 = "14:00:00" : ElseIf (時 = "10" And CInt(分) >= 30) Or (時 = "11" And CInt(分) < 30) Then : X1 = "15:00:00"
        ElseIf (時 = "11" And CInt(分) >= 30) Or (時 = "12" And CInt(分) < 30) Then : X1 = "16:00:00" : ElseIf (時 = "12" And CInt(分) >= 30) Or (時 = "13" And CInt(分) < 30) Then : X1 = "17:00:00"
        ElseIf (時 = "13" And CInt(分) >= 30) Or (時 = "14" And CInt(分) < 30) Then : X1 = "18:00:00" : ElseIf (時 = "14" And CInt(分) >= 30) Or (時 = "15" And CInt(分) < 30) Then : X1 = "19:00:00"
        ElseIf (時 = "15" And CInt(分) >= 30) Or (時 = "16" And CInt(分) < 30) Then : X1 = "20:00:00" : ElseIf (時 = "16" And CInt(分) >= 30) Or (時 = "17" And CInt(分) < 30) Then : X1 = "21:00:00"
        ElseIf (時 = "17" And CInt(分) >= 30) Or (時 = "18" And CInt(分) < 30) Then : X1 = "22:00:00" : ElseIf (時 = "18" And CInt(分) >= 30) Or (時 = "19" And CInt(分) < 30) Then : X1 = "23:00:00"
        ElseIf (時 = "19" And CInt(分) >= 30) Or (時 = "20" And CInt(分) < 30) Then : X1 = "00:00:00" : ElseIf (時 = "20" And CInt(分) >= 30) Or (時 = "21" And CInt(分) < 30) Then : X1 = "01:00:00"
        ElseIf (時 = "21" And CInt(分) >= 30) Or (時 = "22" And CInt(分) < 30) Then : X1 = "02:00:00" : ElseIf (時 = "22" And CInt(分) >= 30) Or (時 = "23" And CInt(分) < 30) Then : X1 = "03:00:00"
        End If
    End Sub
    Private Sub 時間比對()
        Dim dateA As Date = Date.ParseExact("[" & 計算(0) & "]", "[HH:mm:ss]", Nothing)
        Dim dateB As Date = Date.ParseExact("[" & 計算(1) & "]", "[HH:mm:ss]", Nothing)
        Dim hoursDiff As Integer = DateDiff(DateInterval.Minute, dateA, dateB)
        間隔1 = Math.Abs(hoursDiff)
    End Sub
    Private Sub 級別清單()
        SQL_考勤級別讀取() : 級別_cb.Items.Clear() : 級別_cb.Items.Add("")
        While (dr.Read()) : 級別_cb.Items.Add(dr("級別")) : End While : conn.Close()
    End Sub
    Private Sub 地區清單()
        地區_cb.Items.Clear() : 地區_cb.Items.Add("") : 地區_cb.Items.Add(對話框(16)) : 地區_cb.Items.Add(對話框(17))
    End Sub
    Private Sub 年分清單()
        SQL_年分清單() : 年份2_cb.Items.Clear()
        While (dr.Read()) : 年份2_cb.Items.Add(dr("日期")) : End While : conn.Close()
    End Sub
    Private Sub 群組清單()
        SQL_人員薪資表_群組() : 群組_cb.Items.Clear() : 群組1_cb.Items.Clear() : 群組_cb.Items.Add("") : 群組1_cb.Items.Add("")
        While (dr.Read()) : 群組_cb.Items.Add(dr("部門名稱")) : 群組1_cb.Items.Add(dr("部門名稱")) : End While : conn.Close()
    End Sub
    Private Sub 星期設定()
        星1_bt.Text = Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd") : 星2_bt.Text = Strings.Format(開始日期_dtp.Value.AddDays(1), "yyyy/MM/dd")
        星3_bt.Text = Strings.Format(開始日期_dtp.Value.AddDays(2), "yyyy/MM/dd") : 星4_bt.Text = Strings.Format(開始日期_dtp.Value.AddDays(3), "yyyy/MM/dd")
        星5_bt.Text = Strings.Format(開始日期_dtp.Value.AddDays(4), "yyyy/MM/dd") : 星6_bt.Text = Strings.Format(開始日期_dtp.Value.AddDays(5), "yyyy/MM/dd")
        星7_bt.Text = Strings.Format(開始日期_dtp.Value.AddDays(6), "yyyy/MM/dd")
    End Sub
    Private Sub 人員薪資_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        HX_PGS_ERP_SYS.WindowState = 2 : Me.MdiParent = HX_PGS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        HX_PGS_ERP_SYS.MaximizeBox = False : HX_PGS_ERP_SYS.MinimizeBox = False : 之前選擇 = -1
        H(611) = True : 介面 = "H611" : 語言轉換讀取() : 首次開啟 = True : 顯示說明(999, False)

        結束日期_dtp.Value = Today() : 開始日期_dtp.Value = 結束日期_dtp.Value
        Dim oldDate As Date : Dim oldWeekDay As Integer : oldDate = 結束日期_dtp.Value : oldWeekDay = Weekday(oldDate)
        If oldWeekDay = 7 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(1)
        ElseIf oldWeekDay = 6 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(2)
        ElseIf oldWeekDay = 5 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(3)
        ElseIf oldWeekDay = 4 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(4)
        ElseIf oldWeekDay = 3 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(5)
        ElseIf oldWeekDay = 2 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(6)
        End If : 開始日期_dtp.Value = 結束日期_dtp.Value.AddDays(-6) : 結束日期_dtp.Value = 開始日期_dtp.Value.AddDays(+6)
        本周周一 = 開始日期_dtp.Value : 星期設定()

        If 登入人級別 = "00" Then
            縮放2_bt.Visible = True
        Else
            縮放2_bt.Visible = False
        End If
        工人 = True : 在職 = True : 總清單_dgv.Visible = False : 視窗3_pl.Visible = False : 總清單_dgv.SendToBack() : Panel2.SendToBack()
    End Sub
    Private Sub 人員薪資_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        年分清單() : 年份2_cb.Text = Year(Today) : 月份2_cb.SelectedIndex = Month(Today) - 1
        群組清單() : 群組1_cb.Text = "HARIAN GROUP"
        級別清單() : 地區清單() : Set_使用者清單() : 首次開啟 = False
    End Sub
    Private Sub 人員薪資_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        MyMod.清單字體大小調整()
        清單1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 語轉扭_bt_Click(sender As Object, e As EventArgs) Handles 語轉扭_bt.Click
        H(611) = True : 介面 = "H611" : 語言轉換讀取() : 首次開啟 = False
    End Sub
    Private Sub 人員薪資_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        HX_PGS_ERP_SYS.WindowState = 0 : HX_PGS_ERP_SYS.MaximizeBox = True : HX_PGS_ERP_SYS.MinimizeBox = True
        H(611) = False : MyMod.虛擬桌面開啟()
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : HX_PGS_ERP_SYS.Timer1.Enabled = False : HX_PGS_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : HX_PGS_ERP_SYS.Timer1.Enabled = False : HX_PGS_ERP_SYS.Timer1.Enabled = True
    End Sub

    Private Sub 清單1_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 清單1_dgv.MouseUp
        'If 清單1_dgv.SelectedCells.Count = 1 Then : MsgBox(清單1_dgv.SelectedCells(0).ColumnIndex & "  " & 清單1_dgv.SelectedCells(0).RowIndex) : End If
        If 清單1_dgv.SelectedCells.Count > 0 Then
            If 之前選擇 = -1 Then : Else
                If 深色風格 = False Then : 清單1_dgv.Rows(之前選擇).DefaultCellStyle.BackColor = Color.White
                Else : 清單1_dgv.Rows(之前選擇).DefaultCellStyle.BackColor = Color.Black : End If
            End If
            If 深色風格 = False Then
                清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).DefaultCellStyle.BackColor = Color.LightGreen : 之前選擇 = 清單1_dgv.SelectedCells(0).RowIndex
            Else
                清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).DefaultCellStyle.BackColor = Color.Green : 之前選擇 = 清單1_dgv.SelectedCells(0).RowIndex
            End If
            If 清單1_dgv.SelectedCells(0).ColumnIndex = 0 Then
                If 群組選擇_ch.Checked = True Then
                    群組_cb.Text = 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(0).Value.ToString
                    CB選擇清單(群組_cb, 群組_cb.Text)
                    清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(0).Value = 群組_cb.Text
                End If
            ElseIf 清單1_dgv.SelectedCells(0).ColumnIndex = 11 Then
                Dim 原來的 As String = 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(11).Value.ToString
                For I As Integer = 0 To 3000 : PPBB(I) = "" : Next
                For I As Integer = 0 To 4 : PPBB(I) = 對話框(I) : NN1 = I : Next
                下拉清單_2.ShowDialog()
                If PPAA = "" Then : 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(11).Value = 原來的
                Else : 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(11).Value = PPAA : End If
            ElseIf 清單1_dgv.SelectedCells(0).ColumnIndex = 49 Then
                PA30 = 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(0).Value
                PA31 = 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(0).Value
                PA32 = 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(12).Value
                PA33 = 清單1_dgv.Rows(清單1_dgv.SelectedCells(0).RowIndex).Cells(50).Value
                SQL_人員薪資表_修改() : 群組清單() : MGB(系統語言字典("H509-126-" & 語言), 1)
            End If
        End If
    End Sub
    Private Sub 清單1_dgv_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles 清單1_dgv.CellEnter
        Dim TSSL As Long
        For XC As Integer = 0 To 清單1_dgv.Rows.Count - 1
            If IsDBNull(清單1_dgv.Rows(XC).Cells(12).Value) Then : Else
                If 清單1_dgv.Rows(XC).Cells(12).Value.ToString <> "" Then
                    清單1_dgv.Rows(XC).Cells(31).Value = Strings.Format(清單1_dgv.Rows(XC).Cells(12).Value / 8, "#,##0")
                    清單1_dgv.Rows(XC).Cells(32).Value = Strings.Format(清單1_dgv.Rows(XC).Cells(12).Value / 6, "#,##0")
                    清單1_dgv.Rows(XC).Cells(29).Value = Strings.Format((清單1_dgv.Rows(XC).Cells(12).Value / 8) * CLng(清單1_dgv.Rows(XC).Cells(33).Value.ToString), "#,##0")
                    清單1_dgv.Rows(XC).Cells(30).Value = Strings.Format((清單1_dgv.Rows(XC).Cells(12).Value / 6) * CLng(清單1_dgv.Rows(XC).Cells(34).Value.ToString), "#,##0")
                    清單1_dgv.Rows(XC).Cells(13).Value = CLng(清單1_dgv.Rows(XC).Cells(29).Value.ToString) + CLng(清單1_dgv.Rows(XC).Cells(30).Value.ToString)
                    TSSL += CLng(清單1_dgv.Rows(XC).Cells(13).Value.ToString)
                    HX_PGS_ERP_SYS.合計_TSSL.Text = "Total : " & Strings.Format(TSSL, "#,##0")
                End If
            End If
            清單1_dgv.Rows(XC).Cells(表頭(30)).Value = 清單1_dgv.Rows(XC).Cells(表頭(25)).Value
            If 清單1_dgv.Rows(XC).Cells(0).Value.ToString <> "" Then : 清單1_dgv.Rows(XC).Cells(0).Value = 清單1_dgv.Rows(XC).Cells(0).Value.ToString.ToUpper : End If
            If 清單1_dgv.Rows(XC).Cells(1).Value.ToString <> "" Then : 清單1_dgv.Rows(XC).Cells(1).Value = 清單1_dgv.Rows(XC).Cells(1).Value.ToString.ToUpper : End If
        Next
    End Sub
    Private Sub DA1_bt_Click(sender As Object, e As EventArgs) Handles DA1_bt.Click
        結束日期_dtp.Value = 開始日期_dtp.Value.AddDays(-1) : 開始日期_dtp.Value = 開始日期_dtp.Value.AddDays(-7)
        日期判斷() : 星期設定() : Set_使用者清單()
    End Sub
    Private Sub DA2_bt_Click(sender As Object, e As EventArgs) Handles DA2_bt.Click
        結束日期_dtp.Value = Today() : 開始日期_dtp.Value = 結束日期_dtp.Value
        Dim oldDate As Date : Dim oldWeekDay As Integer : oldDate = 結束日期_dtp.Value : oldWeekDay = Weekday(oldDate)
        If oldWeekDay = 7 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(1) : ElseIf oldWeekDay = 6 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(2)
        ElseIf oldWeekDay = 5 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(3) : ElseIf oldWeekDay = 4 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(4)
        ElseIf oldWeekDay = 3 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(5) : ElseIf oldWeekDay = 2 Then : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(6)
        End If : 開始日期_dtp.Value = 結束日期_dtp.Value.AddDays(-6) : 結束日期_dtp.Value = 開始日期_dtp.Value.AddDays(+6)
        日期判斷() : 星期設定() : Set_使用者清單()
    End Sub
    Private Sub DA3_bt_Click(sender As Object, e As EventArgs) Handles DA3_bt.Click
        結束日期_dtp.Value = 開始日期_dtp.Value.AddDays(+13) : 開始日期_dtp.Value = 開始日期_dtp.Value.AddDays(+7)
        日期判斷() : 星期設定() : Set_使用者清單()
    End Sub
    Private Sub 重新讀取_bt_Click(sender As Object, e As EventArgs) Handles 重新讀取_bt.Click
        日期判斷() : 星期設定() : Set_使用者清單()
    End Sub
    Private Sub 日期判斷()
        If Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 4) <> Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 4) Then
            PA17 = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 4) : PA18 = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 4)
            選擇考勤月份.ShowDialog() : 年份2_cb.Text = PA19
        Else
            If Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 4) <> 年份2_cb.Text Then : 年份2_cb.Text = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 4) : End If
        End If
        If Strings.Mid(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 6, 2) <> Strings.Mid(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 6, 2) Then
            PA17 = Strings.Mid(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 6, 2) : PA18 = Strings.Mid(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 6, 2)
            選擇考勤月份.ShowDialog() : 月份2_cb.Text = PA19
        Else
            If Strings.Mid(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 6, 2) <> 月份2_cb.Text Then : 月份2_cb.Text = Strings.Mid(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 6, 2) : End If
        End If
    End Sub
    Private Sub 群組輸入_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 群組輸入_ch.Click
        群組輸入_ch.Checked = True : 群組選擇_ch.Checked = False : 清單1_dgv.Columns(0).ReadOnly = False
    End Sub
    Private Sub 群組選擇_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 群組選擇_ch.Click
        群組輸入_ch.Checked = False : 群組選擇_ch.Checked = True : 清單1_dgv.Columns(0).ReadOnly = True
    End Sub
    Private Sub 設定_bt_Click(sender As Object, e As EventArgs) Handles 設定_bt.Click
        'If 清單1_dgv.Columns(11).Visible = False Then : 清單1_dgv.Columns(11).Visible = True : Else : 清單1_dgv.Columns(11).Visible = False : End If
        Dim XC As Integer = Me.Size.Width : Dim YC As Integer = Me.Size.Height : Dim XD As Integer = 視窗3_pl.Width : Dim YD As Integer = 視窗3_pl.Height : 首次開啟 = False
        If 視窗3_pl.Visible = False Then
            If 群組1_cb.Text <> "HARIAN GROUP" Then : MGB(系統語言字典("H611-110-" & 語言), 1) : Else
                視窗3_pl.Location = New System.Drawing.Point((XC - XD) / 2, (YC - YD) / 2) : 視窗3_pl.Visible = True : 視窗3_pl.BringToFront()
                極限設定()
            End If
        Else : 視窗3_pl.Visible = False : End If
    End Sub
    Private Sub 加班_nud_ValueChanged(sender As Object, e As EventArgs) Handles 加班_nud.ValueChanged
        極限設定()
    End Sub
    Private Sub 沖帳金額_nud_ValueChanged(sender As Object, e As EventArgs) Handles 沖帳金額_nud.ValueChanged
        休假比例_nud.Value = (沖帳金額_nud.Value / 總數_nud.Value * 100)
        休假天數_nud.Value = 可沖天數_nud.Value - (沖帳金額_nud.Value / 平均每天_nud.Value)
    End Sub
    Private Sub 極限設定()
        If 首次開啟 = False Then
            Dim 總次數 As Integer = 0 : 總數_nud.Value = 0
            For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
                If 清單1_dgv.Rows(i).Cells(12).Value.ToString <> "" Then
                    總數_nud.Value += (清單1_dgv.Rows(i).Cells(12).Value + ((清單1_dgv.Rows(i).Cells(12).Value / 6) * 加班_nud.Value)) * 7 : 總次數 += 7
                End If
            Next : 可沖天數_nud.Value = 總次數 : 平均每天_nud.Value = 總數_nud.Value / 可沖天數_nud.Value
            沖帳金額_nud.Maximum = 總數_nud.Value : 沖帳金額_nud.Minimum = 可沖天數_nud.Value : 沖帳金額_nud.Value = 平均每天_nud.Value * 7
            休假比例_nud.Value = 100 - (沖帳金額_nud.Value / 總數_nud.Value * 100)
            休假天數_nud.Value = 可沖天數_nud.Value - (沖帳金額_nud.Value / 平均每天_nud.Value)
        End If
    End Sub
    Private Sub 縮放2_bt_Click(sender As Object, e As EventArgs) Handles 縮放2_bt.Click
        If 總清單_dgv.Visible = False Then : 總清單_dgv.Visible = True : 總清單_dgv.BringToFront() : Else : 總清單_dgv.Visible = False : 總清單_dgv.SendToBack() : End If
    End Sub
    Private Sub 考勤表_bt_Click(sender As Object, e As EventArgs) Handles 考勤表_bt.Click
        合計_dgv.Columns(12).Visible = True : For i As Integer = 15 To 28 : 合計_dgv.Columns(i).Visible = True : Next
        合計_dgv.Columns(13).Visible = False : For i As Integer = 29 To 48 : 合計_dgv.Columns(i).Visible = False : Next
        清單1_dgv.Columns(12).Visible = True : For i As Integer = 15 To 28 : 清單1_dgv.Columns(i).Visible = True : Next
        清單1_dgv.Columns(13).Visible = False : For i As Integer = 29 To 48 : 清單1_dgv.Columns(i).Visible = False : Next : 表頭變形1()
    End Sub
    Private Sub 薪資表_bt_Click(sender As Object, e As EventArgs) Handles 薪資表_bt.Click
        合計_dgv.Columns(12).Visible = False : For i As Integer = 15 To 28 : 合計_dgv.Columns(i).Visible = False : Next
        合計_dgv.Columns(13).Visible = True : For i As Integer = 29 To 48 : 合計_dgv.Columns(i).Visible = True : Next
        清單1_dgv.Columns(12).Visible = False : For i As Integer = 15 To 28 : 清單1_dgv.Columns(i).Visible = False : Next
        清單1_dgv.Columns(13).Visible = True : For i As Integer = 29 To 48 : 清單1_dgv.Columns(i).Visible = True : Next : 表頭變形2()
    End Sub
    Private Sub 級別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 級別_cb.SelectedIndexChanged
        Set_使用者清單()
    End Sub
    Private Sub 地區_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 地區_cb.SelectedIndexChanged
        Set_使用者清單()
    End Sub
    Private Sub 群組_cb_Click(sender As Object, e As EventArgs) Handles 群組_cb.Click
        CB選擇清單_可選空白(群組_cb) : Set_使用者清單()
    End Sub
    Private Sub 年份2_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 年份2_cb.SelectedIndexChanged
        If 首次開啟 = False Then : Set_使用者清單() : End If
    End Sub
    Private Sub 年份2_cb_Click(sender As Object, e As EventArgs) Handles 年份2_cb.Click
        CB選擇清單(年份2_cb, 年份2_cb.Text) : Set_使用者清單()
    End Sub
    Private Sub 月份2_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月份2_cb.SelectedIndexChanged
        If 首次開啟 = False Then : Set_使用者清單() : End If
    End Sub
    Private Sub 月份2_cb_Click(sender As Object, e As EventArgs) Handles 月份2_cb.Click
        CB選擇清單(月份2_cb, 月份2_cb.Text) : Set_使用者清單()
    End Sub
    Private Sub 工人_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 工人_ch.Click
        If 工人_ch.Checked = True Then : 工人 = True : Else : 工人 = False : End If : Set_使用者清單()
    End Sub
    Private Sub CanceL3_bt_Click(sender As Object, e As EventArgs) Handles CanceL3_bt.Click
        If 視窗3_pl.Visible = False Then : 視窗3_pl.Visible = True : 視窗3_pl.BringToFront() : Else : 視窗3_pl.Visible = False : End If
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            PA30 = 清單1_dgv.Rows(i).Cells(0).Value.ToString : PA31 = 清單1_dgv.Rows(i).Cells(0).Value.ToString
            PA32 = 清單1_dgv.Rows(i).Cells(12).Value.ToString : PA33 = 清單1_dgv.Rows(i).Cells(50).Value.ToString
            SQL_人員薪資表_修改()
        Next : 群組清單() : MGB(系統語言字典("H509-126-" & 語言), 1)
    End Sub
    Private Sub 考勤調整_bt_Click(sender As Object, e As EventArgs) Handles 考勤調整_bt.Click
        Dim random1 As New Random() : Dim random2 As New Random() : Dim random3 As New Random() : Dim random4 As New Random() : Dim random5 As New Random()
        Dim random6 As New Random() : Dim random7 As New Random() : Dim hours As Integer
        If 群組1_cb.Text <> "HARIAN GROUP" Then : MGB(系統語言字典("H611-110-" & 語言), 1) : Else : 清除_bt.PerformClick()

            For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
                If 休假比例_nud.Value > 0 And 休假比例_nud.Value < 20 Then
                    Dim 計數 As Integer
                    Randomize() : hours = random1.Next(1, 100) : If hours < 休假比例_nud.Value + 45 Then
                        If 清單1_dgv.Rows(i).Cells(15).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(15).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(16).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(16).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 10 Then : Exit For : End If
                    Randomize() : hours = random2.Next(1, 100) : If hours < 休假比例_nud.Value + 45 Then
                        If 清單1_dgv.Rows(i).Cells(17).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(17).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(18).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(18).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 10 Then : Exit For : End If
                    Randomize() : hours = random3.Next(1, 100) : If hours < 休假比例_nud.Value + 45 Then
                        If 清單1_dgv.Rows(i).Cells(19).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(19).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(20).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(20).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 10 Then : Exit For : End If
                    Randomize() : hours = random4.Next(1, 100) : If hours < 休假比例_nud.Value + 45 Then
                        If 清單1_dgv.Rows(i).Cells(21).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(21).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(22).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(22).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 10 Then : Exit For : End If
                    Randomize() : hours = random5.Next(1, 100) : If hours < 休假比例_nud.Value + 45 Then
                        If 清單1_dgv.Rows(i).Cells(23).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(23).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(24).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(24).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 10 Then : Exit For : End If
                    Randomize() : hours = random6.Next(1, 100) : If hours < 休假比例_nud.Value + 45 Then
                        If 清單1_dgv.Rows(i).Cells(25).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(25).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(26).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(26).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 10 Then : Exit For : End If
                ElseIf 休假比例_nud.Value >= 20 And 休假比例_nud.Value < 40 Then
                    Dim 計數 As Integer
                    Randomize() : hours = random1.Next(1, 100) : If hours < 休假比例_nud.Value + 25 Then
                        If 清單1_dgv.Rows(i).Cells(15).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(15).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(16).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(16).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 7 Then : Exit For : End If
                    Randomize() : hours = random2.Next(1, 100) : If hours < 休假比例_nud.Value + 25 Then
                        If 清單1_dgv.Rows(i).Cells(17).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(17).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(18).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(18).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 7 Then : Exit For : End If
                    Randomize() : hours = random3.Next(1, 100) : If hours < 休假比例_nud.Value + 25 Then
                        If 清單1_dgv.Rows(i).Cells(19).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(19).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(20).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(20).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 7 Then : Exit For : End If
                    Randomize() : hours = random4.Next(1, 100) : If hours < 休假比例_nud.Value + 25 Then
                        If 清單1_dgv.Rows(i).Cells(21).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(21).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(22).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(22).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 7 Then : Exit For : End If
                    Randomize() : hours = random5.Next(1, 100) : If hours < 休假比例_nud.Value + 25 Then
                        If 清單1_dgv.Rows(i).Cells(23).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(23).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(24).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(24).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 7 Then : Exit For : End If
                    Randomize() : hours = random6.Next(1, 100) : If hours < 休假比例_nud.Value + 25 Then
                        If 清單1_dgv.Rows(i).Cells(25).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(25).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(26).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(26).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 7 Then : Exit For : End If
                ElseIf 休假比例_nud.Value >= 40 And 休假比例_nud.Value < 60 Then
                    Dim 計數 As Integer
                    Randomize() : hours = random1.Next(1, 100) : If hours < 休假比例_nud.Value + 15 Then
                        If 清單1_dgv.Rows(i).Cells(15).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(15).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(16).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(16).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 5 Then : Exit For : End If
                    Randomize() : hours = random2.Next(1, 100) : If hours < 休假比例_nud.Value + 15 Then
                        If 清單1_dgv.Rows(i).Cells(17).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(17).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(18).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(18).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 5 Then : Exit For : End If
                    Randomize() : hours = random3.Next(1, 100) : If hours < 休假比例_nud.Value + 15 Then
                        If 清單1_dgv.Rows(i).Cells(19).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(19).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(20).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(20).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 5 Then : Exit For : End If
                    Randomize() : hours = random4.Next(1, 100) : If hours < 休假比例_nud.Value + 15 Then
                        If 清單1_dgv.Rows(i).Cells(21).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(21).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(22).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(22).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 5 Then : Exit For : End If
                    Randomize() : hours = random5.Next(1, 100) : If hours < 休假比例_nud.Value + 15 Then
                        If 清單1_dgv.Rows(i).Cells(23).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(23).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(24).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(24).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 5 Then : Exit For : End If
                    Randomize() : hours = random6.Next(1, 100) : If hours < 休假比例_nud.Value + 15 Then
                        If 清單1_dgv.Rows(i).Cells(25).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(25).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(26).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(26).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 5 Then : Exit For : End If
                ElseIf 休假比例_nud.Value >= 60 And 休假比例_nud.Value < 80 Then
                    Dim 計數 As Integer
                    Randomize() : hours = random1.Next(1, 100) : If hours < 休假比例_nud.Value + 10 Then
                        If 清單1_dgv.Rows(i).Cells(15).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(15).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(16).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(16).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                    Randomize() : hours = random2.Next(1, 100) : If hours < 休假比例_nud.Value + 10 Then
                        If 清單1_dgv.Rows(i).Cells(17).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(17).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(18).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(18).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                    Randomize() : hours = random3.Next(1, 100) : If hours < 休假比例_nud.Value + 10 Then
                        If 清單1_dgv.Rows(i).Cells(19).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(19).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(20).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(20).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                    Randomize() : hours = random4.Next(1, 100) : If hours < 休假比例_nud.Value + 10 Then
                        If 清單1_dgv.Rows(i).Cells(21).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(21).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(22).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(22).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                    Randomize() : hours = random5.Next(1, 100) : If hours < 休假比例_nud.Value + 10 Then
                        If 清單1_dgv.Rows(i).Cells(23).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(23).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(24).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(24).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                    Randomize() : hours = random6.Next(1, 100) : If hours < 休假比例_nud.Value + 10 Then
                        If 清單1_dgv.Rows(i).Cells(25).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(25).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(26).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(26).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                    Randomize() : hours = random7.Next(1, 100) : If hours < 休假比例_nud.Value - 48 Then
                        If 清單1_dgv.Rows(i).Cells(27).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(27).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(28).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(28).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If
                    If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 3 Then : Exit For : End If
                ElseIf 休假比例_nud.Value >= 80 And 休假比例_nud.Value < 100 Then
                    Dim 計數 As Integer
                    Randomize() : hours = random1.Next(1, 100) : If hours < 休假比例_nud.Value + 5 Then
                        If 清單1_dgv.Rows(i).Cells(15).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(15).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(16).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(16).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                    Randomize() : hours = random2.Next(1, 100) : If hours < 休假比例_nud.Value + 5 Then
                        If 清單1_dgv.Rows(i).Cells(17).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(17).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(18).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(18).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                    Randomize() : hours = random3.Next(1, 100) : If hours < 休假比例_nud.Value + 5 Then
                        If 清單1_dgv.Rows(i).Cells(19).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(19).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(20).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(20).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                    Randomize() : hours = random4.Next(1, 100) : If hours < 休假比例_nud.Value + 5 Then
                        If 清單1_dgv.Rows(i).Cells(21).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(21).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(22).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(22).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                    Randomize() : hours = random5.Next(1, 100) : If hours < 休假比例_nud.Value + 5 Then
                        If 清單1_dgv.Rows(i).Cells(23).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(23).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(24).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(24).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                    Randomize() : hours = random6.Next(1, 100) : If hours < 休假比例_nud.Value + 5 Then
                        If 清單1_dgv.Rows(i).Cells(25).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(25).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(26).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(26).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                    Randomize() : hours = random7.Next(1, 100) : If hours < 休假比例_nud.Value - 30 Then
                        If 清單1_dgv.Rows(i).Cells(27).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(27).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                        If 清單1_dgv.Rows(i).Cells(28).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(28).Value = AUTO時 : AUTO舊2 = AUTO時 : End If : 計數 += 1
                    End If : If 計數 > 可沖天數_nud.Value - 休假天數_nud.Value + 1 Then : Exit For : End If
                ElseIf 休假比例_nud.Value = 100 Then
                    If 清單1_dgv.Rows(i).Cells(15).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(15).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(16).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(16).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(17).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(17).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(18).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(18).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(19).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(19).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(20).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(20).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(21).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(21).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(22).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(22).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(23).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(23).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(24).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(24).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(25).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(25).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(26).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(26).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(27).Value = "" Then : AUTO時段1() : 清單1_dgv.Rows(i).Cells(27).Value = AUTO時 : AUTO舊1 = AUTO時 : End If
                    If 清單1_dgv.Rows(i).Cells(28).Value = "" Then : AUTO時段2() : 清單1_dgv.Rows(i).Cells(28).Value = AUTO時 : AUTO舊2 = AUTO時 : End If
                End If
            Next : AUTO時段()
        End If
    End Sub
    Private Sub AUTO時段()
        Dim TSSL As Integer : Dim 加總1, 加總2, 加總3, 加總4, 加總5, 加總6, 加總7 As Long
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            '-------------------------計算星期一--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(15).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(16).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(15).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(16).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= -120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(35).Value = 時間 : 清單1_dgv.Rows(i).Cells(36).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(35).Value = "" : 清單1_dgv.Rows(i).Cells(36).Value = "" : End If
            '-------------------------計算星期二--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(17).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(18).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(17).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(18).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= 120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(37).Value = 時間 : 清單1_dgv.Rows(i).Cells(38).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(37).Value = "" : 清單1_dgv.Rows(i).Cells(38).Value = "" : End If
            '-------------------------計算星期三--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(19).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(20).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(19).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(20).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= 120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(39).Value = 時間 : 清單1_dgv.Rows(i).Cells(40).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(39).Value = "" : 清單1_dgv.Rows(i).Cells(40).Value = "" : End If
            '-------------------------計算星期四--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(21).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(22).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(21).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(22).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= 120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(41).Value = 時間 : 清單1_dgv.Rows(i).Cells(42).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(41).Value = "" : 清單1_dgv.Rows(i).Cells(42).Value = "" : End If
            '-------------------------計算星期五--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(23).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(24).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(23).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(24).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= 120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(43).Value = 時間 : 清單1_dgv.Rows(i).Cells(44).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(43).Value = "" : 清單1_dgv.Rows(i).Cells(44).Value = "" : End If
            '-------------------------計算星期六--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(25).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(26).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(25).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(26).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= 120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(45).Value = 時間 : 清單1_dgv.Rows(i).Cells(46).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(45).Value = "" : 清單1_dgv.Rows(i).Cells(46).Value = "" : End If
            '-------------------------計算星期日--------------------------------------------------------------------------------------------------------------------
            If 清單1_dgv.Rows(i).Cells(27).Value.ToString <> "" And 清單1_dgv.Rows(i).Cells(28).Value.ToString <> "" Then
                X1 = 清單1_dgv.Rows(i).Cells(27).Value.ToString : Set_時段定點() : 計算(0) = X1 : X1 = 清單1_dgv.Rows(i).Cells(28).Value.ToString : Set_時段定點() : 計算(1) = X1 : 時間比對()
                If 間隔1 >= 240 And 間隔1 < 660 Then : 間隔1 -= 60 : ElseIf 間隔1 >= 660 Then : 間隔1 -= 120 : End If
                Dim 加班1 As Integer = 0 : Dim 時間 As Integer = 間隔1 / 60 : If 時間 <= 8 Then : Else : 加班1 = 時間 - 8 : 時間 = 8 : End If
                清單1_dgv.Rows(i).Cells(47).Value = 時間 : 清單1_dgv.Rows(i).Cells(48).Value = 加班1
            Else : 清單1_dgv.Rows(i).Cells(47).Value = "" : 清單1_dgv.Rows(i).Cells(48).Value = "" : End If

            Dim 正常(6), 加班(6) As Integer
            If 清單1_dgv.Rows(i).Cells(35).Value <> "" Then : 正常(0) = 清單1_dgv.Rows(i).Cells(35).Value.ToString : Else : 正常(0) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(37).Value <> "" Then : 正常(1) = 清單1_dgv.Rows(i).Cells(37).Value.ToString : Else : 正常(1) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(39).Value <> "" Then : 正常(2) = 清單1_dgv.Rows(i).Cells(39).Value.ToString : Else : 正常(2) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(41).Value <> "" Then : 正常(3) = 清單1_dgv.Rows(i).Cells(41).Value.ToString : Else : 正常(3) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(43).Value <> "" Then : 正常(4) = 清單1_dgv.Rows(i).Cells(43).Value.ToString : Else : 正常(4) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(45).Value <> "" Then : 正常(5) = 清單1_dgv.Rows(i).Cells(45).Value.ToString : Else : 正常(5) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(47).Value <> "" Then : 正常(6) = 清單1_dgv.Rows(i).Cells(47).Value.ToString : Else : 正常(6) = 0 : End If

            If 清單1_dgv.Rows(i).Cells(36).Value <> "" Then : 加班(0) = 清單1_dgv.Rows(i).Cells(36).Value.ToString : Else : 加班(0) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(38).Value <> "" Then : 加班(1) = 清單1_dgv.Rows(i).Cells(38).Value.ToString : Else : 加班(1) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(40).Value <> "" Then : 加班(2) = 清單1_dgv.Rows(i).Cells(40).Value.ToString : Else : 加班(2) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(42).Value <> "" Then : 加班(3) = 清單1_dgv.Rows(i).Cells(42).Value.ToString : Else : 加班(3) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(44).Value <> "" Then : 加班(4) = 清單1_dgv.Rows(i).Cells(44).Value.ToString : Else : 加班(4) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(46).Value <> "" Then : 加班(5) = 清單1_dgv.Rows(i).Cells(46).Value.ToString : Else : 加班(5) = 0 : End If
            If 清單1_dgv.Rows(i).Cells(48).Value <> "" Then : 加班(6) = 清單1_dgv.Rows(i).Cells(48).Value.ToString : Else : 加班(6) = 0 : End If

            清單1_dgv.Rows(i).Cells(33).Value = 正常(0) + 正常(1) + 正常(2) + 正常(3) + 正常(4) + 正常(5) + 正常(6)
            清單1_dgv.Rows(i).Cells(34).Value = 加班(0) + 加班(1) + 加班(2) + 加班(3) + 加班(4) + 加班(5) + 加班(6)
            '-------------------------計算工資單價--------------------------------------------------------------------------------------------------------------------
            If IsDBNull(清單1_dgv.Rows(i).Cells(12).Value) Then : Else
                If 清單1_dgv.Rows(i).Cells(12).Value.ToString <> "" Then
                    清單1_dgv.Rows(i).Cells(31).Value = Strings.Format(清單1_dgv.Rows(i).Cells(12).Value / 8, "#,##0")
                    清單1_dgv.Rows(i).Cells(32).Value = Strings.Format(清單1_dgv.Rows(i).Cells(12).Value / 6, "#,##0")
                    清單1_dgv.Rows(i).Cells(29).Value = Strings.Format((清單1_dgv.Rows(i).Cells(12).Value / 8) * CLng(清單1_dgv.Rows(i).Cells(33).Value.ToString), "#,##0")
                    清單1_dgv.Rows(i).Cells(30).Value = Strings.Format((清單1_dgv.Rows(i).Cells(12).Value / 6) * CLng(清單1_dgv.Rows(i).Cells(34).Value.ToString), "#,##0")
                    清單1_dgv.Rows(i).Cells(13).Value = CLng(清單1_dgv.Rows(i).Cells(29).Value.ToString) + CLng(清單1_dgv.Rows(i).Cells(30).Value.ToString)
                    TSSL += CLng(清單1_dgv.Rows(i).Cells(13).Value.ToString)
                    HX_PGS_ERP_SYS.合計_TSSL.Text = "Total : " & Strings.Format(TSSL, "#,##0")
                End If
            End If
            '-------------------------計算工資單價--------------------------------------------------------------------------------------------------------------------
            清單1_dgv.Rows(i).Cells(4).Value = i + 1 : 合計_dgv.Rows(0).Cells(4).Value = i + 1 : 合計_dgv.Rows(0).Cells(13).Value += CLng(清單1_dgv.Rows(i).Cells(13).Value.ToString)
            合計_dgv.Rows(0).Cells(29).Value += CLng(清單1_dgv.Rows(i).Cells(29).Value.ToString) : 合計_dgv.Rows(0).Cells(30).Value += CLng(清單1_dgv.Rows(i).Cells(30).Value.ToString)

            If 清單1_dgv.Rows(i).Cells(33).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(33).Value += CLng(清單1_dgv.Rows(i).Cells(33).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(34).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(34).Value += CLng(清單1_dgv.Rows(i).Cells(34).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(35).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(35).Value += CLng(清單1_dgv.Rows(i).Cells(35).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(36).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(36).Value += CLng(清單1_dgv.Rows(i).Cells(36).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(37).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(37).Value += CLng(清單1_dgv.Rows(i).Cells(37).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(38).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(38).Value += CLng(清單1_dgv.Rows(i).Cells(38).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(39).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(39).Value += CLng(清單1_dgv.Rows(i).Cells(39).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(40).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(40).Value += CLng(清單1_dgv.Rows(i).Cells(40).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(41).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(41).Value += CLng(清單1_dgv.Rows(i).Cells(41).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(42).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(42).Value += CLng(清單1_dgv.Rows(i).Cells(42).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(43).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(43).Value += CLng(清單1_dgv.Rows(i).Cells(43).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(44).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(44).Value += CLng(清單1_dgv.Rows(i).Cells(44).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(45).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(45).Value += CLng(清單1_dgv.Rows(i).Cells(45).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(46).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(46).Value += CLng(清單1_dgv.Rows(i).Cells(46).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(47).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(47).Value += CLng(清單1_dgv.Rows(i).Cells(47).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(48).Value.ToString <> "" Then : 合計_dgv.Rows(0).Cells(48).Value += CLng(清單1_dgv.Rows(i).Cells(48).Value.ToString) : End If
            If 清單1_dgv.Rows(i).Cells(15).Value.ToString = "" Then : Else : 加總1 += 1 : End If
            If 清單1_dgv.Rows(i).Cells(17).Value.ToString = "" Then : Else : 加總2 += 1 : End If
            If 清單1_dgv.Rows(i).Cells(19).Value.ToString = "" Then : Else : 加總3 += 1 : End If
            If 清單1_dgv.Rows(i).Cells(21).Value.ToString = "" Then : Else : 加總4 += 1 : End If
            If 清單1_dgv.Rows(i).Cells(23).Value.ToString = "" Then : Else : 加總5 += 1 : End If
            If 清單1_dgv.Rows(i).Cells(25).Value.ToString = "" Then : Else : 加總6 += 1 : End If
            If 清單1_dgv.Rows(i).Cells(27).Value.ToString = "" Then : Else : 加總7 += 1 : End If
        Next
        合計_dgv.Rows(0).Cells(15).Value = 加總1 : 合計_dgv.Rows(0).Cells(17).Value = 加總2 : 合計_dgv.Rows(0).Cells(19).Value = 加總3 : 合計_dgv.Rows(0).Cells(21).Value = 加總4
        合計_dgv.Rows(0).Cells(23).Value = 加總5 : 合計_dgv.Rows(0).Cells(25).Value = 加總6 : 合計_dgv.Rows(0).Cells(27).Value = 加總7
        合計_dgv.Rows(0).Cells(29).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(29).Value), "#,##0")
        合計_dgv.Rows(0).Cells(30).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(30).Value), "#,##0")
        合計_dgv.Rows(0).Cells(33).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(33).Value), "#,##0")
        合計_dgv.Rows(0).Cells(34).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(34).Value), "#,##0")
        合計_dgv.Rows(0).Cells(35).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(35).Value), "#,##0")
        合計_dgv.Rows(0).Cells(36).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(36).Value), "#,##0")
        合計_dgv.Rows(0).Cells(37).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(37).Value), "#,##0")
        合計_dgv.Rows(0).Cells(38).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(38).Value), "#,##0")
        合計_dgv.Rows(0).Cells(39).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(39).Value), "#,##0")
        合計_dgv.Rows(0).Cells(40).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(40).Value), "#,##0")
        合計_dgv.Rows(0).Cells(41).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(41).Value), "#,##0")
        合計_dgv.Rows(0).Cells(42).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(42).Value), "#,##0")
        合計_dgv.Rows(0).Cells(43).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(43).Value), "#,##0")
        合計_dgv.Rows(0).Cells(44).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(44).Value), "#,##0")
        合計_dgv.Rows(0).Cells(45).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(45).Value), "#,##0")
        合計_dgv.Rows(0).Cells(46).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(46).Value), "#,##0")
        合計_dgv.Rows(0).Cells(47).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(47).Value), "#,##0")
        合計_dgv.Rows(0).Cells(48).Value = Strings.Format(CLng(合計_dgv.Rows(0).Cells(48).Value), "#,##0")
    End Sub
    Private Sub AUTO時段1()
        Dim random As New Random()
        For i As Integer = 1 To 1000
            Randomize() : Dim hours As Integer = random.Next(6, 7) : Dim minutes As Integer
            If hours = 6 Then : Randomize() : minutes = random.Next(45, 59) : Else : Randomize() : minutes = random.Next(0, 3) : End If
            Randomize() : Dim seconds As Integer = random.Next(0, 60) : AUTO時 = $"{hours:00}:{minutes:00}:{seconds:00}"
            If AUTO舊1 <> AUTO時 Then : Exit For : End If
        Next
    End Sub
    Private Sub AUTO時段2()
        Dim random As New Random()
        For i As Integer = 1 To 1000
            Dim hours As Integer
            If 加班_nud.Value = 1 Then : Randomize() : hours = random.Next(16, 17)
            ElseIf 加班_nud.Value = 2 Then : Randomize() : hours = random.Next(18, 19)
            ElseIf 加班_nud.Value = 3 Then : Randomize() : hours = random.Next(19, 20) : End If
            Dim minutes As Integer
            If 加班_nud.Value = 1 Then : If hours = 16 Then : Randomize() : minutes = random.Next(55, 59) : Else : Randomize() : minutes = random.Next(0, 15) : End If
            ElseIf 加班_nud.Value = 2 Then : If hours = 18 Then : Randomize() : minutes = random.Next(55, 59) : Else : Randomize() : minutes = random.Next(0, 15) : End If
            ElseIf 加班_nud.Value = 3 Then : If hours = 19 Then : Randomize() : minutes = random.Next(55, 59) : Else : Randomize() : minutes = random.Next(0, 15) : End If : End If
            Randomize() : Dim seconds As Integer = random.Next(0, 60) : AUTO時 = $"{hours:00}:{minutes:00}:{seconds:00}"
            If AUTO舊2 <> AUTO時 Then : Exit For : End If
        Next
    End Sub
    Private Sub 清除_bt_Click(sender As Object, e As EventArgs) Handles 清除_bt.Click
        If 群組1_cb.Text <> "HARIAN GROUP" Then : MGB(系統語言字典("H611-110-" & 語言), 1) : Else
            For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
                清單1_dgv.Rows(i).Cells(15).Value = "" : 清單1_dgv.Rows(i).Cells(16).Value = "" : 清單1_dgv.Rows(i).Cells(17).Value = "" : 清單1_dgv.Rows(i).Cells(18).Value = ""
                清單1_dgv.Rows(i).Cells(19).Value = "" : 清單1_dgv.Rows(i).Cells(20).Value = "" : 清單1_dgv.Rows(i).Cells(21).Value = "" : 清單1_dgv.Rows(i).Cells(22).Value = ""
                清單1_dgv.Rows(i).Cells(23).Value = "" : 清單1_dgv.Rows(i).Cells(24).Value = "" : 清單1_dgv.Rows(i).Cells(25).Value = "" : 清單1_dgv.Rows(i).Cells(26).Value = ""
                清單1_dgv.Rows(i).Cells(27).Value = "" : 清單1_dgv.Rows(i).Cells(28).Value = ""
            Next : AUTO時段()
        End If
    End Sub
    Private Sub 虛擬存檔_bt_Click(sender As Object, e As EventArgs) Handles 虛擬存檔_bt.Click
        If 群組1_cb.Text <> "HARIAN GROUP" Then : MGB(系統語言字典("H611-110-" & 語言), 1) : Else
            Dim 可以存檔 As Boolean = False
            For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
                If 清單1_dgv.Rows(i).Cells(15).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(20).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(25).Value.ToString = "" And
                   清單1_dgv.Rows(i).Cells(16).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(21).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(26).Value.ToString = "" And
                   清單1_dgv.Rows(i).Cells(17).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(22).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(27).Value.ToString = "" And
                   清單1_dgv.Rows(i).Cells(18).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(23).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(28).Value.ToString = "" And
                   清單1_dgv.Rows(i).Cells(19).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(24).Value.ToString = "" Then : Else : 可以存檔 = True : End If
            Next
            If 可以存檔 = True Then
                Dim AAS As String = "" : PA45 = 星1_bt.Text : SQL_虛擬考勤明細表刪除()
                For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
                    If 清單1_dgv.Rows(i).Cells(15).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(20).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(25).Value.ToString = "" And
                       清單1_dgv.Rows(i).Cells(16).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(21).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(26).Value.ToString = "" And
                       清單1_dgv.Rows(i).Cells(17).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(22).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(27).Value.ToString = "" And
                       清單1_dgv.Rows(i).Cells(18).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(23).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(28).Value.ToString = "" And
                       清單1_dgv.Rows(i).Cells(19).Value.ToString = "" And 清單1_dgv.Rows(i).Cells(24).Value.ToString = "" Then : Else
                        AAS = "(N'" & 清單1_dgv.Rows(i).Cells(50).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(15).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(16).Value.ToString & "', 
                        N'" & 清單1_dgv.Rows(i).Cells(17).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(18).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(19).Value.ToString & "', 
                        N'" & 清單1_dgv.Rows(i).Cells(20).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(21).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(22).Value.ToString & "', 
                        N'" & 清單1_dgv.Rows(i).Cells(23).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(24).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(25).Value.ToString & "', 
                        N'" & 清單1_dgv.Rows(i).Cells(26).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(27).Value.ToString & "', N'" & 清單1_dgv.Rows(i).Cells(28).Value.ToString & "', 
                        N'" & 星1_bt.Text & "')"
                    End If : If i = 0 Then : SQL2 = AAS : Else : SQL2 = SQL2 & "," & AAS : End If
                Next
                SQL_虛擬考勤明細表新增() : Set_使用者清單() : MGB(系統語言字典("H509-126-" & 語言), 1)
            Else : MGB(系統語言字典("H611-121-" & 語言), 1) : End If
        End If
    End Sub
    Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
        PA17 = "EXCEL" : PA18 = "PDF" : 選擇考勤月份.ShowDialog()

        Dim FVG As String
        xlApp = CType(CreateObject("Excel.Application"), Application)
        xlBook = xlApp.Workbooks.Add
        xlApp.DisplayAlerts = True
        xlApp.Visible = True
        xlApp.Application.WindowState = xlMaximized
        GN1 = 0
        ''----------------------------------------------------------------------------------------------------------------------
        xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Select
        If 群組1_cb.Text = "" Then : FVG = "ALL GROUP 伙食費" : Else : FVG = 群組1_cb.Text & "伙食費" : End If
        xlApp.Sheets(1).Name = FVG : xlBook.Activate() : xlSheet.Activate()

        xlSheet.Cells(1, 1) = "點工伙食費表(吃飯錢) UANG MAKAN BURUH HARIAN " & FVG
        xlSheet.Cells(2, 1) = "STT" : xlSheet.Cells(2, 2) = "員工編號" & vbCrLf & "ID_No" : xlSheet.Cells(2, 3) = "姓名" & vbCrLf & "Name" : xlSheet.Cells(2, 4) = "TOTAL UANG MAKAN"
        xlSheet.Cells(2, 5) = "TOTAL MASUK KERJA" : xlSheet.Cells(2, 6) = "UANG MAKAN / HARI"
        xlSheet.Cells(2, 7) = 星1_bt.Text : xlSheet.Cells(3, 7) = "上班" : xlSheet.Cells(2, 8) = 星2_bt.Text : xlSheet.Cells(3, 8) = "上班"
        xlSheet.Cells(2, 9) = 星3_bt.Text : xlSheet.Cells(3, 9) = "上班" : xlSheet.Cells(2, 10) = 星4_bt.Text : xlSheet.Cells(3, 10) = "上班"
        xlSheet.Cells(2, 11) = 星5_bt.Text : xlSheet.Cells(3, 11) = "上班" : xlSheet.Cells(2, 12) = 星6_bt.Text : xlSheet.Cells(3, 12) = "上班"
        xlSheet.Cells(2, 13) = 星7_bt.Text : xlSheet.Cells(3, 13) = "上班" : xlSheet.Cells(2, 14) = "備註"
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            xlSheet.Cells(4 + i, 1) = i + 1 : xlSheet.Cells(4 + i, 2) = 清單1_dgv.Rows(i).Cells("ID卡號").Value.ToString
            xlSheet.Cells(4 + i, 3) = 清單1_dgv.Rows(i).Cells(表頭(0)).Value.ToString : xlSheet.Cells(4 + i, 6) = "5000"
            xlSheet.Cells(4 + i, 5) = "= SUM(G" & 4 + i & ": M" & 4 + i & ")" : xlSheet.Cells(4 + i, 4) = "=F" & 4 + i & "*E" & 4 + i & ""
            If 清單1_dgv.Rows(i).Cells(表頭(64)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 7) = "1" : End If
            If 清單1_dgv.Rows(i).Cells(表頭(32)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 8) = "1" : End If
            If 清單1_dgv.Rows(i).Cells(表頭(34)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 9) = "1" : End If
            If 清單1_dgv.Rows(i).Cells(表頭(36)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 10) = "1" : End If
            If 清單1_dgv.Rows(i).Cells(表頭(38)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 11) = "1" : End If
            If 清單1_dgv.Rows(i).Cells(表頭(40)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 12) = "1" : End If
            If 清單1_dgv.Rows(i).Cells(表頭(42)).Value.ToString <> "" Then : xlSheet.Cells(4 + i, 13) = "1" : End If : GN1 += 1
        Next : xlSheet.Cells(4 + GN1 + 1, 3) = "TOTAL : " : xlSheet.Cells(4 + GN1 + 1, 4) = "=SUM(D4:D" & 4 + GN1 & ")" : BB(xlApp, xlSheet)
        '----------------------------------------------------------------------------------------------------------------------
        xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Select
        If 群組1_cb.Text = "" Then : FVG = "ALL GROUP 薪資表" : Else : FVG = 群組1_cb.Text & "薪資表" : End If
        xlApp.Sheets(1).Name = FVG : xlBook.Activate() : xlSheet.Activate()

        xlSheet.Cells(1, 1) = "點     工     薪     資     表  TABEL GAJI " & FVG
        xlSheet.Cells(2, 1) = "STT" : xlSheet.Cells(2, 2) = "員工編號" & vbCrLf & "ID_No" : xlSheet.Cells(2, 3) = "姓名" & vbCrLf & "Name" : xlSheet.Cells(2, 4) = "總計" & vbCrLf & "A=B+C"
        xlSheet.Cells(2, 5) = "工資金額" : xlSheet.Cells(3, 5) = "正常" & vbCrLf & "B=D*F" : xlSheet.Cells(3, 6) = "加班" & vbCrLf & "C=E*G"
        xlSheet.Cells(2, 7) = "工資單價" : xlSheet.Cells(3, 7) = "正常/H" & vbCrLf & "D" : xlSheet.Cells(3, 8) = "加班/H" & vbCrLf & "E"
        xlSheet.Cells(2, 9) = "合計" : xlSheet.Cells(3, 9) = "正常/H" & vbCrLf & "F" : xlSheet.Cells(3, 10) = "加班/H" & vbCrLf & "G"
        xlSheet.Cells(2, 11) = 星1_bt.Text : xlSheet.Cells(3, 11) = "正常/H" : xlSheet.Cells(3, 12) = "加班/H"
        xlSheet.Cells(2, 13) = 星2_bt.Text : xlSheet.Cells(3, 13) = "正常/H" : xlSheet.Cells(3, 14) = "加班/H"
        xlSheet.Cells(2, 15) = 星3_bt.Text : xlSheet.Cells(3, 15) = "正常/H" : xlSheet.Cells(3, 16) = "加班/H"
        xlSheet.Cells(2, 17) = 星4_bt.Text : xlSheet.Cells(3, 17) = "正常/H" : xlSheet.Cells(3, 18) = "加班/H"
        xlSheet.Cells(2, 19) = 星5_bt.Text : xlSheet.Cells(3, 19) = "正常/H" : xlSheet.Cells(3, 20) = "加班/H"
        xlSheet.Cells(2, 21) = 星6_bt.Text : xlSheet.Cells(3, 21) = "正常/H" : xlSheet.Cells(3, 22) = "加班/H"
        xlSheet.Cells(2, 23) = 星7_bt.Text : xlSheet.Cells(3, 23) = "正常/H" : xlSheet.Cells(3, 24) = "加班/H"
        xlSheet.Cells(2, 25) = "備註"
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            xlSheet.Cells(4 + i, 1) = i + 1 : xlSheet.Cells(4 + i, 2) = 清單1_dgv.Rows(i).Cells("ID卡號").Value.ToString
            xlSheet.Cells(4 + i, 3) = 清單1_dgv.Rows(i).Cells(表頭(0)).Value.ToString : xlSheet.Cells(4 + i, 4) = 清單1_dgv.Rows(i).Cells(表頭(28)).Value.ToString
            xlSheet.Cells(4 + i, 5) = 清單1_dgv.Rows(i).Cells(表頭(58)).Value.ToString : xlSheet.Cells(4 + i, 6) = 清單1_dgv.Rows(i).Cells(表頭(59)).Value.ToString
            xlSheet.Cells(4 + i, 7) = 清單1_dgv.Rows(i).Cells(表頭(60)).Value.ToString : xlSheet.Cells(4 + i, 8) = 清單1_dgv.Rows(i).Cells(表頭(61)).Value.ToString
            xlSheet.Cells(4 + i, 9) = 清單1_dgv.Rows(i).Cells(表頭(62)).Value.ToString : xlSheet.Cells(4 + i, 10) = 清單1_dgv.Rows(i).Cells(表頭(63)).Value.ToString
            xlSheet.Cells(4 + i, 11) = 清單1_dgv.Rows(i).Cells(表頭(44)).Value.ToString : xlSheet.Cells(4 + i, 12) = 清單1_dgv.Rows(i).Cells(表頭(45)).Value.ToString
            xlSheet.Cells(4 + i, 13) = 清單1_dgv.Rows(i).Cells(表頭(46)).Value.ToString : xlSheet.Cells(4 + i, 14) = 清單1_dgv.Rows(i).Cells(表頭(47)).Value.ToString
            xlSheet.Cells(4 + i, 15) = 清單1_dgv.Rows(i).Cells(表頭(48)).Value.ToString : xlSheet.Cells(4 + i, 16) = 清單1_dgv.Rows(i).Cells(表頭(49)).Value.ToString
            xlSheet.Cells(4 + i, 17) = 清單1_dgv.Rows(i).Cells(表頭(50)).Value.ToString : xlSheet.Cells(4 + i, 18) = 清單1_dgv.Rows(i).Cells(表頭(51)).Value.ToString
            xlSheet.Cells(4 + i, 19) = 清單1_dgv.Rows(i).Cells(表頭(52)).Value.ToString : xlSheet.Cells(4 + i, 20) = 清單1_dgv.Rows(i).Cells(表頭(53)).Value.ToString
            xlSheet.Cells(4 + i, 21) = 清單1_dgv.Rows(i).Cells(表頭(54)).Value.ToString : xlSheet.Cells(4 + i, 22) = 清單1_dgv.Rows(i).Cells(表頭(55)).Value.ToString
            xlSheet.Cells(4 + i, 23) = 清單1_dgv.Rows(i).Cells(表頭(56)).Value.ToString : xlSheet.Cells(4 + i, 24) = 清單1_dgv.Rows(i).Cells(表頭(57)).Value.ToString
        Next
        xlSheet.Cells(4 + GN1 + 1, 3) = "TOTAL : " : xlSheet.Cells(4 + GN1 + 1, 4) = "=SUM(D4:D" & 4 + GN1 & ")"
        xlSheet.Cells(4 + GN1 + 1, 5) = "=SUM(E4:E" & 4 + GN1 & ")" : xlSheet.Cells(4 + GN1 + 1, 6) = "=SUM(F4:F" & 4 + GN1 & ")" : CC(xlApp, xlSheet)
        '----------------------------------------------------------------------------------------------------------------------
        xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Select
        If 群組1_cb.Text = "" Then : FVG = "ALL GROUP 考勤表" : Else : FVG = 群組1_cb.Text & "考勤表" : End If
        xlApp.Sheets(1).Name = FVG : xlBook.Activate() : xlSheet.Activate()

        xlSheet.Cells(1, 1) = "點     工     薪     資     表  GAJI BURUH HARIAN " & FVG
        xlSheet.Cells(2, 1) = "STT" : xlSheet.Cells(2, 2) = "員工編號" & vbCrLf & "ID_No" : xlSheet.Cells(2, 3) = "姓名" & vbCrLf & "Name" : xlSheet.Cells(2, 4) = "基本薪資" & vbCrLf & "天/RP"
        xlSheet.Cells(2, 5) = 星1_bt.Text : xlSheet.Cells(3, 5) = "上班" : xlSheet.Cells(3, 6) = "下班"
        xlSheet.Cells(2, 7) = 星2_bt.Text : xlSheet.Cells(3, 7) = "上班" : xlSheet.Cells(3, 8) = "下班"
        xlSheet.Cells(2, 9) = 星3_bt.Text : xlSheet.Cells(3, 9) = "上班" : xlSheet.Cells(3, 10) = "下班"
        xlSheet.Cells(2, 11) = 星4_bt.Text : xlSheet.Cells(3, 11) = "上班" : xlSheet.Cells(3, 12) = "下班"
        xlSheet.Cells(2, 13) = 星5_bt.Text : xlSheet.Cells(3, 13) = "上班" : xlSheet.Cells(3, 14) = "下班"
        xlSheet.Cells(2, 15) = 星6_bt.Text : xlSheet.Cells(3, 15) = "上班" : xlSheet.Cells(3, 16) = "下班"
        xlSheet.Cells(2, 17) = 星7_bt.Text : xlSheet.Cells(3, 17) = "上班" : xlSheet.Cells(3, 18) = "下班"
        xlSheet.Cells(2, 19) = "備註"
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            xlSheet.Cells(4 + i, 1) = i + 1 : xlSheet.Cells(4 + i, 2) = 清單1_dgv.Rows(i).Cells("ID卡號").Value.ToString
            xlSheet.Cells(4 + i, 3) = 清單1_dgv.Rows(i).Cells(表頭(0)).Value.ToString : xlSheet.Cells(4 + i, 4) = 清單1_dgv.Rows(i).Cells(表頭(27)).Value.ToString
            xlSheet.Cells(4 + i, 5) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(64)).Value.ToString, 5) : xlSheet.Cells(4 + i, 6) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(31)).Value.ToString, 5)
            xlSheet.Cells(4 + i, 7) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(32)).Value.ToString, 5) : xlSheet.Cells(4 + i, 8) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(33)).Value.ToString, 5)
            xlSheet.Cells(4 + i, 9) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(34)).Value.ToString, 5) : xlSheet.Cells(4 + i, 10) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(35)).Value.ToString, 5)
            xlSheet.Cells(4 + i, 11) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(36)).Value.ToString, 5) : xlSheet.Cells(4 + i, 12) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(37)).Value.ToString, 5)
            xlSheet.Cells(4 + i, 13) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(38)).Value.ToString, 5) : xlSheet.Cells(4 + i, 14) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(39)).Value.ToString, 5)
            xlSheet.Cells(4 + i, 15) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(40)).Value.ToString, 5) : xlSheet.Cells(4 + i, 16) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(41)).Value.ToString, 5)
            xlSheet.Cells(4 + i, 17) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(42)).Value.ToString, 5) : xlSheet.Cells(4 + i, 18) = Strings.Left(清單1_dgv.Rows(i).Cells(表頭(43)).Value.ToString, 5)
        Next : AA(xlApp, xlSheet)
        xlApp.Sheets(4).Delete : xlSheet.PageSetup.PrintArea = ""
        xlApp.Cells.Select()
        xlApp.Application.WindowState = xlMinimized

        If PA19 = "PDF" Then
            '-------------轉換成PDF---------------------------------------------------------------------
            Dim SERT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & FVG & "_X1.pdf", XlFixedFormatQuality.xlQualityStandard, True)
            xlBook.Sheets(2).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & FVG & "_X2.pdf", XlFixedFormatQuality.xlQualityStandard, True)
            xlBook.Sheets(3).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & FVG & "_X3.pdf", XlFixedFormatQuality.xlQualityStandard, True)
            Dim pdf1 As String = SERT & "\" & FVG & "_X1.pdf"
            Dim pdf2 As String = SERT & "\" & FVG & "_X2.pdf"
            Dim pdf3 As String = SERT & "\" & FVG & "_X3.pdf"
            Dim outputPDF As String = SERT & "\" & FVG & "請款單.pdf"
            Dim mergedDocument As New PdfDocument()                                                      ' 创建一个新的PDF文档对象
            Dim document1 As PdfDocument = PdfReader.Open(pdf1, PdfDocumentOpenMode.Import)              ' 打开第一个PDF文件
            For Each page As PdfPage In document1.Pages : mergedDocument.AddPage(page) : Next            ' 将第一个PDF文件的页面逐一添加到合并文档
            Dim document2 As PdfDocument = PdfReader.Open(pdf2, PdfDocumentOpenMode.Import)              ' 打开第二个PDF文件
            For Each page As PdfPage In document2.Pages : mergedDocument.AddPage(page) : Next            ' 将第二个PDF文件的页面逐一添加到合并文档
            Dim document3 As PdfDocument = PdfReader.Open(pdf3, PdfDocumentOpenMode.Import)              ' 打开第三个PDF文件
            For Each page As PdfPage In document3.Pages : mergedDocument.AddPage(page) : Next            ' 将第三个PDF文件的页面逐一添加到合并文档
            mergedDocument.Save(outputPDF)                                                               ' 保存合并后的PDF文件
            document1.Close() : document2.Close() : document3.Close()                                    ' 关闭文档对象
            File.Delete(SERT & "\" & FVG & "_X1.pdf")
            File.Delete(SERT & "\" & FVG & "_X2.pdf")
            File.Delete(SERT & "\" & FVG & "_X3.pdf")            ' 删除文件1和文件2
            '-------------關閉EXCEL---------------------------------------------------------------------
            xlSheet.PageSetup.PrintArea = "" : xlApp.Cells.Select()
            xlApp.Application.WindowState = xlMinimized
            xlBook.Close(False)
            Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
            Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
            Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
            xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
        End If
        PA17 = "" : PA18 = "" : PA19 = ""
        MGB(系統語言字典("H508-121-" & 語言), 1)
    End Sub
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)
        xlSheet.Cells.Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 4 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 22 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("D:D").Select : myExcel.Selection.NumberFormatLocal = "#,##0" : xlSheet.Columns("E:R").Select : myExcel.Selection.ColumnWidth = 6
        xlSheet.Range("A2:S3").Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Range("C4:R" & GN1 + 4).Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Range("A4:B" & GN1 + 4).Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 9 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Range("A1:S1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .Color = 49407 : .TintAndShade = 0 : .PatternTintAndShade = 0 : End With
        xlSheet.Range("A2:A3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B2:B3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("C2:C3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("D2:D3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("E2:F2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("G2:H2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("I2:J2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("K2:L2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("M2:N2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("O2:P2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("Q2:R2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("S2:S3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 30 : xlSheet.Rows("2:3").Select : myExcel.Selection.RowHeight = 20
        xlSheet.Rows("4:" & GN1 + 4).Select : myExcel.Selection.RowHeight = 25

        xlSheet.Range("A1:S3").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With

        xlSheet.Range("A4:S" & GN1 + 4).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With

        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            If 清單1_dgv.Rows(i).Cells(表頭(64)).Value.ToString = "" Then : xlSheet.Range("E" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(31)).Value.ToString = "" Then : xlSheet.Range("F" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(32)).Value.ToString = "" Then : xlSheet.Range("G" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(33)).Value.ToString = "" Then : xlSheet.Range("H" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(34)).Value.ToString = "" Then : xlSheet.Range("I" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(35)).Value.ToString = "" Then : xlSheet.Range("J" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(36)).Value.ToString = "" Then : xlSheet.Range("K" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(37)).Value.ToString = "" Then : xlSheet.Range("L" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(38)).Value.ToString = "" Then : xlSheet.Range("M" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(39)).Value.ToString = "" Then : xlSheet.Range("N" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(40)).Value.ToString = "" Then : xlSheet.Range("O" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(41)).Value.ToString = "" Then : xlSheet.Range("P" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(42)).Value.ToString = "" Then : xlSheet.Range("Q" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(43)).Value.ToString = "" Then : xlSheet.Range("R" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
        Next
        xlSheet.Range("B2:D3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : End With
        xlSheet.Range("C4:C" & GN1 + 4).Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        myExcel.ActiveWindow.DisplayGridlines = False
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$3" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "第 &P 頁，共 &N 頁" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .RightMargin = myExcel.Application.InchesToPoints(0.196850393700787)
            .TopMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .BottomMargin = myExcel.Application.InchesToPoints(0.393700787401575)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .FooterMargin = myExcel.Application.InchesToPoints(0.196850393700787)
            .PrintHeadings = False : .PrintGridlines = False : .PrintQuality = 600 : .CenterHorizontally = True : .CenterVertically = False : .Orientation = xlLandscape
            .Draft = False : .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = False
            .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With
        myExcel.Application.PrintCommunication = True
    End Sub
    Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)
        xlSheet.Cells.Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With

        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 4 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 14
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 25 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 13
        xlSheet.Columns("E:F").Select : myExcel.Selection.ColumnWidth = 8 : xlSheet.Columns("G:M").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Rows("2:3").Select : myExcel.Selection.RowHeight = 25 : xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 30
        xlSheet.Columns("D:F").Select : myExcel.Selection.NumberFormatLocal = "#,##0"
        xlSheet.Rows("4:" & GN1 + 5).Select : myExcel.Selection.RowHeight = 25

        xlSheet.Range("A2:A3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B2:B3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("C2:C3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("D2:D3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With : myExcel.Selection.Merge
        xlSheet.Range("E2:E3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With : myExcel.Selection.Merge
        xlSheet.Range("F2:F3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With : myExcel.Selection.Merge
        xlSheet.Range("G3:M3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("N2:N3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A1:N1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .Color = 49407 : .TintAndShade = 0 : .PatternTintAndShade = 0 : End With
        xlSheet.Range("A1:N3").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        xlSheet.Range("A4:N" & GN1 + 5).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        xlSheet.Range("C" & GN1 + 5).Select()
        With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            If 清單1_dgv.Rows(i).Cells(表頭(64)).Value.ToString = "" Then : xlSheet.Range("G" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(32)).Value.ToString = "" Then : xlSheet.Range("H" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(34)).Value.ToString = "" Then : xlSheet.Range("I" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(36)).Value.ToString = "" Then : xlSheet.Range("J" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(38)).Value.ToString = "" Then : xlSheet.Range("K" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(40)).Value.ToString = "" Then : xlSheet.Range("L" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(42)).Value.ToString = "" Then : xlSheet.Range("M" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
        Next
        xlSheet.Range("A2:N3").Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        myExcel.ActiveWindow.DisplayGridlines = False
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$3" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "第 &P 頁，共 &N 頁" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .RightMargin = myExcel.Application.InchesToPoints(0.196850393700787)
            .TopMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .BottomMargin = myExcel.Application.InchesToPoints(0.393700787401575)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .FooterMargin = myExcel.Application.InchesToPoints(0.196850393700787)
            .PrintHeadings = False : .PrintGridlines = False : .PrintQuality = 600 : .CenterHorizontally = True : .CenterVertically = False : .Orientation = xlLandscape
            .Draft = False : .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = False
            .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With
        myExcel.Application.PrintCommunication = True
    End Sub
    Private Sub CC(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)
        xlSheet.Cells.Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 4 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 22 : xlSheet.Columns("D:E").Select : myExcel.Selection.ColumnWidth = 11
        xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 8 : xlSheet.Columns("G:H").Select : myExcel.Selection.ColumnWidth = 8
        xlSheet.Columns("I:X").Select : myExcel.Selection.ColumnWidth = 5 : xlSheet.Columns("I:J").Select : myExcel.Selection.ColumnWidth = 7
        xlSheet.Columns("K:X").Select : myExcel.Selection.ColumnWidth = 4 : xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 30
        xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 15 : xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 35
        xlSheet.Rows("4:" & GN1 + 5).Select : myExcel.Selection.RowHeight = 25 : xlSheet.Columns("D:F").Select : myExcel.Selection.NumberFormatLocal = "#,##0"
        xlSheet.Range("C4:Y" & GN1 + 5).Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Range("A4:B" & GN1 + 5).Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 9 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With

        xlSheet.Range("K3:X3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("I4:X" & GN1 + 5).Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("A2:A3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B2:B3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("C2:C3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("D2:D3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("E2:F2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("G2:H2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("I2:J2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("K2:L2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("M2:N2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("O2:P2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("Q2:R2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("S2:T2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("U2:V2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("W2:X2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("Y2:Y3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A2:Y3").Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With
        xlSheet.Range("K2:X2").Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 8 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Range("A1:Y1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .Color = 49407 : .TintAndShade = 0 : .PatternTintAndShade = 0 : End With
        xlSheet.Range("A1:Y3").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        xlSheet.Range("A4:Y" & GN1 + 5).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            If 清單1_dgv.Rows(i).Cells(表頭(64)).Value.ToString = "" Then : xlSheet.Range("K" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(31)).Value.ToString = "" Then : xlSheet.Range("L" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(32)).Value.ToString = "" Then : xlSheet.Range("M" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(33)).Value.ToString = "" Then : xlSheet.Range("N" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(34)).Value.ToString = "" Then : xlSheet.Range("O" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(35)).Value.ToString = "" Then : xlSheet.Range("P" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(36)).Value.ToString = "" Then : xlSheet.Range("Q" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(37)).Value.ToString = "" Then : xlSheet.Range("R" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(38)).Value.ToString = "" Then : xlSheet.Range("S" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(39)).Value.ToString = "" Then : xlSheet.Range("T" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(40)).Value.ToString = "" Then : xlSheet.Range("U" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(41)).Value.ToString = "" Then : xlSheet.Range("V" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(42)).Value.ToString = "" Then : xlSheet.Range("W" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
            If 清單1_dgv.Rows(i).Cells(表頭(43)).Value.ToString = "" Then : xlSheet.Range("X" & 4 + i).Select()
                With myExcel.Selection.Borders(xlDiagonalUp) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With : End If
        Next
        myExcel.ActiveWindow.DisplayGridlines = False
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$3" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "第 &P 頁，共 &N 頁" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .RightMargin = myExcel.Application.InchesToPoints(0.196850393700787)
            .TopMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .BottomMargin = myExcel.Application.InchesToPoints(0.393700787401575)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.196850393700787) : .FooterMargin = myExcel.Application.InchesToPoints(0.196850393700787)
            .PrintHeadings = False : .PrintGridlines = False : .PrintQuality = 600 : .CenterHorizontally = True : .CenterVertically = False : .Orientation = xlLandscape
            .Draft = False : .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = False
            .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With
        myExcel.Application.PrintCommunication = True
    End Sub
    '----------------------自創視窗滑鼠拖曳功能---------------------------------------------------------------------------------------------------------
    Dim OldX, OldY As Long : Dim drag As Boolean
    Private Sub 視窗3_pl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗3_pl.MouseDown
        If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If
    End Sub
    Private Sub 視窗3_pl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗3_pl.MouseMove
        If drag Then : 視窗3_pl.Left = 視窗3_pl.Left + e.X - OldX : 視窗3_pl.Top = 視窗3_pl.Top + e.Y - OldY : End If
    End Sub
    Private Sub 視窗3_pl_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗3_pl.MouseUp
        drag = False
    End Sub
    Private Sub Label11_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label11.MouseDown
        If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If
    End Sub
    Private Sub Label11_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label11.MouseMove
        If drag Then : 視窗3_pl.Left = 視窗3_pl.Left + e.X - OldX : 視窗3_pl.Top = 視窗3_pl.Top + e.Y - OldY : End If
    End Sub
    Private Sub Label11_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label11.MouseUp
        drag = False
    End Sub
End Class