Imports System.Windows.Forms.DataVisualization.Charting
Public Class 人員貢獻分析表
    ReadOnly ds, ds2 As New DataSet
    Dim 月1, 月2, 月3 As Integer
    Private Sub SET_產品()
        產品_dgv.DataSource = Nothing : ds2.Clear()
        產品_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        產品_dgv.ColumnHeadersHeight = 40 : 產品_dgv.AllowUserToAddRows = False
        If RadioButton1.Checked = True Then : PA = "一般產品" : PA1 = "產品銷售" : SQL_客戶交易明細表2_清單()
        ElseIf RadioButton2.Checked = True Then : PA = "人工皮" : PA1 = "產品銷售" : SQL_客戶交易明細表2_清單()
        ElseIf RadioButton3.Checked = True Then : PA = "雷射" : PA1 = "排程人員" : SQL_客戶交易明細表2_清單()
        ElseIf RadioButton4.Checked = True Then : PA = "治療" : PA1 = "排程人員" : SQL_客戶交易明細表2_清單()
        ElseIf RadioButton5.Checked = True Then : PA = "手術" : PA1 = "排程人員" : SQL_客戶交易明細表2_清單()
        ElseIf RadioButton6.Checked = True Then : PA = "美療" : PA1 = "排程人員" : SQL_客戶交易明細表2_清單()
        ElseIf RadioButton7.Checked = True Then : PA = "植髮" : PA1 = "排程人員" : SQL_客戶交易明細表2_清單()
        End If
        da.Fill(ds2) : 產品_dgv.DataSource = ds2.Tables(0) : conn.Close()

        產品_dgv.Columns(0).FillWeight = 50 : 產品_dgv.Columns(1).FillWeight = 150 : 產品_dgv.Columns(2).FillWeight = 50 : 產品_dgv.Columns(3).FillWeight = 80

        產品_dgv.Columns(2).DefaultCellStyle.Format = "#,##0"
        產品_dgv.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        產品_dgv.Sort(產品_dgv.Columns("備註"), System.ComponentModel.ListSortDirection.Descending)
    End Sub
    Private Sub SET_客戶交易明細表()
        交易明細_dgv.DataSource = Nothing : ds.Clear()
        交易明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        交易明細_dgv.ColumnHeadersHeight = 40 : 交易明細_dgv.AllowUserToAddRows = False
        SQL_客戶交易明細表1_清單()

        da.Fill(ds) : 交易明細_dgv.DataSource = ds.Tables(0) : conn.Close()

        交易明細_dgv.Columns(0).Visible = False : 交易明細_dgv.Columns(2).Visible = False : 交易明細_dgv.Columns(4).Visible = False : 交易明細_dgv.Columns(5).Visible = False
        交易明細_dgv.Columns(13).Visible = False : 交易明細_dgv.Columns(18).Visible = False : 交易明細_dgv.Columns(19).Visible = False
        交易明細_dgv.Columns(6).FillWeight = 300 : 交易明細_dgv.Columns(12).FillWeight = 150

        For I As Integer = 0 To 20 : 交易明細_dgv.Columns(I).ReadOnly = True : Next

        交易明細_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 交易明細_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        交易明細_dgv.Columns(9).DefaultCellStyle.Format = "#,##0.00" : 交易明細_dgv.Columns(10).DefaultCellStyle.Format = "#,##0.0"
        交易明細_dgv.Columns(11).DefaultCellStyle.Format = "#,##0"
        交易明細_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        交易明細_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        交易明細_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        交易明細_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        交易明細_dgv.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        SET_獎金計算()
    End Sub
    Private Sub SET_獎金計算()
        Dim ds1 As New DataSet
        獎金計算_dgv.DataSource = Nothing : ds1.Clear()
        獎金計算_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        獎金計算_dgv.ColumnHeadersHeight = 40 : 獎金計算_dgv.AllowUserToAddRows = False
        SQL_獎金計算1_清單()

        da.Fill(ds1) : 獎金計算_dgv.DataSource = ds1.Tables(0) : conn.Close()

        For I As Integer = 2 To 27
            獎金計算_dgv.Columns(I).DefaultCellStyle.Format = "#,##0"
            獎金計算_dgv.Columns(I).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For I As Integer = 0 To 28 : 獎金計算_dgv.Columns(I).ReadOnly = True : Next
        獎金計算_dgv.Columns(0).FillWeight = 75 : 獎金計算_dgv.Columns(1).FillWeight = 60
        獎金計算_dgv.Columns(4).Visible = False : 獎金計算_dgv.Columns(6).Visible = False : 獎金計算_dgv.Columns(8).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).Visible = False
        獎金計算_dgv.Columns(28).Visible = False
        獎金計算_dgv.Columns(28).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        For I As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
            資料數 = 獎金計算_dgv.Rows.Count : MyModule1.進度條()
            獎金計算_dgv("一般產品業績", I).Value = 0 : 獎金計算_dgv("美療排程", I).Value = 0 : 獎金計算_dgv("美療操作", I).Value = 0
            獎金計算_dgv("排程業績", I).Value = 0 : 獎金計算_dgv("操作業績", I).Value = 0 : 獎金計算_dgv("手術排程", I).Value = 0
            獎金計算_dgv("手術操作", I).Value = 0 : 獎金計算_dgv("植髮/電波業績", I).Value = 0 : 獎金計算_dgv("預購療程", I).Value = 0
            獎金計算_dgv("償還業績", I).Value = 0 : 獎金計算_dgv("一般產品", I).Value = 0 : 獎金計算_dgv("美療", I).Value = 0
            獎金計算_dgv("雷射/治療", I).Value = 0 : 獎金計算_dgv("手術", I).Value = 0 : 獎金計算_dgv("植髮/電波", I).Value = 0
            For ii As Integer = 0 To 交易明細_dgv.Rows.Count - 1
                '------一般產品，人工皮-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("產品銷售", ii).Value.ToString, 4, 5) And
                  (交易明細_dgv("類別", ii).Value.ToString = "一般產品" Or 交易明細_dgv("類別", ii).Value.ToString = "人工皮") Then
                    獎金計算_dgv("一般產品業績", I).Value = 獎金計算_dgv("一般產品業績", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("產品銷售", ii).Value.ToString, 4, 5) And
                  (交易明細_dgv("類別", ii).Value.ToString = "一般產品" Or 交易明細_dgv("類別", ii).Value.ToString = "人工皮") Then
                    獎金計算_dgv("一般產品", I).Value = 獎金計算_dgv("一般產品", I).Value + 交易明細_dgv("業績", ii).Value
                End If

                '------美療排程-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                    交易明細_dgv("類別", ii).Value.ToString = "美療" And 交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("美療排程", I).Value = 獎金計算_dgv("美療排程", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                '------美療操作-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("操作人員", ii).Value.ToString, 4, 5) And
                    交易明細_dgv("類別", ii).Value.ToString = "美療" And 交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("美療操作", I).Value = 獎金計算_dgv("美療操作", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                '------美療-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                    交易明細_dgv("類別", ii).Value.ToString = "美療" And (交易明細_dgv("備註", ii).Value.ToString = "預購療程" Or
                    交易明細_dgv("備註", ii).Value.ToString = ".") Then
                    獎金計算_dgv("美療", I).Value = 獎金計算_dgv("美療", I).Value + 交易明細_dgv("業績", ii).Value
                End If

                '------雷射、治療排程-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                  (交易明細_dgv("類別", ii).Value.ToString = "雷射" Or 交易明細_dgv("類別", ii).Value.ToString = "治療") And
                   交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("排程業績", I).Value = 獎金計算_dgv("排程業績", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                '------雷射、治療操作-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("操作人員", ii).Value.ToString, 4, 5) And
                  (交易明細_dgv("類別", ii).Value.ToString = "雷射" Or 交易明細_dgv("類別", ii).Value.ToString = "治療") And
                   交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("操作業績", I).Value = 獎金計算_dgv("操作業績", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                '------雷射、治療-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                    (交易明細_dgv("類別", ii).Value.ToString = "雷射" Or 交易明細_dgv("類別", ii).Value.ToString = "治療") And
                    (交易明細_dgv("備註", ii).Value.ToString = "預購療程" Or 交易明細_dgv("備註", ii).Value.ToString = ".") Then
                    獎金計算_dgv("雷射/治療", I).Value = 獎金計算_dgv("雷射/治療", I).Value + 交易明細_dgv("業績", ii).Value
                End If

                '------手術排程-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                  交易明細_dgv("類別", ii).Value.ToString = "手術" And 交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("手術排程", I).Value = 獎金計算_dgv("手術排程", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                '------手術操作-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("操作人員", ii).Value.ToString, 4, 5) And
                   交易明細_dgv("類別", ii).Value.ToString = "手術" And 交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("手術操作", I).Value = 獎金計算_dgv("手術操作", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                '------手術-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                   交易明細_dgv("類別", ii).Value.ToString = "手術" And
                    (交易明細_dgv("備註", ii).Value.ToString = "預購療程" Or 交易明細_dgv("備註", ii).Value.ToString = ".") Then
                    獎金計算_dgv("手術", I).Value = 獎金計算_dgv("手術", I).Value + 交易明細_dgv("業績", ii).Value
                End If

                '------植髮/電波-------------------------------------------------------------------------------------------
                If (獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) Or
                    獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("操作人員", ii).Value.ToString, 4, 5)) And
                    (交易明細_dgv("類別", ii).Value.ToString = "植髮" Or 交易明細_dgv("類別", ii).Value.ToString = "電波") And
                    交易明細_dgv("備註", ii).Value.ToString <> "預購療程" Then
                    獎金計算_dgv("植髮/電波業績", I).Value = 獎金計算_dgv("植髮/電波業績", I).Value + 交易明細_dgv("業績", ii).Value
                End If
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                    (交易明細_dgv("類別", ii).Value.ToString = "植髮" Or 交易明細_dgv("類別", ii).Value.ToString = "電波") And
                    (交易明細_dgv("備註", ii).Value.ToString = "預購療程" Or 交易明細_dgv("備註", ii).Value.ToString = ".") Then
                    獎金計算_dgv("植髮/電波", I).Value = 獎金計算_dgv("植髮/電波", I).Value + 交易明細_dgv("業績", ii).Value
                End If

                '------預購療程-------------------------------------------------------------------------------------------
                If 獎金計算_dgv("人員", I).Value.ToString = Strings.Mid(交易明細_dgv("排程人員", ii).Value.ToString, 4, 5) And
                   交易明細_dgv("備註", ii).Value.ToString = "預購療程" Then
                    獎金計算_dgv("預購療程", I).Value = 獎金計算_dgv("預購療程", I).Value + 交易明細_dgv("業績", ii).Value
                End If
            Next
            '------一般產品，人工皮-------------------------------------------------------------------------------------------
            If 獎金計算_dgv("時薪", I).Value.ToString = "時薪" Then
                If 獎金計算_dgv("一般產品業績", I).Value < 產品_時薪_nud.Value Then
                    獎金計算_dgv("一般產品獎金", I).Value = 獎金計算_dgv("一般產品業績", I).Value / 100 * 業績_未達標1_nud.Value
                Else
                    獎金計算_dgv("一般產品獎金", I).Value = 獎金計算_dgv("一般產品業績", I).Value / 100 * 業績_達標1_nud.Value
                End If
            Else
                If 獎金計算_dgv("一般產品業績", I).Value < 產品_月薪_nud.Value Then
                    獎金計算_dgv("一般產品獎金", I).Value = 獎金計算_dgv("一般產品業績", I).Value / 100 * 業績_未達標1_nud.Value
                Else
                    獎金計算_dgv("一般產品獎金", I).Value = 獎金計算_dgv("一般產品業績", I).Value / 100 * 業績_達標1_nud.Value
                End If
            End If
            '------美療操作-------------------------------------------------------------------------------------------
            獎金計算_dgv("美療獎金", I).Value = (獎金計算_dgv("美療排程", I).Value / 100 * 美療獎金_nud.Value) + (獎金計算_dgv("美療操作", I).Value / 100 * 美療獎金_nud.Value)
            '------雷射、治療排程-------------------------------------------------------------------------------------------
            If 獎金計算_dgv("排程業績", I).Value < 排程業績_nud.Value Then
                獎金計算_dgv("排程獎金", I).Value = 獎金計算_dgv("排程業績", I).Value / 100 * 業績_未達標2_nud.Value
            Else
                獎金計算_dgv("排程獎金", I).Value = 獎金計算_dgv("排程業績", I).Value / 100 * 業績_達標2_nud.Value
            End If
            '------雷射、治療操作-------------------------------------------------------------------------------------------
            獎金計算_dgv("操作獎金", I).Value = 獎金計算_dgv("操作業績", I).Value / 100 * 操作獎金_nud.Value
            '------手術排程-------------------------------------------------------------------------------------------
            獎金計算_dgv("手術排程獎金", I).Value = 獎金計算_dgv("手術排程", I).Value / 100 * 手術排程_nud.Value
            '------手術操作-------------------------------------------------------------------------------------------
            獎金計算_dgv("手術操作獎金", I).Value = 獎金計算_dgv("手術操作", I).Value / 100 * 手術操作_nud.Value
            '------植髮-------------------------------------------------------------------------------------------
            獎金計算_dgv("植髮/電波獎金", I).Value = 獎金計算_dgv("植髮/電波業績", I).Value / 100 * 植髮獎金_nud.Value
            '------預購療程-------------------------------------------------------------------------------------------
            If 獎金計算_dgv("預購療程", I).Value < 預售_nud.Value Then
                獎金計算_dgv("預購獎金", I).Value = 0
            Else
                獎金計算_dgv("預購獎金", I).Value = 獎金計算_dgv("預購療程", I).Value / 100 * 預售獎金_nud.Value
            End If
            '------彙總-------------------------------------------------------------------------------------------
            獎金計算_dgv("總獎金", I).Value = 獎金計算_dgv("預購獎金", I).Value + 獎金計算_dgv("植髮/電波獎金", I).Value + 獎金計算_dgv("手術操作獎金", I).Value +
                                              獎金計算_dgv("手術排程獎金", I).Value + 獎金計算_dgv("操作獎金", I).Value + 獎金計算_dgv("排程獎金", I).Value +
                                              獎金計算_dgv("美療獎金", I).Value + 獎金計算_dgv("一般產品獎金", I).Value
            獎金計算_dgv("實收業績", I).Value = 獎金計算_dgv("植髮/電波", I).Value + 獎金計算_dgv("手術", I).Value + 獎金計算_dgv("雷射/治療", I).Value +
                                                 獎金計算_dgv("美療", I).Value + 獎金計算_dgv("一般產品", I).Value
            獎金計算_dgv("償還業績", I).Value = (獎金計算_dgv("一般產品業績", I).Value + 獎金計算_dgv("美療排程", I).Value + 獎金計算_dgv("排程業績", I).Value +
                                                 獎金計算_dgv("手術排程", I).Value + 獎金計算_dgv("植髮/電波業績", I).Value + 獎金計算_dgv("預購療程", I).Value -
                                                 獎金計算_dgv("實收業績", I).Value)
            獎金計算_dgv("總業績", I).Value = 獎金計算_dgv("償還業績", I).Value + 獎金計算_dgv("實收業績", I).Value
            If 獎金計算_dgv("總業績", I).Value = 0 Then
                獎金計算_dgv("獎金比", I).Value = "0 %"
            Else
                獎金計算_dgv("獎金比", I).Value = Math.Round(獎金計算_dgv("總獎金", I).Value / 獎金計算_dgv("總業績", I).Value * 100, 2) & " %"
            End If
        Next : GRAMS_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0

        獎金計算_dgv.Columns(2).DefaultCellStyle.BackColor = Color.LightGreen : 獎金計算_dgv.Columns(3).DefaultCellStyle.BackColor = Color.LightGreen
        獎金計算_dgv.Columns(4).DefaultCellStyle.BackColor = Color.LightGreen : 獎金計算_dgv.Columns(5).DefaultCellStyle.BackColor = Color.LightGreen
        獎金計算_dgv.Columns(6).DefaultCellStyle.BackColor = Color.LightGreen : 獎金計算_dgv.Columns(7).DefaultCellStyle.BackColor = Color.LightGreen
        獎金計算_dgv.Columns(8).DefaultCellStyle.BackColor = Color.LightGreen : 獎金計算_dgv.Columns(9).DefaultCellStyle.BackColor = Color.LightGreen
        獎金計算_dgv.Columns(10).DefaultCellStyle.BackColor = Color.LightGreen
        獎金計算_dgv.Columns(11).DefaultCellStyle.BackColor = Color.LightBlue : 獎金計算_dgv.Columns(12).DefaultCellStyle.BackColor = Color.LightBlue
        獎金計算_dgv.Columns(13).DefaultCellStyle.BackColor = Color.LightBlue : 獎金計算_dgv.Columns(14).DefaultCellStyle.BackColor = Color.LightBlue
        獎金計算_dgv.Columns(15).DefaultCellStyle.BackColor = Color.LightBlue : 獎金計算_dgv.Columns(16).DefaultCellStyle.BackColor = Color.LightBlue
        獎金計算_dgv.Columns(17).DefaultCellStyle.BackColor = Color.LightBlue : 獎金計算_dgv.Columns(18).DefaultCellStyle.BackColor = Color.LightBlue
        獎金計算_dgv.Columns(19).DefaultCellStyle.BackColor = Color.LightBlue
        獎金計算_dgv.Columns(20).DefaultCellStyle.BackColor = Color.LightPink : 獎金計算_dgv.Columns(21).DefaultCellStyle.BackColor = Color.LightPink
        獎金計算_dgv.Columns(22).DefaultCellStyle.BackColor = Color.LightPink : 獎金計算_dgv.Columns(23).DefaultCellStyle.BackColor = Color.LightPink
        獎金計算_dgv.Columns(24).DefaultCellStyle.BackColor = Color.LightPink : 獎金計算_dgv.Columns(25).DefaultCellStyle.BackColor = Color.LightPink
        獎金計算_dgv.Columns(26).DefaultCellStyle.BackColor = Color.OrangeRed

        獎金計算_dgv.Sort(獎金計算_dgv.Columns("實收業績"), System.ComponentModel.ListSortDirection.Descending)
        表格繪製()
    End Sub
    Private Sub SET_使用者下拉清單載入()
        SQL_客戶交易明細表_月份() : 月份_cb.Items.Clear() : 月份1_cb.Items.Clear() : 月份2_cb.Items.Clear()
        While (dr.Read()) : 月份_cb.Items.Add(dr("月份")) : 月份1_cb.Items.Add(dr("月份")) : 月份2_cb.Items.Add(dr("月份")) : End While : conn.Close()
    End Sub
    Private Sub 表格繪製()
        '-------線狀圖------------------------------------------------------
        Chart1.Series.Clear() : Chart1.ChartAreas(0).AxisX.Minimum = 0 : Chart1.ChartAreas(0).AxisX.Maximum = 獎金計算_dgv.Rows.Count
        Chart1.Series.Add("實收業績") : Chart1.Series("實收業績").ChartType = SeriesChartType.Column
        For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
            Chart1.Series("實收業績").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("實收業績").Value.ToString)
        Next
        Chart1.Series.Add("償還業績") : Chart1.Series("償還業績").ChartType = SeriesChartType.Column
        For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
            Chart1.Series("償還業績").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("償還業績").Value.ToString)
        Next
        If CheckBox1.Checked = True Then
            Chart1.Series.Add("一般產品") : Chart1.Series("一般產品").ChartType = SeriesChartType.Line
            For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
                Chart1.Series("一般產品").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("一般產品").Value.ToString)
            Next
        End If
        If CheckBox2.Checked = True Then
            Chart1.Series.Add("美療") : Chart1.Series("美療").ChartType = SeriesChartType.Line
            For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
                Chart1.Series("美療").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("美療").Value.ToString)
            Next
        End If
        If CheckBox3.Checked = True Then
            Chart1.Series.Add("雷射/治療") : Chart1.Series("雷射/治療").ChartType = SeriesChartType.Line
            For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
                Chart1.Series("雷射/治療").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("雷射/治療").Value.ToString)
            Next
        End If
        If CheckBox4.Checked = True Then
            Chart1.Series.Add("手術") : Chart1.Series("手術").ChartType = SeriesChartType.Line
            For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
                Chart1.Series("手術").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("手術").Value.ToString)
            Next
        End If
        If CheckBox5.Checked = True Then
            Chart1.Series.Add("植髮/電波") : Chart1.Series("植髮/電波").ChartType = SeriesChartType.Line
            For i As Integer = 0 To 獎金計算_dgv.Rows.Count - 1
                Chart1.Series("植髮/電波").Points.AddXY(獎金計算_dgv.Rows(i).Cells("人員").Value.ToString, 獎金計算_dgv.Rows(i).Cells("植髮/電波").Value.ToString)
            Next
        End If
    End Sub
    Private Sub 人員貢獻分析表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = GRAMS_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        SET_使用者下拉清單載入() : 月份_cb.SelectedIndex = 月份_cb.Items.Count - 1 : 月份1_cb.SelectedIndex = 月份1_cb.Items.Count - 2 : 月份2_cb.SelectedIndex = 月份2_cb.Items.Count - 3
        SET_客戶交易明細表() : 月1 = 1 : 月2 = 2 : 月3 = 3

        姓名_tb.Text = 獎金計算_dgv("人員", 0).Value.ToString
        Label18.Text = "從 " & 月份2_cb.Text & " 到 " & 月份_cb.Text & " 的"

        Chart2.Series.Clear()
        Chart2.Series.Add("總業績") : Chart2.Series("總業績").ChartType = SeriesChartType.Pie
        Chart2.Series("總業績").IsValueShownAsLabel = True
        Chart2.Series("總業績").IsVisibleInLegend = True
        Chart2.Series("總業績").IsXValueIndexed = True
        Chart2.Series("總業績").Points.AddXY("實收業績", Format(獎金計算_dgv.Rows(0).Cells("實收業績").Value, "#,##0"))
        Chart2.Series("總業績").Points.AddXY("償還業績", Format(獎金計算_dgv.Rows(0).Cells("償還業績").Value, "#,##0"))

        Chart3.Series.Clear()
        Chart3.Series.Add("整體業績") : Chart3.Series("整體業績").ChartType = SeriesChartType.Pie
        Chart3.Series("整體業績").IsValueShownAsLabel = True
        Chart3.Series("整體業績").IsVisibleInLegend = True
        Chart3.Series("整體業績").IsXValueIndexed = True
        Chart3.Series("整體業績").Points.AddXY("一般產品", Format(獎金計算_dgv.Rows(0).Cells("一般產品業績").Value, "#,##0"))
        Chart3.Series("整體業績").Points.AddXY("美療", Format(獎金計算_dgv.Rows(0).Cells("美療排程").Value, "#,##0"))
        Chart3.Series("整體業績").Points.AddXY("雷射/治療", Format(獎金計算_dgv.Rows(0).Cells("排程業績").Value, "#,##0"))
        Chart3.Series("整體業績").Points.AddXY("手術", Format(獎金計算_dgv.Rows(0).Cells("手術排程").Value, "#,##0"))
        Chart3.Series("整體業績").Points.AddXY("植髮/電波", Format(獎金計算_dgv.Rows(0).Cells("植髮/電波業績").Value, "#,##0"))
        Chart3.Series("整體業績").Points.AddXY("預購療程", Format(獎金計算_dgv.Rows(0).Cells("預購療程").Value, "#,##0"))

        Chart4.Series.Clear()
        Chart4.Series.Add("實收業績") : Chart4.Series("實收業績").ChartType = SeriesChartType.Pie
        Chart4.Series("實收業績").IsValueShownAsLabel = True
        Chart4.Series("實收業績").IsVisibleInLegend = True
        Chart4.Series("實收業績").IsXValueIndexed = True
        Chart4.Series("實收業績").Points.AddXY("一般產品", Format(獎金計算_dgv.Rows(0).Cells("一般產品").Value, "#,##0"))
        Chart4.Series("實收業績").Points.AddXY("美療", Format(獎金計算_dgv.Rows(0).Cells("美療").Value, "#,##0"))
        Chart4.Series("實收業績").Points.AddXY("雷射/治療", Format(獎金計算_dgv.Rows(0).Cells("雷射/治療").Value, "#,##0"))
        Chart4.Series("實收業績").Points.AddXY("手術", Format(獎金計算_dgv.Rows(0).Cells("手術").Value, "#,##0"))
        Chart4.Series("實收業績").Points.AddXY("植髮/電波", Format(獎金計算_dgv.Rows(0).Cells("植髮/電波").Value, "#,##0"))

        SET_產品()
    End Sub
    Private Sub 產品_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 產品_dgv.MouseUp
        If 產品_dgv.SelectedRows.Count > 0 Then
            Dim sb As New System.Text.StringBuilder()
            Dim x As Double = 0
            'Dim y As Double = 0
            For i As Integer = 0 To 產品_dgv.SelectedRows.Count - 1
                x += Math.Round(產品_dgv.Rows(產品_dgv.SelectedRows.Item(i).Index).Cells(2).Value, 1)
            Next i
            選擇加總_tb.Text = Strings.Format(x, "#,##0")
        End If
    End Sub
    Private Sub 獎金計算_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 獎金計算_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            姓名_tb.Text = 獎金計算_dgv("人員", e.RowIndex).Value.ToString
            Label18.Text = "從 " & 月份2_cb.Text & " 到 " & 月份_cb.Text & " 的"

            Chart2.Series.Clear()
            Chart2.Series.Add("總業績") : Chart2.Series("總業績").ChartType = SeriesChartType.Pie
            Chart2.Series("總業績").IsValueShownAsLabel = True
            Chart2.Series("總業績").IsVisibleInLegend = True
            Chart2.Series("總業績").IsXValueIndexed = True
            Chart2.Series("總業績").Points.AddXY("實收業績", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("實收業績").Value, "#,##0"))
            Chart2.Series("總業績").Points.AddXY("償還業績", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("償還業績").Value, "#,##0"))

            Chart3.Series.Clear()
            Chart3.Series.Add("整體業績") : Chart3.Series("整體業績").ChartType = SeriesChartType.Pie
            Chart3.Series("整體業績").IsValueShownAsLabel = True
            Chart3.Series("整體業績").IsVisibleInLegend = True
            Chart3.Series("整體業績").IsXValueIndexed = True
            Chart3.Series("整體業績").Points.AddXY("一般產品", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("一般產品業績").Value, "#,##0"))
            Chart3.Series("整體業績").Points.AddXY("美療", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("美療排程").Value, "#,##0"))
            Chart3.Series("整體業績").Points.AddXY("雷射/治療", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("排程業績").Value, "#,##0"))
            Chart3.Series("整體業績").Points.AddXY("手術", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("手術排程").Value, "#,##0"))
            Chart3.Series("整體業績").Points.AddXY("植髮/電波", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("植髮/電波業績").Value, "#,##0"))
            Chart3.Series("整體業績").Points.AddXY("預購療程", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("預購療程").Value, "#,##0"))

            Chart4.Series.Clear()
            Chart4.Series.Add("實收業績") : Chart4.Series("實收業績").ChartType = SeriesChartType.Pie
            Chart4.Series("實收業績").IsValueShownAsLabel = True
            Chart4.Series("實收業績").IsVisibleInLegend = True
            Chart4.Series("實收業績").IsXValueIndexed = True
            Chart4.Series("實收業績").Points.AddXY("一般產品", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("一般產品").Value, "#,##0"))
            Chart4.Series("實收業績").Points.AddXY("美療", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("美療").Value, "#,##0"))
            Chart4.Series("實收業績").Points.AddXY("雷射/治療", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("雷射/治療").Value, "#,##0"))
            Chart4.Series("實收業績").Points.AddXY("手術", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("手術").Value, "#,##0"))
            Chart4.Series("實收業績").Points.AddXY("植髮/電波", Format(獎金計算_dgv.Rows(e.RowIndex).Cells("植髮/電波").Value, "#,##0"))

            SET_產品()
        End If
    End Sub
    Private Sub 獎金計算_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 獎金計算_dgv.RowPostPaint
        表格繪製()
    End Sub
    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
        表格繪製()
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click
        表格繪製()
    End Sub
    Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.Click
        表格繪製()
    End Sub
    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
        表格繪製()
    End Sub
    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.Click
        表格繪製()
    End Sub
    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
        SET_產品()
    End Sub
    Private Sub RadioButton6_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton6.Click
        SET_產品()
    End Sub
    Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.Click
        SET_產品()
    End Sub
    Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.Click
        SET_產品()
    End Sub
    Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.Click
        SET_產品()
    End Sub
    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click
        SET_產品()
    End Sub
    Private Sub RadioButton7_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton7.Click
        SET_產品()
    End Sub
    Private Sub 上個月_bt_Click(sender As Object, e As EventArgs) Handles 上個月_bt.Click
        If 月3 = 月份2_cb.Items.Count Then
            MsgBox("沒有上個月了!!")
        Else
            月1 += 1 : 月2 += 1 : 月3 += 1
            月份_cb.SelectedIndex = 月份_cb.Items.Count - 月1 : 月份1_cb.SelectedIndex = 月份1_cb.Items.Count - 月2 : 月份2_cb.SelectedIndex = 月份2_cb.Items.Count - 月3
            SET_客戶交易明細表()
        End If
    End Sub
    Private Sub 下個月_bt_Click(sender As Object, e As EventArgs) Handles 下個月_bt.Click
        If 月1 = 1 Then
            MsgBox("沒有下個月了!!")
        Else
            月1 -= 1 : 月2 -= 1 : 月3 -= 1
            月份_cb.SelectedIndex = 月份_cb.Items.Count - 月1 : 月份1_cb.SelectedIndex = 月份1_cb.Items.Count - 月2 : 月份2_cb.SelectedIndex = 月份2_cb.Items.Count - 月3
            SET_客戶交易明細表()
        End If
    End Sub
End Class