Public Class 應收帳款已收
    ReadOnly ds1, ds2, ds4, ds5, ds6, ds7 As New DataSet
    Dim EDR As Integer : Dim ESTR As String
    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 = 120
        收款事項_dgv.Columns(4).FillWeight = 960 : 收款事項_dgv.Columns(5).FillWeight = 180

        收款事項_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
        Next
        收款事項_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        '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)
    End Sub

    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
        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 = 50 : 銷售單據_dgv.Columns(6).Visible = False : 銷售單據_dgv.Columns(7).FillWeight = 110
        銷售單據_dgv.Columns(8).FillWeight = 85 : 銷售單據_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("金額").DefaultCellStyle.Format = "#,##0"
        銷售單據_dgv.Columns("金額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售單據_dgv.Columns("金額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    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
        業務_cb.Text = 業務號碼 : Set_清單1()
    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
                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

                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 : PA = 單號_tb.Text
                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
                    SQL_銷售收款事項_修改() : conn.Close()
                Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

                Set_清單6()
            End If
        End If
    End Sub
    Private Sub 業務_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 業務_cb.SelectedIndexChanged
        Set_清單1()
    End Sub
End Class