Option Strict Off
Public Class 訂單控制表
    ReadOnly ds1, ds2, ds4, ds5, ds6, ds7 As New DataSet : Dim 稅金另算有資料 As Boolean
    Dim 首次開啟 As Boolean = False : Dim 運費 As Integer : Dim 稅金存檔 As Integer
    Private Sub Set_清單1()
        銷售單據_dgv.DataSource = Nothing : ds1.Clear()
        銷售單據_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售單據_dgv.ColumnHeadersHeight = 25
        銷售單據_dgv.AllowUserToAddRows = False
        銷售單據_dgv.RowTemplate.Height = 35

        PA19 = 業務_cb.Text : PA20 = 客戶1_tb.Text : PA21 = 物料關鍵字_tb.Text : PA22 = 帳務關鍵字_tb.Text
        If 帳務關鍵字_tb.Text = "" Then : SQL_銷售控制表_訂單控制表() : Else : SQL_銷售控制表_訂單控制表1() : End If

        da.Fill(ds1) : 銷售單據_dgv.DataSource = ds1.Tables(0) : conn.Close()

        銷售單據_dgv.Columns(0).Visible = False : 銷售單據_dgv.Columns(1).FillWeight = 85 : 銷售單據_dgv.Columns(2).FillWeight = 100 : 銷售單據_dgv.Columns(3).FillWeight = 100
        銷售單據_dgv.Columns(4).FillWeight = 100 : 銷售單據_dgv.Columns(5).FillWeight = 65 : 銷售單據_dgv.Columns(6).Visible = False : 銷售單據_dgv.Columns(7).Visible = False
        銷售單據_dgv.Columns(8).Visible = False : 銷售單據_dgv.Columns(9).FillWeight = 100 : 銷售單據_dgv.Columns(10).Visible = False : 銷售單據_dgv.Columns(11).Visible = False
        銷售單據_dgv.Columns(12).Visible = False : 銷售單據_dgv.Columns(13).Visible = False : 銷售單據_dgv.Columns(14).Visible = False : 銷售單據_dgv.Columns(15).Visible = False
        銷售單據_dgv.Columns(16).Visible = False : 銷售單據_dgv.Columns(17).Visible = False : 銷售單據_dgv.Columns(18).Visible = False : 銷售單據_dgv.Columns(19).FillWeight = 65
        銷售單據_dgv.Columns(20).Visible = False : 銷售單據_dgv.Columns(21).FillWeight = 65 : 銷售單據_dgv.Columns("銷貨總額").FillWeight = 80 : 銷售單據_dgv.Columns("稅金另扣").Visible = False
        銷售單據_dgv.Columns("未收額額").DefaultCellStyle.Format = "#,##0"
        銷售單據_dgv.Columns("未收額額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售單據_dgv.Columns("未收額額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售單據_dgv.Columns("銷貨總額").DefaultCellStyle.Format = "#,##0"
        銷售單據_dgv.Columns("銷貨總額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售單據_dgv.Columns("銷貨總額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        For i As Integer = 0 To 銷售單據_dgv.Rows.Count - 1
            If IsDBNull(銷售單據_dgv("銷貨總額", i).Value) = True Then : 銷售單據_dgv("銷貨總額", i).Value = "0" : End If
            If IsDBNull(銷售單據_dgv("轉業績日期", i).Value) Then : 銷售單據_dgv("轉業績日期", i).Value = "" : End If
            If IsDBNull(銷售單據_dgv("已結單", i).Value) Then : 銷售單據_dgv("已結單", i).Value = False : Else : 銷售單據_dgv("已結單", i).Value = False : End If
            If 銷售單據_dgv("轉業績日期", i).Value.ToString <> "" Then : 銷售單據_dgv("已結單", i).Value = True : End If
        Next
    End Sub
    Private Sub Set_清單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_清單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()

        銷售明細_dgv.Columns(0).Visible = False : 銷售明細_dgv.Columns(1).FillWeight = 40 : 銷售明細_dgv.Columns(2).FillWeight = 110 : 銷售明細_dgv.Columns(3).FillWeight = 200
        銷售明細_dgv.Columns(4).FillWeight = 120 : 銷售明細_dgv.Columns(5).FillWeight = 120 : 銷售明細_dgv.Columns(6).FillWeight = 120 : 銷售明細_dgv.Columns(7).FillWeight = 190
        銷售明細_dgv.Columns(8).FillWeight = 80 : 銷售明細_dgv.Columns(9).FillWeight = 80 : 銷售明細_dgv.Columns(10).FillWeight = 80 : 銷售明細_dgv.Columns(11).FillWeight = 50
        銷售明細_dgv.Columns(12).FillWeight = 80 : 銷售明細_dgv.Columns(13).Visible = False : 銷售明細_dgv.Columns(14).Visible = False : 銷售明細_dgv.Columns(15).Visible = False
        銷售明細_dgv.Columns(16).Visible = False : 銷售明細_dgv.Columns(17).Visible = False : 銷售明細_dgv.Columns(18).FillWeight = 50

        銷售明細_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(6).ReadOnly = True : 銷售明細_dgv.Columns(8).ReadOnly = True : 銷售明細_dgv.Columns(12).ReadOnly = True
        銷售明細_dgv.Columns(13).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
    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 : 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
        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
        Set_合記計算()
    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 Set_日期格式轉換()
        DTP = Format(開單日期_dtp.Value, "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
                    無管物料 = 無管物料 + (銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value)
                End If
            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 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_下拉表單資料載入()
        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
        中間距_ch.Checked = True '--------------------控件隱藏、操作許可設定與其他基本顯示設定
        送貨地點_cb_下拉表單資料載入() : 業務_cb_下拉表單資料載入()
        首次開啟 = False : 業務_cb.Text = 業務號碼 : 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 = 8
        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 YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 8
        End If
    End Sub
    Dim 已超出 As Boolean
    Private Sub 銷售單據_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 銷售單據_dgv.MouseUp
        If 銷售單據_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 銷售單據_dgv.SelectedCells.Count > 0 Then
            If 銷售單據_dgv.SelectedCells(0).ColumnIndex = 9 Or 銷售單據_dgv.SelectedCells(0).ColumnIndex = 22 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 銷售單據_dgv.SelectedCells.Count - 1
                        x += CLng(銷售單據_dgv.Rows(銷售單據_dgv.SelectedCells.Item(i).RowIndex).Cells(銷售單據_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
        'If 銷售單據_dgv.SelectedCells.Count = 1 Then : MsgBox(銷售單據_dgv.SelectedCells(0).ColumnIndex & "  " & 銷售單據_dgv.SelectedCells(0).RowIndex) : End If
    End Sub
    Private Sub 銷售明細_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 銷售明細_dgv.MouseUp
        If 銷售明細_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 銷售明細_dgv.SelectedCells.Count > 0 Then
            If 銷售明細_dgv.SelectedCells(0).ColumnIndex = 12 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 銷售明細_dgv.SelectedCells.Count - 1
                        x += CLng(銷售明細_dgv.Rows(銷售明細_dgv.SelectedCells.Item(i).RowIndex).Cells(銷售明細_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
        'If 銷售明細_dgv.SelectedCells.Count = 1 Then : MsgBox(銷售明細_dgv.SelectedCells(0).ColumnIndex & "  " & 銷售明細_dgv.SelectedCells(0).RowIndex) : End If
    End Sub
    Private Sub 銷售備註_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 銷售備註_dgv.MouseUp
        If 銷售備註_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 銷售備註_dgv.SelectedCells.Count > 0 Then
            If 銷售備註_dgv.SelectedCells(0).ColumnIndex >= 3 And 銷售備註_dgv.SelectedCells(0).ColumnIndex <= 4 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 銷售備註_dgv.SelectedCells.Count - 1
                        x += CLng(銷售備註_dgv.Rows(銷售備註_dgv.SelectedCells.Item(i).RowIndex).Cells(銷售備註_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
        'If 銷售備註_dgv.SelectedCells.Count = 1 Then : MsgBox(銷售備註_dgv.SelectedCells(0).ColumnIndex & "  " & 銷售備註_dgv.SelectedCells(0).RowIndex) : End If
    End Sub
    Private Sub 銷售衍生運費_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 銷售衍生運費_dgv.MouseUp
        If 銷售衍生運費_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 銷售衍生運費_dgv.SelectedCells.Count > 0 Then
            If 銷售衍生運費_dgv.SelectedCells(0).ColumnIndex = 4 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 銷售衍生運費_dgv.SelectedCells.Count - 1
                        x += CLng(銷售衍生運費_dgv.Rows(銷售衍生運費_dgv.SelectedCells.Item(i).RowIndex).Cells(銷售衍生運費_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
        'If 銷售衍生運費_dgv.SelectedCells.Count = 1 Then : MsgBox(銷售衍生運費_dgv.SelectedCells(0).ColumnIndex & "  " & 銷售衍生運費_dgv.SelectedCells(0).RowIndex) : End If
    End Sub
    Private Sub 收款事項_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 收款事項_dgv.MouseUp
        'If 收款事項_dgv.SelectedCells.Count = 1 Then : MsgBox(收款事項_dgv.SelectedCells(0).ColumnIndex & "  " & 收款事項_dgv.SelectedCells(0).RowIndex) : End If
        If 收款事項_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 收款事項_dgv.SelectedCells.Count > 0 Then
            If 收款事項_dgv.SelectedCells(0).ColumnIndex = 5 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 收款事項_dgv.SelectedCells.Count - 1
                        x += CLng(收款事項_dgv.Rows(收款事項_dgv.SelectedCells.Item(i).RowIndex).Cells(收款事項_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
    End Sub
    Private Sub 收款事項_dgv_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 銷售備註_dgvCellEndEdit(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
            項次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 * 銷售明細_dgv("單價", i).Value * 1.05
            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

            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
            PA1 = 流水號_tb.Text : NU5 = 銷售合計_tb.Text
            SQL_銷貨總額_修改()
        End If
    End Sub
    Private Sub 批量刷銷售_bt_Click(sender As Object, e As EventArgs) Handles 批量刷銷售_bt.Click
        資料數 = 銷售單據_dgv.Rows.Count : MyModule1.進度條()
        For I As Integer = 0 To 銷售單據_dgv.Rows.Count - 1 : MyModule1.進度條()
            稅金存檔 = 銷售單據_dgv.Rows(I).Cells("稅金").Value
            流水號_tb.Text = 銷售單據_dgv.Rows(I).Cells("流水號").Value : 單號_tb.Text = 銷售單據_dgv.Rows(I).Cells("單號").Value
            開單日期_dtp.Value = 銷售單據_dgv.Rows(I).Cells("開單日期").Value : 客戶編號_tb.Text = 銷售單據_dgv.Rows(I).Cells("客戶編號").Value
            交貨日期_dtp.Value = 銷售單據_dgv.Rows(I).Cells("交貨日期").Value : 含稅_ch.Checked = 銷售單據_dgv.Rows(I).Cells("含稅").Value
            送貨地點_cb_下拉表單資料載入() : 送貨地點_cb.Text = 銷售單據_dgv.Rows(I).Cells("送貨地點").Value.ToString
            運費 = 銷售單據_dgv.Rows(I).Cells("運費").Value

            If 銷售單據_dgv.Rows(I).Cells("稅金另扣").Value.ToString <> "" Then
                稅金另算有資料 = True : 稅金25_tb.Text = 銷售單據_dgv.Rows(I).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
            PA1 = 流水號_tb.Text : NU5 = 銷售合計_tb.Text
            SQL_銷貨總額_修改()
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub 窄間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距_ch.Click
        小間距_ch.Checked = True : 中間距_ch.Checked = False : 大間距_ch.Checked = False
        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
        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
        Set_清單4()
    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 業務_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
        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
                銷售明細_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
        Next : Set_合記計算()
    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)
    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 物料關鍵字_tb_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 物料關鍵字_tb.KeyPress
        If e.KeyChar = Chr(13) Then : Set_清單1() : End If
    End Sub
    Private Sub 客戶1_tb_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 客戶1_tb.KeyPress
        If e.KeyChar = Chr(13) Then : Set_清單1() : End If
    End Sub
    Private Sub 重新整理_tsm_Click(sender As Object, e As EventArgs) Handles 重新整理_tsm.Click
        Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
    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 + 556
        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(559, 2)
        NU1 = Panel3.Size.Width
        NU2 = Panel3.Size.Height
        NU1 = Panel3.Size.Width - 556
        Panel3.Size = New Size(NU1, NU2)
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        Set_清單1() : 帳務關鍵字_tb.Text = ""
    End Sub
    Private Sub 查詢1_bt_Click(sender As Object, e As EventArgs) Handles 查詢1_bt.Click
        Set_清單1() : 帳務關鍵字_tb.Text = ""
    End Sub
End Class