Option Strict Off
Public Class 銷售單審核
    ReadOnly ds, ds1, ds2, ds3, ds4, ds5, ds6, ds7 As New DataSet
    Dim 首次開啟 As Boolean = False : Dim EDR As Integer = 0 : Dim ESTR As String : Dim EDR1 As Integer = 0 : Dim ESTR1 As String : Dim NUM1 As Integer
    Dim 運費 As Integer : Dim 刷卡控制 As Boolean = False : Dim 稅金存檔 As Integer : Dim 稅金另算有資料 As Boolean
    Private Sub Set_清單()
        物料清單_dgv.DataSource = Nothing : ds.Clear()
        物料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料清單_dgv.ColumnHeadersHeight = 40 : 物料清單_dgv.AllowUserToAddRows = False : 物料清單_dgv.RowTemplate.Height = 25

        PA1 = "" : PA2 = "" : PA2 = 供應商編碼_cb.Text : PA1 = 查詢_tb.Text
        SQL_盤盈盤損申請_物料清單()
        da.Fill(ds) : 物料清單_dgv.DataSource = ds.Tables(0) : conn.Close()
        物料清單_dgv.Columns(0).FillWeight = 90 : 物料清單_dgv.Columns(1).FillWeight = 100 : 物料清單_dgv.Columns(2).FillWeight = 250
        物料清單_dgv.Columns(3).FillWeight = 60 : 物料清單_dgv.Columns(4).Visible = False
        物料清單_dgv.Columns(5).FillWeight = 40 : 物料清單_dgv.Columns(6).Visible = False
        物料清單_dgv.Columns(0).ReadOnly = True : 物料清單_dgv.Columns(1).ReadOnly = True : 物料清單_dgv.Columns(2).ReadOnly = True
        物料清單_dgv.Columns(3).ReadOnly = True : 物料清單_dgv.Columns(4).ReadOnly = True : 物料清單_dgv.Columns(5).ReadOnly = True
        物料清單_dgv.Columns("庫存").DefaultCellStyle.Format = "#,##0"
        物料清單_dgv.Columns("庫存").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料清單_dgv.Columns("庫存").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        資料筆數_tb.Text = 物料清單_dgv.Rows.Count
        For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
            資料數 = 物料清單_dgv.Rows.Count : MyModule1.進度條()
            If 物料清單_dgv("庫存", i).Value.ToString = "" Then : 物料清單_dgv("庫存", i).Value = 0 : End If
            If 物料清單_dgv("未出庫", i).Value.ToString = "" Then : 物料清單_dgv("未出庫", i).Value = 0 : End If
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub Set_清單1()
        銷售單據_dgv.DataSource = Nothing : ds1.Clear()
        銷售單據_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售單據_dgv.ColumnHeadersHeight = 25 : 銷售單據_dgv.AllowUserToAddRows = False : 銷售單據_dgv.RowTemplate.Height = 25

        PA19 = 業務_cb.Text : SQL_銷售控制表_審核()
        da.Fill(ds1) : 銷售單據_dgv.DataSource = ds1.Tables(0) : conn.Close()
        銷售單據_dgv.Columns(0).Visible = False : 銷售單據_dgv.Columns(1).FillWeight = 100 : 銷售單據_dgv.Columns(2).Visible = False : 銷售單據_dgv.Columns(3).Visible = False
        銷售單據_dgv.Columns(4).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(10).Visible = False : 銷售單據_dgv.Columns(11).Visible = False
        銷售單據_dgv.Columns(12).Visible = False
    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

        PA16 = 客戶_tb.Text : SQL_銷售單申請_客戶資料驗證()
        da.Fill(ds2) : 客戶資料_dgv.DataSource = ds2.Tables(0) : conn.Close()
    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

        PA20 = 料號_tb.Text : SQL_倉名_物料分配查詢()
        da.Fill(ds3) : 區域庫存_dgv.DataSource = ds3.Tables(0) : conn.Close()
        區域庫存_dgv.Columns(0).FillWeight = 200 : 區域庫存_dgv.Columns(1).FillWeight = 80
        區域庫存_dgv.Columns(0).ReadOnly = True : 區域庫存_dgv.Columns(1).ReadOnly = True
        區域庫存_dgv.Columns("可用").DefaultCellStyle.Format = "#,##0"
        區域庫存_dgv.Columns("可用").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        區域庫存_dgv.Columns("可用").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    End Sub
    Private Sub Set_清單4()
        銷售明細_dgv.DataSource = Nothing : ds4.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 = 95
        ElseIf 小間距_ch.Checked = False And 中間距_ch.Checked = True And 大間距_ch.Checked = False Then
            銷售明細_dgv.RowTemplate.Height = 60
        ElseIf 小間距_ch.Checked = True And 中間距_ch.Checked = False And 大間距_ch.Checked = False Then
            銷售明細_dgv.RowTemplate.Height = 25
        End If

        PA2 = "" : PA2 = 單號_tb.Text
        SQL_銷售明細表()
        da.Fill(ds4) : 銷售明細_dgv.DataSource = ds4.Tables(0) : conn.Close()
        Set_銷售明細_dgv_下拉式清單1() : Set_銷售明細_dgv_下拉式清單2() : Set_銷售明細_dgv_下拉式清單3()
        銷售明細_dgv.Columns(0).Visible = False : 銷售明細_dgv.Columns(1).FillWeight = 40 : 銷售明細_dgv.Columns(2).FillWeight = 110 : 銷售明細_dgv.Columns(3).FillWeight = 200
        銷售明細_dgv.Columns(4).Visible = False : 銷售明細_dgv.Columns(5).FillWeight = 130 : 銷售明細_dgv.Columns(6).Visible = False : 銷售明細_dgv.Columns(7).FillWeight = 130
        銷售明細_dgv.Columns(8).Visible = False : 銷售明細_dgv.Columns(9).FillWeight = 130 : 銷售明細_dgv.Columns(10).FillWeight = 150 : 銷售明細_dgv.Columns(11).FillWeight = 80
        銷售明細_dgv.Columns(12).FillWeight = 80 : 銷售明細_dgv.Columns(13).FillWeight = 80 : 銷售明細_dgv.Columns(14).FillWeight = 50 : 銷售明細_dgv.Columns(15).FillWeight = 80
        銷售明細_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).FillWeight = 50
        銷售明細_dgv.Columns(1).ReadOnly = True : 銷售明細_dgv.Columns(2).ReadOnly = True : 銷售明細_dgv.Columns(3).ReadOnly = True : 銷售明細_dgv.Columns(4).ReadOnly = True
        銷售明細_dgv.Columns(11).ReadOnly = True : 銷售明細_dgv.Columns(13).ReadOnly = True : 銷售明細_dgv.Columns(16).ReadOnly = True
        銷售明細_dgv.Columns("數量").DefaultCellStyle.Format = "#,##0" : 銷售明細_dgv.Columns("成本").DefaultCellStyle.Format = "#,##0"
        銷售明細_dgv.Columns("單價").DefaultCellStyle.Format = "#,##0.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
        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            If 銷售明細_dgv("含稅", i).Value = False Then
                銷售明細_dgv("售價", i).Value = 銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value
            ElseIf 銷售明細_dgv("含稅", i).Value = True Then
                銷售明細_dgv("售價", i).Value = 銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value * 1.05
            End If
            銷售明細_dgv("項次", i).Value = i + 1
        Next : 銷售明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub Set_銷售明細_dgv_下拉式清單1()
        Dim Col As New DataGridViewComboBoxColumn With {
            .FillWeight = 130,
            .DataPropertyName = "倉名"
        }
        SQL_倉名_下拉清單()
        Col.Items.Clear()
        While (dr.Read()) : Col.Items.Add(dr("倉名")) : End While : conn.Close()
        Col.HeaderText = "倉名" : Col.Name = "倉名"
        銷售明細_dgv.Columns.Insert(5, Col)
    End Sub
    Private Sub Set_銷售明細_dgv_下拉式清單2()
        Dim Col As New DataGridViewComboBoxColumn With {
            .FillWeight = 130,
            .DataPropertyName = "訂製"
        }
        SQL_訂製狀態_下拉清單()
        Col.Items.Clear()
        While (dr.Read()) : Col.Items.Add(dr("訂製")) : End While : conn.Close()
        Col.HeaderText = "訂製" : Col.Name = "訂製"
        銷售明細_dgv.Columns.Insert(7, Col)
    End Sub
    Private Sub Set_銷售明細_dgv_下拉式清單3()
        Dim Col As New DataGridViewComboBoxColumn With {
            .FillWeight = 130,
            .DataPropertyName = "狀態"
        }
        SQL_倉儲狀態_下拉清單()
        Col.Items.Clear()
        While (dr.Read()) : Col.Items.Add(dr("狀態")) : End While : conn.Close()
        Col.HeaderText = "狀態" : Col.Name = "狀態"
        銷售明細_dgv.Columns.Insert(9, Col)
    End Sub
    Private Sub Set_清單5()
        銷售備註_dgv.DataSource = Nothing : ds5.Clear()
        銷售備註_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售備註_dgv.ColumnHeadersHeight = 25
        銷售備註_dgv.AllowUserToAddRows = False
        銷售備註_dgv.RowTemplate.Height = 45

        PA2 = "" : PA2 = 單號_tb.Text : SQL_銷售備註表()
        da.Fill(ds5) : 銷售備註_dgv.DataSource = ds5.Tables(0) : conn.Close()
        銷售備註_dgv.Columns(0).Visible = False : 銷售備註_dgv.Columns(1).FillWeight = 110 : 銷售備註_dgv.Columns(2).FillWeight = 800 : 銷售備註_dgv.Columns(3).FillWeight = 120
        銷售備註_dgv.Columns(4).FillWeight = 120 : 銷售備註_dgv.Columns(5).FillWeight = 280 : 銷售備註_dgv.Columns(6).FillWeight = 100 : 銷售備註_dgv.Columns(7).FillWeight = 100
        銷售備註_dgv.Columns(0).ReadOnly = True : 銷售備註_dgv.Columns(1).ReadOnly = True
        銷售備註_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
        For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
            銷售備註_dgv("項次", i).Value = i + 1
        Next : 銷售備註_dgv.EditMode = DataGridViewEditMode.EditOnEnter : Set_合記計算()
    End Sub
    Private Sub Set_清單6()
        收款事項_dgv.DataSource = Nothing : ds6.Clear()
        收款事項_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        收款事項_dgv.ColumnHeadersHeight = 25
        收款事項_dgv.AllowUserToAddRows = False
        收款事項_dgv.RowTemplate.Height = 25

        PA2 = "" : PA2 = 單號_tb.Text : SQL_銷售收款事項()
        da.Fill(ds6) : 收款事項_dgv.DataSource = ds6.Tables(0) : conn.Close()
        收款事項_dgv.Columns(0).Visible = False : 收款事項_dgv.Columns(1).Visible = False : 收款事項_dgv.Columns(2).Visible = False : 收款事項_dgv.Columns(3).FillWeight = 100
        收款事項_dgv.Columns(4).FillWeight = 700 : 收款事項_dgv.Columns(5).FillWeight = 150 : 收款事項_dgv.Columns(6).FillWeight = 250 : 收款事項_dgv.Columns(7).FillWeight = 90
        收款事項_dgv.Columns(8).FillWeight = 90
        收款事項_dgv.Columns(2).ReadOnly = True
        收款事項_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
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            收款事項_dgv("項次", i).Value = i + 1
            If IsDBNull(收款事項_dgv("含稅", i).Value) = True Then
                收款事項_dgv("含稅", i).Value = False
            End If
        Next : 收款事項_dgv.EditMode = DataGridViewEditMode.EditOnEnter : Set_合記計算()
    End Sub
    Private Sub Set_清單7()
        銷售衍生運費_dgv.DataSource = Nothing : ds7.Clear()
        銷售衍生運費_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售衍生運費_dgv.ColumnHeadersHeight = 25
        銷售衍生運費_dgv.AllowUserToAddRows = False
        銷售衍生運費_dgv.RowTemplate.Height = 45

        PA2 = "" : PA2 = 單號_tb.Text : SQL_銷售衍生費用()
        da.Fill(ds7) : 銷售衍生運費_dgv.DataSource = ds7.Tables(0) : conn.Close()
        銷售衍生運費_dgv.Columns(0).Visible = False : 銷售衍生運費_dgv.Columns(1).FillWeight = 25 : 銷售衍生運費_dgv.Columns(2).Visible = False : 銷售衍生運費_dgv.Columns(3).FillWeight = 150
        銷售衍生運費_dgv.Columns(4).FillWeight = 30 : 銷售衍生運費_dgv.Columns(5).FillWeight = 60 : 銷售衍生運費_dgv.Columns(6).FillWeight = 20 : 銷售衍生運費_dgv.Columns(7).FillWeight = 20
        銷售衍生運費_dgv.Columns(0).ReadOnly = True : 銷售衍生運費_dgv.Columns(1).ReadOnly = True
        銷售衍生運費_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
        For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
            銷售衍生運費_dgv("項次", i).Value = i + 1
        Next : 銷售衍生運費_dgv.EditMode = DataGridViewEditMode.EditOnEnter : Set_合記計算()
    End Sub
    Private Sub 供應商_下拉表單資料載入()
        BL1 = False : PA3 = "" : PA4 = ""
        If 地區_cb.Text = "" Then : PA3 = ""
        ElseIf 地區_cb.Text = "北部" Then : PA3 = "2"
        ElseIf 地區_cb.Text = "南部" Then : PA3 = "3"
        ElseIf 地區_cb.Text = "材料" Then : PA3 = "9"
        ElseIf 地區_cb.Text = "調貨" Then : PA3 = "Y"
        ElseIf 地區_cb.Text = "其他" Then : PA3 = "1"
        End If
        SQL_盤盈盤損申請_供應商_下拉清單() : 供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
        While (dr.Read()) : 供應商_cb.Items.Add(dr("簡稱")) : 供應商編碼_cb.Items.Add(dr("編號")) : End While : conn.Close()
    End Sub
    Private Sub 送貨地點_cb_下拉表單資料載入()
        SQL_送貨地點_下拉清單() : 送貨地點_cb.Items.Clear() : 最低運費_cb.Items.Clear() : 最低售價_cb.Items.Clear() : 司機運費_tb.Text = "0"
        While (dr.Read()) : 送貨地點_cb.Items.Add(dr("地區")) : 最低運費_cb.Items.Add(dr("起車")) : 最低售價_cb.Items.Add(dr("最低售額")) : End While : conn.Close()
    End Sub
    Private Sub 倉儲狀態_cb_下拉表單資料載入()
        SQL_倉儲狀態_下拉清單() : 倉儲狀態_cb.Items.Clear() : 儲態編號_cb.Items.Clear()
        While (dr.Read()) : 倉儲狀態_cb.Items.Add(dr("狀態")) : 儲態編號_cb.Items.Add(dr("編碼")) : End While : conn.Close()
    End Sub
    Private Sub 訂製狀態_cb_下拉表單資料載入()
        SQL_訂製狀態_下拉清單() : 訂製狀態_cb.Items.Clear() : 訂製編碼_cb.Items.Clear()
        While (dr.Read()) : 訂製狀態_cb.Items.Add(dr("訂製")) : 訂製編碼_cb.Items.Add(dr("編碼")) : End While : conn.Close()
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd")
    End Sub
    Private Sub Set_合記計算()
        Dim 不含1類銷售小記 As Integer : Dim 金額1 As Integer = 0 : Dim 無管物料 As Integer
        售價小計_tb.Text = "0" : 稅金_tb.Text = "0" : 銷售合計_tb.Text = "0" : 收入小計_tb.Text = "0" : 支出小計_tb.Text = "0" : 額外收支_tb.Text = "0" : 物料成本_tb.Text = "0"
        司機運費_tb.Text = "0" : 管銷費用_tb.Text = "0" : 其他成本_tb.Text = "0" : 刷卡總和_tb.Text = "0" : 刷卡稅金_tb.Text = "0" : 刷卡傭金_tb.Text = "0"
        If 稅金另算有資料 = False Then : 稅金25_tb.Text = "0" : End If
        '-------001-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                刷卡總和_tb.Text = CLng(刷卡總和_tb.Text) + 收款事項_dgv("金額", i).Value
            End If
        Next
        刷卡稅金_tb.Text = CInt(CLng(CLng(刷卡總和_tb.Text) * 0.05)) : 刷卡傭金_tb.Text = CInt(CLng(CLng(刷卡總和_tb.Text) * 0.02))
        '-------002-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            銷售合計_tb.Text = CLng(銷售合計_tb.Text) + 銷售明細_dgv("售價", i).Value
            售價小計_tb.Text = CLng(售價小計_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value)
            If 銷售明細_dgv("無管銷", i).Value = False Then
                If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) <> "1001" Then
                    If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                    If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                    無管物料 = 無管物料 + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                End If
            End If
            If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) <> "1001" Then
                If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                物料成本_tb.Text = CLng(物料成本_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                不含1類銷售小記 = 不含1類銷售小記 + 銷售明細_dgv("售價", i).Value
            End If
            If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) = "1001" Then
                其他成本_tb.Text = CLng(其他成本_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                '不含1類銷售小記 = 不含1類銷售小記 - 銷售明細_dgv("成本", i).Value
            End If

            If 銷售明細_dgv("含稅", i).Value = True Then
                稅金_tb.Text = CLng(稅金_tb.Text) + ((銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value * 1.05) - (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value))
            End If
        Next
        管銷費用_tb.Text = 無管物料 * 1.06 - 無管物料

        If CLng(稅金_tb.Text) = 0 And CLng(刷卡稅金_tb.Text) = 0 Then
            通知_lb.Text = "無稅金"
        ElseIf CLng(稅金_tb.Text) = 0 And CLng(刷卡稅金_tb.Text) <> 0 Then
            通知_lb.Text = "因清單中沒有打勾含稅，但有刷卡帶入的稅金，所以稅金以刷卡稅金為主"
            稅金_tb.Text = CLng(刷卡總和_tb.Text) / 21 : 售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
        ElseIf (CLng(稅金_tb.Text) <> 0 Or CLng(刷卡稅金_tb.Text) <> 0) And CLng(稅金_tb.Text) > CLng(刷卡稅金_tb.Text) Then
            通知_lb.Text = "因售價稅金大於刷卡稅金，計算正常，利潤中扣除刷卡傭金"
        ElseIf (CLng(稅金_tb.Text) <> 0 Or CLng(刷卡稅金_tb.Text) <> 0) And CLng(稅金_tb.Text) < CLng(刷卡稅金_tb.Text) Then
            通知_lb.Text = "刷卡稅金大於自動計算後的稅金，邏輯有誤，請從新拆售價。"
        End If

        If 稅金存檔 <> CLng(稅金_tb.Text) Then
            稅金_tb.Text = 稅金存檔
            售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
            銷售合計_tb.Text = CLng(售價小計_tb.Text) + CLng(稅金_tb.Text)
        ElseIf 稅金存檔 = CLng(稅金_tb.Text) Then
            稅金_tb.Text = 稅金存檔
            銷售合計_tb.Text = CLng(售價小計_tb.Text) + CLng(稅金_tb.Text)
            售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
        End If
        If 稅金另算有資料 = False Then
            '稅金25_tb.Text = CLng(稅金_tb.Text) / 2
        End If
        '-------003-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
            收入小計_tb.Text = CLng(收入小計_tb.Text) + 銷售備註_dgv("收入", i).Value
            支出小計_tb.Text = CLng(支出小計_tb.Text) + 銷售備註_dgv("支出", i).Value
        Next
        額外收支_tb.Text = CLng(收入小計_tb.Text) - CLng(支出小計_tb.Text)
        '-------004-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        Dim 金額 As Integer = 0
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("真項次", i).Value.ToString <> "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                金額 = 金額 + 收款事項_dgv("金額", i).Value
            ElseIf 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                金額 = 金額 + 收款事項_dgv("金額", i).Value
            ElseIf 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString = "未收餘額" Then
                收款事項_dgv("金額", i).Value = CInt(CLng(銷售合計_tb.Text)) - 金額
            End If
        Next
        '-------005-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        If 送貨地點_cb.Text = "" Or 送貨地點_cb.Text = "自取" Or 最低運費_cb.Text = "" Or 最低售價_cb.Text = "" Then
            司機運費_tb.Text = "0"
        Else
            If 運費 = 0 Then
                If (不含1類銷售小記 - CLng(其他成本_tb.Text)) <= CLng(最低售價_cb.Text) Then
                    司機運費_tb.Text = 最低運費_cb.Text
                ElseIf (不含1類銷售小記 - CLng(其他成本_tb.Text)) > CLng(最低售價_cb.Text) Then
                    司機運費_tb.Text = (不含1類銷售小記 - CLng(稅金_tb.Text) - CLng(刷卡傭金_tb.Text) - CLng(其他成本_tb.Text)) / 100 * 3
                End If
            Else
                司機運費_tb.Text = 運費
            End If
        End If
        '-------006-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        預估利潤_tb.Text = CLng(售價小計_tb.Text) + CLng(額外收支_tb.Text) - CLng(其他成本_tb.Text) - CLng(物料成本_tb.Text) -
                           CLng(司機運費_tb.Text) - CLng(管銷費用_tb.Text) - CLng(刷卡傭金_tb.Text) + CLng(稅金25_tb.Text)
        If 銷售衍生運費_dgv.Rows.Count > 0 Then
            For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                預估利潤_tb.Text = CLng(預估利潤_tb.Text) - 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
            Next
        End If
        '-------007-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        售價小計_tb.Text = Format(CLng(售價小計_tb.Text), "#,##0") : 稅金_tb.Text = Format(CLng(稅金_tb.Text), "#,##0") : 銷售合計_tb.Text = Format(CLng(銷售合計_tb.Text), "#,##0")
        收入小計_tb.Text = Format(CLng(收入小計_tb.Text), "#,##0") : 支出小計_tb.Text = Format(CLng(支出小計_tb.Text), "#,##0") : 額外收支_tb.Text = Format(CLng(額外收支_tb.Text), "#,##0")
        司機運費_tb.Text = Format(CLng(司機運費_tb.Text), "#,##0") : 管銷費用_tb.Text = Format(CLng(管銷費用_tb.Text), "#,##0") : 預估利潤_tb.Text = Format(CLng(預估利潤_tb.Text), "#,##0")
        物料成本_tb.Text = Format(CLng(物料成本_tb.Text), "#,##0") : 其他成本_tb.Text = Format(CLng(其他成本_tb.Text), "#,##0") : 刷卡總和_tb.Text = Format(CLng(刷卡總和_tb.Text), "#,##0")
        刷卡稅金_tb.Text = Format(CLng(刷卡稅金_tb.Text), "#,##0") : 刷卡傭金_tb.Text = Format(CLng(刷卡傭金_tb.Text), "#,##0") : 稅金25_tb.Text = Strings.Format(CLng(稅金25_tb.Text), "#,##0.0")
    End Sub
    Private Sub 指定倉庫_cb_下拉表單資料載入()
        If 需要全部庫存區域清單_ch.Checked = True Then
            SQL_倉名_下拉清單()
        Else
            If 料號_tb.Text = "" Then
                SQL_倉名_下拉清單()
            Else
                PA20 = 料號_tb.Text : SQL_倉名_下拉清單_有條件()
            End If
        End If
        指定倉庫_cb.Items.Clear()
        While (dr.Read()) : 指定倉庫_cb.Items.Add(dr("倉名")) : End While : conn.Close()
        If 指定倉庫_cb.Items.Count = 0 Then
            SQL_倉名_下拉清單()
            While (dr.Read()) : 指定倉庫_cb.Items.Add(dr("倉名")) : End While : conn.Close()
        End If
    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
        Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        顯示_bt.Enabled = False : 隱藏_bt.Enabled = True : 業務_cb_下拉表單資料載入()
        If 登入人級別 <= 3 Then : 已審核資料_ch.Enabled = True : Else : 已審核資料_ch.Enabled = False : End If
        If CC(37) = False Then : 已審核資料_ch.Checked = False : Else : 已審核資料_ch.Checked = True : End If
        料號_tb.Enabled = False : 供應商編碼_tb.Visible = False : 中間距_ch.Checked = True '--------------------控件隱藏、操作許可設定與其他基本顯示設定

        指定倉庫_cb_下拉表單資料載入() : 訂製狀態_cb_下拉表單資料載入() : 倉儲狀態_cb_下拉表單資料載入() : 送貨地點_cb_下拉表單資料載入()
        首次開啟 = False : Set_清單() : Set_清單1() : 首次開啟 = 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 = 7.6
        End If
    End Sub
    Private Sub 銷售單申請_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        If 單號_tb.Text = "" Then : Else
            Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
        End If
        If Me.Size.Width > 1600 Then
            物料圖1_pb.Visible = True : 物料圖1_pb.Size = New Size(300, 167)
        Else
            物料圖1_pb.Visible = False
        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 = 7.6
        End If
    End Sub
    Private Sub 收款事項_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 收款事項_dgv.CellEndEdit
        Set_合記計算()
    End Sub
    Private Sub 收款事項_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 收款事項_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            銷售收款流水號_tb.Text = 收款事項_dgv("資料流水號", e.RowIndex).Value.ToString : 項次2_tb.Text = 收款事項_dgv("項次", e.RowIndex).Value.ToString
            項次3_tb.Text = 收款事項_dgv("真項次", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 銷售備註_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售備註_dgv.CellEndEdit
        If (CLng(銷售備註_dgv.Rows(e.RowIndex).Cells("收入").Value) <> 0 And CLng(銷售備註_dgv.Rows(e.RowIndex).Cells("支出").Value) <> 0) Then
            MsgBox("支出與收入不能同時有金額")
            Set_清單5()
            Exit Sub
        End If
        Set_合記計算()
    End Sub
    Private Sub 銷售備註_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售備註_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            銷售備註流水號_tb.Text = 銷售備註_dgv("資料流水號", e.RowIndex).Value.ToString : 項次1_tb.Text = 銷售備註_dgv("項次", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 銷售衍生運費_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售衍生運費_dgv.CellEndEdit
        Set_合記計算()
    End Sub
    Private Sub 銷售衍生運費_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售衍生運費_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            運費資料流水號_tb.Text = 銷售衍生運費_dgv("資料流水號", e.RowIndex).Value.ToString : 項次4_tb.Text = 銷售衍生運費_dgv("項次", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 銷售明細_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售明細_dgv.CellEndEdit
        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            If 銷售明細_dgv("含稅", i).Value = False Then
                銷售明細_dgv("單價", i).Value = 銷售明細_dgv("售價", i).Value / 銷售明細_dgv("數量", i).Value
            ElseIf 銷售明細_dgv("含稅", i).Value = True Then
                銷售明細_dgv("單價", i).Value = (銷售明細_dgv("售價", i).Value / 1.05) / 銷售明細_dgv("數量", i).Value
            End If

            If 銷售明細_dgv("倉儲情況", i).Value <> "已有貨" Then
                PA20 = 銷售明細_dgv(5, i).Value : PA19 = 銷售明細_dgv(7, i).Value : PA18 = 銷售明細_dgv(9, i).Value
                SQL_銷售明細_改倉名()
                If dr.Read() Then
                    銷售明細_dgv("倉儲狀態", i).Value = dr("倉名編號")
                End If
                SQL_銷售明細_改物料訂製狀態()
                If dr.Read() Then
                    銷售明細_dgv("訂製狀態", i).Value = dr("編碼")
                End If
                SQL_銷售明細_倉儲狀態()
                If dr.Read() Then
                    銷售明細_dgv("物料狀態", i).Value = dr("編碼")
                End If : conn.Close()
            End If
        Next : Set_合記計算()
    End Sub
    Private Sub 銷售明細_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售明細_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            銷售資料流水號_tb.Text = 銷售明細_dgv("資料流水號", e.RowIndex).Value.ToString : 倉儲資料流水號_tb.Text = 銷售明細_dgv("倉儲流水號", e.RowIndex).Value.ToString
            項次_tb.Text = 銷售明細_dgv("項次", e.RowIndex).Value.ToString
            物料圖1_pb.Image = Nothing : PA1 = 銷售明細_dgv("料號", e.RowIndex).Value : SQL_物料檔案_是否有圖()
            If dr.Read() Then
                If dr("是否有圖") = True Then
                    物料圖1_pb.BackgroundImage = Nothing
                    PA = 銷售明細_dgv("料號", e.RowIndex).Value : SQL_物料圖庫_圖片顯示() '--------------------圖片顯示
                    While dr.Read() = True
                        Dim unused As Byte() = New Byte(-1) {}
                        Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
                        Dim oStream As New MemoryStream(bytes)
                        物料圖1_pb.Image = Bitmap.FromStream(oStream)
                    End While
                    conn.Close()
                    物料圖1_pb.SizeMode = 4
                Else
                    物料圖1_pb.BackgroundImage = My.Resources.底圖1 : 物料圖1_pb.BackgroundImageLayout = 3
                    物料圖1_pb.Image = Nothing
                End If
            End If : conn.Close()
        End If
    End Sub
    Private Sub 銷售單據_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 銷售單據_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            稅金存檔 = 銷售單據_dgv.Rows(e.RowIndex).Cells("稅金").Value
            流水號_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("流水號").Value : 單號_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("單號").Value
            開單日期_dtp.Value = 銷售單據_dgv.Rows(e.RowIndex).Cells("開單日期").Value : 客戶編號_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("客戶編號").Value
            交貨日期_dtp.Value = 銷售單據_dgv.Rows(e.RowIndex).Cells("交貨日期").Value : 含稅_ch.Checked = 銷售單據_dgv.Rows(e.RowIndex).Cells("含稅").Value
            送貨地點_cb_下拉表單資料載入() : 送貨地點_cb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("送貨地點").Value.ToString
            運費 = 銷售單據_dgv.Rows(e.RowIndex).Cells("運費").Value : 客戶流水_tb.Text = ""
            業務_cb.Text = Strings.Left(銷售單據_dgv.Rows(e.RowIndex).Cells("單號").Value, 1)

            If 銷售單據_dgv.Rows(e.RowIndex).Cells("稅金另扣").Value.ToString <> "" Then
                稅金另算有資料 = True : 稅金25_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("稅金另扣").Value.ToString
                稅金25_tb.Text = Strings.Format(CLng(稅金25_tb.Text), "#,##0")
            Else : 稅金另算有資料 = False : 稅金25_tb.Text = "" : End If

            Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
            PA = 單號_tb.Text : SQL_銷售單號串聯倉儲表取得倉儲單號()
            If dr.Read() Then : 調庫單號_tb.Text = dr("執行單號") : Else : 調庫單號_tb.Text = "" : End If
        End If
    End Sub
    Private Sub 區域庫存_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 區域庫存_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            指定倉庫_cb.Text = 區域庫存_dgv.Rows(e.RowIndex).Cells("倉名").Value
        End If
    End Sub
    Private Sub 物料清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料清單_dgv.CellClick
        If 首次開啟 = True Then
            If e.RowIndex = -1 Then : Else
                料號_tb.Text = 物料清單_dgv("料號", e.RowIndex).Value.ToString : 供應商編碼_tb.Text = 物料清單_dgv("供應商", e.RowIndex).Value.ToString
                品名_tb.Text = 物料清單_dgv("品名", e.RowIndex).Value.ToString : 最大庫存量_tb.Text = 物料清單_dgv("最低庫存量", e.RowIndex).Value.ToString
                庫存量_tb.Text = CLng(物料清單_dgv("庫存", e.RowIndex).Value.ToString)
                可申請_tb.Text = CLng(物料清單_dgv("庫存", e.RowIndex).Value.ToString) - CLng(物料清單_dgv("未出庫", e.RowIndex).Value.ToString)

                物料圖_pb.Image = Nothing : PA1 = 料號_tb.Text : SQL_物料檔案_是否有圖()
                If dr.Read() Then
                    If dr("是否有圖") = True Then
                        物料圖_pb.BackgroundImage = Nothing
                        PA = 料號_tb.Text : SQL_物料圖庫_圖片顯示() '--------------------圖片顯示
                        While dr.Read() = True
                            Dim unused As Byte() = New Byte(-1) {}
                            Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
                            Dim oStream As New MemoryStream(bytes)
                            物料圖_pb.Image = Bitmap.FromStream(oStream)
                        End While
                        conn.Close()
                        物料圖_pb.SizeMode = 4
                    Else
                        物料圖_pb.BackgroundImage = My.Resources.底圖1 : 物料圖_pb.BackgroundImageLayout = 3
                        物料圖_pb.Image = Nothing
                    End If
                End If : conn.Close()

                指定倉庫_cb_下拉表單資料載入()
                成本_nud.Value = 0
                訂製狀態_cb_下拉表單資料載入() : 倉儲狀態_cb_下拉表單資料載入()
                PA12 = 料號_tb.Text
                SQL_銷售明細表_成本讀取()
                If dr.Read() Then : 成本_nud.Value = dr("成本")
                Else : 成本_nud.Value = 0
                End If : conn.Close()
            End If
        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 窄間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距_ch.Click
        小間距_ch.Checked = True : 中間距_ch.Checked = False : 大間距_ch.Checked = False
        存檔1() : Set_清單4()
    End Sub
    Private Sub 中間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False
        存檔1() : Set_清單4()
    End Sub
    Private Sub 大間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = False : 大間距_ch.Checked = True
        存檔1() : Set_清單4()
    End Sub
    Private Sub 地區_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 地區_cb.SelectedIndexChanged
        If 地區_cb.Text = "" And 查詢_tb.Text = "" Then
            供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear() : Set_清單()
        ElseIf 地區_cb.Text = "" Then
            查詢_tb.Text = "" : 供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
        ElseIf 地區_cb.Text <> "" Then
            查詢_tb.Text = "" : 供應商_下拉表單資料載入()
        End If
    End Sub
    Private Sub 供應商_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商_cb.SelectedIndexChanged
        If 地區_cb.Text <> "" Then
            查詢_tb.Text = "" : 供應商編碼_cb.SelectedIndex = 供應商_cb.SelectedIndex
        End If
    End Sub
    Private Sub 供應商編碼_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商編碼_cb.SelectedIndexChanged
        If 地區_cb.Text <> "" Then
            查詢_tb.Text = "" : 供應商_cb.SelectedIndex = 供應商編碼_cb.SelectedIndex : 供應商編碼_tb.Text = 供應商編碼_cb.Text : Set_清單()
        End If
    End Sub
    Private Sub 清空_bt_Click(sender As Object, e As EventArgs) Handles 清空_bt.Click
        查詢_tb.Text = "" : 地區_cb.Text = ""
    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
            供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
            PA = 查詢_tb.Text : Set_清單() : 地區_cb.Text = ""
        End If
    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
            稅金存檔 = 稅金_tb.Text
            Set_合記計算()
        End If
    End Sub
    Private Sub 指定倉庫_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 指定倉庫_cb.SelectedIndexChanged
        PA6 = 指定倉庫_cb.Text : SQL_指定倉儲_資料讀取()
        If dr.Read() Then : 倉庫級別_tb.Text = dr("倉級") : 倉庫編號_tb.Text = dr("倉名編號") : End If : conn.Close()
    End Sub
    Private Sub 倉儲狀態_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 倉儲狀態_cb.SelectedIndexChanged
        儲態編號_cb.SelectedIndex = 倉儲狀態_cb.SelectedIndex
    End Sub
    Private Sub 儲態編號_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 儲態編號_cb.SelectedIndexChanged
        倉儲狀態_cb.SelectedIndex = 儲態編號_cb.SelectedIndex
    End Sub
    Private Sub 訂製狀態_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 訂製狀態_cb.SelectedIndexChanged
        訂製編碼_cb.SelectedIndex = 訂製狀態_cb.SelectedIndex
    End Sub
    Private Sub 訂製編碼_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 訂製編碼_cb.SelectedIndexChanged
        訂製狀態_cb.SelectedIndex = 訂製編碼_cb.SelectedIndex
        If 訂製編碼_cb.Text = "MA0001" Then
            PA12 = 料號_tb.Text
            SQL_銷售明細表_成本讀取()
            If dr.Read() Then : 成本_nud.Value = dr("成本")
            Else : 成本_nud.Value = 0
            End If : conn.Close()
        Else
            成本_nud.Value = 0
        End If
    End Sub
    Private Sub 業務_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 業務_cb.SelectedIndexChanged
        Set_清單1()
    End Sub
    Private Sub 需要全部庫存區域清單_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 需要全部庫存區域清單_ch.CheckedChanged
        指定倉庫_cb_下拉表單資料載入()
    End Sub
    Private Sub 送貨地點_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 送貨地點_cb.SelectedIndexChanged
        最低運費_cb.SelectedIndex = 送貨地點_cb.SelectedIndex : 最低售價_cb.SelectedIndex = 送貨地點_cb.SelectedIndex : Set_合記計算()
    End Sub
    Private Sub 最低運費_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 最低運費_cb.SelectedIndexChanged
        送貨地點_cb.SelectedIndex = 最低運費_cb.SelectedIndex : 最低售價_cb.SelectedIndex = 最低運費_cb.SelectedIndex
    End Sub
    Private Sub 最低售價_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 最低售價_cb.SelectedIndexChanged
        送貨地點_cb.SelectedIndex = 最低售價_cb.SelectedIndex : 最低運費_cb.SelectedIndex = 最低售價_cb.SelectedIndex
    End Sub
    Private Sub 含稅_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 含稅_ch.CheckedChanged
        If 刷卡控制 = False Then
            For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
                If 含稅_ch.Checked = False Then : 銷售明細_dgv("含稅", i).Value = False
                ElseIf 含稅_ch.Checked = True Then : 銷售明細_dgv("含稅", i).Value = True
                End If
                If 銷售明細_dgv("含稅", i).Value = False Then
                    If IsDBNull(銷售明細_dgv("售價", i).Value) = True Then : 銷售明細_dgv("售價", i).Value = "0" : End If
                    If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                    銷售明細_dgv("售價", i).Value = 銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value
                ElseIf 銷售明細_dgv("含稅", i).Value = True Then
                    If IsDBNull(銷售明細_dgv("售價", i).Value) = True Then : 銷售明細_dgv("售價", i).Value = "0" : End If
                    If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                    銷售明細_dgv("售價", i).Value = 銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value * 1.05
                End If
            Next
            Set_合記計算()
        End If
    End Sub
    Private Sub 客戶編號_tb_TextChanged(sender As Object, e As EventArgs) Handles 客戶編號_tb.TextChanged
        PA15 = 客戶編號_tb.Text
        SQL_銷售單申請_客戶資料()
        If dr.Read() Then
            客戶_tb.Text = dr("名稱") : 公司_tb.Text = dr("公司名稱") : 統編_tb.Text = dr("統編") : 住址_tb.Text = dr("地址") : 電話1_tb.Text = dr("電話1") : 電話2_tb.Text = dr("電話2")
        Else
            客戶_tb.Text = "" : 公司_tb.Text = "" : 統編_tb.Text = "" : 住址_tb.Text = "" : 電話1_tb.Text = "" : 電話2_tb.Text = ""
        End If
    End Sub
    Private Sub 客戶資料查詢_bt_Click(sender As Object, e As EventArgs) Handles 客戶資料查詢_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("指定客戶前要先有銷售單號，請新增單號或是挑選歷史資料!!")
        Else
            客戶資料強制對話框模式 = True : 客戶資料表.Close() : 客戶資料表.ShowDialog() : 客戶資料強制對話框模式 = False : 客戶編號_tb.Text = PA15 : 客戶資料表.Close()
        End If
    End Sub
    Private Sub 客戶資料驗證_bt_Click(sender As Object, e As EventArgs) Handles 客戶資料驗證_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            Set_清單2()
            If 客戶資料_dgv.Rows.Count = 1 Then
                客戶編號_tb.Text = 客戶資料_dgv.Rows(0).Cells("舊編").Value
            ElseIf 客戶資料_dgv.Rows.Count > 1 Then
                MsgBox("該客戶名稱有多筆資料，請點擊  [客戶資料查詢]  由操作介面中查詢確認。")
            ElseIf 客戶資料_dgv.Rows.Count = 0 Then
                Dim aa1 As MsgBoxResult = MsgBox("資料庫中查詢不到該客戶資料，是否依照目前資料新增客戶資料?", MsgBoxStyle.OkCancel)
                If aa1 = MsgBoxResult.Ok Then
                    SQL_客戶資料表_流水號_最後一筆資料() '--------------------自動取得新流水號
                    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 = "CL" & "00000000" & EDR
                    ElseIf EDR > 9 And EDR < 100 Then : ESTR = "CL" & "0000000" & EDR
                    ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "CL" & "000000" & EDR
                    ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "CL" & "00000" & EDR
                    ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "CL" & "0000" & EDR
                    ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "CL" & "000" & EDR
                    ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "CL" & "00" & EDR
                    ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "CL" & "0" & EDR
                    ElseIf EDR > 99999999 Then : ESTR = "CL" & EDR
                    End If : 客戶流水_tb.Text = ESTR : PA16 = ESTR
                    PA18 = 業務_cb.Text
                    SQL_客戶資料表_編號_最後一筆資料()  '--------------------自動取得新編號
                    If dr.Read() Then : EDR1 = Double.Parse(Strings.Right(dr("舊編").ToString, 4)) : Else : EDR1 = 0 : End If
                    conn.Close() : EDR1 += 1
                    If EDR1 < 10 Then : ESTR1 = 業務_cb.Text & "000" & EDR1
                    ElseIf EDR1 > 9 And EDR1 < 100 Then : ESTR1 = 業務_cb.Text & "00" & EDR1
                    ElseIf EDR1 > 99 And EDR1 < 1000 Then : ESTR1 = 業務_cb.Text & "0" & EDR1
                    ElseIf EDR1 > 999 And EDR1 < 10000 Then : ESTR1 = 業務_cb.Text & EDR1
                    End If : PA17 = ESTR1
                    SQL_客戶資料表_新增() '--------------------人事資料表中寫入一筆資料
                    PA14 = 客戶_tb.Text : PA13 = 電話1_tb.Text : PA12 = 電話2_tb.Text : PA11 = 住址_tb.Text
                    PA10 = 公司_tb.Text : PA9 = 統編_tb.Text : PA8 = 客戶流水_tb.Text
                    SQL_客戶資料表_修改() : conn.Close() '--------------------資料修改
                    客戶編號_tb.Text = ESTR1
                    MsgBox("客戶資料新增完畢，請記得存檔。")
                End If
            End If
        End If
    End Sub
    Private Sub 存檔1()
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                PA14 = 客戶_tb.Text : PA13 = 電話1_tb.Text : PA12 = 電話2_tb.Text : PA11 = 住址_tb.Text
                PA10 = 公司_tb.Text : PA9 = 統編_tb.Text : PA8 = 客戶流水_tb.Text
                SQL_客戶資料表_修改() '--------------------資料修改

                DTP = Format(開單日期_dtp.Value, "yyyy/MM/dd") : DTP1 = Format(交貨日期_dtp.Value, "yyyy/MM/dd") : BL1 = 含稅_ch.Checked : 運費 = 司機運費_tb.Text
                PA1 = 流水號_tb.Text : PA2 = 單號_tb.Text : PA3 = 客戶編號_tb.Text : PA4 = 流水號_tb.Text : PA5 = 送貨地點_cb.Text : NU1 = 司機運費_tb.Text : NU2 = 管銷費用_tb.Text
                NU3 = 稅金_tb.Text : NU4 = 刷卡傭金_tb.Text : NU5 = 銷售合計_tb.Text : SQL5 = ""
                SQL_銷售控制表_修改() '--------------------資料修改

                For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
                    資料數 = 銷售明細_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售明細_dgv.Rows(i).Cells("備註").Value : PA11 = 銷售明細_dgv.Rows(i).Cells("資料流水號").Value : PA9 = 銷售明細_dgv.Rows(i).Cells("倉儲狀態").Value
                    NU1 = 銷售明細_dgv.Rows(i).Cells("成本").Value : NU2 = 銷售明細_dgv.Rows(i).Cells("單價").Value : PA8 = 銷售明細_dgv.Rows(i).Cells("物料狀態").Value
                    BL5 = 銷售明細_dgv.Rows(i).Cells("含稅").Value : PA7 = 銷售明細_dgv.Rows(i).Cells("訂製狀態").Value
                    SQL_銷售明細表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
                    資料數 = 銷售備註_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售備註_dgv.Rows(i).Cells("備註").Value : PA11 = 銷售備註_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售備註_dgv.Rows(i).Cells("收入").Value : NU2 = 銷售備註_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售備註表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                    資料數 = 收款事項_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 收款事項_dgv.Rows(i).Cells("內容").Value : PA11 = 收款事項_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 收款事項_dgv.Rows(i).Cells("金額").Value : PA12 = 收款事項_dgv.Rows(i).Cells("含稅").Value
                    SQL_銷售收款事項_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                    資料數 = 銷售衍生運費_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售衍生運費_dgv.Rows(i).Cells("運費備註").Value : PA11 = 銷售衍生運費_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售衍生運費_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                MsgBox("存檔完成。")
                Set_清單1()
            End If
        End If
    End Sub
    Private Sub 存檔2()
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            Set_清單2()
            If 客戶資料_dgv.Rows.Count = 1 Then
                客戶編號_tb.Text = 客戶資料_dgv.Rows(0).Cells("舊編").Value
            ElseIf 客戶資料_dgv.Rows.Count > 1 Then
                Dim aa1 As MsgBoxResult = MsgBox("系統查詢到該客戶有多筆客戶資料，你是否已經確定單據上顯示的客戶資料正確?", MsgBoxStyle.OkCancel)
                If aa1 = MsgBoxResult.Ok Then : Else
                    MsgBox("即將幫您打開客戶資料表，請在客戶資料表中查詢，選取您確認的正確訊息，並指定到銷售申請單。")
                    客戶資料查詢_bt.PerformClick()
                    MsgBox("指定客戶後請寄的再次存檔。")
                    Exit Sub
                End If
            ElseIf 客戶資料_dgv.Rows.Count = 0 Then
                Dim aa1 As MsgBoxResult = MsgBox("資料庫中查詢不到該客戶資料，是否依照目前資料新增客戶資料?", MsgBoxStyle.OkCancel)
                If aa1 = MsgBoxResult.Ok Then
                    SQL_客戶資料表_流水號_最後一筆資料() '--------------------自動取得新流水號
                    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 = "CL" & "00000000" & EDR
                    ElseIf EDR > 9 And EDR < 100 Then : ESTR = "CL" & "0000000" & EDR
                    ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "CL" & "000000" & EDR
                    ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "CL" & "00000" & EDR
                    ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "CL" & "0000" & EDR
                    ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "CL" & "000" & EDR
                    ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "CL" & "00" & EDR
                    ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "CL" & "0" & EDR
                    ElseIf EDR > 99999999 Then : ESTR = "CL" & EDR
                    End If : 客戶流水_tb.Text = ESTR : PA16 = ESTR

                    PA18 = 業務_cb.Text
                    SQL_客戶資料表_編號_最後一筆資料()  '--------------------自動取得新編號
                    If dr.Read() Then : EDR1 = Double.Parse(Strings.Right(dr("舊編").ToString, 4)) : Else : EDR1 = 0 : End If
                    conn.Close() : EDR1 += 1
                    If EDR1 < 10 Then : ESTR1 = 業務_cb.Text & "000" & EDR1
                    ElseIf EDR1 > 9 And EDR1 < 100 Then : ESTR1 = 業務_cb.Text & "00" & EDR1
                    ElseIf EDR1 > 99 And EDR1 < 1000 Then : ESTR1 = 業務_cb.Text & "0" & EDR1
                    ElseIf EDR1 > 999 And EDR1 < 10000 Then : ESTR1 = 業務_cb.Text & EDR1
                    End If : PA17 = ESTR1

                    SQL_客戶資料表_新增() '--------------------人事資料表中寫入一筆資料

                    PA14 = 客戶_tb.Text : PA13 = 電話1_tb.Text : PA12 = 電話2_tb.Text : PA11 = 住址_tb.Text
                    PA10 = 公司_tb.Text : PA9 = 統編_tb.Text : PA8 = 客戶流水_tb.Text
                    SQL_客戶資料表_修改() : conn.Close() '--------------------資料修改
                    客戶編號_tb.Text = ESTR1
                End If
            End If

            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                PA14 = 客戶_tb.Text : PA13 = 電話1_tb.Text : PA12 = 電話2_tb.Text : PA11 = 住址_tb.Text
                PA10 = 公司_tb.Text : PA9 = 統編_tb.Text : PA8 = 客戶流水_tb.Text
                SQL_客戶資料表_修改() '--------------------資料修改

                DTP = Format(開單日期_dtp.Value, "yyyy/MM/dd") : DTP1 = Format(交貨日期_dtp.Value, "yyyy/MM/dd") : BL1 = 含稅_ch.Checked : 運費 = 司機運費_tb.Text
                PA1 = 流水號_tb.Text : PA2 = 單號_tb.Text : PA3 = 客戶編號_tb.Text : PA4 = 流水號_tb.Text : PA5 = 送貨地點_cb.Text : NU1 = 司機運費_tb.Text : NU2 = 管銷費用_tb.Text
                NU3 = 稅金_tb.Text : NU4 = 刷卡傭金_tb.Text : NU5 = 銷售合計_tb.Text : SQL5 = ""
                SQL_銷售控制表_修改() '--------------------資料修改

                For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
                    資料數 = 銷售明細_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售明細_dgv.Rows(i).Cells("備註").Value : PA11 = 銷售明細_dgv.Rows(i).Cells("資料流水號").Value : PA9 = 銷售明細_dgv.Rows(i).Cells("倉儲狀態").Value
                    NU1 = 銷售明細_dgv.Rows(i).Cells("成本").Value : NU2 = 銷售明細_dgv.Rows(i).Cells("單價").Value : PA8 = 銷售明細_dgv.Rows(i).Cells("物料狀態").Value
                    BL5 = 銷售明細_dgv.Rows(i).Cells("含稅").Value : PA7 = 銷售明細_dgv.Rows(i).Cells("訂製狀態").Value
                    SQL_銷售明細表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
                    資料數 = 銷售備註_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售備註_dgv.Rows(i).Cells("備註").Value : PA11 = 銷售備註_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售備註_dgv.Rows(i).Cells("收入").Value : NU2 = 銷售備註_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售備註表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                    資料數 = 收款事項_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 收款事項_dgv.Rows(i).Cells("內容").Value : PA11 = 收款事項_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 收款事項_dgv.Rows(i).Cells("金額").Value : PA12 = 收款事項_dgv.Rows(i).Cells("含稅").Value
                    SQL_銷售收款事項_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                    資料數 = 銷售衍生運費_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售衍生運費_dgv.Rows(i).Cells("運費備註").Value : PA11 = 銷售衍生運費_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售衍生運費_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                MsgBox("存檔完成。")
                Set_清單1()
            End If
        End If
    End Sub
    Private Sub 存檔3()
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                PA14 = 客戶_tb.Text : PA13 = 電話1_tb.Text : PA12 = 電話2_tb.Text : PA11 = 住址_tb.Text
                PA10 = 公司_tb.Text : PA9 = 統編_tb.Text : PA8 = 客戶流水_tb.Text
                SQL_客戶資料表_修改() '--------------------資料修改

                DTP = Format(開單日期_dtp.Value, "yyyy/MM/dd") : DTP1 = Format(交貨日期_dtp.Value, "yyyy/MM/dd") : BL1 = 含稅_ch.Checked : 運費 = 司機運費_tb.Text
                PA1 = 流水號_tb.Text : PA2 = 單號_tb.Text : PA3 = 客戶編號_tb.Text : PA4 = 流水號_tb.Text : PA5 = 送貨地點_cb.Text : NU1 = 司機運費_tb.Text : NU2 = 管銷費用_tb.Text
                NU3 = 稅金_tb.Text : NU4 = 刷卡傭金_tb.Text : NU5 = 銷售合計_tb.Text : SQL5 = ""
                SQL_銷售控制表_修改() '--------------------資料修改

                For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
                    資料數 = 銷售明細_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售明細_dgv.Rows(i).Cells("備註").Value.ToString : PA11 = 銷售明細_dgv.Rows(i).Cells("資料流水號").Value : PA9 = 銷售明細_dgv.Rows(i).Cells("倉儲狀態").Value
                    NU1 = 銷售明細_dgv.Rows(i).Cells("成本").Value : NU2 = 銷售明細_dgv.Rows(i).Cells("單價").Value : PA8 = 銷售明細_dgv.Rows(i).Cells("物料狀態").Value
                    BL5 = 銷售明細_dgv.Rows(i).Cells("含稅").Value : PA7 = 銷售明細_dgv.Rows(i).Cells("訂製狀態").Value
                    SQL_銷售明細表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
                    資料數 = 銷售備註_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售備註_dgv.Rows(i).Cells("備註").Value : PA11 = 銷售備註_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售備註_dgv.Rows(i).Cells("收入").Value : NU2 = 銷售備註_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售備註表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                    資料數 = 收款事項_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 收款事項_dgv.Rows(i).Cells("內容").Value : PA11 = 收款事項_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 收款事項_dgv.Rows(i).Cells("金額").Value : PA12 = 收款事項_dgv.Rows(i).Cells("含稅").Value
                    SQL_銷售收款事項_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                    資料數 = 銷售衍生運費_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售衍生運費_dgv.Rows(i).Cells("運費備註").Value : PA11 = 銷售衍生運費_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售衍生運費_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                Set_清單1() : 銷售單據_dgv.Enabled = True
            End If
        End If
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        存檔2()
    End Sub
    Private Sub 選定內容加入庫存調整申請單_bt_Click(sender As Object, e As EventArgs) Handles 選定內容加入庫存調整申請單_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                If 料號_tb.Text = "" Then
                    MsgBox("請選擇物料，調整庫存需要指定物料!!")
                Else
                    If 儲態編號_cb.Text = "" Then
                        MsgBox("倉儲狀態是一定要選擇的!!")
                    Else
                        If 訂製狀態_cb.Text = "" Then
                            MsgBox("物品的訂製狀態也是一定要選擇的!!")
                        Else
                            If 訂購數量_nud.Value = 0 Then
                                MsgBox("訂購數量為零是不容許的!!")
                            Else
                                存檔3()

                                PA1 = 單號_tb.Text : PA2 = 料號_tb.Text : PA3 = 倉庫編號_tb.Text
                                SQL_銷售明細表_確認單據是否申請()
                                If dr.Read() Then
                                    conn.Close() : MsgBox("該料號已經在本單據中申請過了，如果是標準規格品，請不要重複開兩次。。")
                                Else
                                End If
                                SQL_銷售明細表_最後一筆資料()
                                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 = "SA" & "00000000" & EDR
                                ElseIf EDR > 9 And EDR < 100 Then : ESTR = "SA" & "0000000" & EDR
                                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "SA" & "000000" & EDR
                                ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "SA" & "00000" & EDR
                                ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "SA" & "0000" & EDR
                                ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "SA" & "000" & EDR
                                ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "SA" & "00" & EDR
                                ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "SA" & "0" & EDR
                                ElseIf EDR > 99999999 Then : ESTR = "SA" & EDR : End If

                                Set_日期格式轉換()
                                PA3 = ESTR : PA4 = 單號_tb.Text : PA5 = 倉庫級別_tb.Text : PA6 = 倉庫編號_tb.Text : NU1 = 訂購數量_nud.Value : NU2 = 成本_nud.Value : NU3 = 售價_nud.Value
                                PA7 = 儲態編號_cb.Text : PA8 = 訂製編碼_cb.Text : BL2 = 含稅_ch.Checked : PA9 = "未有貨"

                                Dim 排序 As Integer
                                SQL_銷售明細表_排序()
                                If dr.Read() Then : 排序 = CLng(dr("排序")) + 1 : Else : 排序 = 1 : End If : PA11 = 排序

                                SQL_銷售單申請_銷售明細表_新增() : conn.Close()
                                Set_清單4() : Set_清單()
                                PA = 單號_tb.Text : SQL_銷售控制表_驗證解除()
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub
    Private Sub 刪除單據上點選的資料_bt_Click(sender As Object, e As EventArgs) Handles 刪除單據上點選的資料_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                If aa1 = MsgBoxResult.Ok Then
                    PA = 銷售資料流水號_tb.Text : PA1 = 倉儲資料流水號_tb.Text
                    SQL_銷售明細表_單筆刪除() : SQL_倉儲控制表_依銷售單號單筆刪除() : Set_清單() : Set_清單4()
                    PA = 單號_tb.Text : SQL_銷售控制表_驗證解除() : PA = "" : PA1 = ""
                End If
            End If
        End If
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            Dim aa1 As MsgBoxResult = MsgBox("刪除銷售單會連同該單據串連的採購，倉儲等聯繫單據都依同刪除，請再次確定是否刪除該單據?", MsgBoxStyle.OkCancel)
            If aa1 = MsgBoxResult.Ok Then
                Dim SSA As String
                SSA = InputBox("確定刪除資料請輸入 [YES] !")
                If SSA = "YES" Then
                    PA = 單號_tb.Text
                    SQL_銷售控制表_刪除() : SQL_銷售明細表_整體刪除() : SQL_銷售備註表_整體刪除() : SQL_倉儲控制表_依銷售單號刪除() : SQL_銷售收款事項_整體刪除()
                    Set_清單() : Set_清單1() : Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
                    conn.Close()
                End If
            End If
        End If
    End Sub
    Private Sub 銷售備註_bt_Click(sender As Object, e As EventArgs) Handles 銷售備註_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                PA = 單號_tb.Text
                SQL_銷售備註表_最後一筆資料()
                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 = "SR" & "00000000" & EDR
                ElseIf EDR > 9 And EDR < 100 Then : ESTR = "SR" & "0000000" & EDR
                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "SR" & "000000" & EDR
                ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "SR" & "00000" & EDR
                ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "SR" & "0000" & EDR
                ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "SR" & "000" & EDR
                ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "SR" & "00" & EDR
                ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "SR" & "0" & EDR
                ElseIf EDR > 99999999 Then : ESTR = "SR" & EDR : End If

                PA1 = ESTR
                SQL_銷售備註表_新增()

                For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
                    資料數 = 銷售備註_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售備註_dgv.Rows(i).Cells("備註").Value : PA11 = 銷售備註_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售備註_dgv.Rows(i).Cells("收入").Value : NU2 = 銷售備註_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售備註表_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                Set_清單5()
            End If
        End If
    End Sub
    Private Sub 刪除備註_bt_Click(sender As Object, e As EventArgs) Handles 刪除備註_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                If aa1 = MsgBoxResult.Ok Then
                    PA = 銷售備註流水號_tb.Text
                    SQL_銷售備註表_刪除() : Set_清單5()
                End If
            End If
        End If
    End Sub
    Private Sub 刪除收款事項上點選的資料_bt_Click(sender As Object, e As EventArgs) Handles 刪除收款事項上點選的資料_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                If 項次3_tb.Text = "" Then
                    MsgBox("沒有選擇收款事項，無法作業。")
                Else
                    If 刷卡可刪除_ch.Checked = False Then
                        If 項次3_tb.Text = "0" Then
                            MsgBox("不能刪除 [未收餘額] 或 [刷卡] 選項!!")
                        Else
                            Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                            If aa1 = MsgBoxResult.Ok Then
                                PA = 銷售收款流水號_tb.Text
                                SQL_銷售收款事項_刪除() : Set_清單6()
                            End If
                        End If
                    ElseIf 刷卡可刪除_ch.Checked = True Then
                        Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                        If aa1 = MsgBoxResult.Ok Then
                            PA = 銷售收款流水號_tb.Text
                            SQL_銷售收款事項_刪除() : Set_清單6()
                        End If
                    End If
                    刷卡可刪除_ch.Checked = False
                End If
            End If
        End If
    End Sub
    Private Sub 新增一筆收款事項_bt_Click(sender As Object, e As EventArgs) Handles 新增一筆收款事項_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                PA = 單號_tb.Text
                SQL_銷售收款事項_最後一筆資料()
                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 = "ST" & "00000000" & EDR
                ElseIf EDR > 9 And EDR < 100 Then : ESTR = "ST" & "0000000" & EDR
                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "ST" & "000000" & EDR
                ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "ST" & "00000" & EDR
                ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "ST" & "0000" & EDR
                ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "ST" & "000" & EDR
                ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "ST" & "00" & EDR
                ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "ST" & "0" & EDR
                ElseIf EDR > 99999999 Then : ESTR = "ST" & EDR : End If
                PA1 = ESTR
                PA = 單號_tb.Text
                SQL_銷售收款事項_最後一筆項次()
                If dr.Read() Then : EDR = dr("項次").ToString : Else : EDR = 0 : End If
                conn.Close() : EDR += 1
                If EDR < 10 Then : ESTR = EDR
                ElseIf EDR > 9 And EDR < 100 Then : ESTR = EDR : End If
                PA2 = ESTR
                SQL_銷售收款事項_新增2()

                For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                    資料數 = 收款事項_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 收款事項_dgv.Rows(i).Cells("內容").Value : PA11 = 收款事項_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 收款事項_dgv.Rows(i).Cells("金額").Value : PA12 = 收款事項_dgv.Rows(i).Cells("含稅").Value
                    SQL_銷售收款事項_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                Set_清單6()
            End If
        End If
    End Sub
    Private Sub 單據核准_bt_Click(sender As Object, e As EventArgs) Handles 單據核准_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                Set_日期格式轉換() : PA = gUserName : PA1 = 單號_tb.Text
                SQL_銷售控制表_審核確認() : Set_清單() : Set_清單1() : conn.Close()
                MsgBox("銷售單 [" & 單號_tb.Text & "] 審核完成，可繼續進行後續會計、採購等相關作業 。")
            End If
        End If
    End Sub
    Private Sub 單據作廢_bt_Click(sender As Object, e As EventArgs) Handles 單據作廢_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                Set_日期格式轉換() : PA = "作廢-" & gUserName : PA1 = 單號_tb.Text
                SQL_銷售控制表_審核確認()
                Set_日期格式轉換() : PA10 = "作廢 - " & gUserName : PA9 = "" : PA11 = 單號_tb.Text : DTP2 = ""
                SQL_銷售單審核_連帶作廢倉儲明細表() : Set_清單() : Set_清單1() : conn.Close()
                MsgBox("銷售單 [" & 單號_tb.Text & "] 已完成單據作廢，可在 [訂單控制表] 中找到歷史資料 。")
            End If
        End If
    End Sub
    Private Sub 讀取標準成本_bt_Click(sender As Object, e As EventArgs) Handles 讀取標準成本_bt.Click
        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            資料數 = 銷售明細_dgv.Rows.Count : MyModule1.進度條()
            PA12 = 銷售明細_dgv.Rows(i).Cells("料號").Value
            SQL_銷售明細表_成本讀取()
            If dr.Read() Then : 銷售明細_dgv.Rows(i).Cells("成本").Value = dr("成本")
            Else : 銷售明細_dgv.Rows(i).Cells("成本").Value = 0
            End If : conn.Close() : Set_合記計算()
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub Reset_bt_Click(sender As Object, e As EventArgs) Handles Reset_bt.Click
        Dim 不含1類銷售小記 As Integer : Dim 金額1 As Integer = 0 : Dim 無管物料 As Integer
        售價小計_tb.Text = "0" : 稅金_tb.Text = "0" : 銷售合計_tb.Text = "0" : 收入小計_tb.Text = "0" : 支出小計_tb.Text = "0" : 額外收支_tb.Text = "0" : 物料成本_tb.Text = "0"
        司機運費_tb.Text = "0" : 管銷費用_tb.Text = "0" : 其他成本_tb.Text = "0" : If 稅金另算有資料 = False Then : 稅金25_tb.Text = "0" : End If
        '-------001-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                刷卡總和_tb.Text = CLng(刷卡總和_tb.Text) + 收款事項_dgv("金額", i).Value
            End If
        Next
        刷卡稅金_tb.Text = CInt(CLng(CLng(刷卡總和_tb.Text) * 0.05)) : 刷卡傭金_tb.Text = CInt(CLng(CLng(刷卡總和_tb.Text) * 0.02))
        '-------002-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            銷售合計_tb.Text = CLng(銷售合計_tb.Text) + 銷售明細_dgv("售價", i).Value
            售價小計_tb.Text = CLng(售價小計_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value)
            If 銷售明細_dgv("無管銷", i).Value = False Then
                If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) <> "1001" Then
                    If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                    If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                    無管物料 = 無管物料 + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                End If
            End If
            If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) <> "1001" Then
                If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                物料成本_tb.Text = CLng(物料成本_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                不含1類銷售小記 = 不含1類銷售小記 + 銷售明細_dgv("售價", i).Value
            End If
            If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) = "1001" Then
                If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                其他成本_tb.Text = CLng(其他成本_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                '不含1類銷售小記 = 不含1類銷售小記 - 銷售明細_dgv("成本", i).Value
            End If

            If 銷售明細_dgv("含稅", i).Value = True Then
                稅金_tb.Text = CLng(稅金_tb.Text) + ((銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value * 1.05) - (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value))
            End If
        Next
        管銷費用_tb.Text = 無管物料 * 1.06 - 無管物料

        If CLng(稅金_tb.Text) = 0 And CLng(刷卡稅金_tb.Text) = 0 Then
            通知_lb.Text = "無稅金"
        ElseIf CLng(稅金_tb.Text) = 0 And CLng(刷卡稅金_tb.Text) <> 0 Then
            通知_lb.Text = "因清單中沒有打勾含稅，但有刷卡帶入的稅金，所以稅金以刷卡稅金為主"
            稅金_tb.Text = CLng(刷卡總和_tb.Text) / 21 : 售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
        ElseIf (CLng(稅金_tb.Text) <> 0 Or CLng(刷卡稅金_tb.Text) <> 0) And CLng(稅金_tb.Text) > CLng(刷卡稅金_tb.Text) Then
            通知_lb.Text = "因售價稅金大於刷卡稅金，計算正常，利潤中扣除刷卡傭金"
        ElseIf (CLng(稅金_tb.Text) <> 0 Or CLng(刷卡稅金_tb.Text) <> 0) And CLng(稅金_tb.Text) < CLng(刷卡稅金_tb.Text) Then
            通知_lb.Text = "刷卡稅金大於自動計算後的稅金，邏輯有誤，請從新拆售價。"
        End If

        If 稅金存檔 <> CLng(稅金_tb.Text) Then
            稅金_tb.Text = 稅金存檔
            售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
            銷售合計_tb.Text = CLng(售價小計_tb.Text) + CLng(稅金_tb.Text)
        ElseIf 稅金存檔 = CLng(稅金_tb.Text) Then
            稅金_tb.Text = 稅金存檔
            銷售合計_tb.Text = CLng(售價小計_tb.Text) + CLng(稅金_tb.Text)
            售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
        End If
        If 稅金另算有資料 = False Then
            '稅金25_tb.Text = CLng(稅金_tb.Text) / 2
        End If
        '-------003-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
            收入小計_tb.Text = CLng(收入小計_tb.Text) + 銷售備註_dgv("收入", i).Value
            支出小計_tb.Text = CLng(支出小計_tb.Text) + 銷售備註_dgv("支出", i).Value
        Next
        額外收支_tb.Text = CLng(收入小計_tb.Text) - CLng(支出小計_tb.Text)
        '-------004-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        Dim 金額 As Integer = 0
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("真項次", i).Value.ToString <> "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                金額 = 金額 + 收款事項_dgv("金額", i).Value
            ElseIf 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                金額 = 金額 + 收款事項_dgv("金額", i).Value
            ElseIf 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString = "未收餘額" Then
                收款事項_dgv("金額", i).Value = CInt(CLng(銷售合計_tb.Text)) - 金額
            End If
        Next
        '-------005-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        If 送貨地點_cb.Text = "" Or 送貨地點_cb.Text = "自取" Or 最低運費_cb.Text = "" Or 最低售價_cb.Text = "" Then
            司機運費_tb.Text = "0"
        Else
            If (不含1類銷售小記 - CLng(其他成本_tb.Text)) <= CLng(最低售價_cb.Text) Then
                司機運費_tb.Text = 最低運費_cb.Text
            ElseIf (不含1類銷售小記 - CLng(其他成本_tb.Text)) > CLng(最低售價_cb.Text) Then
                司機運費_tb.Text = (不含1類銷售小記 - CLng(稅金_tb.Text) - CLng(刷卡傭金_tb.Text) - CLng(其他成本_tb.Text)) / 100 * 3
            End If
        End If
        存檔1()
        '-------004-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        預估利潤_tb.Text = CLng(售價小計_tb.Text) + CLng(額外收支_tb.Text) - CLng(其他成本_tb.Text) - CLng(物料成本_tb.Text) -
                           CLng(司機運費_tb.Text) - CLng(管銷費用_tb.Text) - CLng(刷卡傭金_tb.Text) + CLng(稅金25_tb.Text)
        If 銷售衍生運費_dgv.Rows.Count > 0 Then
            For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                預估利潤_tb.Text = CLng(預估利潤_tb.Text) - 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
            Next
        End If
        '-------004-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        售價小計_tb.Text = Format(CLng(售價小計_tb.Text), "#,##0") : 稅金_tb.Text = Format(CLng(稅金_tb.Text), "#,##0") : 銷售合計_tb.Text = Format(CLng(銷售合計_tb.Text), "#,##0")
        收入小計_tb.Text = Format(CLng(收入小計_tb.Text), "#,##0") : 支出小計_tb.Text = Format(CLng(支出小計_tb.Text), "#,##0") : 額外收支_tb.Text = Format(CLng(額外收支_tb.Text), "#,##0")
        司機運費_tb.Text = Format(CLng(司機運費_tb.Text), "#,##0") : 管銷費用_tb.Text = Format(CLng(管銷費用_tb.Text), "#,##0") : 預估利潤_tb.Text = Format(CLng(預估利潤_tb.Text), "#,##0")
        物料成本_tb.Text = Format(CLng(物料成本_tb.Text), "#,##0") : 其他成本_tb.Text = Format(CLng(其他成本_tb.Text), "#,##0") : 刷卡總和_tb.Text = Format(CLng(刷卡總和_tb.Text), "#,##0")
        刷卡稅金_tb.Text = Format(CLng(刷卡稅金_tb.Text), "#,##0") : 刷卡傭金_tb.Text = Format(CLng(刷卡傭金_tb.Text), "#,##0") : 稅金25_tb.Text = Strings.Format(CLng(稅金25_tb.Text), "#,##0.0")
    End Sub
    Private Sub 司機運費_tb_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 司機運費_tb.KeyPress
        If e.KeyChar = Chr(13) Then
            運費 = 司機運費_tb.Text : 存檔1() : Set_合記計算()
        End If
    End Sub
    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        銷售單據_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        銷售明細_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        銷售衍生運費_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        區域庫存_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        收款事項_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        銷售備註_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        物料清單_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
    End Sub
    Private Sub Reset1_bt_Click(sender As Object, e As EventArgs) Handles Reset1_bt.Click
        Dim 不含1類銷售小記 As Integer : Dim 金額1 As Integer = 0 : Dim 無管物料 As Integer
        售價小計_tb.Text = "0" : 稅金_tb.Text = "0" : 銷售合計_tb.Text = "0" : 收入小計_tb.Text = "0" : 支出小計_tb.Text = "0" : 額外收支_tb.Text = "0" : 物料成本_tb.Text = "0"
        司機運費_tb.Text = "0" : 管銷費用_tb.Text = "0" : 其他成本_tb.Text = "0" : 刷卡總和_tb.Text = "0" : 刷卡稅金_tb.Text = "0" : 刷卡傭金_tb.Text = "0"
        If 稅金另算有資料 = False Then : 稅金25_tb.Text = "0" : End If
        '-------001-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                刷卡總和_tb.Text = CLng(刷卡總和_tb.Text) + 收款事項_dgv("金額", i).Value
            End If
        Next
        刷卡稅金_tb.Text = CInt(CLng(CLng(刷卡總和_tb.Text) * 0.05)) : 刷卡傭金_tb.Text = CInt(CLng(刷卡總和_tb.Text) * 0.02)
        '-------002-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            銷售合計_tb.Text = CLng(銷售合計_tb.Text) + 銷售明細_dgv("售價", i).Value
            售價小計_tb.Text = CLng(售價小計_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value)
            If 銷售明細_dgv("無管銷", i).Value = False Then
                If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) <> "1001" Then
                    If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                    If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                    無管物料 = 無管物料 + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                End If
            End If
            If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) <> "1001" Then
                If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                物料成本_tb.Text = CLng(物料成本_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                不含1類銷售小記 = 不含1類銷售小記 + 銷售明細_dgv("售價", i).Value
            End If
            If Strings.Left(銷售明細_dgv("料號", i).Value.ToString, 4) = "1001" Then
                If IsDBNull(銷售明細_dgv("數量", i).Value) = True Then : 銷售明細_dgv("數量", i).Value = "0" : End If
                If IsDBNull(銷售明細_dgv("成本", i).Value) = True Then : 銷售明細_dgv("成本", i).Value = "0" : End If
                其他成本_tb.Text = CLng(其他成本_tb.Text) + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                '不含1類銷售小記 = 不含1類銷售小記 - 銷售明細_dgv("成本", i).Value
            End If

            If 銷售明細_dgv("含稅", i).Value = True Then
                稅金_tb.Text = CLng(稅金_tb.Text) + ((銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value * 1.05) - (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("單價", i).Value))
            End If
        Next
        管銷費用_tb.Text = 無管物料 * 1.06 - 無管物料
        銷售合計_tb.Text = CLng(售價小計_tb.Text) + CLng(稅金_tb.Text)

        If CLng(稅金_tb.Text) = 0 And CLng(刷卡稅金_tb.Text) = 0 Then
            通知_lb.Text = "無稅金"
        ElseIf CLng(稅金_tb.Text) = 0 And CLng(刷卡稅金_tb.Text) <> 0 Then
            通知_lb.Text = "因清單中沒有打勾含稅，但有刷卡帶入的稅金，所以稅金以刷卡稅金為主"
            稅金_tb.Text = CLng(刷卡總和_tb.Text) / 21 : 售價小計_tb.Text = CLng(銷售合計_tb.Text) - CLng(稅金_tb.Text)
        ElseIf (CLng(稅金_tb.Text) <> 0 Or CLng(刷卡稅金_tb.Text) <> 0) And CLng(稅金_tb.Text) > CLng(刷卡稅金_tb.Text) Then
            通知_lb.Text = "因售價稅金大於刷卡稅金，計算正常，利潤中扣除刷卡傭金"
        ElseIf (CLng(稅金_tb.Text) <> 0 Or CLng(刷卡稅金_tb.Text) <> 0) And CLng(稅金_tb.Text) < CLng(刷卡稅金_tb.Text) Then
            通知_lb.Text = "刷卡稅金大於自動計算後的稅金，邏輯有誤，請從新拆售價。"
        End If

        稅金存檔 = CLng(稅金_tb.Text)
        If 稅金另算有資料 = False Then
            '稅金25_tb.Text = CLng(稅金_tb.Text) / 2
        End If
        '-------003-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To 銷售備註_dgv.Rows.Count - 1
            收入小計_tb.Text = CLng(收入小計_tb.Text) + 銷售備註_dgv("收入", i).Value
            支出小計_tb.Text = CLng(支出小計_tb.Text) + 銷售備註_dgv("支出", i).Value
        Next
        額外收支_tb.Text = CLng(收入小計_tb.Text) - CLng(支出小計_tb.Text)
        '-------004-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        Dim 金額 As Integer = 0
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("真項次", i).Value.ToString <> "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                金額 = 金額 + 收款事項_dgv("金額", i).Value
            ElseIf 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" Then
                金額 = 金額 + 收款事項_dgv("金額", i).Value
            ElseIf 收款事項_dgv("真項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString = "未收餘額" Then
                收款事項_dgv("金額", i).Value = CInt(CLng(銷售合計_tb.Text)) - 金額
            End If
        Next
        '-------005-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        If 送貨地點_cb.Text = "" Or 送貨地點_cb.Text = "自取" Or 最低運費_cb.Text = "" Or 最低售價_cb.Text = "" Then
            司機運費_tb.Text = "0"
        Else
            If 運費 = 0 Then
                If (不含1類銷售小記 - CLng(其他成本_tb.Text)) <= CLng(最低售價_cb.Text) Then
                    司機運費_tb.Text = 最低運費_cb.Text
                ElseIf (不含1類銷售小記 - CLng(其他成本_tb.Text)) > CLng(最低售價_cb.Text) Then
                    司機運費_tb.Text = (不含1類銷售小記 - CLng(稅金_tb.Text) - CLng(刷卡傭金_tb.Text) - CLng(其他成本_tb.Text)) / 100 * 3
                End If
            Else
                司機運費_tb.Text = 運費
            End If
        End If
        '-------006-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        預估利潤_tb.Text = CLng(售價小計_tb.Text) + CLng(額外收支_tb.Text) - CLng(其他成本_tb.Text) - CLng(物料成本_tb.Text) -
                           CLng(司機運費_tb.Text) - CLng(管銷費用_tb.Text) - CLng(刷卡傭金_tb.Text) + CLng(稅金25_tb.Text)
        If 銷售衍生運費_dgv.Rows.Count > 0 Then
            For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                預估利潤_tb.Text = CLng(預估利潤_tb.Text) - 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
            Next
        End If
        '-------007-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        售價小計_tb.Text = Format(CLng(售價小計_tb.Text), "#,##0") : 稅金_tb.Text = Format(CLng(稅金_tb.Text), "#,##0") : 銷售合計_tb.Text = Format(CLng(銷售合計_tb.Text), "#,##0")
        收入小計_tb.Text = Format(CLng(收入小計_tb.Text), "#,##0") : 支出小計_tb.Text = Format(CLng(支出小計_tb.Text), "#,##0") : 額外收支_tb.Text = Format(CLng(額外收支_tb.Text), "#,##0")
        司機運費_tb.Text = Format(CLng(司機運費_tb.Text), "#,##0") : 管銷費用_tb.Text = Format(CLng(管銷費用_tb.Text), "#,##0") : 預估利潤_tb.Text = Format(CLng(預估利潤_tb.Text), "#,##0")
        物料成本_tb.Text = Format(CLng(物料成本_tb.Text), "#,##0") : 其他成本_tb.Text = Format(CLng(其他成本_tb.Text), "#,##0") : 刷卡總和_tb.Text = Format(CLng(刷卡總和_tb.Text), "#,##0")
        刷卡稅金_tb.Text = Format(CLng(刷卡稅金_tb.Text), "#,##0") : 刷卡傭金_tb.Text = Format(CLng(刷卡傭金_tb.Text), "#,##0") : 稅金25_tb.Text = Strings.Format(CLng(稅金25_tb.Text), "#,##0.0")
    End Sub
    Private Sub 刷卡收款_bt_Click(sender As Object, e As EventArgs) Handles 刷卡收款_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            PA = 單號_tb.Text
            SQL_銷售收款事項_最後一筆資料()
            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 = "ST" & "00000000" & EDR
            ElseIf EDR > 9 And EDR < 100 Then : ESTR = "ST" & "0000000" & EDR
            ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "ST" & "000000" & EDR
            ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "ST" & "00000" & EDR
            ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "ST" & "0000" & EDR
            ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "ST" & "000" & EDR
            ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "ST" & "00" & EDR
            ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "ST" & "0" & EDR
            ElseIf EDR > 99999999 Then : ESTR = "ST" & EDR : End If
            PA1 = ESTR
            PA = 單號_tb.Text
            SQL_銷售收款事項_最後一筆項次()
            If dr.Read() Then : EDR = dr("項次").ToString : Else : EDR = 0 : End If
            conn.Close() : EDR += 1
            If EDR < 10 Then : ESTR = EDR
            ElseIf EDR > 9 And EDR < 100 Then : ESTR = EDR : End If
            PA2 = ESTR
            SQL_銷售收款事項_新增3()

            For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                資料數 = 收款事項_dgv.Rows.Count : MyModule1.進度條()
                PA10 = 收款事項_dgv.Rows(i).Cells("內容").Value : PA11 = 收款事項_dgv.Rows(i).Cells("資料流水號").Value
                NU1 = 收款事項_dgv.Rows(i).Cells("金額").Value : PA12 = 收款事項_dgv.Rows(i).Cells("含稅").Value
                SQL_銷售收款事項_修改() : conn.Close()
            Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : Set_清單6()
            刷卡控制 = True : 含稅_ch.Checked = True : 刷卡控制 = False
        End If
    End Sub
    Private Sub 已審核資料_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 已審核資料_ch.CheckedChanged
        Set_清單1()
    End Sub
    Private Sub 隱藏_bt_Click(sender As Object, e As EventArgs) Handles 隱藏_bt.Click
        顯示_bt.Enabled = True : 隱藏_bt.Enabled = False
        Panel2.Visible = False
        Panel3.Location = New Point(2, 2)
        NU1 = Panel3.Size.Width
        NU2 = Panel3.Size.Height
        NU1 = Panel3.Size.Width + 543
        Panel3.Size = New Size(NU1, NU2)
    End Sub
    Private Sub 顯示_bt_Click(sender As Object, e As EventArgs) Handles 顯示_bt.Click
        顯示_bt.Enabled = False : 隱藏_bt.Enabled = True
        Panel2.Visible = True
        Panel3.Location = New Point(546, 2)
        NU1 = Panel3.Size.Width
        NU2 = Panel3.Size.Height
        NU1 = Panel3.Size.Width - 543
        Panel3.Size = New Size(NU1, NU2)
    End Sub
    Private Sub Panel3_Size(sender As Object, e As EventArgs) Handles Panel3.SizeChanged
        If Panel3.Size.Width > 914 Then
            物料圖1_pb.Visible = True : 物料圖1_pb.Size = New Size(300, 167)
        Else
            物料圖1_pb.Visible = False
        End If
    End Sub
    Private Sub 新增衍生運費_bt_Click(sender As Object, e As EventArgs) Handles 新增衍生運費_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                PA = 單號_tb.Text
                SQL_銷售衍生運費_最後一筆資料()
                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 = "SE" & "00000000" & EDR
                ElseIf EDR > 9 And EDR < 100 Then : ESTR = "SE" & "0000000" & EDR
                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "SE" & "000000" & EDR
                ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "SE" & "00000" & EDR
                ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "SE" & "0000" & EDR
                ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "SE" & "000" & EDR
                ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "SE" & "00" & EDR
                ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "SE" & "0" & EDR
                ElseIf EDR > 99999999 Then : ESTR = "SE" & EDR : End If

                PA1 = ESTR
                SQL_銷售衍生運費_新增()

                For i As Integer = 0 To 銷售衍生運費_dgv.Rows.Count - 1
                    資料數 = 銷售衍生運費_dgv.Rows.Count : MyModule1.進度條()
                    PA10 = 銷售衍生運費_dgv.Rows(i).Cells("運費備註").Value : PA11 = 銷售衍生運費_dgv.Rows(i).Cells("資料流水號").Value
                    NU1 = 銷售衍生運費_dgv.Rows(i).Cells("支出").Value
                    SQL_銷售衍生運費_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                Set_清單7()
            End If
        End If
    End Sub
    Private Sub 刪除衍生運費_bt_Click(sender As Object, e As EventArgs) Handles 刪除衍生運費_bt.Click
        If 流水號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            If 客戶編號_tb.Text = "" Then
                MsgBox("銷售單據要指定完客戶才可存檔，如你已手動輸入客戶資料請按一下  [客戶驗證]  ，系統會自動判斷客戶資訊。")
            Else
                Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                If aa1 = MsgBoxResult.Ok Then
                    PA = 運費資料流水號_tb.Text
                    SQL_銷售衍生費用_刪除() : Set_清單7()
                End If
            End If
        End If
    End Sub
End Class