Option Strict Off
Public Class 貨款試算表
    ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet : ReadOnly ds3 As New DataSet : ReadOnly ds4 As New DataSet : ReadOnly ds5 As New DataSet
    Dim 首次開啟 As Boolean = False : Dim 比例 As Integer
    Private Sub Set_清單1()
        廠商彙總_dgv.DataSource = Nothing : ds1.Clear()
        廠商彙總_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        廠商彙總_dgv.ColumnHeadersHeight = 25
        廠商彙總_dgv.AllowUserToAddRows = False
        廠商彙總_dgv.RowTemplate.Height = 30

        PA19 = 業務_cb.Text
        SQL_貨款試算表_廠商彙總()
        da.Fill(ds1) : 廠商彙總_dgv.DataSource = ds1.Tables(0) : conn.Close()

        廠商彙總_dgv.Columns(0).FillWeight = 100 : 廠商彙總_dgv.Columns(1).FillWeight = 100 : 廠商彙總_dgv.Columns(2).FillWeight = 150
        廠商彙總_dgv.Columns(3).FillWeight = 100

        For I As Integer = 0 To 3 : 廠商彙總_dgv.Columns(I).ReadOnly = True : Next

        廠商彙總_dgv.Columns("預估進貨").DefaultCellStyle.Format = "#,##0"
        廠商彙總_dgv.Columns("預估進貨").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        廠商彙總_dgv.Columns("預估進貨").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        廠商彙總_dgv.Columns("編號").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        廠商彙總_dgv.Columns("編號").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        廠商彙總_dgv.Columns("項次").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        廠商彙總_dgv.Columns("項次").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        物料成本_tb.Text = "0"
        For i As Integer = 0 To 廠商彙總_dgv.Rows.Count - 1
            廠商彙總_dgv("項次", i).Value = i + 1
            物料成本_tb.Text = Val(物料成本_tb.Text) + 廠商彙總_dgv("預估進貨", i).Value
        Next
        For i As Integer = 0 To 廠商彙總_dgv.Rows.Count - 1
            比例 = 廠商彙總_dgv("預估進貨", i).Value / Val(物料成本_tb.Text) * 100
            If 比例 > 100 Then : 比例 = 100 : End If
            If 比例 = 0 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._000 : ElseIf 比例 = 1 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._001
            ElseIf 比例 = 2 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._002 : ElseIf 比例 = 3 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._003
            ElseIf 比例 = 4 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._004 : ElseIf 比例 = 5 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._005
            ElseIf 比例 = 6 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._006 : ElseIf 比例 = 7 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._007
            ElseIf 比例 = 8 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._008 : ElseIf 比例 = 9 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._009
            ElseIf 比例 = 10 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._010 : ElseIf 比例 = 11 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._011
            ElseIf 比例 = 12 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._012 : ElseIf 比例 = 13 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._013
            ElseIf 比例 = 14 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._014 : ElseIf 比例 = 15 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._015
            ElseIf 比例 = 16 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._016 : ElseIf 比例 = 17 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._017
            ElseIf 比例 = 18 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._018 : ElseIf 比例 = 19 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._019
            ElseIf 比例 = 20 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._020 : ElseIf 比例 = 21 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._021
            ElseIf 比例 = 22 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._022 : ElseIf 比例 = 23 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._023
            ElseIf 比例 = 24 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._024 : ElseIf 比例 = 25 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._025
            ElseIf 比例 = 26 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._026 : ElseIf 比例 = 27 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._027
            ElseIf 比例 = 28 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._028 : ElseIf 比例 = 29 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._029
            ElseIf 比例 = 30 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._030 : ElseIf 比例 = 31 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._031
            ElseIf 比例 = 32 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._032 : ElseIf 比例 = 33 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._033
            ElseIf 比例 = 34 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._034 : ElseIf 比例 = 35 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._035
            ElseIf 比例 = 36 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._036 : ElseIf 比例 = 37 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._037
            ElseIf 比例 = 38 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._038 : ElseIf 比例 = 39 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._039
            ElseIf 比例 = 40 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._040 : ElseIf 比例 = 41 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._041
            ElseIf 比例 = 42 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._042 : ElseIf 比例 = 43 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._043
            ElseIf 比例 = 44 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._044 : ElseIf 比例 = 45 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._045
            ElseIf 比例 = 46 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._046 : ElseIf 比例 = 47 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._047
            ElseIf 比例 = 48 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._048 : ElseIf 比例 = 49 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._049
            ElseIf 比例 = 50 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._050 : ElseIf 比例 = 51 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._051
            ElseIf 比例 = 52 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._052 : ElseIf 比例 = 53 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._053
            ElseIf 比例 = 54 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._054 : ElseIf 比例 = 55 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._055
            ElseIf 比例 = 56 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._056 : ElseIf 比例 = 57 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._057
            ElseIf 比例 = 58 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._058 : ElseIf 比例 = 59 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._059
            ElseIf 比例 = 60 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._060 : ElseIf 比例 = 61 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._061
            ElseIf 比例 = 62 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._062 : ElseIf 比例 = 63 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._063
            ElseIf 比例 = 64 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._064 : ElseIf 比例 = 65 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._065
            ElseIf 比例 = 66 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._066 : ElseIf 比例 = 67 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._067
            ElseIf 比例 = 68 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._068 : ElseIf 比例 = 69 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._069
            ElseIf 比例 = 70 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._070 : ElseIf 比例 = 71 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._071
            ElseIf 比例 = 72 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._072 : ElseIf 比例 = 73 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._073
            ElseIf 比例 = 74 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._074 : ElseIf 比例 = 75 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._075
            ElseIf 比例 = 76 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._076 : ElseIf 比例 = 77 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._077
            ElseIf 比例 = 78 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._078 : ElseIf 比例 = 79 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._079
            ElseIf 比例 = 80 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._080 : ElseIf 比例 = 81 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._081
            ElseIf 比例 = 82 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._082 : ElseIf 比例 = 83 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._083
            ElseIf 比例 = 84 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._084 : ElseIf 比例 = 85 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._085
            ElseIf 比例 = 86 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._086 : ElseIf 比例 = 87 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._087
            ElseIf 比例 = 88 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._088 : ElseIf 比例 = 89 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._089
            ElseIf 比例 = 90 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._090 : ElseIf 比例 = 91 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._091
            ElseIf 比例 = 92 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._092 : ElseIf 比例 = 93 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._093
            ElseIf 比例 = 94 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._094 : ElseIf 比例 = 95 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._095
            ElseIf 比例 = 96 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._096 : ElseIf 比例 = 97 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._097
            ElseIf 比例 = 98 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._098 : ElseIf 比例 = 99 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._099
            ElseIf 比例 >= 100 Then : 廠商彙總_dgv.Rows(i).Cells("成本佔比").Value = My.Resources._100 : End If
        Next
        物料成本_tb.Text = Format(Val(物料成本_tb.Text), "#,##0")
    End Sub
    Private Sub Set_清單4()
        訂貨明細_dgv.DataSource = Nothing : ds4.Clear()
        訂貨明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        訂貨明細_dgv.ColumnHeadersHeight = 25
        訂貨明細_dgv.AllowUserToAddRows = False
        訂貨明細_dgv.RowTemplate.Height = 90

        SQL_貨款試算表_物料明細()
        da.Fill(ds4) : 訂貨明細_dgv.DataSource = ds4.Tables(0) : conn.Close()
        訂貨明細_dgv.Columns(0).FillWeight = 80 : 訂貨明細_dgv.Columns(1).FillWeight = 80 : 訂貨明細_dgv.Columns(2).FillWeight = 80
        訂貨明細_dgv.Columns(3).FillWeight = 110 : 訂貨明細_dgv.Columns(4).FillWeight = 200 : 訂貨明細_dgv.Columns(5).FillWeight = 120 : 訂貨明細_dgv.Columns(6).FillWeight = 120
        訂貨明細_dgv.Columns(7).FillWeight = 120 : 訂貨明細_dgv.Columns(8).FillWeight = 200 : 訂貨明細_dgv.Columns(9).FillWeight = 80 : 訂貨明細_dgv.Columns(10).FillWeight = 100
        訂貨明細_dgv.Columns(11).Visible = False : 訂貨明細_dgv.Columns(12).Visible = False : 訂貨明細_dgv.Columns(13).FillWeight = 100 : 訂貨明細_dgv.Columns(14).Visible = False
        For I As Integer = 0 To 14 : 訂貨明細_dgv.Columns(I).ReadOnly = True : Next
        訂貨明細_dgv.Columns("數量").DefaultCellStyle.Format = "#,##0" : 訂貨明細_dgv.Columns("成本").DefaultCellStyle.Format = "#,##0"
        訂貨明細_dgv.Columns("單價").DefaultCellStyle.Format = "#,##0" : 訂貨明細_dgv.Columns("金額").DefaultCellStyle.Format = "#,##0"
        訂貨明細_dgv.Columns("數量").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("數量").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("成本").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("成本").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("單價").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("單價").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("金額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("金額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("項次").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("項次").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("倉儲情況").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("倉儲情況").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("料號").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("料號").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("單號").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        訂貨明細_dgv.Columns("單號").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        進貨成本_tb.Text = "0"
        For i As Integer = 0 To 訂貨明細_dgv.Rows.Count - 1
            訂貨明細_dgv("金額", i).Value = 訂貨明細_dgv("數量", i).Value * 訂貨明細_dgv("成本", i).Value
            訂貨明細_dgv("項次", i).Value = i + 1
            進貨成本_tb.Text = Val(進貨成本_tb.Text) + 訂貨明細_dgv("金額", i).Value
        Next : 進貨成本_tb.Text = Format(Val(進貨成本_tb.Text), "#,##0")
    End Sub
    Private Sub 貨款試算表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        開始日期_dtp.Value = Today() : 結束日期_dtp.Value = Today() : 日期格式() : 首次開啟 = True
        If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 8
        End If
    End Sub
    Private Sub 貨款試算表_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        If 首次開啟 = True Then
            Set_清單1() : Set_清單4()
        End If
        If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 8
        End If
    End Sub
    Dim 已超出 As Boolean
    Private Sub 廠商彙總_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 廠商彙總_dgv.MouseUp
        'If 廠商彙總_dgv.SelectedCells.Count = 1 Then : MsgBox(廠商彙總_dgv.SelectedCells(0).ColumnIndex & "  " & 廠商彙總_dgv.SelectedCells(0).RowIndex) : End If
        If 廠商彙總_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 廠商彙總_dgv.SelectedCells.Count > 0 Then
            If 廠商彙總_dgv.SelectedCells(0).ColumnIndex = 3 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 廠商彙總_dgv.SelectedCells.Count - 1
                        x += Val(廠商彙總_dgv.Rows(廠商彙總_dgv.SelectedCells.Item(i).RowIndex).Cells(廠商彙總_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
    End Sub
    Private Sub 訂貨明細_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 訂貨明細_dgv.MouseUp
        'If 訂貨明細_dgv.SelectedCells.Count = 1 Then : MsgBox(訂貨明細_dgv.SelectedCells(0).ColumnIndex & "  " & 訂貨明細_dgv.SelectedCells(0).RowIndex) : End If
        If 訂貨明細_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 訂貨明細_dgv.SelectedCells.Count > 0 Then
            If 訂貨明細_dgv.SelectedCells(0).ColumnIndex = 13 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 訂貨明細_dgv.SelectedCells.Count - 1
                        x += Val(訂貨明細_dgv.Rows(訂貨明細_dgv.SelectedCells.Item(i).RowIndex).Cells(訂貨明細_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
    End Sub
    Private Sub 日期格式()
        If 會計月_ch.Checked = True Then
            '-------------日期一----------------------------------------------------------------------------------------
            DTP = Strings.Left(Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
            開始日期_dtp.Value = 開始日期_dtp.Value.AddMonths(-1)
            DTP = Strings.Left(Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "26" : 開始日期_dtp.Value = DTP
            '-------------日期二----------------------------------------------------------------------------------------
            DTP = Strings.Left(Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "25" : 結束日期_dtp.Value = DTP
        Else
            '-------------日期一----------------------------------------------------------------------------------------
            開始日期_dtp.Value = 開始日期_dtp.Value.AddMonths(1)
            DTP = Strings.Left(Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
            '-------------日期二----------------------------------------------------------------------------------------
            DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 結束日期_dtp.Value = DTP
            結束日期_dtp.Value = 結束日期_dtp.Value.AddMonths(1) : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(-1)
        End If
    End Sub
    Private Sub 上個月_bt_Click(sender As Object, e As EventArgs) Handles 上個月_bt.Click
        If 會計月_ch.Checked = True Then
            中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
            開始日期_dtp.Value = 中間日期_dtp.Value
            結束日期_dtp.Value = 中間日期_dtp.Value
        Else
            中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
            開始日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
            結束日期_dtp.Value = 中間日期_dtp.Value
        End If : 日期格式()
    End Sub
    Private Sub 下個月_bt_Click(sender As Object, e As EventArgs) Handles 下個月_bt.Click
        If 會計月_ch.Checked = True Then
            中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
            開始日期_dtp.Value = 中間日期_dtp.Value
            結束日期_dtp.Value = 中間日期_dtp.Value
        Else
            中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
            開始日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
            結束日期_dtp.Value = 中間日期_dtp.Value
        End If : 日期格式()
    End Sub
    Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月_ch.Click
        會計月_ch.Checked = True : 一般月_ch.Checked = False : 日期格式()
    End Sub
    Private Sub 一般月_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月_ch.Click
        會計月_ch.Checked = False : 一般月_ch.Checked = True : 日期格式()
    End Sub
    Private Sub 開始日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 開始日期_dtp.ValueChanged
        Set_清單1() : PA19 = "" : PA20 = 業務_cb.Text : Set_清單4() : 供應商_lb.Text = "全供應商"
    End Sub
    Private Sub 結束日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 結束日期_dtp.ValueChanged
        Set_清單1() : PA19 = "" : PA20 = 業務_cb.Text : Set_清單4() : 供應商_lb.Text = "全供應商"
    End Sub
    Private Sub 業務_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 業務_cb.SelectedIndexChanged
        Set_清單1() : PA19 = "" : PA20 = 業務_cb.Text : Set_清單4() : 供應商_lb.Text = "全供應商"
    End Sub
    Private Sub 依開單日期_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 依開單日期_ch.Click
        依開單日期_ch.Checked = True : 依交貨日期_ch.Checked = False : Set_清單1() : PA19 = "" : PA20 = 業務_cb.Text : Set_清單4() : 供應商_lb.Text = "全供應商"
    End Sub
    Private Sub 依交貨日期_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 依交貨日期_ch.Click
        依開單日期_ch.Checked = False : 依交貨日期_ch.Checked = True : Set_清單1() : PA19 = "" : PA20 = 業務_cb.Text : Set_清單4() : 供應商_lb.Text = "全供應商"
    End Sub
    Private Sub 廠商彙總_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 廠商彙總_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            PA19 = 廠商彙總_dgv("編號", e.RowIndex).Value : Set_清單4() : 供應商_lb.Text = 廠商彙總_dgv("供應商", e.RowIndex).Value
        End If
    End Sub
    Private Sub 銷售它項_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 訂貨明細_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 訂貨明細_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 訂貨明細_dgv("單號", e.RowIndex).Value.ToString <> 訂貨明細_dgv("單號", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(訂貨明細_dgv.RowHeadersVisible, 訂貨明細_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 訂貨明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 訂貨明細_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
        End If
    End Sub
    Private Sub 所有訂貨明細_bt_Click(sender As Object, e As EventArgs) Handles 所有訂貨明細_bt.Click
        PA19 = "" : Set_清單4() : 供應商_lb.Text = "全供應商"
    End Sub
    Private Sub 重新整理_tsm_Click(sender As Object, e As EventArgs) Handles 重新整理_tsm.Click
        Set_清單1() : Set_清單4()
    End Sub
    Private Sub 字體_NUD_ValueChanged_1(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        廠商彙總_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        訂貨明細_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
    End Sub
End Class