Public Class 業務系統資料管理
    ReadOnly ds, ds1, ds2, ds3, ds4, ds5, ds6 As New DataSet
    Dim NUM1 As Integer : Dim EDR As Integer = 0 : Dim ESTR As String
    Private Sub SET_客戶交易明細表()
        交易明細_dgv.DataSource = Nothing : ds.Clear()
        交易明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        交易明細_dgv.ColumnHeadersHeight = 30 : 交易明細_dgv.AllowUserToAddRows = False
        SQL_客戶交易明細表_無類別資料()
        da.Fill(ds) : 交易明細_dgv.DataSource = ds.Tables(0) : conn.Close()
        交易明細_dgv.Columns(0).FillWeight = 300 : 交易明細_dgv.Columns(1).FillWeight = 70
    End Sub
    Private Sub SET_客戶交易明細表1()
        交易明細1_dgv.DataSource = Nothing : ds4.Clear()
        交易明細1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        交易明細1_dgv.ColumnHeadersHeight = 30 : 交易明細1_dgv.AllowUserToAddRows = False
        SQL_客戶交易明細表_集合資料()
        da.Fill(ds4) : 交易明細1_dgv.DataSource = ds4.Tables(0) : conn.Close()
        交易明細1_dgv.Columns(0).FillWeight = 300 : 交易明細1_dgv.Columns(1).FillWeight = 70
    End Sub
    Private Sub SET_產品類別表()
        產品類別表_dgv.DataSource = Nothing : ds1.Clear()
        產品類別表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        產品類別表_dgv.ColumnHeadersHeight = 30 : 產品類別表_dgv.AllowUserToAddRows = False
        PA14 = 品名1_tb.Text
        SQL_產品類別表()
        da.Fill(ds1) : 產品類別表_dgv.DataSource = ds1.Tables(0) : conn.Close()
        產品類別表_dgv.Columns(0).Visible = False : 產品類別表_dgv.Columns(1).FillWeight = 300 : 產品類別表_dgv.Columns(2).FillWeight = 70
    End Sub
    Private Sub SET_產品類別表1()
        產品類別表1_dgv.DataSource = Nothing : ds6.Clear()
        產品類別表1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        產品類別表1_dgv.ColumnHeadersHeight = 30 : 產品類別表1_dgv.AllowUserToAddRows = False
        PA14 = 品名2_tb.Text
        SQL_產品類別表()
        da.Fill(ds6) : 產品類別表1_dgv.DataSource = ds6.Tables(0) : conn.Close()
        產品類別表1_dgv.Columns(0).Visible = False : 產品類別表1_dgv.Columns(1).FillWeight = 300 : 產品類別表1_dgv.Columns(2).FillWeight = 70
    End Sub
    Private Sub 讀取人員資料表()
        人員1_dgv.DataSource = Nothing : ds2.Clear()
        人員1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        人員1_dgv.ColumnHeadersHeight = 30
        人員1_dgv.AllowUserToAddRows = False
        SQL_人員資料2()
        da.Fill(ds2) : 人員1_dgv.DataSource = ds2.Tables(0) : conn.Close()
        人員1_dgv.Columns(1).Visible = False : 人員1_dgv.Columns(2).Visible = False : 人員1_dgv.Columns(3).Visible = False
        For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
            If 人員1_dgv(1, I).Value.ToString <> "" Then
                人員1_dgv(0, I).Value = 人員1_dgv(1, I).Value.ToString
            ElseIf 人員1_dgv(2, I).Value.ToString <> "" Then
                人員1_dgv(0, I).Value = 人員1_dgv(2, I).Value.ToString
            ElseIf 人員1_dgv(3, I).Value.ToString <> "" Then
                人員1_dgv(0, I).Value = 人員1_dgv(3, I).Value.ToString
            End If
        Next
    End Sub
    Private Sub 讀取人員資料表2()
        人員2_dgv.DataSource = Nothing : ds3.Clear()
        人員2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        人員2_dgv.ColumnHeadersHeight = 30
        人員2_dgv.AllowUserToAddRows = False
        SQL_人員資料1()
        da.Fill(ds3) : 人員2_dgv.DataSource = ds3.Tables(0) : conn.Close()
        人員2_dgv.Columns(0).FillWeight = 65 : 人員2_dgv.Columns(1).FillWeight = 75 : 人員2_dgv.Columns(2).FillWeight = 45
    End Sub
    Private Sub 業務系統資料管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = GRAMS_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        品名1_tb.Text = "%%"
        SET_客戶交易明細表() : 讀取人員資料表() : 讀取人員資料表2() : SET_客戶交易明細表1() : SET_產品類別表1()
    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
            品名1_tb.Text = 交易明細_dgv("品名", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 交易明細1_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 交易明細1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            品名2_tb.Text = 交易明細1_dgv("品名", e.RowIndex).Value.ToString
            品名3_tb.Text = 交易明細1_dgv("品名", e.RowIndex).Value.ToString
        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
            流水號1_tb.Text = 產品類別表_dgv("流水號", e.RowIndex).Value.ToString
            類別_cb.Text = 產品類別表_dgv("類別", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 人員1_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 人員1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            姓名_tb.Text = 人員1_dgv("診所員工", e.RowIndex).Value.ToString
            For I As Integer = 0 To 人員2_dgv.Rows.Count - 1
                If 姓名_tb.Text = 人員2_dgv("診所員工", I).Value.ToString Then
                    MsgBox("該人員已經在清單中") : 姓名_tb.Text = "" : 流水號2_tb.Text = "" : 時薪_cb.Text = ""
                    Exit Sub
                End If
            Next
            SQL_診所員工_最後一筆資料()
            If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("流水號").ToString, 3)) : Else : EDR = 0 : End If
            conn.Close() : EDR += 1
            If EDR < 10 Then : ESTR = "BL" & "00" & EDR
            ElseIf EDR > 9 And EDR < 100 Then : ESTR = "BL" & "0" & EDR
            ElseIf EDR > 99 Then : ESTR = "BL" & EDR : End If
            流水號2_tb.Text = ESTR : 時薪_cb.Text = ""
        End If
    End Sub
    Private Sub 人員2_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 人員2_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            姓名_tb.Text = 人員2_dgv("診所員工", e.RowIndex).Value.ToString : 流水號2_tb.Text = 人員2_dgv("流水號", e.RowIndex).Value.ToString
            時薪_cb.Text = 人員2_dgv("時薪", e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub 品名1_tb_TextChanged(sender As Object, e As EventArgs) Handles 品名1_tb.TextChanged
        SET_產品類別表()
    End Sub
    Private Sub 重新整理1_bt_Click(sender As Object, e As EventArgs) Handles 重新整理1_bt.Click
        品名1_tb.Text = "%%"
    End Sub
    Private Sub 新增1_bt_Click(sender As Object, e As EventArgs) Handles 新增1_bt.Click
        If 流水號2_tb.Text = "" Or 姓名_tb.Text = "" Then
            MsgBox("資料不足!!!")
        Else
            PA = 流水號2_tb.Text : PA1 = 姓名_tb.Text : PA2 = 時薪_cb.Text
            SQL_診所員工_新增() : conn.Close() : MsgBox("新增完成!!!") : 讀取人員資料表() : 讀取人員資料表2()
        End If
    End Sub
    Private Sub 交易明細表品名修正_bt_Click(sender As Object, e As EventArgs) Handles 交易明細表品名修正_bt.Click
        If 品名2_tb.Text = "" Or 品名3_tb.Text = "" Then
            MsgBox("資料不足!!!")
        Else
            SQL_客戶交易明細表_品名修改() : conn.Close() : MsgBox("修改完成!!!") : SET_客戶交易明細表1() : SET_產品類別表1()
        End If
    End Sub
    Private Sub 重新整理2_bt_Click(sender As Object, e As EventArgs) Handles 重新整理2_bt.Click
        SET_客戶交易明細表1() : SET_產品類別表1()
    End Sub
    Private Sub 重新整理3_bt_Click(sender As Object, e As EventArgs) Handles 重新整理3_bt.Click
        品名2_tb.Text = "" : 品名3_tb.Text = "" : SET_客戶交易明細表1() : SET_產品類別表1()
    End Sub
    Private Sub 刪除2_bt_Click(sender As Object, e As EventArgs) Handles 刪除2_bt.Click
        If 流水號2_tb.Text = "" Or 姓名_tb.Text = "" Then
            MsgBox("資料不足!!!")
        Else
            Dim aa1 As MsgBoxResult = MsgBox("確定要刪除選中的資料!!!", MsgBoxStyle.OkCancel)
            If aa1 = MsgBoxResult.Ok Then
                SQL_診所員工_刪除() : conn.Close() : MsgBox("刪除完成!!!") : 讀取人員資料表() : 讀取人員資料表2()
            End If
        End If
    End Sub
    Private Sub 修改1_bt_Click(sender As Object, e As EventArgs) Handles 修改1_bt.Click
        If 流水號1_tb.Text = "" Or 品名1_tb.Text = "" Then
            MsgBox("資料不足!!!")
        Else
            SQL_產品類別表_修改() : conn.Close() : MsgBox("修改完成!!!") : SET_產品類別表()
        End If
    End Sub
    Private Sub 刪除1_bt_Click(sender As Object, e As EventArgs) Handles 刪除1_bt.Click
        If 流水號1_tb.Text = "" Or 品名1_tb.Text = "" Then
            MsgBox("資料不足!!!")
        Else
            Dim aa1 As MsgBoxResult = MsgBox("確定要刪除選中的資料!!!", MsgBoxStyle.OkCancel)
            If aa1 = MsgBoxResult.Ok Then
                SQL_產品類別表_刪除() : conn.Close() : MsgBox("刪除完成!!!") : SET_產品類別表()
            End If
        End If
    End Sub
    Private Sub 產品類別存檔_bt_Click(sender As Object, e As EventArgs) Handles 產品類別存檔_bt.Click
        SQL_產品類別表_最後一筆資料()
        If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("流水號").ToString, 5)) : Else : EDR = 0 : End If
        conn.Close() : EDR += 1
        If EDR < 10 Then : ESTR = "AS" & "0000" & EDR
        ElseIf EDR > 9 And EDR < 100 Then : ESTR = "AS" & "000" & EDR
        ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "AS" & "00" & EDR
        ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "AS" & "0" & EDR
        ElseIf EDR > 9999 Then : ESTR = "AS" & EDR : End If
        PA = ESTR : PA1 = 品名_tb.Text : PA2 = 類別_tb.Text
        SQL_產品類別表_新增() : SET_客戶交易明細表() : SET_產品類別表()
    End Sub
End Class