Public Class 高層客製報表
    ReadOnly ds, ds1, ds2, ds3, ds4, ds5, ds6, ds7, ds8 As New DataSet
    Dim ESTR, ESTR1, 合計判斷 As String
    Dim EDR, EDR1 As Integer
    Dim 啟動運算 As Boolean
    Dim A1, A2, A3, B2, B3 As Integer
    Private Sub Set_清單1()
        今日簽單_dgv.DataSource = Nothing : ds1.Clear()
        今日簽單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        今日簽單_dgv.ColumnHeadersHeight = 25
        今日簽單_dgv.AllowUserToAddRows = False
        今日簽單_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        SQL_今日簽單()
        da.Fill(ds1) : 今日簽單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        今日簽單_dgv.Columns(0).Visible = False : 今日簽單_dgv.Columns(1).Visible = False : 今日簽單_dgv.Columns(10).Visible = False
        今日簽單_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" : 今日簽單_dgv.Columns(6).DefaultCellStyle.Format = "#,##0"
        今日簽單_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 今日簽單_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        今日簽單_dgv.Columns(4).DefaultCellStyle.Format = "#,##0"
        今日簽單_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日簽單_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日簽單_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日簽單_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日簽單_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日簽單_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        Set_今日簽單_dgv_計算() : 流水1_lb.Text = ".........."
    End Sub
    Private Sub Set_清單2()
        今日出貨_dgv.DataSource = Nothing : ds2.Clear()
        今日出貨_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        今日出貨_dgv.ColumnHeadersHeight = 25
        今日出貨_dgv.AllowUserToAddRows = False
        今日出貨_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        SQL_今日送貨()
        da.Fill(ds2) : 今日出貨_dgv.DataSource = ds2.Tables(0) : conn.Close()
        今日出貨_dgv.Columns(0).Visible = False : 今日出貨_dgv.Columns(1).Visible = False : 今日出貨_dgv.Columns(10).Visible = False
        今日出貨_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" : 今日出貨_dgv.Columns(6).DefaultCellStyle.Format = "#,##0"
        今日出貨_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 今日出貨_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        今日出貨_dgv.Columns(4).DefaultCellStyle.Format = "#,##0"
        今日出貨_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日出貨_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日出貨_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日出貨_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日出貨_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日出貨_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        Set_今日出貨_dgv_計算() : 流水2_lb.Text = ".........."
    End Sub
    Private Sub Set_清單3()
        今日支出_dgv.DataSource = Nothing : ds3.Clear()
        今日支出_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        今日支出_dgv.ColumnHeadersHeight = 25
        今日支出_dgv.AllowUserToAddRows = False
        今日支出_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        SQL_今日支出()
        da.Fill(ds3) : 今日支出_dgv.DataSource = ds3.Tables(0) : conn.Close()
        今日支出_dgv.Columns(0).Visible = False : 今日支出_dgv.Columns(1).Visible = False : 今日支出_dgv.Columns(10).Visible = False : 今日支出_dgv.Columns(4).FillWeight = 250
        今日支出_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" : 今日支出_dgv.Columns(6).DefaultCellStyle.Format = "#,##0"
        今日支出_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 今日支出_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        今日支出_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日支出_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日支出_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日支出_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日支出_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        Set_今日支出_dgv_計算() : 流水3_lb.Text = ".........."
    End Sub
    Private Sub Set_清單4()
        今日結算_dgv.DataSource = Nothing : ds.Clear()
        今日結算_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        今日結算_dgv.ColumnHeadersHeight = 25
        今日結算_dgv.AllowUserToAddRows = False
        今日結算_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        SQL_今日結算()
        da.Fill(ds) : 今日結算_dgv.DataSource = ds.Tables(0) : conn.Close()
        今日結算_dgv.Columns(0).Visible = False : 今日結算_dgv.Columns(1).Visible = False : 今日結算_dgv.Columns("支出(不含刷卡)").ReadOnly = True
        今日結算_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" : 今日結算_dgv.Columns(11).DefaultCellStyle.Format = "#,##0" : 今日結算_dgv.Columns(5).DefaultCellStyle.Format = "#,##0"
        今日結算_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 今日結算_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 今日結算_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        今日結算_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        今日結算_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        今日結算_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        Dim 合計 As Integer = 0
        For i As Integer = 0 To 今日結算_dgv.Rows.Count - 1
            If i = 0 Then
                今日結算_dgv("支出(不含刷卡)", i).Value = 0
            Else
                If 今日結算_dgv(2, i).Value.ToString <> "7.合計" Then
                    今日結算_dgv("支出(不含刷卡)", i).Value = 今日結算_dgv("支出", i).Value : 合計 += 今日結算_dgv("支出", i).Value
                Else
                    今日結算_dgv("支出(不含刷卡)", i).Value = 合計
                End If
            End If
        Next
    End Sub
    Private Sub Set_清單4_1()
        過去結算_dgv.DataSource = Nothing : ds8.Clear()
        過去結算_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        過去結算_dgv.ColumnHeadersHeight = 25
        過去結算_dgv.AllowUserToAddRows = False
        過去結算_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期1_dtp.Value, "yyyy/MM/dd")
        SQL_今日結算()
        da.Fill(ds8) : 過去結算_dgv.DataSource = ds8.Tables(0) : conn.Close()
        過去結算_dgv.Columns(0).Visible = False : 過去結算_dgv.Columns(1).Visible = False : 過去結算_dgv.Columns(3).Visible = False : 過去結算_dgv.Columns(5).Visible = False
        過去結算_dgv.Columns(6).Visible = False : 過去結算_dgv.Columns(7).Visible = False : 過去結算_dgv.Columns(8).Visible = False : 過去結算_dgv.Columns(9).Visible = False
        過去結算_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" : 過去結算_dgv.Columns(11).DefaultCellStyle.Format = "#,##0" : 過去結算_dgv.Columns(5).DefaultCellStyle.Format = "#,##0"
        過去結算_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 過去結算_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 過去結算_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        過去結算_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        過去結算_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        過去結算_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        過去結算_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        過去結算_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        過去結算_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        過去結算_dgv.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Set_清單4_自動判斷2()
    End Sub
    Private Sub Set_清單4_自動判斷2()
        If 過去結算_dgv.Rows.Count > 0 Then
            If 順向_ch.Checked = True Then
                For I As Integer = 0 To 過去結算_dgv.Rows.Count - 1 : 今日結算_dgv(4, I).Value = 過去結算_dgv(11, I).Value.ToString : Next
            Else
                For I As Integer = 0 To 過去結算_dgv.Rows.Count - 1 : 今日結算_dgv(11, I).Value = 過去結算_dgv(4, I).Value.ToString : Next
            End If : Set_今日結算_dgv_計算()
        End If
    End Sub
    Private Sub Set_清單4_自動判斷()
        If 今日結算_dgv.Rows.Count > 0 Then
            Set_今日結算_dgv_計算()
        Else
            PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
            新增資料流水1() : PA2 = "1.刷卡" : PA3 = "支票" : SQL_客製表2_新增()
            新增資料流水1() : PA2 = "2.雅邸" : PA3 = "活存" : SQL_客製表2_新增()
            新增資料流水1() : PA2 = "3.呂苡瑄" : PA3 = "活存" : SQL_客製表2_新增()
            新增資料流水1() : PA2 = "4.Doris" : PA3 = "" : SQL_客製表2_新增()
            新增資料流水1() : PA2 = "5.國泰世華" : PA3 = "活存" : SQL_客製表2_新增()
            新增資料流水1() : PA2 = "6.EDA" : PA3 = "" : SQL_客製表2_新增()
            新增資料流水1() : PA2 = "7.合計" : PA3 = "" : SQL_客製表2_新增()
            Set_清單4()
        End If
    End Sub
    Private Sub 新增資料流水1()
        SQL_客製表2_最後一筆資料()
        If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("流水號").ToString, 9)) : Else : EDR = 0 : End If
        conn.Close() : EDR += 1
        If EDR < 10 Then : ESTR = "YD" & "00000000" & EDR
        ElseIf EDR > 9 And EDR < 100 Then : ESTR = "YD" & "0000000" & EDR
        ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "YD" & "000000" & EDR
        ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "YD" & "00000" & EDR
        ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "YD" & "0000" & EDR
        ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "YD" & "000" & EDR
        ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "YD" & "00" & EDR
        ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "YD" & "0" & EDR
        ElseIf EDR > 99999999 Then : ESTR = "YD" & EDR : End If
        PA1 = ESTR
    End Sub
    Private Sub Set_清單5()
        今日開單_dgv.DataSource = Nothing : ds4.Clear()
        今日開單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        今日開單_dgv.ColumnHeadersHeight = 25
        今日開單_dgv.AllowUserToAddRows = False
        今日開單_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        SQL_當日簽單()
        da.Fill(ds4) : 今日開單_dgv.DataSource = ds4.Tables(0) : conn.Close()
        今日開單_dgv.Columns(3).Visible = False : 今日開單_dgv.Columns(4).Visible = False : 今日開單_dgv.Columns(5).Visible = False : 今日開單_dgv.Columns(6).Visible = False
        今日開單_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
        For i As Integer = 0 To 今日開單_dgv.Rows.Count - 1
            If 今日開單_dgv("簽單金額", i).Value.ToString = "" Then : 今日開單_dgv("簽單金額", i).Value = 0 : End If
            If 今日開單_dgv("目前已收", i).Value.ToString = "" Then : 今日開單_dgv("目前已收", i).Value = 0 : End If
            If 今日開單_dgv("其他應收", i).Value.ToString = "" Then : 今日開單_dgv("其他應收", i).Value = 0 : End If
            今日開單_dgv("未收餘額", i).Value =
                    CInt(今日開單_dgv("簽單金額", i).Value.ToString) + CInt(今日開單_dgv("其他應收", i).Value.ToString) - CInt(今日開單_dgv("目前已收", i).Value.ToString)
        Next
    End Sub
    Private Sub Set_清單6()
        今日送貨_dgv.DataSource = Nothing : ds5.Clear()
        今日送貨_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        今日送貨_dgv.ColumnHeadersHeight = 25
        今日送貨_dgv.AllowUserToAddRows = False
        今日送貨_dgv.RowTemplate.Height = 25

        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        SQL_當日送貨1()
        da.Fill(ds5) : 今日送貨_dgv.DataSource = ds5.Tables(0) : conn.Close()
        今日送貨_dgv.Columns(3).Visible = False : 今日送貨_dgv.Columns(4).Visible = False : 今日送貨_dgv.Columns(5).Visible = False : 今日送貨_dgv.Columns(6).Visible = False
        今日送貨_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
        For i As Integer = 0 To 今日送貨_dgv.Rows.Count - 1
            If 今日送貨_dgv("簽單金額", i).Value.ToString = "" Then : 今日送貨_dgv("簽單金額", i).Value = 0 : End If
            If 今日送貨_dgv("目前已收", i).Value.ToString = "" Then : 今日送貨_dgv("目前已收", i).Value = 0 : End If
            If 今日送貨_dgv("其他應收", i).Value.ToString = "" Then : 今日送貨_dgv("其他應收", i).Value = 0 : End If
            今日送貨_dgv("未收餘額", i).Value =
                    CInt(今日送貨_dgv("簽單金額", i).Value.ToString) + CInt(今日送貨_dgv("其他應收", i).Value.ToString) - CInt(今日送貨_dgv("目前已收", i).Value.ToString)
        Next
    End Sub
    Private Sub Set_清單7()
        銷售單據_dgv.DataSource = Nothing : ds6.Clear()
        銷售單據_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售單據_dgv.ColumnHeadersHeight = 25
        銷售單據_dgv.AllowUserToAddRows = False
        銷售單據_dgv.RowTemplate.Height = 25

        PA19 = 單號_tb.Text : PA20 = "" : PA21 = 單號_tb.Text
        SQL_客製表_訂單控制表()
        da.Fill(ds6) : 銷售單據_dgv.DataSource = ds6.Tables(0) : conn.Close()

        銷售單據_dgv.Columns(0).Visible = False : 銷售單據_dgv.Columns(1).FillWeight = 85 : 銷售單據_dgv.Columns(2).FillWeight = 100 : 銷售單據_dgv.Columns(3).FillWeight = 100
        銷售單據_dgv.Columns(4).FillWeight = 100 : 銷售單據_dgv.Columns(5).FillWeight = 65 : 銷售單據_dgv.Columns(6).Visible = False : 銷售單據_dgv.Columns(7).Visible = False
        銷售單據_dgv.Columns(8).Visible = False : 銷售單據_dgv.Columns(9).FillWeight = 100 : 銷售單據_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).FillWeight = 65
        銷售單據_dgv.Columns(20).Visible = False : 銷售單據_dgv.Columns(21).FillWeight = 65 : 銷售單據_dgv.Columns("未收額額").Visible = False

        銷售單據_dgv.Columns("銷貨總額").DefaultCellStyle.Format = "#,##0"
        銷售單據_dgv.Columns("銷貨總額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售單據_dgv.Columns("銷貨總額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        For i As Integer = 0 To 銷售單據_dgv.Rows.Count - 1
            If IsDBNull(銷售單據_dgv("轉業績日期", i).Value) Then : 銷售單據_dgv("轉業績日期", i).Value = "" : End If
            If IsDBNull(銷售單據_dgv("已結單", i).Value) Then : 銷售單據_dgv("已結單", i).Value = False : Else : 銷售單據_dgv("已結單", i).Value = False : End If
            If 銷售單據_dgv("轉業績日期", i).Value.ToString <> "" Then : 銷售單據_dgv("已結單", i).Value = True : End If
        Next
    End Sub
    Private Sub Set_費用清單()
        明細_dgv.DataSource = Nothing : ds7.Clear()
        明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        明細_dgv.ColumnHeadersHeight = 25
        明細_dgv.AllowUserToAddRows = False
        明細_dgv.RowTemplate.Height = 30

        SQL2 = "" : SQL_客製表_查詢費用清單()
        da.Fill(ds7) : 明細_dgv.DataSource = ds7.Tables(0) : conn.Close()

        明細_dgv.Columns(0).FillWeight = 250 : 明細_dgv.Columns(1).Visible = False : 明細_dgv.Columns(2).FillWeight = 250 : 明細_dgv.Columns(3).FillWeight = 400
        明細_dgv.Columns(4).FillWeight = 140 : 明細_dgv.Columns(5).FillWeight = 140 : 明細_dgv.Columns(6).FillWeight = 140 : 明細_dgv.Columns(7).FillWeight = 140
        明細_dgv.Columns(8).FillWeight = 140 : 明細_dgv.Columns(9).FillWeight = 140 : 明細_dgv.Columns(10).FillWeight = 140 : 明細_dgv.Columns(11).Visible = False
        明細_dgv.Columns(12).Visible = False : 明細_dgv.Columns(9).Visible = False : 明細_dgv.Columns(10).Visible = False : 明細_dgv.Columns("票期").Visible = False
        明細_dgv.Columns("零用金").Visible = False : 明細_dgv.Columns("支票").Visible = False
        明細_dgv.Columns(1).ReadOnly = True : 明細_dgv.Columns(2).ReadOnly = True : 明細_dgv.Columns(9).ReadOnly = True : 明細_dgv.Columns(10).ReadOnly = True

        明細_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(6).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns(7).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    End Sub
    Private Sub 業務_cb_下拉表單資料載入()
        SQL_業務編號_下拉清單()
        業務_cb.Items.Clear() : 業務_cb.Items.Clear()
        While (dr.Read()) : 業務_cb.Items.Add(dr("業務號")) : End While : conn.Close()
    End Sub
    Private Sub 高層客製報表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        YD_ERP_SYS.WindowState = 2 : Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        A1 = 空間1.Location.X : A2 = 空間2.Location.X : B2 = 空間2.Location.Y : A3 = 空間2.Size.Width : B3 = 空間2.Size.Height
        啟動運算 = False
        業務_cb_下拉表單資料載入()

        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
        啟動運算 = True : ZOOM_tb.PerformClick()
    End Sub
    Private Sub 高層客製報表_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        YD_ERP_SYS.WindowState = 0
    End Sub
    Private Sub 高層客製報表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        Set_清單5() : Set_清單6() : Set_費用清單() : Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4() : Set_清單4_自動判斷() : Set_清單4_自動判斷()
    End Sub
    Private Sub 高層客製報表_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        A1 = 空間1.Location.X : A2 = 錨點1.Location.X : B2 = 空間2.Location.Y
        If 空間1.Visible = False Then : A3 = 空間2.Size.Width : B3 = 空間2.Size.Height : A3 -= (A2 - A1) : End If
    End Sub
    Private Sub 今日簽單_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日簽單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            流水1_lb.Text = 今日簽單_dgv("流水號", e.RowIndex).Value.ToString : 合計判斷 = 今日簽單_dgv(2, e.RowIndex).Value.ToString
            帶入格1_tb.Text = 今日簽單_dgv(e.ColumnIndex, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 今日出貨_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日出貨_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            流水2_lb.Text = 今日出貨_dgv("流水號", e.RowIndex).Value.ToString : 合計判斷 = 今日出貨_dgv(2, e.RowIndex).Value.ToString
            帶入格1_tb.Text = 今日出貨_dgv(e.ColumnIndex, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 今日支出_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日支出_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            流水3_lb.Text = 今日支出_dgv("流水號", e.RowIndex).Value.ToString : 合計判斷 = 今日支出_dgv(2, e.RowIndex).Value.ToString
            帶入格1_tb.Text = 今日支出_dgv(e.ColumnIndex, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 今日開單_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日開單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            單號_tb.Text = 今日開單_dgv("單號", e.RowIndex).Value.ToString
            帶入格_tb.Text = 今日開單_dgv(e.ColumnIndex, e.RowIndex).Value.ToString : Set_清單7()
        End If
    End Sub
    Private Sub 今日送貨_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日送貨_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            單號_tb.Text = 今日送貨_dgv("單號", e.RowIndex).Value.ToString
            帶入格_tb.Text = 今日送貨_dgv(e.ColumnIndex, e.RowIndex).Value.ToString : Set_清單7()
        End If
    End Sub
    Private Sub 銷售單據_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 銷售單據_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 帶入格_tb.Text = 銷售單據_dgv(e.ColumnIndex, e.RowIndex).Value.ToString : End If
    End Sub
    Private Sub 明細_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 明細_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            S1_tb.Text = 明細_dgv(0, e.RowIndex).Value.ToString : S2_tb.Text = 明細_dgv(2, e.RowIndex).Value.ToString
            S3_tb.Text = 明細_dgv(3, e.RowIndex).Value.ToString : S4_tb.Text = 明細_dgv(4, e.RowIndex).Value.ToString
            S5_tb.Text = 明細_dgv(5, e.RowIndex).Value.ToString : S6_tb.Text = 明細_dgv(6, e.RowIndex).Value.ToString
            S7_tb.Text = 明細_dgv(7, e.RowIndex).Value.ToString : S8_tb.Text = 明細_dgv(8, e.RowIndex).Value.ToString
            If IsNumeric(Strings.Mid(明細_dgv(3, e.RowIndex).Value.ToString, 2, 5)) Then
                單號_tb.Text = Strings.Left(明細_dgv(3, e.RowIndex).Value.ToString, 7) : Set_清單7()
            End If
        End If
    End Sub
    Private Sub 今日結算_dgv_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日結算_dgv.CellDoubleClick
        If e.RowIndex = -1 Then : Else
            If 帶入格_tb.Text <> "" Then
                今日結算_dgv(e.ColumnIndex, e.RowIndex).Value = 帶入格_tb.Text : 帶入格_tb.Text = "" : 帶入格1_tb.Text = ""
            Else
                今日結算_dgv(e.ColumnIndex, e.RowIndex).Value = 帶入格1_tb.Text : 帶入格_tb.Text = "" : 帶入格1_tb.Text = ""
            End If
        End If
    End Sub
    Private Sub 今日簽單_dgv_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日簽單_dgv.CellDoubleClick
        If e.RowIndex = -1 Then : Else
            If 帶入格_tb.Text <> "" Then
                今日簽單_dgv(e.ColumnIndex, e.RowIndex).Value = 帶入格_tb.Text : 帶入格_tb.Text = "" : 帶入格1_tb.Text = ""
            Else
                今日簽單_dgv(e.ColumnIndex, e.RowIndex).Value = 帶入格1_tb.Text : 帶入格_tb.Text = "" : 帶入格1_tb.Text = ""
            End If
        End If
    End Sub
    Private Sub 今日出貨_dgv_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日出貨_dgv.CellDoubleClick
        If e.RowIndex = -1 Then : Else
            If 帶入格_tb.Text <> "" Then
                今日出貨_dgv(e.ColumnIndex, e.RowIndex).Value = 帶入格_tb.Text : 帶入格_tb.Text = "" : 帶入格1_tb.Text = ""
            Else
                今日出貨_dgv(e.ColumnIndex, e.RowIndex).Value = 帶入格1_tb.Text : 帶入格_tb.Text = "" : 帶入格1_tb.Text = ""
            End If
        End If
    End Sub
    Private Sub 今日支出_dgv_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles 今日支出_dgv.CellDoubleClick
        If e.RowIndex = -1 Then : Else
            今日支出_dgv(2, e.RowIndex).Value = S1_tb.Text : S1_tb.Text = "" : 今日支出_dgv(3, e.RowIndex).Value = S2_tb.Text : S2_tb.Text = ""
            今日支出_dgv(4, e.RowIndex).Value = S3_tb.Text : S3_tb.Text = "" : 今日支出_dgv(5, e.RowIndex).Value = S4_tb.Text : S4_tb.Text = ""
            今日支出_dgv(6, e.RowIndex).Value = S5_tb.Text : S5_tb.Text = "" : 今日支出_dgv(7, e.RowIndex).Value = S6_tb.Text : S6_tb.Text = ""
            今日支出_dgv(8, e.RowIndex).Value = S7_tb.Text : S7_tb.Text = "" : 今日支出_dgv(9, e.RowIndex).Value = S8_tb.Text : S8_tb.Text = ""
        End If
    End Sub
    Private Sub 今日簽單_dgv_CellContentCl(sender As Object, e As DataGridViewCellEventArgs) Handles 今日簽單_dgv.CellEndEdit
        If 啟動運算 = True Then : Set_今日簽單_dgv_計算() : End If
    End Sub
    Private Sub 今日出貨_dgv_CellContentCl(sender As Object, e As DataGridViewCellEventArgs) Handles 今日出貨_dgv.CellEndEdit
        If 啟動運算 = True Then : Set_今日出貨_dgv_計算() : End If
    End Sub
    Private Sub 今日支出_dgv_CellContentCl(sender As Object, e As DataGridViewCellEventArgs) Handles 今日支出_dgv.CellEndEdit
        If 啟動運算 = True Then : Set_今日支出_dgv_計算() : End If
    End Sub
    Private Sub 今日結算_dgv_CellContentCl(sender As Object, e As DataGridViewCellEventArgs) Handles 今日結算_dgv.CellEndEdit
        If 啟動運算 = True Then : Set_今日結算_dgv_計算() : End If
    End Sub
    Private Sub Set_今日簽單_dgv_計算()
        Dim A3, A4, A5, A6, A7 As Integer
        For i As Integer = 0 To 今日簽單_dgv.Rows.Count - 1
            If 今日簽單_dgv(4, i).Value.ToString = "" Then : 今日簽單_dgv(4, i).Value = "0" : End If
            If IsNumeric(今日簽單_dgv(4, i).Value.ToString) = True Then
                今日簽單_dgv(4, i).Value = Strings.Format(CInt(今日簽單_dgv(4, i).Value), "#,##0")
            End If
            If 今日簽單_dgv(2, i).Value.ToString <> "合計" Then
                A4 += 今日簽單_dgv(5, i).Value : A5 += 今日簽單_dgv(6, i).Value : A6 += 今日簽單_dgv(7, i).Value : A7 += 今日簽單_dgv(8, i).Value
                A3 += CInt(今日簽單_dgv(4, i).Value)
            End If
        Next
        For i As Integer = 0 To 今日簽單_dgv.Rows.Count - 1
            If 今日簽單_dgv(2, i).Value.ToString = "合計" Then
                今日簽單_dgv(5, i).Value = A4 : 今日簽單_dgv(6, i).Value = A5 : 今日簽單_dgv(7, i).Value = A6 : 今日簽單_dgv(8, i).Value = A7
                今日簽單_dgv(4, i).Value = A3
            End If
        Next
    End Sub
    Private Sub Set_今日出貨_dgv_計算()
        Dim A3, A4, A5, A6, A7 As Integer
        For i As Integer = 0 To 今日出貨_dgv.Rows.Count - 1
            If 今日出貨_dgv(4, i).Value.ToString = "" Then : 今日出貨_dgv(4, i).Value = "0" : End If
            If IsNumeric(今日出貨_dgv(4, i).Value.ToString) = True Then
                今日出貨_dgv(4, i).Value = Strings.Format(CInt(今日出貨_dgv(4, i).Value), "#,##0")
            End If
            If 今日出貨_dgv(2, i).Value.ToString <> "合計" Then
                A4 += 今日出貨_dgv(5, i).Value : A5 += 今日出貨_dgv(6, i).Value : A6 += 今日出貨_dgv(7, i).Value : A7 += 今日出貨_dgv(8, i).Value
                A3 += CInt(今日出貨_dgv(4, i).Value)
            End If
        Next
        For i As Integer = 0 To 今日出貨_dgv.Rows.Count - 1
            If 今日出貨_dgv(2, i).Value.ToString = "合計" Then
                今日出貨_dgv(5, i).Value = A4 : 今日出貨_dgv(6, i).Value = A5 : 今日出貨_dgv(7, i).Value = A6 : 今日出貨_dgv(8, i).Value = A7
                今日出貨_dgv(4, i).Value = A3
            End If
        Next
    End Sub
    Private Sub Set_今日支出_dgv_計算()
        Dim A4, A5, A6, A7 As Integer
        For i As Integer = 0 To 今日支出_dgv.Rows.Count - 1
            If 今日支出_dgv(2, i).Value.ToString <> "合計" Then
                A4 += 今日支出_dgv(5, i).Value : A5 += 今日支出_dgv(6, i).Value : A6 += 今日支出_dgv(7, i).Value : A7 += 今日支出_dgv(8, i).Value
            End If
        Next
        For i As Integer = 0 To 今日支出_dgv.Rows.Count - 1
            If 今日支出_dgv(2, i).Value.ToString = "合計" Then
                今日支出_dgv(5, i).Value = A4 : 今日支出_dgv(6, i).Value = A5 : 今日支出_dgv(7, i).Value = A6 : 今日支出_dgv(8, i).Value = A7
            End If
        Next
    End Sub
    Private Sub Set_今日結算_dgv_計算()
        Dim A4, A5, A6, A7, A8, A10 As Integer
        For i As Integer = 0 To 今日結算_dgv.Rows.Count - 1
            If 今日結算_dgv(2, i).Value.ToString <> "7.合計" Then
                If 順向_ch.Checked = True Then
                    今日結算_dgv(11, i).Value = 今日結算_dgv(4, i).Value + 今日結算_dgv(5, i).Value + 今日結算_dgv(6, i).Value + 今日結算_dgv(7, i).Value - 今日結算_dgv(8, i).Value
                Else
                    今日結算_dgv(4, i).Value = 今日結算_dgv(11, i).Value + 今日結算_dgv(8, i).Value - 今日結算_dgv(7, i).Value - 今日結算_dgv(6, i).Value - 今日結算_dgv(5, i).Value
                End If
                A4 += 今日結算_dgv(4, i).Value : A5 += 今日結算_dgv(5, i).Value : A6 += 今日結算_dgv(6, i).Value : A7 += 今日結算_dgv(7, i).Value
                A8 += 今日結算_dgv(8, i).Value : A10 += 今日結算_dgv(11, i).Value
            End If
        Next
        For i As Integer = 0 To 今日結算_dgv.Rows.Count - 1
            If 今日結算_dgv(2, i).Value.ToString = "7.合計" Then
                今日結算_dgv(4, i).Value = A4 : 今日結算_dgv(5, i).Value = A5 : 今日結算_dgv(6, i).Value = A6 : 今日結算_dgv(7, i).Value = A7
                今日結算_dgv(8, i).Value = A8 : 今日結算_dgv(11, i).Value = A10
            End If
        Next
        Dim 合計 As Integer = 0
        For i As Integer = 0 To 今日結算_dgv.Rows.Count - 1
            If i = 0 Then
                今日結算_dgv("支出(不含刷卡)", i).Value = 0
            Else
                If 今日結算_dgv(2, i).Value.ToString <> "7.合計" Then
                    今日結算_dgv("支出(不含刷卡)", i).Value = 今日結算_dgv("支出", i).Value : 合計 += 今日結算_dgv("支出", i).Value
                Else
                    今日結算_dgv("支出(不含刷卡)", i).Value = 合計
                End If
            End If
        Next
    End Sub
    Private Sub 新增資料流水()
        SQL_客製表1_最後一筆資料()
        If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("流水號").ToString, 9)) : Else : EDR = 0 : End If
        conn.Close() : EDR += 1
        If EDR < 10 Then : ESTR = "YD" & "00000000" & EDR : ElseIf EDR > 9 And EDR < 100 Then : ESTR = "YD" & "0000000" & EDR
        ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "YD" & "000000" & EDR : ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "YD" & "00000" & EDR
        ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "YD" & "0000" & EDR : ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "YD" & "000" & EDR
        ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "YD" & "00" & EDR : ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "YD" & "0" & EDR
        ElseIf EDR > 99999999 Then : ESTR = "YD" & EDR : End If : PA1 = ESTR
    End Sub
    Private Sub 新增一筆資料1_bt_Click(sender As Object, e As EventArgs) Handles 新增一筆資料1_bt.Click
        存檔() : 類別 = "A" : PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd") : PA2 = "" : 新增資料流水() : SQL_客製表1_新增() : Set_清單1()
        Dim 開單 As Boolean
        For i As Integer = 0 To 今日簽單_dgv.Rows.Count - 1
            If 今日簽單_dgv(2, i).Value.ToString = "合計" Then : 開單 = False : Exit For : Else : 開單 = True : End If
        Next
        If 開單 = True Then : PA2 = "合計" : 新增資料流水() : SQL_客製表1_新增() : End If
        Set_清單1()
    End Sub
    Private Sub 新增一筆資料2_bt_Click(sender As Object, e As EventArgs) Handles 新增一筆資料2_bt.Click
        存檔() : 類別 = "B" : PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd") : PA2 = "" : 新增資料流水() : SQL_客製表1_新增() : Set_清單2()
        Dim 開單 As Boolean
        For i As Integer = 0 To 今日出貨_dgv.Rows.Count - 1
            If 今日出貨_dgv(2, i).Value.ToString = "合計" Then : 開單 = False : Exit For : Else : 開單 = True : End If
        Next
        If 開單 = True Then : PA2 = "合計" : 新增資料流水() : SQL_客製表1_新增() : End If
        Set_清單2()
    End Sub
    Private Sub 新增一筆資料3_bt_Click(sender As Object, e As EventArgs) Handles 新增一筆資料3_bt.Click
        存檔() : 類別 = "C" : PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd") : PA2 = "" : 新增資料流水() : SQL_客製表1_新增() : Set_清單3()
        Dim 開單 As Boolean
        For i As Integer = 0 To 今日支出_dgv.Rows.Count - 1
            If 今日支出_dgv(2, i).Value.ToString = "合計" Then : 開單 = False : Exit For : Else : 開單 = True : End If
        Next
        If 開單 = True Then : PA2 = "合計" : 新增資料流水() : SQL_客製表1_新增() : End If
        Set_清單3()
    End Sub
    Private Sub 刪除選中資料1_bt_Click(sender As Object, e As EventArgs) Handles 刪除選中資料1_bt.Click
        存檔() : If 合計判斷 <> "合計" Then : PA1 = 流水1_lb.Text : SQL_客製表1_刪除() : Set_清單1() : End If
    End Sub
    Private Sub 刪除選中資料2_bt_Click(sender As Object, e As EventArgs) Handles 刪除選中資料2_bt.Click
        存檔() : If 合計判斷 <> "合計" Then : PA1 = 流水2_lb.Text : SQL_客製表1_刪除() : Set_清單2() : End If
    End Sub
    Private Sub 刪除選中資料3_bt_Click(sender As Object, e As EventArgs) Handles 刪除選中資料3_bt.Click
        存檔() : If 合計判斷 <> "合計" Then : PA1 = 流水3_lb.Text : SQL_客製表1_刪除() : Set_清單3() : End If
    End Sub
    Private Sub 存檔()
        PA = Strings.Format(開單日期_dtp.Value, "yyyy/MM/dd")
        For i As Integer = 0 To 今日簽單_dgv.Rows.Count - 1
            PA1 = 今日簽單_dgv("流水號", i).Value.ToString : PA2 = 今日簽單_dgv(2, i).Value.ToString : PA3 = 今日簽單_dgv(3, i).Value.ToString
            PA4 = 今日簽單_dgv(4, i).Value.ToString : PA5 = 今日簽單_dgv(5, i).Value.ToString : PA6 = 今日簽單_dgv(6, i).Value.ToString
            PA7 = 今日簽單_dgv(7, i).Value.ToString : PA8 = 今日簽單_dgv(8, i).Value.ToString : PA9 = 今日簽單_dgv(9, i).Value.ToString
            SQL_客製表1_修改()
        Next
        For i As Integer = 0 To 今日出貨_dgv.Rows.Count - 1
            PA1 = 今日出貨_dgv("流水號", i).Value.ToString : PA2 = 今日出貨_dgv(2, i).Value.ToString : PA3 = 今日出貨_dgv(3, i).Value.ToString
            PA4 = 今日出貨_dgv(4, i).Value.ToString : PA5 = 今日出貨_dgv(5, i).Value.ToString : PA6 = 今日出貨_dgv(6, i).Value.ToString
            PA7 = 今日出貨_dgv(7, i).Value.ToString : PA8 = 今日出貨_dgv(8, i).Value.ToString : PA9 = 今日出貨_dgv(9, i).Value.ToString
            SQL_客製表1_修改()
        Next
        For i As Integer = 0 To 今日支出_dgv.Rows.Count - 1
            PA1 = 今日支出_dgv("流水號", i).Value.ToString : PA2 = 今日支出_dgv(2, i).Value.ToString : PA3 = 今日支出_dgv(3, i).Value.ToString
            PA4 = 今日支出_dgv(4, i).Value.ToString : PA5 = 今日支出_dgv(5, i).Value.ToString : PA6 = 今日支出_dgv(6, i).Value.ToString
            PA7 = 今日支出_dgv(7, i).Value.ToString : PA8 = 今日支出_dgv(8, i).Value.ToString : PA9 = 今日支出_dgv(9, i).Value.ToString
            SQL_客製表1_修改()
        Next
        For i As Integer = 0 To 今日結算_dgv.Rows.Count - 1
            PA1 = 今日結算_dgv("流水號", i).Value.ToString : PA4 = 今日結算_dgv(4, i).Value.ToString : PA5 = 今日結算_dgv(5, i).Value.ToString
            PA6 = 今日結算_dgv(6, i).Value.ToString : PA7 = 今日結算_dgv(7, i).Value.ToString : PA8 = 今日結算_dgv(8, i).Value.ToString
            PA9 = 今日結算_dgv(10, i).Value.ToString : PA10 = 今日結算_dgv(11, i).Value.ToString
            SQL_客製表2_修改()
        Next
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        存檔() : MsgBox("存檔完成!!")
    End Sub
    Private Sub 翻頁存檔()
        For i As Integer = 0 To 今日結算_dgv.Rows.Count - 1
            PA1 = 今日結算_dgv("流水號", i).Value.ToString : PA4 = 今日結算_dgv(4, i).Value.ToString : PA5 = 今日結算_dgv(5, i).Value.ToString
            PA6 = 今日結算_dgv(6, i).Value.ToString : PA7 = 今日結算_dgv(7, i).Value.ToString : PA8 = 今日結算_dgv(8, i).Value.ToString
            PA9 = 今日結算_dgv(10, i).Value.ToString : PA10 = 今日結算_dgv(11, i).Value.ToString
            SQL_客製表2_修改()
        Next
    End Sub
    Private Sub 上一天_bt_Click(sender As Object, e As EventArgs) Handles 上一天_bt.Click
        開單日期_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        If 順向_ch.Checked = True Then : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        Else : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(1) : End If
    End Sub
    Private Sub 今天_bt_Click(sender As Object, e As EventArgs) Handles 今天_bt.Click
        開單日期_dtp.Value = Today()
        If 順向_ch.Checked = True Then : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        Else : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(1) : End If
    End Sub
    Private Sub 下一天_bt_Click(sender As Object, e As EventArgs) Handles 下一天_bt.Click
        開單日期_dtp.Value = 開單日期_dtp.Value.AddDays(1)
        If 順向_ch.Checked = True Then : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        Else : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(1) : End If
    End Sub
    Private Sub 開單日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 開單日期_dtp.ValueChanged
        翻頁存檔() : Set_清單5() : Set_清單6() : Set_費用清單() : Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4() : Set_清單4_自動判斷() : Set_清單4_自動判斷()
        If 順向_ch.Checked = True Then : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        Else : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(1) : End If
    End Sub
    Private Sub 開單日期1_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 開單日期1_dtp.ValueChanged
        Set_清單4_1()
    End Sub
    Private Sub 單號_tb_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 單號_tb.KeyPress
        If e.KeyChar = Chr(13) Then : Set_清單7() : End If
    End Sub
    Private Sub ZOOM_tb_Click_1(sender As Object, e As EventArgs) Handles ZOOM_tb.Click
        If 空間1.Visible = True Then
            A3 = 空間2.Size.Width : B3 = 空間2.Size.Height
            空間1.Visible = False : 空間2.Location = New Point(A1, B2) : 空間2.Size = New Point((A2 - A1) + A3, B3)
        Else
            空間1.Visible = True : 空間2.Location = New Point(A2, B2) : 空間2.Size = New Point(A3, B3)
        End If
    End Sub
    Private Sub 順向_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 順向_ch.Click
        順向_ch.Checked = True : 逆向_ch.Checked = False : If 順向_ch.Checked = True Then : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        Else : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(1) : End If
    End Sub

    Private Sub 逆向_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 逆向_ch.Click
        順向_ch.Checked = False : 逆向_ch.Checked = True : If 順向_ch.Checked = True Then : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(-1)
        Else : 開單日期1_dtp.Value = 開單日期_dtp.Value.AddDays(1) : End If
    End Sub
End Class