Public Class 應收帳款未收
    ReadOnly ds1, ds2, ds3, ds4, ds5, ds6, ds7, ds8 As New DataSet
    Dim EDR As Integer : Dim ESTR As String : Dim 首次開啟 As Boolean = False : Dim ESTR1 As String : Dim EDR1 As Integer : ReadOnly ds As New DataSet
    Dim 刪除狀態 As Boolean : Dim 新項次 As String : Dim 新流水1 As String : Dim 新流水2 As String : Dim NUM1 As Integer : Dim 匯率1 As Double
    Private Sub Set_清單1()
        銷售單據_dgv.DataSource = Nothing : ds1.Clear()
        銷售單據_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售單據_dgv.ColumnHeadersHeight = 40
        銷售單據_dgv.AllowUserToAddRows = False
        銷售單據_dgv.RowTemplate.Height = 30

        PA19 = 業務_cb.Text : PA20 = 客戶1_tb.Text
        SQL_應收帳款未收_訂單控制表()
        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 = 110
        銷售單據_dgv.Columns(4).FillWeight = 110 : 銷售單據_dgv.Columns(5).FillWeight = 100 : 銷售單據_dgv.Columns(6).Visible = False : 銷售單據_dgv.Columns(7).FillWeight = 85
        銷售單據_dgv.Columns(8).FillWeight = 85 : 銷售單據_dgv.Columns(9).FillWeight = 100 : 銷售單據_dgv.Columns(10).FillWeight = 85 : 銷售單據_dgv.Columns(11).FillWeight = 85
        銷售單據_dgv.Columns(12).Visible = False : 銷售單據_dgv.Columns(13).FillWeight = 85 : 銷售單據_dgv.Columns(14).FillWeight = 85 : 銷售單據_dgv.Columns(15).Visible = False
        銷售單據_dgv.Columns(16).FillWeight = 85 : 銷售單據_dgv.Columns(17).FillWeight = 85 : 銷售單據_dgv.Columns(18).Visible = False : 銷售單據_dgv.Columns(19).FillWeight = 40
        銷售單據_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
        For I As Integer = 0 To 銷售單據_dgv.Rows.Count - 1
            If IsDBNull(銷售單據_dgv("轉財務", I).Value) = True Then
                銷售單據_dgv("轉財務", I).Value = False
            End If
            If 銷售單據_dgv("轉財務", I).Value = True Then
                銷售單據_dgv.Rows(I).DefaultCellStyle.BackColor = Color.LightGreen
            Else
                銷售單據_dgv.Rows(I).DefaultCellStyle.BackColor = Color.White
            End If
        Next
    End Sub
    Private Sub Set_清單2()
        收款事項_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 = 120
        收款事項_dgv.Columns(4).FillWeight = 960 : 收款事項_dgv.Columns(5).FillWeight = 180 : 收款事項_dgv.Columns(6).FillWeight = 250 : 收款事項_dgv.Columns(7).FillWeight = 50
        收款事項_dgv.Columns(8).FillWeight = 50
        收款事項_dgv.Columns(3).ReadOnly = True : 收款事項_dgv.Columns(7).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
        If 刪除狀態 = False Then
            銷售合計1_tb.Text = "0" : 售價小計_tb.Text = "0"
            For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                收款事項_dgv("項次", i).Value = i + 1
                銷售合計1_tb.Text = Val(銷售合計1_tb.Text) + 收款事項_dgv("金額", i).Value
                售價小計_tb.Text = Val(售價小計_tb.Text) + 收款事項_dgv("金額", i).Value
            Next
            銷售合計1_tb.Text = Format(Val(銷售合計1_tb.Text), "#,##0")
        Else
            For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                收款事項_dgv("項次", i).Value = i + 1
            Next
        End If
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If IsDBNull(收款事項_dgv.Rows(i).Cells("轉財務").Value) Then
                收款事項_dgv.Rows(i).Cells("轉財務").Value = False
            End If
            If IsDBNull(收款事項_dgv("含稅", i).Value) = True Then
                收款事項_dgv("含稅", i).Value = False
            End If
        Next : 收款事項_dgv.EditMode = DataGridViewEditMode.EditOnEnter : Set_合記計算()
    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
        PA2 = "" : PA2 = 單號_tb.Text : SQL_銷售衍生費用()
        da.Fill(ds3) : 衍生運費_dgv.DataSource = ds3.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
        For i As Integer = 0 To 衍生運費_dgv.Rows.Count - 1
            If IsDBNull(衍生運費_dgv.Rows(i).Cells("轉財務").Value) Then : 衍生運費_dgv.Rows(i).Cells("轉財務").Value = False : End If
            If IsDBNull(衍生運費_dgv("含稅", i).Value) = True Then : 衍生運費_dgv("含稅", i).Value = False : End If
        Next : 衍生運費_dgv.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub Set_清單4()
        其他費用_dgv.DataSource = Nothing : ds8.Clear()
        其他費用_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        其他費用_dgv.ColumnHeadersHeight = 25
        其他費用_dgv.AllowUserToAddRows = False
        其他費用_dgv.RowTemplate.Height = 25
        PA2 = "" : PA2 = 單號_tb.Text : SQL_銷售備註表()
        da.Fill(ds8) : 其他費用_dgv.DataSource = ds8.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
        For i As Integer = 0 To 其他費用_dgv.Rows.Count - 1
            If IsDBNull(其他費用_dgv.Rows(i).Cells("轉財務").Value) Then : 其他費用_dgv.Rows(i).Cells("轉財務").Value = False : End If
            If IsDBNull(其他費用_dgv("含稅", i).Value) = True Then : 其他費用_dgv("含稅", i).Value = False : End If
        Next
        其他費用_dgv.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn.Close()
        SQL_應收帳款未收_查詢公帳控制表會計科目() : ComboBox1.Items.Clear() : ComboBox6.Items.Clear()
        While (dr.Read()) : ComboBox1.Items.Add(dr("會計科目")) : ComboBox6.Items.Add(dr("編號")) : End While : conn.Close()
        If ComboBox1.Items.Count <> 0 Then : ComboBox1.SelectedIndex = 0 : End If
    End Sub
    Private Sub ComboBox2下拉表單資料載入()
        conn.Close()
        SQL_應收帳款未收_查詢最後一筆公帳控制表會計科目() : 會科1_ch.Items.Clear() : 會科碼1_ch.Items.Clear() : 會科1_ch.Text = "" : 會科碼1_ch.Text = ""
        While (dr.Read()) : 會科1_ch.Items.Add(dr("第一階")) : 會科碼1_ch.Items.Add(dr("編號")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox3下拉表單資料載入()
        conn.Close()
        SQL_應收帳款未收_查詢最左邊公帳控制表會計科目() : ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : ComboBox3.Text = "" : ComboBox4.Text = ""
        While (dr.Read()) : ComboBox3.Items.Add(dr("第二階")) : ComboBox4.Items.Add(dr("編號")) : End While : conn.Close()
    End Sub
    Private Sub 開立零用金支付單()
        Dim NUM1 As Integer : Timer1.Enabled = True
        Set_日期格式轉換()
        For i As Integer = 1 To 999
            NUM1 = 0 + i
            If NUM1 < 10 Then : 營運成本收支單號_tb.Text = "OE-" & DTP1 & "-00" & NUM1
            ElseIf NUM1 > 9 And NUM1 < 100 Then : 營運成本收支單號_tb.Text = "OE-" & DTP1 & "-0" & NUM1
            ElseIf NUM1 > 99 Then : 營運成本收支單號_tb.Text = "OE-" & DTP1 & "-" & NUM1
            End If
            conn.Close()
            PA = 營運成本收支單號_tb.Text
            SQL_營運成本收支單申請_查詢第一筆公帳支付單號()
            If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
        Next
        PA = 營運成本收支單號_tb.Text
        SQL_營運成本收支單申請_新增一筆公帳控制表() : conn.Close()
    End Sub
    Private Sub Set_日期格式轉換()
        DTP1 = Format(申請日期_dtp.Value, "yyyyMMdd") : DTP4 = Format(申請日期_dtp.Value, "yyyy/MM/dd")
    End Sub
    Private Sub Set_合記計算()
        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(Val(售價小計_tb.Text)) - 金額
            End If
        Next
    End Sub
    Private Sub 匯率()
        PA1 = Strings.Left(Format(申請日期_dtp.Value, "yyyyMMdd"), 4)
        PA2 = Strings.Mid(Format(申請日期_dtp.Value, "yyyyMMdd"), 5, 2)
        SQL_營運成本收支單申請_查詢匯率()
        If dr.Read() Then
            人民幣匯率_tb.Text = dr("中心匯率").ToString : 美金匯率_tb.Text = dr("美金匯率").ToString : conn.Close() : dr.Close()
        Else
            conn.Close() : dr.Close() : 匯率管理.Close() : 匯率管理.Show() : 匯率管理.BringToFront()
        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
        營運成本收支單號_tb.Text = "" : 申請人_tb.Text = "" : SQL2 = ""
        SQL_應收帳款未收_轉財務Null為False() : 業務_cb_下拉表單資料載入()
        首次開啟 = False : 業務_cb.Text = 業務號碼 : Set_清單1() : 首次開啟 = True '--------------------資料讀取
        ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : ComboBox3.Text = "" : ComboBox4.Text = ""
        會科1_ch.Items.Clear() : 會科碼1_ch.Items.Clear() : 會科1_ch.Text = "" : 會科碼1_ch.Text = ""
        銷售合計1_tb.Enabled = False : ComboBox6.Visible = False : 銷售收款_bt.Enabled = False : 衍生運費_bt.Enabled = True
        其他費用_bt.Enabled = True : 收款事項_dgv.Visible = True : 衍生運費_dgv.Visible = False : 其他費用_dgv.Visible = False
        ComboBox2下拉表單資料載入() : 幣別_cb.SelectedIndex = 0
        會科1_ch.SelectedIndex = 1 : ComboBox3.SelectedIndex = 1 : ComboBox1.SelectedIndex = 0
        申請人_tb.Text = gUserName : 申請日期_dtp.Value = Today() : 匯率()
        If 收款事項_dgv.Rows.Count = 0 Then : 轉財務系統_bt.Enabled = False : End If : 業務_cb.SelectedIndex = 0
        If Me.Size.Width > 1440 And Me.Size.Height > 900 Then : 字體_NUD.Value = 9
        ElseIf Me.Size.Width <= 1440 And Me.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 Me.Size.Width > 1440 And Me.Size.Height > 900 Then
            字體_NUD.Value = 9
        ElseIf Me.Size.Width <= 1440 And Me.Size.Height <= 900 Then
            字體_NUD.Value = 7.6
        End If
    End Sub
    Dim 已超出 As Boolean
    Private Sub 銷售單據_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 銷售單據_dgv.MouseUp
        'If 銷售單據_dgv.SelectedCells.Count = 1 Then : MsgBox(銷售單據_dgv.SelectedCells(0).ColumnIndex & "  " & 銷售單據_dgv.SelectedCells(0).RowIndex) : End If
        If 銷售單據_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 銷售單據_dgv.SelectedCells.Count > 0 Then
            If 銷售單據_dgv.SelectedCells(0).ColumnIndex = 9 Or 銷售單據_dgv.SelectedCells(0).ColumnIndex = 11 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 銷售單據_dgv.SelectedCells.Count - 1
                        x += Val(銷售單據_dgv.Rows(銷售單據_dgv.SelectedCells.Item(i).RowIndex).Cells(銷售單據_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
    End Sub
    Private Sub 轉財務系統可運作()
        If 銷售收款_bt.Enabled = False Then
            For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                If 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" And 收款事項_dgv("金額", i).Value <> 0 And 收款事項_dgv("轉財務", i).Value = False Then
                    轉財務系統_bt.Enabled = True : Exit For
                Else
                    轉財務系統_bt.Enabled = False
                End If
            Next
        ElseIf 衍生運費_bt.Enabled = False Then
            If 衍生運費_dgv.Rows.Count = 0 Then : 轉財務系統_bt.Enabled = False : End If
            For i As Integer = 0 To 衍生運費_dgv.Rows.Count - 1
                If Val(衍生運費_dgv("支出", i).Value) <> 0 Or 項次2_tb.Text = "" Then
                    轉財務系統_bt.Enabled = True : Exit For
                Else
                    轉財務系統_bt.Enabled = False
                End If
            Next
        ElseIf 其他費用_bt.Enabled = False Then
            If 其他費用_dgv.Rows.Count = 0 Then : 轉財務系統_bt.Enabled = False : End If
            For i As Integer = 0 To 其他費用_dgv.Rows.Count - 1
                If (Val(其他費用_dgv("支出", i).Value) = 0 And Val(其他費用_dgv("收入", i).Value) = 0) Or 項次2_tb.Text = "" Then
                    轉財務系統_bt.Enabled = False
                Else
                    轉財務系統_bt.Enabled = True : Exit For
                End If
            Next
        End If
    End Sub
    Private Sub 銷售單據_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 銷售單據_dgv.RowPostPaint
        For I As Integer = 0 To 銷售單據_dgv.Rows.Count - 1
            If 銷售單據_dgv("轉財務", I).Value = True Then
                銷售單據_dgv.Rows(I).DefaultCellStyle.BackColor = Color.LightGreen
            Else
                銷售單據_dgv.Rows(I).DefaultCellStyle.BackColor = Color.White
            End If
        Next
    End Sub
    Private Sub 收款事項_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 收款事項_dgv.CellEndEdit
        Set_合記計算() : 轉財務系統可運作()
    End Sub
    Private Sub 衍生運費_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 衍生運費_dgv.CellEndEdit
        轉財務系統可運作()
    End Sub
    Private Sub 其他費用_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 其他費用_dgv.CellEndEdit
        轉財務系統可運作()
    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
            營運成本收支單號_tb.Text = 收款事項_dgv("收支單號", e.RowIndex).Value.ToString
            流水號2_bt.Text = 收款事項_dgv("資料流水號", e.RowIndex).Value.ToString
        End If
        For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
            If 收款事項_dgv("內容", i).Value.ToString = "未收餘額" Then
                If 收款事項_dgv("項次", i).Value.ToString = "0" And 收款事項_dgv("內容", i).Value.ToString = "未收餘額" Then
                ElseIf 收款事項_dgv("金額", i).Value = 0 Then
                    收款事項_dgv("轉財務", i).Value = True
                ElseIf 收款事項_dgv("金額", i).Value <> 0 Then
                    收款事項_dgv("轉財務", i).Value = False
                End If
            End If
        Next
        轉財務系統可運作()
    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.Rows(e.RowIndex).Cells("單號").Value
            客戶_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("名稱").Value
            電話1_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("電話1").Value
            電話2_tb.Text = 銷售單據_dgv.Rows(e.RowIndex).Cells("電話2").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
            交貨日期_dtp.Value = 銷售單據_dgv.Rows(e.RowIndex).Cells("交貨日期").Value
            含稅_ch.Checked = 銷售單據_dgv.Rows(e.RowIndex).Cells("含稅").Value
            申請日期_dtp.Value = 銷售單據_dgv.Rows(e.RowIndex).Cells("交貨日期").Value
            營運成本收支單號_tb.Text = "" : 項次2_tb.Text = ""
            Set_清單2() : Set_清單3() : Set_清單4() : 轉財務系統可運作()
        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
            運費資料流水號_tb.Text = 衍生運費_dgv("資料流水號", e.RowIndex).Value.ToString : 項次2_tb.Text = 衍生運費_dgv("項次", e.RowIndex).Value.ToString
            流水號2_bt.Text = 衍生運費_dgv("資料流水號", e.RowIndex).Value.ToString : 營運成本收支單號_tb.Text = 衍生運費_dgv("收支單號", e.RowIndex).Value.ToString
        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
            If Val(其他費用_dgv("收入", e.RowIndex).Value.ToString) <> 0 And Val(其他費用_dgv("支出", e.RowIndex).Value.ToString) = 0 Then
                會科1_ch.SelectedIndex = 1 : ComboBox3.SelectedIndex = 1 : ComboBox1.SelectedIndex = 0
            ElseIf Val(其他費用_dgv("收入", e.RowIndex).Value.ToString) = 0 And Val(其他費用_dgv("支出", e.RowIndex).Value.ToString) <> 0 Then
                會科1_ch.SelectedIndex = 0 : ComboBox3.SelectedIndex = 3 : ComboBox1.SelectedIndex = 12
            End If
            銷售備註流水號_tb.Text = 其他費用_dgv("資料流水號", e.RowIndex).Value.ToString : 項次2_tb.Text = 其他費用_dgv("項次", e.RowIndex).Value.ToString
            流水號2_bt.Text = 收款事項_dgv("資料流水號", e.RowIndex).Value.ToString : 營運成本收支單號_tb.Text = 其他費用_dgv("收支單號", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 會科1_ch.TextChanged
        會科碼1_ch.SelectedIndex = 會科1_ch.SelectedIndex : 關鍵字查詢會計科目_tb.Text = "" : ComboBox3下拉表單資料載入() : ComboBox1下拉表單資料載入()
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 會科碼1_ch.TextChanged
        會科1_ch.SelectedIndex = 會科碼1_ch.SelectedIndex : ComboBox3下拉表單資料載入() : ComboBox1下拉表單資料載入()
    End Sub
    Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.TextChanged
        ComboBox4.SelectedIndex = ComboBox3.SelectedIndex : ComboBox1下拉表單資料載入()
    End Sub
    Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.TextChanged
        ComboBox3.SelectedIndex = ComboBox4.SelectedIndex : ComboBox1下拉表單資料載入()
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        ComboBox6.SelectedIndex = ComboBox1.SelectedIndex
    End Sub
    Private Sub ComboBox6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox6.SelectedIndexChanged
        ComboBox1.SelectedIndex = ComboBox6.SelectedIndex
    End Sub
    Private Sub 新增一筆收款事項_bt_Click(sender As Object, e As EventArgs) Handles 新增一筆收款事項_bt.Click
        If 銷售收款_bt.Enabled = False Then
            If 單號_tb.Text = "" Then
                MsgBox("沒有銷售單號，無法作業。")
            Else
                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_清單2()
            End If
        ElseIf 衍生運費_bt.Enabled = False Then
            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_清單3()
            End If
        ElseIf 其他費用_bt.Enabled = False Then
            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_清單4()
            End If
        End If
    End Sub
    Private Sub 刪除收款事項上點選的資料_bt_Click(sender As Object, e As EventArgs) Handles 刪除收款事項上點選的資料_bt.Click
        If 銷售收款_bt.Enabled = False Then
            If 單號_tb.Text = "" Then
                MsgBox("沒有銷售單號，無法作業。")
            Else
                If 項次3_tb.Text = "" Then
                    MsgBox("沒有選擇收款事項，無法作業。")
                Else
                    If 項次3_tb.Text = "0" Then
                        MsgBox("不能刪除 [未收餘額] 或 [刷卡] 選項!!")
                    Else
                        Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                        If aa1 = MsgBoxResult.Ok Then
                            刪除狀態 = True
                            PA = 銷售收款流水號_tb.Text
                            存檔2()
                            SQL_銷售收款事項_刪除() : Set_清單2() : 項次2_tb.Text = ""
                            刪除狀態 = False
                            存檔2()
                        End If
                    End If
                End If
            End If
        ElseIf 衍生運費_bt.Enabled = False Then
            If 單號_tb.Text = "" Then
                MsgBox("沒有銷售單號，無法作業。")
            Else
                If 項次2_tb.Text = "" Then
                    MsgBox("沒有選擇收款事項，無法作業。")
                Else
                    Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                    If aa1 = MsgBoxResult.Ok Then
                        PA = 運費資料流水號_tb.Text
                        SQL_銷售衍生費用_刪除() : Set_清單3() : 項次2_tb.Text = ""
                    End If
                End If
            End If
        ElseIf 其他費用_bt.Enabled = False Then
            If 單號_tb.Text = "" Then
                MsgBox("沒有銷售單號，無法作業。")
            Else
                If 單號_tb.Text = "" Then
                    MsgBox("沒有銷售單號，無法作業。")
                Else
                    If 項次2_tb.Text = "" Then
                        MsgBox("沒有選擇收款事項，無法作業。")
                    Else
                        Dim aa1 As MsgBoxResult = MsgBox("你確定要刪除這筆資料?", MsgBoxStyle.OkCancel)
                        If aa1 = MsgBoxResult.Ok Then
                            PA = 銷售備註流水號_tb.Text
                            SQL_銷售備註表_刪除() : Set_清單4() : 項次2_tb.Text = ""
                        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
            PA = 營運成本收支單號_tb.Text
            SQL_營運成本收支單申請_刪除公帳控制表_應收用() : SQL_營運成本收支單申請_刪除公帳流水帳_應收用()
            PA12 = 流水號2_bt.Text : SQL_應收帳款未收_轉財務_退回() : conn.Close() : Set_清單2() : Set_清單3() : Set_清單4()
        End If
    End Sub
    Private Sub 轉財務系統_bt_Click(sender As Object, e As EventArgs) Handles 轉財務系統_bt.Click
        If 銷售收款_bt.Enabled = False Then
            存檔2()
            SQL_應收帳款未收_轉財務Null為False()
            Dim AA As Boolean = True
            For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                If 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" And 收款事項_dgv("轉財務", i).Value = False Then
                    AA = False
                    Exit For
                End If
            Next
            If AA = False Then
                開立零用金支付單()
                For i As Integer = 0 To 收款事項_dgv.Rows.Count - 1
                    資料數 = 收款事項_dgv.Rows.Count : MyModule1.進度條()
                    If 收款事項_dgv("內容", i).Value.ToString <> "未收餘額" And 收款事項_dgv("轉財務", i).Value = False And 收款事項_dgv("金額", i).Value <> 0 Then
                        If ComboBox6.Text = "" Or 幣別_cb.Text = "" Then
                            MsgBox("沒有選擇會計科目或幣別。")
                        Else
                            Set_日期格式轉換() : Set_流水號()
                            PA = 營運成本收支單號_tb.Text
                            SQL_營運成本收支單申請_查詢最後一筆公帳支付單號()
                            If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close()
                            NUM1 = Double.Parse(新項次) + 1
                            If NUM1 < 10 Then : 新項次 = "00" & NUM1 : ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = "0" & NUM1 : ElseIf NUM1 > 99 Then : 新項次 = NUM1 : End If

                            If 幣別_cb.Text = "台幣現金" Then : 匯率1 = 1
                            ElseIf 幣別_cb.Text = "人民幣現金" Then : 匯率1 = 人民幣匯率_tb.Text
                            ElseIf 幣別_cb.Text = "美金" Then : 匯率1 = 美金匯率_tb.Text : End If

                            Dim RR As String
                            If Len(客戶_tb.Text & 收款事項_dgv.Rows(i).Cells("內容").Value) <= 21 Then
                                RR = 收款事項_dgv.Rows(i).Cells("內容").Value
                            Else
                                RR = Strings.Left(收款事項_dgv.Rows(i).Cells("內容").Value, 21 - Len(客戶_tb.Text))
                            End If
                            PA14 = 單號_tb.Text & " - " & 客戶_tb.Text & " - " & RR & " - [" & 收款事項_dgv.Rows(i).Cells("資料流水號").Value & "]"

                            PA16 = 匯率1 : PA15 = 新項次 : PA17 = 幣別_cb.Text : PA18 = ComboBox6.Text : PA20 = 收款事項_dgv.Rows(i).Cells("金額").Value
                            PA21 = 收款事項_dgv.Rows(i).Cells("含稅").Value : PA22 = "0"
                            SQL_應收轉財務_新增公帳流水帳資料()

                            PA12 = 收款事項_dgv.Rows(i).Cells("資料流水號").Value
                            SQL_應收帳款未收_轉財務()

                            conn.Close() : Set_清單2() : Set_清單3() : Set_清單4()
                        End If
                    End If
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
                Set_清單1() : MsgBox("收款資料轉財務單完成!!!")
            Else
                MsgBox("沒有滿足可以轉財務的需求!!!")
            End If
        ElseIf 衍生運費_bt.Enabled = False Then
            存檔2()
            SQL_銷售衍生運費_轉財務Null為False()
            Dim AA As Boolean = True
            For i As Integer = 0 To 衍生運費_dgv.Rows.Count - 1
                If 衍生運費_dgv("轉財務", i).Value = False Then
                    AA = False
                    Exit For
                End If
            Next
            If AA = False Then
                開立零用金支付單()
                For i As Integer = 0 To 衍生運費_dgv.Rows.Count - 1
                    資料數 = 衍生運費_dgv.Rows.Count : MyModule1.進度條()
                    If 衍生運費_dgv("轉財務", i).Value = False And 衍生運費_dgv("支出", i).Value <> 0 Then
                        If ComboBox6.Text = "" Or 幣別_cb.Text = "" Then
                            MsgBox("沒有選擇會計科目或幣別。")
                        Else
                            Set_日期格式轉換() : Set_流水號()
                            PA = 營運成本收支單號_tb.Text
                            SQL_營運成本收支單申請_查詢最後一筆公帳支付單號()
                            If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close()
                            NUM1 = Double.Parse(新項次) + 1
                            If NUM1 < 10 Then : 新項次 = "00" & NUM1 : ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = "0" & NUM1 : ElseIf NUM1 > 99 Then : 新項次 = NUM1 : End If

                            If 幣別_cb.Text = "台幣現金" Then : 匯率1 = 1
                            ElseIf 幣別_cb.Text = "人民幣現金" Then : 匯率1 = 人民幣匯率_tb.Text
                            ElseIf 幣別_cb.Text = "美金" Then : 匯率1 = 美金匯率_tb.Text : End If

                            Dim RR As String
                            If Len(客戶_tb.Text & 衍生運費_dgv.Rows(i).Cells("運費備註").Value) <= 21 Then
                                RR = 衍生運費_dgv.Rows(i).Cells("運費備註").Value
                            Else
                                RR = Strings.Left(衍生運費_dgv.Rows(i).Cells("運費備註").Value, 21 - Len(客戶_tb.Text))
                            End If
                            PA14 = 單號_tb.Text & " - " & 客戶_tb.Text & " - " & RR & " - [" & 衍生運費_dgv.Rows(i).Cells("資料流水號").Value & "]"

                            PA16 = 匯率1 : PA15 = 新項次 : PA17 = 幣別_cb.Text : PA18 = ComboBox6.Text : PA22 = 衍生運費_dgv.Rows(i).Cells("支出").Value
                            PA21 = 衍生運費_dgv.Rows(i).Cells("含稅").Value : PA20 = "0"
                            SQL_應收轉財務_新增公帳流水帳資料()

                            PA12 = 衍生運費_dgv.Rows(i).Cells("資料流水號").Value
                            SQL_銷售衍生運費_轉財務()

                            conn.Close() : Set_清單2() : Set_清單3() : Set_清單4()
                        End If
                    End If
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
                Set_清單1() : MsgBox("收款資料轉財務單完成!!!")
            Else
                MsgBox("沒有滿足可以轉財務的需求!!!")
            End If
        ElseIf 其他費用_bt.Enabled = False Then
            存檔2()
            SQL_銷售備註表_轉財務Null為False()
            Dim AA As Boolean = True
            For i As Integer = 0 To 其他費用_dgv.Rows.Count - 1
                If 其他費用_dgv("轉財務", i).Value = False Then
                    AA = False
                    Exit For
                End If
            Next
            If AA = False Then
                開立零用金支付單()
                For i As Integer = 0 To 其他費用_dgv.Rows.Count - 1
                    資料數 = 其他費用_dgv.Rows.Count : MyModule1.進度條()
                    If (Val(其他費用_dgv("收入", i).Value.ToString) <> 0 And Val(其他費用_dgv("支出", i).Value.ToString) = 0 And 會科1_ch.Text = "歲入合計") Or
                           (Val(其他費用_dgv("收入", i).Value.ToString) = 0 And Val(其他費用_dgv("支出", i).Value.ToString) <> 0 And 會科1_ch.Text = "歲出合計") Then
                        If 其他費用_dgv("轉財務", i).Value = False And (其他費用_dgv("支出", i).Value <> 0 Or 其他費用_dgv("收入", i).Value <> 0) Then
                            If ComboBox6.Text = "" Or 幣別_cb.Text = "" Then
                                MsgBox("沒有選擇會計科目或幣別。")
                            Else
                                Set_日期格式轉換() : Set_流水號()
                                PA = 營運成本收支單號_tb.Text
                                SQL_營運成本收支單申請_查詢最後一筆公帳支付單號()
                                If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close()
                                NUM1 = Double.Parse(新項次) + 1
                                If NUM1 < 10 Then : 新項次 = "00" & NUM1 : ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = "0" & NUM1 : ElseIf NUM1 > 99 Then : 新項次 = NUM1 : End If

                                If 幣別_cb.Text = "台幣現金" Then : 匯率1 = 1
                                ElseIf 幣別_cb.Text = "人民幣現金" Then : 匯率1 = 人民幣匯率_tb.Text
                                ElseIf 幣別_cb.Text = "美金" Then : 匯率1 = 美金匯率_tb.Text : End If

                                Dim RR As String
                                If Len(客戶_tb.Text & 其他費用_dgv.Rows(i).Cells("備註").Value) <= 21 Then
                                    RR = 其他費用_dgv.Rows(i).Cells("備註").Value
                                Else
                                    RR = Strings.Left(其他費用_dgv.Rows(i).Cells("備註").Value, 21 - Len(客戶_tb.Text))
                                End If
                                PA14 = 單號_tb.Text & " - " & 客戶_tb.Text & " - " & RR & " - [" & 其他費用_dgv.Rows(i).Cells("資料流水號").Value & "]"

                                PA16 = 匯率1 : PA15 = 新項次 : PA17 = 幣別_cb.Text : PA18 = ComboBox6.Text : PA20 = 其他費用_dgv.Rows(i).Cells("收入").Value
                                PA21 = 其他費用_dgv.Rows(i).Cells("含稅").Value : PA22 = 其他費用_dgv.Rows(i).Cells("支出").Value
                                SQL_應收轉財務_新增公帳流水帳資料()

                                PA12 = 其他費用_dgv.Rows(i).Cells("資料流水號").Value
                                SQL_銷售備註表_轉財務()

                                conn.Close() : Set_清單2() : Set_清單3() : Set_清單4()
                            End If
                        End If
                    End If
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
                Set_清單1() : MsgBox("收款資料轉財務單完成!!!")
            Else
                MsgBox("沒有滿足可以轉財務的需求!!!")
            End If
        End If
    End Sub
    Private Sub Set_流水號()
        conn.Close() : dr.Close()
        Dim NUM1 As Integer
        For NUM1 = 0 To 99
            Dim d As String : Dim f As String : Dim g As Integer = 1
            If Month(申請日期_dtp.Value) < 10 Then : d = "0" & CStr(Month(申請日期_dtp.Value))
            Else : d = CStr(Month(申請日期_dtp.Value))
            End If
            If Val(Strings.Right(申請日期_dtp.Value, 2)) < 10 Then : f = "0" & Val(Strings.Right(申請日期_dtp.Value, 2))
            Else : f = Val(Strings.Right(申請日期_dtp.Value, 2))
            End If
            If NUM1 < 10 Then : 新流水1 = "B" & Microsoft.VisualBasic.Right(CStr(Year(申請日期_dtp.Value)), 2) & d & f & "0" & NUM1
            Else : 新流水1 = "B" & Microsoft.VisualBasic.Right(CStr(Year(申請日期_dtp.Value)), 2) & d & f & NUM1
            End If : PA19 = 新流水1
            SQL_營運成本收支單申請_查詢收支單公帳流水號()
            If dr.Read() Then : conn.Close() : Else : conn.Close() : NUM1 = 99 : End If
        Next
    End Sub
    Private Sub 存檔2()
        If 單號_tb.Text = "" Then
            MsgBox("沒有銷售單號，無法作業。")
        Else
            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
                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
            Set_清單1()
        End If
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        存檔2() : MsgBox("存檔完成。")
    End Sub
    Private Sub 業務_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 業務_cb.SelectedIndexChanged
        Set_清單1()
    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 銷售收款_bt_Click(sender As Object, e As EventArgs) Handles 銷售收款_bt.Click
        銷售收款_bt.Enabled = False : 衍生運費_bt.Enabled = True : 其他費用_bt.Enabled = True : 收款事項_dgv.Visible = True : 衍生運費_dgv.Visible = False : 其他費用_dgv.Visible = False
        會科1_ch.SelectedIndex = 1 : ComboBox3.SelectedIndex = 1 : ComboBox1.SelectedIndex = 0 : 轉財務系統可運作()
    End Sub
    Private Sub 衍生運費_bt_Click(sender As Object, e As EventArgs) Handles 衍生運費_bt.Click
        銷售收款_bt.Enabled = True : 衍生運費_bt.Enabled = False : 其他費用_bt.Enabled = True : 收款事項_dgv.Visible = False : 衍生運費_dgv.Visible = True : 其他費用_dgv.Visible = False
        會科1_ch.SelectedIndex = 0 : ComboBox3.SelectedIndex = 3 : ComboBox1.SelectedIndex = 12 : 轉財務系統可運作()
    End Sub
    Private Sub 其他費用_bt_Click(sender As Object, e As EventArgs) Handles 其他費用_bt.Click
        銷售收款_bt.Enabled = True : 衍生運費_bt.Enabled = True : 其他費用_bt.Enabled = False : 收款事項_dgv.Visible = False : 衍生運費_dgv.Visible = False : 其他費用_dgv.Visible = True
        會科1_ch.SelectedIndex = 0 : ComboBox3.SelectedIndex = 3 : ComboBox1.SelectedIndex = 12 : 轉財務系統可運作()
    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)
    End Sub
    Private Sub 今天_bt_Click(sender As Object, e As EventArgs) Handles 今天_bt.Click
        申請日期_dtp.Value = Today()
    End Sub
    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
        If 首次開啟 = True Then
            SQL2 = "" : Set_清單1()
        End If
    End Sub
    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        If 首次開啟 = True Then
            SQL2 = " AND (QQQ.轉財務 = 1)" : Set_清單1()
        End If
    End Sub
    Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
        If 首次開啟 = True Then
            SQL2 = " AND (QQQ.轉財務 = 0 OR QQQ.轉財務 IS NULL)" : Set_清單1()
        End If
    End Sub
End Class