Public Class 業績單據完單設定
    ReadOnly ds, ds1, ds2, ds3, ds4, ds5, ds6, ds7, ds8 As New DataSet
    Private Sub Set_清單1()
        彙總1_dgv.DataSource = Nothing : ds1.Clear()
        彙總1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        彙總1_dgv.ColumnHeadersHeight = 25
        彙總1_dgv.AllowUserToAddRows = False
        彙總1_dgv.RowTemplate.Height = 25
        If 已完單_bt.Enabled = False Then
            SQL_業績完單2()
        Else
            SQL_業績完單1()
        End If

        da.Fill(ds1) : 彙總1_dgv.DataSource = ds1.Tables(0) : conn.Close()
        For I As Integer = 1 To 5
            彙總1_dgv.Columns(I).DefaultCellStyle.Format = "#,##0" : 彙總1_dgv.Columns(I).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For I As Integer = 0 To 彙總1_dgv.Rows.Count - 1
            If 彙總1_dgv.Rows(I).Cells(1).Value.ToString = "" Then : 彙總1_dgv.Rows(I).Cells(1).Value = 0 : End If
            If 彙總1_dgv.Rows(I).Cells(2).Value.ToString = "" Then : 彙總1_dgv.Rows(I).Cells(2).Value = 0 : End If
            If 彙總1_dgv.Rows(I).Cells(3).Value.ToString = "" Then : 彙總1_dgv.Rows(I).Cells(3).Value = 0 : End If
            If 彙總1_dgv.Rows(I).Cells(4).Value.ToString = "" Then : 彙總1_dgv.Rows(I).Cells(4).Value = 0 : End If
            If 彙總1_dgv.Rows(I).Cells(5).Value.ToString = "" Then : 彙總1_dgv.Rows(I).Cells(5).Value = 0 : End If
        Next
    End Sub
    Private Sub Set_獎金基礎下拉()
        SQL_獎金基礎下拉()
        While (dr.Read()) : 獎金基礎_ch.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
        Set_獎金基礎下拉() : Set_清單1()
    End Sub
    Private Sub 彙總1_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 彙總1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            業務單號_tb.Text = 彙總1_dgv("單號", e.RowIndex).Value.ToString
            If Strings.Left(業務單號_tb.Text, 1) = 預設1_tb.Text Then : 獎金基礎_ch.Text = 基礎1_tb.Text
            ElseIf Strings.Left(業務單號_tb.Text, 1) = 預設2_tb.Text Then : 獎金基礎_ch.Text = 基礎2_tb.Text
            ElseIf Strings.Left(業務單號_tb.Text, 1) = 預設3_tb.Text Then : 獎金基礎_ch.Text = 基礎3_tb.Text
            Else : 獎金基礎_ch.Text = 基礎4_tb.Text : End If
        End If
    End Sub
    Private Sub 已完單_bt_Click(sender As Object, e As EventArgs) Handles 已完單_bt.Click
        已完單_bt.Enabled = False : 未完單_bt.Enabled = True : Set_清單1()
    End Sub
    Private Sub 未完單_bt_Click(sender As Object, e As EventArgs) Handles 未完單_bt.Click
        已完單_bt.Enabled = True : 未完單_bt.Enabled = False : Set_清單1()
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        Set_清單1()
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        SQL_業績完單_修正() : Set_清單1()
    End Sub
End Class