Imports System.Windows.Forms.DataVisualization.Charting
Public Class 財務報表2
    Dim 已付款 As Boolean
    Dim 新項次, 合約號, 物料規格, 新流水1 As String
    Dim NUM1, II As Integer
    Dim 對話框(1) As String
    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
        表頭(11) = 系統語言字典("H206-112-" & 語言) : 表頭(12) = 系統語言字典("H206-106-" & 語言) : 表頭(15) = 系統語言字典("H206-114-" & 語言)
        表頭(134) = 系統語言字典("H206-104-" & 語言) : 表頭(13) = 系統語言字典("H206-108-" & 語言) : 表頭(14) = 系統語言字典("H206-109-" & 語言)
        表頭(16) = 系統語言字典("H206-110-" & 語言) : 表頭(26) = 系統語言字典("H206-111-" & 語言) : 表頭(27) = 系統語言字典("H206-105-" & 語言)
        表頭(19) = 系統語言字典("H206-103-" & 語言) : 表頭(10) = 系統語言字典("H213-101-" & 語言) : 表頭(17) = 系統語言字典("H299-109-" & 語言)
        表頭(18) = 系統語言字典("H206-107-" & 語言) : 表頭(20) = 系統語言字典("H311-100-" & 語言) : 表頭(21) = 系統語言字典("H311-101-" & 語言)
        表頭(22) = 系統語言字典("H311-102-" & 語言) : 表頭(23) = 系統語言字典("H204-116-" & 語言) : 表頭(24) = 系統語言字典("H201-124-" & 語言)
        表頭(25) = 系統語言字典("H311-103-" & 語言) : 表頭(28) = 系統語言字典("H311-104-" & 語言) : Label16.Text = 系統語言字典("H311-107-" & 語言)
        表頭(29) = 系統語言字典("H311-105-" & 語言) : 對話框(0) = 系統語言字典("H312-100-" & 語言) : 對話框(1) = 系統語言字典("H312-101-" & 語言)
        表頭(30) = 系統語言字典("H204-120-" & 語言) : 表頭(31) = 系統語言字典("H312-102-" & 語言) : 表頭(32) = 系統語言字典("H312-103-" & 語言)
        表頭(33) = 系統語言字典("H312-104-" & 語言) : 表頭(34) = 系統語言字典("H312-105-" & 語言) : 表頭(35) = 系統語言字典("H312-106-" & 語言)
        表頭(36) = 系統語言字典("H311-106-" & 語言)
    End Sub
    Private Sub Set_清單1()
        Dim ds1, ds2, ds3, ds4 As New DataSet
        清單_dgv.DataSource = Nothing : ds1.Clear() : 清單1_dgv.DataSource = Nothing : ds2.Clear()
        彙總1_dgv.DataSource = Nothing : ds3.Clear() : 合計1_dgv.DataSource = Nothing : ds4.Clear()

        清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單_dgv.ColumnHeadersHeight = 50 : 清單_dgv.AllowUserToAddRows = False : 清單_dgv.RowTemplate.Height = 25
        清單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單1_dgv.ColumnHeadersHeight = 50 : 清單1_dgv.AllowUserToAddRows = False : 清單1_dgv.RowTemplate.Height = 25
        彙總1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        彙總1_dgv.ColumnHeadersHeight = 50 : 彙總1_dgv.AllowUserToAddRows = False : 彙總1_dgv.RowTemplate.Height = 25
        合計1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        合計1_dgv.ColumnHeadersHeight = 50 : 合計1_dgv.AllowUserToAddRows = False : 合計1_dgv.RowTemplate.Height = 25
        合計1_dgv.ScrollBars = ScrollBars.None : 合計1_dgv.ColumnHeadersVisible = False

        SQL2 = "(採購單控制表.已出納 IS NULL OR 採購單控制表.已出納 = 0)"
        SQL_採購未付款清單1() : da.Fill(ds1) : 清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        SQL2 = "(採購單控制表.已出納 = 1)"
        SQL_採購未付款清單1() : da.Fill(ds2) : 清單1_dgv.DataSource = ds2.Tables(0) : conn.Close()
        SQL_採購付款彙總1() : da.Fill(ds3) : 彙總1_dgv.DataSource = ds3.Tables(0) : conn.Close()
        SQL_採購付款彙總0() : da.Fill(ds4) : 合計1_dgv.DataSource = ds4.Tables(0) : conn.Close()

        清單_dgv.Columns(0).FillWeight = 150 : 清單_dgv.Columns(1).FillWeight = 200 : 清單_dgv.Columns(2).FillWeight = 50 : 清單_dgv.Columns(3).FillWeight = 50
        清單_dgv.Columns(4).FillWeight = 130 : 清單_dgv.Columns(表頭(28)).FillWeight = 50
        清單1_dgv.Columns(0).FillWeight = 150 : 清單1_dgv.Columns(1).FillWeight = 200 : 清單1_dgv.Columns(2).FillWeight = 50 : 清單1_dgv.Columns(3).FillWeight = 50
        清單1_dgv.Columns(4).FillWeight = 130 : 清單1_dgv.Columns(表頭(28)).FillWeight = 50
        彙總1_dgv.Columns("比例1").Visible = False
        彙總1_dgv.Columns(1).DefaultCellStyle.Format = "#,##0"
        彙總1_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        彙總1_dgv.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        合計1_dgv.Columns("比例1").Visible = False
        合計1_dgv.Columns(1).DefaultCellStyle.Format = "#,##0"
        合計1_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        合計1_dgv.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight

        Dim indexArray() As Integer = {2, 3, 5, 6, 7}
        For Each index As Integer In indexArray
            清單_dgv.Columns(index).DefaultCellStyle.Format = "#,##0"
            清單_dgv.Columns(index).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            清單_dgv.Columns(index).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
            清單1_dgv.Columns(index).DefaultCellStyle.Format = "#,##0"
            清單1_dgv.Columns(index).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            清單1_dgv.Columns(index).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        Dim 總和 As Long
        For i As Integer = 0 To 清單_dgv.Rows.Count - 1
            If Strings.Left(清單_dgv.Rows(i).Cells("合約號").Value.ToString, 1) = "H" Or Strings.Left(清單_dgv.Rows(i).Cells("合約號").Value.ToString, 1) = "P" Then : Else
                清單_dgv.Rows(i).Cells("合約號").Value = ""
            End If
            清單_dgv.Rows(i).Cells(表頭(21)).Value = 清單_dgv.Rows(i).Cells(表頭(20)).Value / 100 * 清單_dgv.Rows(i).Cells("DISC").Value
            清單_dgv.Rows(i).Cells(表頭(22)).Value = (清單_dgv.Rows(i).Cells(表頭(20)).Value - 清單_dgv.Rows(i).Cells(表頭(21)).Value) * 清單_dgv.Rows(i).Cells("PPN").Value / 100
            總和 += 清單_dgv.Rows(i).Cells(表頭(20)).Value - 清單_dgv.Rows(i).Cells(表頭(21)).Value + 清單_dgv.Rows(i).Cells(表頭(22)).Value
        Next
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            清單1_dgv.Rows(i).Cells(表頭(21)).Value = 清單1_dgv.Rows(i).Cells(表頭(20)).Value / 100 * 清單1_dgv.Rows(i).Cells("DISC").Value
            清單1_dgv.Rows(i).Cells(表頭(22)).Value = (清單1_dgv.Rows(i).Cells(表頭(20)).Value - 清單1_dgv.Rows(i).Cells(表頭(21)).Value) * 清單_dgv.Rows(i).Cells("PPN").Value / 100
        Next

        合計1_dgv.Rows(0).Cells(0).Value = 對話框(0) : 合計1_dgv.Rows(0).Cells(表頭(29)).Value = "0" : 合計1_dgv.Rows(0).Cells("比例1").Value = "0"
        For i As Integer = 0 To 彙總1_dgv.Rows.Count - 1 : 彙總1_dgv.Rows(i).Cells(表頭(29)).Value = "0" : 彙總1_dgv.Rows(i).Cells("比例1").Value = "0"
            For ii As Integer = 0 To 清單_dgv.Rows.Count - 1
                If 彙總1_dgv.Rows(i).Cells(0).Value.ToString = 清單_dgv.Rows(ii).Cells(0).Value.ToString Then
                    彙總1_dgv.Rows(i).Cells(表頭(29)).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                End If
            Next
            彙總1_dgv.Rows(i).Cells("比例1").Value = 彙總1_dgv.Rows(i).Cells(表頭(29)).Value / 總和 * 100
            合計1_dgv.Rows(0).Cells(表頭(29)).Value += 彙總1_dgv.Rows(i).Cells(表頭(29)).Value
            合計1_dgv.Rows(0).Cells("比例1").Value += 彙總1_dgv.Rows(i).Cells("比例1").Value
        Next
        Set_進度條顯示1() : 彙總1_dgv.Columns(3).FillWeight = 60 : 彙總1_dgv.Columns(0).FillWeight = 150
        Set_進度條顯示0() : 合計1_dgv.Columns(3).FillWeight = 60 : 合計1_dgv.Columns(0).FillWeight = 150
        Dim mycol1 As DataGridViewImageColumn = 清單_dgv.Columns(表頭(28)) : mycol1.ImageLayout = DataGridViewImageCellLayout.Zoom
        Dim mycol2 As DataGridViewImageColumn = 清單1_dgv.Columns(表頭(28)) : mycol2.ImageLayout = DataGridViewImageCellLayout.Zoom
        For I As Integer = 0 To 清單_dgv.Rows.Count - 1 : 清單_dgv.Rows(I).Cells(表頭(28)).Value = My.Resources.visa_2 : Next
        For I As Integer = 0 To 清單1_dgv.Rows.Count - 1 : 清單1_dgv.Rows(I).Cells(表頭(28)).Value = My.Resources.Close : Next
        彙總1_dgv.Sort(彙總1_dgv.Columns(1), System.ComponentModel.ListSortDirection.Descending)
        PA10 = "" : Set_清單2() : Set_清單3()
        '-------------------------合計DGV變形----------------------------------------------------------------------------------------------------------------------
        If IsVerticalScrollBarVisible(彙總1_dgv) Then : 合計1_dgv.Size = New Size(彙總1_dgv.Size.Width - 17, 合計1_dgv.Size.Height)
        Else : 合計1_dgv.Size = New Size(彙總1_dgv.Size.Width, 合計1_dgv.Size.Height) : End If
    End Sub
    Private Sub Set_進度條顯示0()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = "Percent (%)" : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 合計1_dgv.Columns.Insert(3, Col)
    End Sub
    Private Sub Set_進度條顯示1()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = "Percent (%)" : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 彙總1_dgv.Columns.Insert(3, Col)
    End Sub
    Private Sub Set_清單2()
        Dim ds1, ds2 As New DataSet : 彙總2_dgv.DataSource = Nothing : ds1.Clear() : 合計2_dgv.DataSource = Nothing : ds2.Clear()
        彙總2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        彙總2_dgv.ColumnHeadersHeight = 50 : 彙總2_dgv.AllowUserToAddRows = False : 彙總2_dgv.RowTemplate.Height = 25
        合計2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        合計2_dgv.ColumnHeadersHeight = 50 : 合計2_dgv.AllowUserToAddRows = False : 合計2_dgv.RowTemplate.Height = 25
        合計2_dgv.ScrollBars = ScrollBars.None : 合計2_dgv.ColumnHeadersVisible = False

        SQL_採購付款彙總2() : da.Fill(ds1) : 彙總2_dgv.DataSource = ds1.Tables(0) : conn.Close()
        SQL_採購付款彙總3() : da.Fill(ds2) : 合計2_dgv.DataSource = ds2.Tables(0) : conn.Close()

        彙總2_dgv.Columns("比例1").Visible = False
        彙總2_dgv.Columns(1).DefaultCellStyle.Format = "#,##0"
        彙總2_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        彙總2_dgv.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight

        合計2_dgv.Columns("比例1").Visible = False
        合計2_dgv.Columns(1).DefaultCellStyle.Format = "#,##0"
        合計2_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        合計2_dgv.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight

        Dim 總和 As Long
        合計2_dgv.Rows(0).Cells(0).Value = 對話框(0) : 合計2_dgv.Rows(0).Cells(表頭(29)).Value = "0" : 合計2_dgv.Rows(0).Cells("比例1").Value = "0"
        For i As Integer = 0 To 彙總2_dgv.Rows.Count - 1 : 彙總2_dgv.Rows(i).Cells(表頭(29)).Value = "0" : 彙總2_dgv.Rows(i).Cells("比例1").Value = "0"
            For ii As Integer = 0 To 清單_dgv.Rows.Count - 1
                If 彙總2_dgv.Rows(i).Cells(0).Value.ToString = 清單_dgv.Rows(ii).Cells(1).Value.ToString Then
                    彙總2_dgv.Rows(i).Cells(表頭(29)).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                End If
            Next
            總和 += 彙總2_dgv.Rows(i).Cells(表頭(29)).Value
        Next
        For i As Integer = 0 To 彙總2_dgv.Rows.Count - 1
            If 總和 = 0 Then : 彙總2_dgv.Rows(i).Cells("比例1").Value = "0" : Else
                彙總2_dgv.Rows(i).Cells("比例1").Value = 彙總2_dgv.Rows(i).Cells(表頭(29)).Value / 總和 * 100
            End If
            合計2_dgv.Rows(0).Cells(表頭(29)).Value += 彙總2_dgv.Rows(i).Cells(表頭(29)).Value
            合計2_dgv.Rows(0).Cells("比例1").Value += 彙總2_dgv.Rows(i).Cells("比例1").Value
        Next
        Set_進度條顯示2() : 彙總2_dgv.Columns(3).FillWeight = 60 : 彙總2_dgv.Columns(0).FillWeight = 180
        Set_進度條顯示3() : 合計2_dgv.Columns(3).FillWeight = 60 : 合計2_dgv.Columns(0).FillWeight = 180
        彙總2_dgv.Sort(彙總2_dgv.Columns(1), System.ComponentModel.ListSortDirection.Descending)
        '-------------------------合計DGV變形----------------------------------------------------------------------------------------------------------------------
        If IsVerticalScrollBarVisible(彙總2_dgv) Then : 合計2_dgv.Size = New Size(彙總2_dgv.Size.Width - 17, 合計2_dgv.Size.Height)
        Else : 合計2_dgv.Size = New Size(彙總2_dgv.Size.Width, 合計2_dgv.Size.Height) : End If
    End Sub
    Private Sub Set_進度條顯示2()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = "Percent (%)" : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 彙總2_dgv.Columns.Insert(3, Col)
    End Sub
    Private Sub Set_進度條顯示3()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = "Percent (%)" : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 合計2_dgv.Columns.Insert(3, Col)
    End Sub
    Private Sub Set_清單3()
        Dim ds1, ds2, ds3 As New DataSet : 彙總3_dgv.DataSource = Nothing : ds1.Clear() : 彙總4_dgv.DataSource = Nothing : ds1.Clear() : 合計3_dgv.DataSource = Nothing : ds2.Clear()
        彙總3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        彙總3_dgv.ColumnHeadersHeight = 50 : 彙總3_dgv.AllowUserToAddRows = False : 彙總3_dgv.RowTemplate.Height = 25
        彙總4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        彙總4_dgv.ColumnHeadersHeight = 50 : 彙總4_dgv.AllowUserToAddRows = False : 彙總4_dgv.RowTemplate.Height = 25
        彙總4_dgv.ScrollBars = ScrollBars.None : 彙總4_dgv.ColumnHeadersVisible = False
        合計3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        合計3_dgv.ColumnHeadersHeight = 50 : 合計3_dgv.AllowUserToAddRows = False : 合計3_dgv.RowTemplate.Height = 25
        合計3_dgv.ScrollBars = ScrollBars.None : 合計3_dgv.ColumnHeadersVisible = False

        Dim SSA(19) As String
        Dim checkBoxes() As CheckBox = {A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20}
        For i As Integer = 0 To SSA.Length - 1
            If checkBoxes(i).Checked Then : SSA(i) = " 約號甲方 LIKE N'" & checkBoxes(i).Text & "'" : Else : SSA(i) = "" : End If
        Next
        If SSA.All(Function(s) String.IsNullOrEmpty(s)) Then : SQL2 = "" : Else
            Dim selectedSSA = SSA.Where(Function(s) Not String.IsNullOrEmpty(s)).ToArray()
            SQL2 = "AND (" & String.Join(" OR ", selectedSSA) & ")"
        End If
        SQL_採購付款彙總4() : da.Fill(ds1) : 彙總3_dgv.DataSource = ds1.Tables(0) : conn.Close()
        SQL_採購付款彙總5() : da.Fill(ds2) : 彙總4_dgv.DataSource = ds2.Tables(0) : conn.Close()
        SQL_採購付款彙總5() : da.Fill(ds3) : 合計3_dgv.DataSource = ds3.Tables(0) : conn.Close()

        彙總3_dgv.Columns(0).FillWeight = 150 : 彙總3_dgv.Columns("比例1").Visible = False : 彙總3_dgv.Columns("比例2").Visible = False
        彙總4_dgv.Columns(0).FillWeight = 150 : 彙總4_dgv.Columns("比例1").Visible = False : 彙總4_dgv.Columns("比例2").Visible = False
        合計3_dgv.Columns(0).FillWeight = 150 : 合計3_dgv.Columns("比例1").Visible = False : 合計3_dgv.Columns("比例2").Visible = False
        彙總3_dgv.Columns(1).Visible = False : 彙總3_dgv.Columns(2).Visible = False : 彙總3_dgv.Columns(3).Visible = False : 彙總3_dgv.Columns(4).Visible = False
        彙總4_dgv.Columns(1).Visible = False : 彙總4_dgv.Columns(2).Visible = False : 彙總4_dgv.Columns(3).Visible = False : 彙總4_dgv.Columns(4).Visible = False
        合計3_dgv.Columns(1).Visible = False : 合計3_dgv.Columns(2).Visible = False : 合計3_dgv.Columns(3).Visible = False : 合計3_dgv.Columns(4).Visible = False

        Dim indexArray() As Integer = {4, 5, 6, 7, 8, 9, 10}

        For Each index As Integer In indexArray
            彙總3_dgv.Columns(index).DefaultCellStyle.Format = "#,##0" : 彙總4_dgv.Columns(index).DefaultCellStyle.Format = "#,##0" : 合計3_dgv.Columns(index).DefaultCellStyle.Format = "#,##0"
            彙總3_dgv.Columns(index).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            彙總3_dgv.Columns(index).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
            彙總4_dgv.Columns(index).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            彙總4_dgv.Columns(index).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
            合計3_dgv.Columns(index).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            合計3_dgv.Columns(index).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        Next

        彙總4_dgv.Rows(0).Cells(0).Value = 對話框(1) : 彙總4_dgv.Rows(0).Cells(4).Value = "0" : 彙總4_dgv.Rows(0).Cells(5).Value = "0" : 彙總4_dgv.Rows(0).Cells(6).Value = "0"
        彙總4_dgv.Rows(0).Cells(7).Value = "0" : 彙總4_dgv.Rows(0).Cells(8).Value = "0" : 彙總4_dgv.Rows(0).Cells(9).Value = "0" : 彙總4_dgv.Rows(0).Cells(10).Value = "0"
        合計3_dgv.Rows(0).Cells(0).Value = 對話框(0) : 合計3_dgv.Rows(0).Cells(4).Value = "0" : 合計3_dgv.Rows(0).Cells(5).Value = "0" : 合計3_dgv.Rows(0).Cells(6).Value = "0"
        合計3_dgv.Rows(0).Cells(7).Value = "0" : 合計3_dgv.Rows(0).Cells(8).Value = "0" : 合計3_dgv.Rows(0).Cells(9).Value = "0" : 合計3_dgv.Rows(0).Cells(10).Value = "0"
        For i As Integer = 0 To 彙總3_dgv.Rows.Count - 1
            彙總3_dgv.Rows(i).Cells(6).Value = "0" : 彙總3_dgv.Rows(i).Cells(9).Value = "0" : 彙總3_dgv.Rows(i).Cells(10).Value = "0"
            For ii As Integer = 0 To 清單_dgv.Rows.Count - 1
                If 彙總3_dgv.Rows(i).Cells(0).Value.ToString = 清單_dgv.Rows(ii).Cells("合約號").Value.ToString Then
                    彙總3_dgv.Rows(i).Cells(6).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                    彙總3_dgv.Rows(i).Cells(9).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                End If
            Next
        Next
        If SSA.All(Function(s) String.IsNullOrEmpty(s)) Then
            For ii As Integer = 0 To 清單_dgv.Rows.Count - 1
                If 清單_dgv.Rows(ii).Cells("合約號").Value.ToString = "" Then
                    彙總4_dgv.Rows(0).Cells(5).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                    彙總4_dgv.Rows(0).Cells(6).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                    彙總4_dgv.Rows(0).Cells(9).Value += 清單_dgv.Rows(ii).Cells(表頭(20)).Value - 清單_dgv.Rows(ii).Cells(表頭(21)).Value + 清單_dgv.Rows(ii).Cells(表頭(22)).Value
                End If
            Next
        Else : End If
        For i As Integer = 0 To 彙總3_dgv.Rows.Count - 1
            For ii As Integer = 0 To 清單1_dgv.Rows.Count - 1
                If 彙總3_dgv.Rows(i).Cells(0).Value.ToString = 清單1_dgv.Rows(ii).Cells("合約號").Value.ToString Then
                    彙總3_dgv.Rows(i).Cells(6).Value += 清單1_dgv.Rows(ii).Cells(表頭(20)).Value - 清單1_dgv.Rows(ii).Cells(表頭(21)).Value + 清單1_dgv.Rows(ii).Cells(表頭(22)).Value
                    彙總3_dgv.Rows(i).Cells(10).Value += 清單1_dgv.Rows(ii).Cells(表頭(20)).Value - 清單1_dgv.Rows(ii).Cells(表頭(21)).Value + 清單1_dgv.Rows(ii).Cells(表頭(22)).Value
                End If
            Next
        Next
        If SSA.All(Function(s) String.IsNullOrEmpty(s)) Then
            For ii As Integer = 0 To 清單1_dgv.Rows.Count - 1
                If 清單1_dgv.Rows(ii).Cells("合約號").Value.ToString = "" Then
                    彙總4_dgv.Rows(0).Cells(5).Value += 清單1_dgv.Rows(ii).Cells(表頭(20)).Value - 清單1_dgv.Rows(ii).Cells(表頭(21)).Value + 清單1_dgv.Rows(ii).Cells(表頭(22)).Value
                    彙總4_dgv.Rows(0).Cells(6).Value += 清單1_dgv.Rows(ii).Cells(表頭(20)).Value - 清單1_dgv.Rows(ii).Cells(表頭(21)).Value + 清單1_dgv.Rows(ii).Cells(表頭(22)).Value
                    彙總4_dgv.Rows(0).Cells(10).Value += 清單1_dgv.Rows(ii).Cells(表頭(20)).Value - 清單1_dgv.Rows(ii).Cells(表頭(21)).Value + 清單1_dgv.Rows(ii).Cells(表頭(22)).Value
                End If
            Next
        Else : End If
        For i As Integer = 0 To 彙總3_dgv.Rows.Count - 1
            彙總3_dgv.Rows(i).Cells(7).Value = 彙總3_dgv.Rows(i).Cells(5).Value - 彙總3_dgv.Rows(i).Cells(6).Value
            If 彙總3_dgv.Rows(i).Cells(7).Value < 0 Then : 彙總3_dgv.Rows(i).Cells(7).Value = 彙總3_dgv.Rows(i).Cells(7).Value * -1
            Else : 彙總3_dgv.Rows(i).Cells(7).Value = 0 : End If
            If 彙總3_dgv.Rows(i).Cells(5).Value = 0 Then : 彙總3_dgv.Rows(i).Cells("比例1").Value = "0" : Else
                彙總3_dgv.Rows(i).Cells("比例1").Value = 彙總3_dgv.Rows(i).Cells(6).Value / 彙總3_dgv.Rows(i).Cells(5).Value * 100
            End If
            If 彙總3_dgv.Rows(i).Cells(9).Value = 0 And 彙總3_dgv.Rows(i).Cells(10).Value > 0 Then : 彙總3_dgv.Rows(i).Cells("比例2").Value = 100
            ElseIf 彙總3_dgv.Rows(i).Cells(9).Value = 0 And 彙總3_dgv.Rows(i).Cells(10).Value = 0 Then : 彙總3_dgv.Rows(i).Cells("比例2").Value = 0
            Else : 彙總3_dgv.Rows(i).Cells("比例2").Value = 彙總3_dgv.Rows(i).Cells(10).Value / 彙總3_dgv.Rows(i).Cells(9).Value * 100 : End If
            合計3_dgv.Rows(0).Cells(4).Value = 合計3_dgv.Rows(0).Cells(4).Value + 彙總3_dgv.Rows(i).Cells(4).Value
            合計3_dgv.Rows(0).Cells(5).Value = 合計3_dgv.Rows(0).Cells(5).Value + 彙總3_dgv.Rows(i).Cells(5).Value
            合計3_dgv.Rows(0).Cells(6).Value = 合計3_dgv.Rows(0).Cells(6).Value + 彙總3_dgv.Rows(i).Cells(6).Value
            合計3_dgv.Rows(0).Cells(7).Value = 合計3_dgv.Rows(0).Cells(7).Value + 彙總3_dgv.Rows(i).Cells(7).Value
            合計3_dgv.Rows(0).Cells(9).Value = 合計3_dgv.Rows(0).Cells(9).Value + 彙總3_dgv.Rows(i).Cells(9).Value
            合計3_dgv.Rows(0).Cells(10).Value = 合計3_dgv.Rows(0).Cells(10).Value + 彙總3_dgv.Rows(i).Cells(10).Value
        Next
        合計3_dgv.Rows(0).Cells(4).Value = 合計3_dgv.Rows(0).Cells(4).Value + 彙總4_dgv.Rows(0).Cells(4).Value
        合計3_dgv.Rows(0).Cells(5).Value = 合計3_dgv.Rows(0).Cells(5).Value + 彙總4_dgv.Rows(0).Cells(5).Value
        合計3_dgv.Rows(0).Cells(6).Value = 合計3_dgv.Rows(0).Cells(6).Value + 彙總4_dgv.Rows(0).Cells(6).Value
        合計3_dgv.Rows(0).Cells(7).Value = 合計3_dgv.Rows(0).Cells(7).Value + 彙總4_dgv.Rows(0).Cells(7).Value
        合計3_dgv.Rows(0).Cells(9).Value = 合計3_dgv.Rows(0).Cells(9).Value + 彙總4_dgv.Rows(0).Cells(9).Value
        合計3_dgv.Rows(0).Cells(10).Value = 合計3_dgv.Rows(0).Cells(10).Value + 彙總4_dgv.Rows(0).Cells(10).Value
        If 彙總4_dgv.Rows(0).Cells(5).Value = 0 Then : 彙總4_dgv.Rows(0).Cells("比例1").Value = "0" : Else
            彙總4_dgv.Rows(0).Cells("比例1").Value = 彙總4_dgv.Rows(0).Cells(6).Value / 彙總4_dgv.Rows(0).Cells(5).Value * 100
        End If
        合計3_dgv.Rows(0).Cells("比例1").Value = 合計3_dgv.Rows(0).Cells(6).Value / 合計3_dgv.Rows(0).Cells(5).Value * 100
        If 彙總4_dgv.Rows(0).Cells(9).Value = 0 And 彙總4_dgv.Rows(0).Cells(10).Value = 0 Then : 彙總4_dgv.Rows(0).Cells("比例2").Value = 0
        ElseIf 彙總4_dgv.Rows(0).Cells(9).Value = 0 And 彙總4_dgv.Rows(0).Cells(10).Value > 0 Then : 彙總4_dgv.Rows(0).Cells("比例2").Value = 100
        Else : 彙總4_dgv.Rows(0).Cells("比例2").Value = 彙總4_dgv.Rows(0).Cells(10).Value / 彙總4_dgv.Rows(0).Cells(9).Value * 100
        End If
        If 合計3_dgv.Rows(0).Cells(9).Value = 0 And 合計3_dgv.Rows(0).Cells(10).Value = 0 Then : 合計3_dgv.Rows(0).Cells("比例2").Value = 0
        ElseIf 合計3_dgv.Rows(0).Cells(9).Value = 0 And 合計3_dgv.Rows(0).Cells(10).Value > 0 Then : 合計3_dgv.Rows(0).Cells("比例2").Value = 100
        Else : 合計3_dgv.Rows(0).Cells("比例2").Value = 合計3_dgv.Rows(0).Cells(10).Value / 合計3_dgv.Rows(0).Cells(9).Value * 100
        End If : RadTrackBar1.Maximum = 彙總3_dgv.Rows.Count : RadTrackBar1.Value = 1
        If 彙總3_dgv.Rows.Count > 10 Then : RadTrackBar1.Visible = True : Else : RadTrackBar1.Visible = False : End If
        Set_進度條顯示4() : Set_進度條顯示5() : Set_進度條顯示6() : Set_進度條顯示7() : Set_進度條顯示8() : Set_進度條顯示9() : 彙總()
        '-------------------------合計DGV變形----------------------------------------------------------------------------------------------------------------------
        If IsVerticalScrollBarVisible(彙總3_dgv) Then
            合計3_dgv.Size = New Size(彙總3_dgv.Size.Width - 17, 合計3_dgv.Size.Height) : 彙總4_dgv.Size = New Size(彙總3_dgv.Size.Width - 17, 彙總4_dgv.Size.Height)
        Else : 合計3_dgv.Size = New Size(彙總3_dgv.Size.Width, 合計3_dgv.Size.Height) : 彙總4_dgv.Size = New Size(彙總3_dgv.Size.Width, 彙總4_dgv.Size.Height) : End If
    End Sub
    Private Sub Set_進度條顯示4()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = 表頭(32) : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 彙總3_dgv.Columns.Insert(7, Col)
    End Sub
    Private Sub Set_進度條顯示5()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = 表頭(32) : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 合計3_dgv.Columns.Insert(7, Col)
    End Sub
    Private Sub Set_進度條顯示6()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = 表頭(33) : Col.Name = "容量" : Col.DataPropertyName = "比例2" : 彙總3_dgv.Columns.Insert(12, Col)
    End Sub
    Private Sub Set_進度條顯示7()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = 表頭(33) : Col.Name = "容量" : Col.DataPropertyName = "比例2" : 合計3_dgv.Columns.Insert(12, Col)
    End Sub
    Private Sub Set_進度條顯示8()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = 表頭(32) : Col.Name = "容量" : Col.DataPropertyName = "比例1" : 彙總4_dgv.Columns.Insert(7, Col)
    End Sub
    Private Sub Set_進度條顯示9()
        Dim Col As New DataGridViewProgressColumn With {
            .Width = 30,
            .DataPropertyName = "請款比例"
        }
        Col.HeaderText = 表頭(33) : Col.Name = "容量" : Col.DataPropertyName = "比例2" : 彙總4_dgv.Columns.Insert(12, Col)
    End Sub
    Private Sub RadTrackBar1_ValueChanged(sender As Object, e As EventArgs) Handles RadTrackBar1.RangeValueChanged
        If 首次開啟 = True Then : Else
            If RadTrackBar1.Maximum >= 10 Then : If RadTrackBar1.Value > RadTrackBar1.Maximum - 9 Then : RadTrackBar1.Value = RadTrackBar1.Maximum - 9 : End If : 彙總() : Else : 彙總() : End If
        End If
    End Sub
    Private Sub 彙總()
        Chart1.Series.Clear() : Chart1.ChartAreas.Clear() : Chart1.ChartAreas.Add(0)
        Chart1.ChartAreas(0).AxisX.Minimum = 0 ' 设置X轴的最小值
        Chart1.ChartAreas(0).AxisX.Maximum = 10 ' 设置X轴的最大值
        Chart1.Series.Add(表頭(31)) : Chart1.Series(表頭(31)).ChartType = SeriesChartType.FastLine
        Chart1.Series.Add(表頭(34)) : Chart1.Series(表頭(34)).ChartType = SeriesChartType.Column
        Chart1.Series.Add(表頭(29)) : Chart1.Series(表頭(29)).ChartType = SeriesChartType.Column
        Chart1.Series.Add(表頭(36)) : Chart1.Series(表頭(36)).ChartType = SeriesChartType.Column
        Chart1.ChartAreas(0).BackColor = Color.Transparent : Chart1.Legends(0).BackColor = Color.Transparent
        Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Arial", 8) : Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "#,##0" & " M"
        Dim 位置1, 位置2 As Integer
        If RadTrackBar1.Maximum <= 10 Then : 位置1 = 1 : 位置2 = RadTrackBar1.Maximum
        Else : 位置1 = RadTrackBar1.Value : 位置2 = RadTrackBar1.Value + 9 : End If
        For i As Integer = 位置1 - 1 To 位置2 - 1
            Chart1.Series(表頭(31)).Points.AddXY(彙總3_dgv.Rows(i).Cells(0).Value.ToString, CLng(彙總3_dgv.Rows(i).Cells(表頭(31)).Value.ToString) / 1000000)
            Chart1.Series(表頭(34)).Points.AddXY(彙總3_dgv.Rows(i).Cells(0).Value.ToString, CLng(彙總3_dgv.Rows(i).Cells(表頭(34)).Value.ToString) / 1000000)
            Chart1.Series(表頭(29)).Points.AddXY(彙總3_dgv.Rows(i).Cells(0).Value.ToString, CLng(彙總3_dgv.Rows(i).Cells(表頭(29)).Value.ToString) / 1000000)
            Chart1.Series(表頭(36)).Points.AddXY(彙總3_dgv.Rows(i).Cells(0).Value.ToString, CLng(彙總3_dgv.Rows(i).Cells(表頭(36)).Value.ToString) / 1000000)
        Next
        If 深色風格 = False Then
            Chart1.Series(表頭(31)).LabelForeColor = Color.Blue : Chart1.Series(表頭(34)).LabelForeColor = Color.Blue
            Chart1.Series(表頭(29)).LabelForeColor = Color.Blue : Chart1.Series(表頭(36)).LabelForeColor = Color.Blue
            Chart1.Legends(0).ForeColor = Color.Black
            Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.Black : Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.Black
            Chart1.ChartAreas(0).AxisX.LineColor = Color.Black : Chart1.ChartAreas(0).AxisY.LineColor = Color.Black
            Chart1.ChartAreas(0).AxisX.LabelStyle.ForeColor = Color.Black : Chart1.ChartAreas(0).AxisY.LabelStyle.ForeColor = Color.Black
        Else
            Chart1.Series(表頭(31)).LabelForeColor = Color.White : Chart1.Series(表頭(34)).LabelForeColor = Color.White
            Chart1.Series(表頭(29)).LabelForeColor = Color.White : Chart1.Series(表頭(36)).LabelForeColor = Color.White
            Chart1.Legends(0).ForeColor = Color.White
            Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.White : Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.White
            Chart1.ChartAreas(0).AxisX.LineColor = Color.White : Chart1.ChartAreas(0).AxisY.LineColor = Color.White
            Chart1.ChartAreas(0).AxisX.LabelStyle.ForeColor = Color.White : Chart1.ChartAreas(0).AxisY.LabelStyle.ForeColor = Color.White
        End If
    End Sub
    Private Sub Set_採購單清單()
        Dim ds As New DataSet : 明細_dgv.DataSource = Nothing : ds.Clear()
        明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        明細_dgv.ColumnHeadersHeight = 40
        明細_dgv.AllowUserToAddRows = False
        If 小間距_ch.Checked = False And 中間距_ch.Checked = False And 大間距_ch.Checked = True Then : 明細_dgv.RowTemplate.Height = 65
        ElseIf 小間距_ch.Checked = False And 中間距_ch.Checked = True And 大間距_ch.Checked = False Then : 明細_dgv.RowTemplate.Height = 45
        ElseIf 小間距_ch.Checked = True And 中間距_ch.Checked = False And 大間距_ch.Checked = False Then : 明細_dgv.RowTemplate.Height = 25 : End If

        SQL_採購單明細表1()
        da.Fill(ds) : 明細_dgv.DataSource = ds.Tables(0) : conn.Close()

        明細_dgv.Columns(0).Visible = False : 明細_dgv.Columns(1).FillWeight = 50 : 明細_dgv.Columns(3).FillWeight = 250 : 明細_dgv.Columns(4).FillWeight = 250
        明細_dgv.Columns(5).FillWeight = 150 : 明細_dgv.Columns(6).FillWeight = 80 : 明細_dgv.Columns(7).FillWeight = 80 : 明細_dgv.Columns(8).FillWeight = 80
        明細_dgv.Columns(9).FillWeight = 80 : 明細_dgv.Columns(10).Visible = False : 明細_dgv.Columns(11).Visible = False : 明細_dgv.Columns(12).Visible = False
        明細_dgv.Columns(13).Visible = False : 明細_dgv.Columns(14).Visible = False : 明細_dgv.Columns(15).Visible = False : 明細_dgv.Columns(16).Visible = False
        明細_dgv.Columns(17).Visible = False : 明細_dgv.Columns(18).Visible = False : 明細_dgv.Columns(19).Visible = False : 明細_dgv.Columns(20).Visible = False
        明細_dgv.Columns(21).Visible = False : 明細_dgv.Columns(22).Visible = False : 明細_dgv.Columns(23).Visible = False : 明細_dgv.Columns(24).FillWeight = 90
        明細_dgv.Columns(25).FillWeight = 80 : 明細_dgv.Columns("KEY").Visible = False : 明細_dgv.Columns("OUP").FillWeight = 80 : 明細_dgv.Columns(2).FillWeight = 80
        明細_dgv.Columns(26).FillWeight = 80 : 明細_dgv.Columns("SP%").FillWeight = 80
        明細_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(8).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns("OUP").DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(15).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns("OUP").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns("OUP").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        明細_dgv.Columns(1).ReadOnly = True : 明細_dgv.Columns(2).ReadOnly = True : 明細_dgv.Columns(3).ReadOnly = True : 明細_dgv.Columns(4).ReadOnly = True
        明細_dgv.Columns(表頭(16)).ReadOnly = True : 明細_dgv.Columns(表頭(27)).ReadOnly = True : 明細_dgv.Columns("OUP").ReadOnly = True : 明細_dgv.Columns("SP%").ReadOnly = True

        If 低網速模式 = False Then
            明細_dgv.Columns(28).FillWeight = 80 : 明細_dgv.Columns("Image").Visible = True
            Dim mycol As DataGridViewImageColumn = 明細_dgv.Columns("Image")
            mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        Else
            If 明細_dgv.Columns.Count = 29 Then
                明細_dgv.Columns("Image").Visible = False
            End If
        End If
        新項次 = "00"
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            明細_dgv.Columns("OUP").DefaultCellStyle.Format = "#,0"
            NUM1 = Double.Parse(新項次) + 1
            If NUM1 < 10 Then : 新項次 = "0" & NUM1
            ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1
            End If
            明細_dgv.Rows(i).Cells(表頭(11)).Value = 新項次

            '-------------------------規格合併呈現----------------------------------------------------------------------------------------------------------------------------------------
            If i = 0 Then
                AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = ""
                PA3 = 明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value
                SQL_規格庫抬頭讀取()
                If dr.Read() Then
                    AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
                End If
                conn.Close()
            Else
                If 明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value.ToString <> 明細_dgv.Rows(i - 1).Cells("規格庫抬頭指定").Value.ToString Then
                    AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = ""
                    PA3 = 明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value
                    SQL_規格庫抬頭讀取()
                    If dr.Read() Then
                        AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
                    End If
                    conn.Close()
                End If
            End If
            Dim ZA1, ZA2, ZA3, ZA4, ZA5, ZA6, ZA7, ZA8 As String : 物料規格 = ""
            If 詳細資料2_ch.Checked = True Then
                If 明細_dgv.Rows(i).Cells(表頭(13)).Value.ToString <> "" Then
                    ZA1 = AAA1 & "=" & 明細_dgv.Rows(i).Cells(表頭(13)).Value.ToString : 物料規格 = ZA1 : End If
                If 明細_dgv.Rows(i).Cells("A2").Value.ToString <> "" Then : ZA2 = AAA2 & "=" & 明細_dgv.Rows(i).Cells("A2").Value
                    If 物料規格 = "" Then : 物料規格 = ZA2 : Else : 物料規格 = 物料規格 + "、" + ZA2 : End If : End If
                If 明細_dgv.Rows(i).Cells("A3").Value.ToString <> "" Then : ZA3 = AAA3 & "=" & 明細_dgv.Rows(i).Cells("A3").Value
                    If 物料規格 = "" Then : 物料規格 = ZA3 : Else : 物料規格 = 物料規格 + "、" + ZA3 : End If : End If
                If 明細_dgv.Rows(i).Cells("A4").Value.ToString <> "" Then : ZA4 = AAA4 & "=" & 明細_dgv.Rows(i).Cells("A4").Value
                    If 物料規格 = "" Then : 物料規格 = ZA4 : Else : 物料規格 = 物料規格 + "、" + ZA4 : End If : End If
                If 明細_dgv.Rows(i).Cells("A5").Value.ToString <> "" Then : ZA5 = AAA5 & "=" & 明細_dgv.Rows(i).Cells("A5").Value
                    If 物料規格 = "" Then : 物料規格 = ZA5 : Else : 物料規格 = 物料規格 + "、" + ZA5 : End If : End If
                If 明細_dgv.Rows(i).Cells("A6").Value.ToString <> "" Then : ZA6 = AAA6 & "=" & 明細_dgv.Rows(i).Cells("A6").Value
                    If 物料規格 = "" Then : 物料規格 = ZA6 : Else : 物料規格 = 物料規格 + "、" + ZA6 : End If : End If
                If 明細_dgv.Rows(i).Cells("A7").Value.ToString <> "" Then : ZA7 = AAA7 & "=" & 明細_dgv.Rows(i).Cells("A7").Value
                    If 物料規格 = "" Then : 物料規格 = ZA7 : Else : 物料規格 = 物料規格 + "、" + ZA7 : End If : End If
                If 明細_dgv.Rows(i).Cells("A8").Value.ToString <> "" Then : ZA8 = AAA8 & "=" & 明細_dgv.Rows(i).Cells("A8").Value
                    If 物料規格 = "" Then : 物料規格 = ZA8 : Else : 物料規格 = 物料規格 + "、" + ZA8 : End If : End If
            Else
                If 明細_dgv.Rows(i).Cells(表頭(13)).Value.ToString <> "" Then : ZA1 = 明細_dgv.Rows(i).Cells(表頭(13)).Value.ToString : 物料規格 = ZA1 : End If
                If 明細_dgv.Rows(i).Cells("A2").Value.ToString <> "" Then
                    ZA2 = 明細_dgv.Rows(i).Cells("A2").Value : If 物料規格 = "" Then : 物料規格 = ZA2 : Else : 物料規格 = 物料規格 + "、" + ZA2 : End If : End If
                If 明細_dgv.Rows(i).Cells("A3").Value.ToString <> "" Then
                    ZA3 = 明細_dgv.Rows(i).Cells("A3").Value : If 物料規格 = "" Then : 物料規格 = ZA3 : Else : 物料規格 = 物料規格 + "、" + ZA3 : End If : End If
                If 明細_dgv.Rows(i).Cells("A4").Value.ToString <> "" Then
                    ZA4 = 明細_dgv.Rows(i).Cells("A4").Value : If 物料規格 = "" Then : 物料規格 = ZA4 : Else : 物料規格 = 物料規格 + "、" + ZA4 : End If : End If
                If 明細_dgv.Rows(i).Cells("A5").Value.ToString <> "" Then
                    ZA5 = 明細_dgv.Rows(i).Cells("A5").Value : If 物料規格 = "" Then : 物料規格 = ZA5 : Else : 物料規格 = 物料規格 + "、" + ZA5 : End If : End If
                If 明細_dgv.Rows(i).Cells("A6").Value.ToString <> "" Then
                    ZA6 = 明細_dgv.Rows(i).Cells("A6").Value : If 物料規格 = "" Then : 物料規格 = ZA6 : Else : 物料規格 = 物料規格 + "、" + ZA6 : End If : End If
                If 明細_dgv.Rows(i).Cells("A7").Value.ToString <> "" Then
                    ZA7 = 明細_dgv.Rows(i).Cells("A7").Value : If 物料規格 = "" Then : 物料規格 = ZA7 : Else : 物料規格 = 物料規格 + "、" + ZA7 : End If : End If
                If 明細_dgv.Rows(i).Cells("A8").Value.ToString <> "" Then
                    ZA8 = 明細_dgv.Rows(i).Cells("A8").Value : If 物料規格 = "" Then : 物料規格 = ZA8 : Else : 物料規格 = 物料規格 + "、" + ZA8 : End If : End If
            End If
            明細_dgv.Rows(i).Cells(表頭(13)).Value = 物料規格
            '--------------取得歷史單價------------------------------------------------------------------------------------------
            PA = 明細_dgv.Rows(i).Cells("料號").Value
            Set_單價()
            If 價錢_dgv.Rows.Count = 0 Then
                明細_dgv.Rows(i).Cells("OUP").Value = 0
            Else
                明細_dgv.Rows(i).Cells("OUP").Value = 價錢_dgv.Rows(0).Cells("單價").Value
            End If
        Next i
        價格() ': 總金額計算()
    End Sub
    Private Sub Set_單價()
        Dim ds6 As New DataSet : 價錢_dgv.DataSource = Nothing : ds6.Clear()
        價錢_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        價錢_dgv.ColumnHeadersHeight = 25
        價錢_dgv.AllowUserToAddRows = False

        If 日期_rb.Checked = False And 單價_rb.Checked = True Then : SQL_加權平均()
        ElseIf 日期_rb.Checked = True And 單價_rb.Checked = False Then : SQL_最近日期() : End If
        da.Fill(ds6) : 價錢_dgv.DataSource = ds6.Tables(0) : conn.Close()
    End Sub
    Private Sub 價格()
        Dim 差異, 比對 As Double
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            If 明細_dgv.Rows(i).Cells("OUP").Value = 0 And 明細_dgv.Rows(i).Cells(表頭(26)).Value = 0 Then
                If 深色風格 = False Then
                    明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Lavender
                Else
                    明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Navy
                End If
                明細_dgv.Rows(i).Cells("SP%").Value = "0 % →"
            ElseIf 明細_dgv.Rows(i).Cells(表頭(26)).Value = 0 And 明細_dgv.Rows(i).Cells("OUP").Value <> 0 Then
                If 深色風格 = False Then
                    明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Lavender
                Else
                    明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Navy
                End If
                明細_dgv.Rows(i).Cells("SP%").Value = "0 % →"
            ElseIf 明細_dgv.Rows(i).Cells("OUP").Value <> 0 And 明細_dgv.Rows(i).Cells(表頭(26)).Value <> 0 Then
                差異 = 明細_dgv.Rows(i).Cells(表頭(26)).Value - 明細_dgv.Rows(i).Cells("OUP").Value : 比對 = 差異 / 明細_dgv.Rows(i).Cells(表頭(26)).Value * 100
                If 比對 > 0 Then : 明細_dgv.Rows(i).Cells("SP%").Value = CInt(比對) & " % ↗" : 比對 *= 1
                ElseIf 比對 < 0 Then : 明細_dgv.Rows(i).Cells("SP%").Value = CInt(比對) & " % ↘" : 比對 *= -1
                ElseIf 比對 = 0 Then : 明細_dgv.Rows(i).Cells("SP%").Value = CInt(比對) & " % →" : End If
                If 深色風格 = False Then
                    If 比對 < 比例1 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.White
                    ElseIf 比對 > 比例1 And 比對 < 比例2 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
                    ElseIf 比對 > 比例2 And 比對 < 比例3 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
                    ElseIf 比對 >= 比例3 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink : End If
                Else
                    If 比對 < 比例1 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.DimGray
                    ElseIf 比對 > 比例1 And 比對 < 比例2 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.DarkGreen
                    ElseIf 比對 > 比例2 And 比對 < 比例3 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.DarkBlue
                    ElseIf 比對 >= 比例3 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Purple : End If
                End If
            End If
        Next
    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
        SQL_合約甲方() : da.Fill(ds1) : 甲方_dgv.DataSource = ds1.Tables(0) : conn.Close()
        If 甲方_dgv.Rows.Count > 19 Then : MGB(系統語言字典("H312-100-" & 語言), 1) : Me.Close() : End If
        For i As Integer = 1 To 20
            Dim 選擇 As CheckBox = CType(Me.Controls.Find("A" & i, True)(0), CheckBox) : 選擇.Visible = False
        Next
        For i As Integer = 0 To 甲方_dgv.Rows.Count - 1
            Dim 選擇 As CheckBox = CType(Me.Controls.Find("A" & i + 1, True)(0), CheckBox) : 選擇.Text = 甲方_dgv.Rows(i).Cells(0).Value.ToString : 選擇.Visible = True
        Next
    End Sub
    Private Sub 採購付款狀態報表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = HX_PGS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        分母 = 100 : 分段1 = 0.35 : 分段2 = 0.34 : 分段3 = 0.65 : 分段4 = 0.64 : 進度條後墜 = " %"
        風格() : H(312) = True : 介面 = "H312" : 語言轉換讀取() : 顯示說明(999, False)
        Panel2.SendToBack() : 視窗2_pl.Visible = False : 單價_rb.Checked = True : Panel5.BringToFront() : RadTrackBar1.Visible = False : 首次開啟 = True
        If 登入人級別 = "00" Then
            縮放1_bt.Visible = True
        Else
            縮放1_bt.Visible = False
        End If

        MyMod.清單字體大小調整()
        明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        清單1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        彙總1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        彙總2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        彙總3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        彙總4_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        合計1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        合計2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        合計3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 採購付款狀態報表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        Set_合約甲方() : Set_清單1() : 首次開啟 = False
    End Sub
    Private Sub 語轉扭_bt_Click(sender As Object, e As EventArgs) Handles 語轉扭_bt.Click
        H(312) = True : 介面 = "H312" : 語言轉換讀取() : Set_清單1()
    End Sub
    Private Sub 採購付款狀態報表_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        H(312) = False : MyMod.虛擬桌面開啟()
    End Sub
    Private Sub 系統說明_bt_Click(sender As Object, e As EventArgs) Handles 系統說明_bt.Click
        介面 = "H312"
    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 回首頁_bt_Click(sender As Object, e As EventArgs) Handles 回首頁_bt.Click
        Set_清單1()
    End Sub
    Private Sub 縮放2_bt_Click(sender As Object, e As EventArgs) Handles 縮放2_bt.Click
        Panel5.BringToFront() : Panel1.SendToBack()
    End Sub
    Private Sub 縮放1_bt_Click(sender As Object, e As EventArgs) Handles 縮放1_bt.Click
        Panel5.SendToBack() : Panel1.BringToFront()
    End Sub
    Private Sub 彙總3_dgv_Sorted(ByVal sender As Object, ByVal e As EventArgs) Handles 彙總3_dgv.Sorted
        彙總()
    End Sub
    Private Sub 彙總3_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 彙總3_dgv.MouseUp
        'If 彙總3_dgv.SelectedCells.Count = 1 Then : MsgBox(彙總3_dgv.SelectedCells(0).ColumnIndex & "  " & 彙總3_dgv.SelectedCells(0).RowIndex) : End If
        If 彙總3_dgv.SelectedCells.Count > 0 Then
            If 彙總3_dgv.SelectedCells(0).ColumnIndex > -1 Then
                Dim X1, Y1, X2, Y2, X3, Y3 As Integer : X1 = Me.Size.Width : Y1 = Me.Size.Height : X2 = 視窗2_pl.Size.Width : Y2 = 視窗2_pl.Size.Height
                Y3 = (Y1 - Y2) / 2 : X3 = (X1 - X2) / 2
                視窗2_pl.Location = New System.Drawing.Point(X3, Y3) : 視窗2_pl.Visible = True : 視窗2_pl.BringToFront()
                PA10 = 彙總3_dgv.Rows(彙總3_dgv.SelectedCells(0).RowIndex).Cells(0).Value.ToString : Set_採購單清單()
            End If
        End If
    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_dgv.SelectedCells(0).ColumnIndex > -1 Then
                PA10 = 彙總1_dgv.Rows(彙總1_dgv.SelectedCells(0).RowIndex).Cells(0).Value.ToString : Set_清單2()
            End If
        End If
    End Sub
    Private Sub A1_CheckedChanged(sender As Object, e As EventArgs) Handles A1.Click
        Set_清單3()
    End Sub
    Private Sub A2_CheckedChanged(sender As Object, e As EventArgs) Handles A2.Click
        Set_清單3()
    End Sub
    Private Sub A3_CheckedChanged(sender As Object, e As EventArgs) Handles A3.Click
        Set_清單3()
    End Sub
    Private Sub A4_CheckedChanged(sender As Object, e As EventArgs) Handles A4.Click
        Set_清單3()
    End Sub
    Private Sub A5_CheckedChanged(sender As Object, e As EventArgs) Handles A5.Click
        Set_清單3()
    End Sub
    Private Sub A6_CheckedChanged(sender As Object, e As EventArgs) Handles A6.Click
        Set_清單3()
    End Sub
    Private Sub A7_CheckedChanged(sender As Object, e As EventArgs) Handles A7.Click
        Set_清單3()
    End Sub
    Private Sub A8_CheckedChanged(sender As Object, e As EventArgs) Handles A8.Click
        Set_清單3()
    End Sub
    Private Sub A9_CheckedChanged(sender As Object, e As EventArgs) Handles A9.Click
        Set_清單3()
    End Sub
    Private Sub A10_CheckedChanged(sender As Object, e As EventArgs) Handles A10.Click
        Set_清單3()
    End Sub
    Private Sub A11_CheckedChanged(sender As Object, e As EventArgs) Handles A11.Click
        Set_清單3()
    End Sub
    Private Sub A12_CheckedChanged(sender As Object, e As EventArgs) Handles A12.Click
        Set_清單3()
    End Sub
    Private Sub A13_CheckedChanged(sender As Object, e As EventArgs) Handles A13.Click
        Set_清單3()
    End Sub
    Private Sub A14_CheckedChanged(sender As Object, e As EventArgs) Handles A14.Click
        Set_清單3()
    End Sub
    Private Sub A15_CheckedChanged(sender As Object, e As EventArgs) Handles A15.Click
        Set_清單3()
    End Sub
    Private Sub A16_CheckedChanged(sender As Object, e As EventArgs) Handles A16.Click
        Set_清單3()
    End Sub
    Private Sub A17_CheckedChanged(sender As Object, e As EventArgs) Handles A17.Click
        Set_清單3()
    End Sub
    Private Sub A18_CheckedChanged(sender As Object, e As EventArgs) Handles A18.Click
        Set_清單3()
    End Sub
    Private Sub A19_CheckedChanged(sender As Object, e As EventArgs) Handles A19.Click
        Set_清單3()
    End Sub
    Private Sub A20_CheckedChanged(sender As Object, e As EventArgs) Handles A20.Click
        Set_清單3()
    End Sub
    '----------------------自創視窗滑鼠拖曳功能---------------------------------------------------------------------------------------------------------
    Dim OldX, OldY As Long : Dim drag As Boolean
    Private Sub CanceL2_bt_Click(sender As Object, e As EventArgs) Handles CanceL2_bt.Click
        If 視窗2_pl.Visible = False Then : 視窗2_pl.Visible = True : 視窗2_pl.BringToFront() : Else
            視窗2_pl.Visible = False : End If
    End Sub
    Private Sub 視窗2_pl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseDown
        If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If
    End Sub
    Private Sub 視窗2_pl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseMove
        If drag Then : 視窗2_pl.Left = 視窗2_pl.Left + e.X - OldX : 視窗2_pl.Top = 視窗2_pl.Top + e.Y - OldY : End If
    End Sub
    Private Sub 視窗2_pl_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseUp
        drag = False
    End Sub
    Private Sub 風格()
        If 深色風格 = False Then
            Me.BackColor = SystemColors.Control : 視窗2_pl.BackColor = SystemColors.Control : Panel3.BackColor = Color.White
            '----------------黑-------------------------------------------
            回首頁_bt.BackColor = Color.White
            語轉扭_bt.BackColor = Color.White : 語轉扭_bt.ForeColor = Color.Black
            For i As Integer = 1 To 20 : Dim 選擇 As CheckBox = CType(Me.Controls.Find("A" & i, True)(0), CheckBox) : 選擇.ForeColor = Color.Black : Next

            清單_dgv.EnableHeadersVisualStyles = True : 清單_dgv.BackgroundColor = Color.White : 清單_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            清單_dgv.DefaultCellStyle.BackColor = Color.White : 清單_dgv.DefaultCellStyle.ForeColor = Color.Black
            明細_dgv.EnableHeadersVisualStyles = True : 明細_dgv.BackgroundColor = Color.White : 明細_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            明細_dgv.DefaultCellStyle.BackColor = Color.White : 明細_dgv.DefaultCellStyle.ForeColor = Color.Black
            清單1_dgv.EnableHeadersVisualStyles = True : 清單1_dgv.BackgroundColor = Color.White : 清單1_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            清單1_dgv.DefaultCellStyle.BackColor = Color.White : 清單1_dgv.DefaultCellStyle.ForeColor = Color.Black
            彙總1_dgv.EnableHeadersVisualStyles = True : 彙總1_dgv.BackgroundColor = Color.White : 彙總1_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            彙總1_dgv.DefaultCellStyle.BackColor = Color.White : 彙總1_dgv.DefaultCellStyle.ForeColor = Color.Black : 彙總1_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            彙總1_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
            彙總2_dgv.EnableHeadersVisualStyles = True : 彙總2_dgv.BackgroundColor = Color.White : 彙總2_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            彙總2_dgv.DefaultCellStyle.BackColor = Color.White : 彙總2_dgv.DefaultCellStyle.ForeColor = Color.Black : 彙總2_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            彙總2_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
            彙總3_dgv.EnableHeadersVisualStyles = True : 彙總3_dgv.BackgroundColor = Color.White : 彙總3_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            彙總3_dgv.DefaultCellStyle.BackColor = Color.White : 彙總3_dgv.DefaultCellStyle.ForeColor = Color.Black : 彙總3_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            彙總3_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
            彙總4_dgv.EnableHeadersVisualStyles = True : 彙總4_dgv.BackgroundColor = Color.White : 彙總4_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            彙總4_dgv.DefaultCellStyle.BackColor = Color.White : 彙總4_dgv.DefaultCellStyle.ForeColor = Color.Black : 彙總4_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            彙總4_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
            合計1_dgv.EnableHeadersVisualStyles = True : 合計1_dgv.BackgroundColor = Color.White : 合計1_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            合計1_dgv.DefaultCellStyle.BackColor = Color.White : 合計1_dgv.DefaultCellStyle.ForeColor = Color.Black : 合計1_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            合計1_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
            合計2_dgv.EnableHeadersVisualStyles = True : 合計2_dgv.BackgroundColor = Color.White : 合計2_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            合計2_dgv.DefaultCellStyle.BackColor = Color.White : 合計2_dgv.DefaultCellStyle.ForeColor = Color.Black : 合計2_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            合計2_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
            合計3_dgv.EnableHeadersVisualStyles = True : 合計3_dgv.BackgroundColor = Color.White : 合計3_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            合計3_dgv.DefaultCellStyle.BackColor = Color.White : 合計3_dgv.DefaultCellStyle.ForeColor = Color.Black : 合計3_dgv.DefaultCellStyle.SelectionBackColor = Color.White
            合計3_dgv.DefaultCellStyle.SelectionForeColor = Color.Black
        Else
            Me.BackColor = Color.Black : 視窗2_pl.BackColor = Color.White : Panel3.BackColor = Color.Black
            '----------------黑-------------------------------------------
            回首頁_bt.BackColor = Color.DimGray
            語轉扭_bt.BackColor = Color.DimGray : 語轉扭_bt.ForeColor = Color.White
            For i As Integer = 1 To 20 : Dim 選擇 As CheckBox = CType(Me.Controls.Find("A" & i, True)(0), CheckBox) : 選擇.ForeColor = Color.White : Next

            清單_dgv.EnableHeadersVisualStyles = False : 清單_dgv.BackgroundColor = Color.DimGray : 清單_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            清單_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 清單_dgv.DefaultCellStyle.BackColor = Color.Black : 清單_dgv.DefaultCellStyle.ForeColor = Color.White
            明細_dgv.EnableHeadersVisualStyles = False : 明細_dgv.BackgroundColor = Color.DimGray : 明細_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            明細_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 明細_dgv.DefaultCellStyle.BackColor = Color.Black : 明細_dgv.DefaultCellStyle.ForeColor = Color.White
            清單1_dgv.EnableHeadersVisualStyles = False : 清單1_dgv.BackgroundColor = Color.DimGray : 清單1_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            清單1_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 清單1_dgv.DefaultCellStyle.BackColor = Color.Black : 清單1_dgv.DefaultCellStyle.ForeColor = Color.White
            彙總1_dgv.EnableHeadersVisualStyles = False : 彙總1_dgv.BackgroundColor = Color.DimGray : 彙總1_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            彙總1_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 彙總1_dgv.DefaultCellStyle.BackColor = Color.Black : 彙總1_dgv.DefaultCellStyle.ForeColor = Color.White
            彙總1_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
            彙總2_dgv.EnableHeadersVisualStyles = False : 彙總2_dgv.BackgroundColor = Color.DimGray : 彙總2_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            彙總2_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 彙總2_dgv.DefaultCellStyle.BackColor = Color.Black : 彙總2_dgv.DefaultCellStyle.ForeColor = Color.White
            彙總2_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
            彙總3_dgv.EnableHeadersVisualStyles = False : 彙總3_dgv.BackgroundColor = Color.DimGray : 彙總3_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            彙總3_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 彙總3_dgv.DefaultCellStyle.BackColor = Color.Black : 彙總3_dgv.DefaultCellStyle.ForeColor = Color.White
            彙總3_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
            彙總4_dgv.EnableHeadersVisualStyles = False : 彙總4_dgv.BackgroundColor = Color.DimGray : 彙總4_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            彙總4_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 彙總4_dgv.DefaultCellStyle.BackColor = Color.Black : 彙總4_dgv.DefaultCellStyle.ForeColor = Color.White
            彙總4_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
            合計1_dgv.EnableHeadersVisualStyles = False : 合計1_dgv.BackgroundColor = Color.DimGray : 合計1_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            合計1_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 合計1_dgv.DefaultCellStyle.BackColor = Color.Black : 合計1_dgv.DefaultCellStyle.ForeColor = Color.White
            合計1_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
            合計2_dgv.EnableHeadersVisualStyles = False : 合計2_dgv.BackgroundColor = Color.DimGray : 合計2_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            合計2_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 合計2_dgv.DefaultCellStyle.BackColor = Color.Black : 合計2_dgv.DefaultCellStyle.ForeColor = Color.White
            合計2_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
            合計3_dgv.EnableHeadersVisualStyles = False : 合計3_dgv.BackgroundColor = Color.DimGray : 合計3_dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
            合計3_dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Black : 合計3_dgv.DefaultCellStyle.BackColor = Color.Black : 合計3_dgv.DefaultCellStyle.ForeColor = Color.White
            合計3_dgv.DefaultCellStyle.SelectionBackColor = Color.Black
        End If
    End Sub
End Class