Option Strict Off
Public Class 系統使用者管理
    ReadOnly ds As New DataSet
    Dim HH As String : Dim 首次開啟 As Boolean = False
    Private Sub Set_使用者清單()
        使用者清單_dgv.DataSource = Nothing : ds.Clear()
        使用者清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        使用者清單_dgv.ColumnHeadersHeight = 25
        使用者清單_dgv.AllowUserToAddRows = False
        使用者清單_dgv.RowTemplate.Height = 30
        SQL_系統使用者管理清單()
        da.Fill(ds) : 使用者清單_dgv.DataSource = ds.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_grid()
        使用者清單_dgv.Columns(0).FillWeight = 90 : 使用者清單_dgv.Columns(1).FillWeight = 90 : 使用者清單_dgv.Columns(2).FillWeight = 75 : 使用者清單_dgv.Columns(3).FillWeight = 60
        使用者清單_dgv.Columns(4).FillWeight = 60
        For i As Integer = 1 To 權限數量
            使用者清單_dgv.Columns(i + 4).Visible = False
        Next
        For i As Integer = 0 To 使用者清單_dgv.Rows.Count - 1 : 使用者清單_dgv.Rows(i).Cells("密碼").Value = "******" : Next
    End Sub
    Private Sub Set_格式設定()
        確認新增_bt.Enabled = False : 儲存修改_bt.Enabled = False
    End Sub
    Private Sub 職務_cb_下拉表單資料載入()
        SQL_系統使用者管理_職稱下拉清單() : 職務_cb.Items.Clear() : 級別_cb.Items.Clear()
        While (dr.Read()) : 職務_cb.Items.Add(dr("職稱")) : 級別_cb.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
        首次開啟 = False
        Set_使用者清單() : Set_grid() : Set_格式設定() : 職務_cb_下拉表單資料載入()
        首次開啟 = True
        姓名_tb.Enabled = False : 帳號_tb.Enabled = False : 密碼_tb.Enabled = False
    End Sub
    Private Sub 使用者清單_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 使用者清單_dgv.CellEnter
        If 首次開啟 = True Then
            If e.RowIndex = -1 Then : Else
                姓名_tb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("姓名").Value : 帳號_tb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("帳號").Value
                密碼_tb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("密碼").Value : 職務_cb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("職稱").Value
                級別_cb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("級別").Value
                '---------同時控制所有具有一定命名規則的控件---------------------------------------------------------------------------------------------------------------------------------------------
                For no As Integer = 1 To 權限數量
                    If no < 10 Then : HH = "0" & no : ElseIf no >= 10 Then : HH = no : End If
                    Dim checkbox As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
                    checkbox.Checked = 使用者清單_dgv.Rows(e.RowIndex).Cells("CC" & HH).Value
                Next
            End If
        End If
    End Sub
    Private Sub 確認新增_bt_Click(sender As Object, e As EventArgs) Handles 確認新增_bt.Click
        SQL_系統使用者新增()
        conn.Close() : MsgBox("新增完成") : Set_使用者清單() : Set_grid()
        確認新增_bt.Enabled = False : 新增_bt.Enabled = True : 修改_bt.Enabled = True : 姓名_tb.Enabled = False : 帳號_tb.Enabled = False : 密碼_tb.Enabled = False
    End Sub
    Private Sub 儲存修改_bt_Click(sender As Object, e As EventArgs) Handles 儲存修改_bt.Click
        If 姓名_tb.Text = "" Or 帳號_tb.Text = "" Or 密碼_tb.Text = "" Then : MsgBox("輸入資料有誤") : Else
            If 密碼_tb.Text = "******" Then
                SQL_系統使用者密碼顯示()
                If dr.Read() Then : 密碼_tb.Text = dr("密碼") : End If : conn.Close()
            End If
            SQL_系統使用者修改() : conn.Close() : MsgBox("新增完成")
        End If : Set_使用者清單() : Set_grid()
        儲存修改_bt.Enabled = False : 新增_bt.Enabled = True : 修改_bt.Enabled = True : 姓名_tb.Enabled = False : 帳號_tb.Enabled = False : 密碼_tb.Enabled = False
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        Dim aa As MsgBoxResult = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
        If aa = MsgBoxResult.Ok Then
            SQL_系統使用者刪除() : MsgBox("刪除完成")
        End If : conn.Close()
        姓名_tb.Text = "" : 帳號_tb.Text = "" : 帳號_tb.Text = "" : Set_使用者清單() : Set_grid()
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        姓名_tb.Text = "" : 帳號_tb.Text = "" : 密碼_tb.Text = "" : 新增_bt.Enabled = False : 修改_bt.Enabled = False : 確認新增_bt.Enabled = True
        姓名_tb.Enabled = True : 帳號_tb.Enabled = True : 密碼_tb.Enabled = True
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        新增_bt.Enabled = False : 修改_bt.Enabled = False : 儲存修改_bt.Enabled = True
        姓名_tb.Enabled = True : 帳號_tb.Enabled = True : 密碼_tb.Enabled = True
    End Sub
    Private Sub 顯示密碼_bt_Click(sender As Object, e As EventArgs) Handles 顯示密碼_bt.Click
        SQL_系統使用者密碼顯示()
        If dr.Read() Then : 密碼_tb.Text = dr("密碼") : End If : conn.Close()
    End Sub
    Private Sub 職務_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 職務_cb.SelectedIndexChanged
        級別_cb.SelectedIndex = 職務_cb.SelectedIndex
    End Sub
    Private Sub 級別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 級別_cb.SelectedIndexChanged
        職務_cb.SelectedIndex = 級別_cb.SelectedIndex
    End Sub
    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        使用者清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
    End Sub


    '*************************************************************************************************************************************
    Private Sub CheckBox29_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox29.Click
        If CheckBox28.Checked = False Then : CheckBox28.Checked = True : End If
    End Sub
    Private Sub CheckBox30_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox30.Click
        If CheckBox28.Checked = False Then : CheckBox28.Checked = True : End If
    End Sub


    '*************************************************************************************************************************************
    Private Sub CheckBox24_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox24.Click
        If CheckBox23.Checked = False Then : CheckBox23.Checked = True : End If
    End Sub
    Private Sub CheckBox25_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox25.Click
        If CheckBox23.Checked = False Then : CheckBox23.Checked = True : End If
    End Sub
    Private Sub CheckBox26_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox26.Click
        If CheckBox23.Checked = False Then : CheckBox23.Checked = True : End If
    End Sub
    Private Sub CheckBox27_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox27.Click
        If CheckBox23.Checked = False Then : CheckBox23.Checked = True : End If
    End Sub


    '*************************************************************************************************************************************
    Private Sub CheckBox16_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox16.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub
    Private Sub CheckBox17_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox17.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub
    Private Sub CheckBox18_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox18.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub
    Private Sub CheckBox19_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox19.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub
    Private Sub CheckBox20_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox20.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub
    Private Sub CheckBox21_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox21.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub
    Private Sub CheckBox22_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox22.Click
        If CheckBox15.Checked = False Then : CheckBox15.Checked = True : End If
    End Sub


    '*************************************************************************************************************************************
    Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox7.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox9_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox9.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox10_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox10.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox11_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox11.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox12_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox12.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox13_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox13.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox14_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox14.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub


    '*************************************************************************************************************************************
    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
        If CheckBox1.Checked = False Then : CheckBox1.Checked = True : End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.Click
        If CheckBox1.Checked = False Then : CheckBox1.Checked = True : End If
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click
        If CheckBox1.Checked = False Then : CheckBox1.Checked = True : End If
    End Sub
    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.Click
        If CheckBox1.Checked = False Then : CheckBox1.Checked = True : End If
    End Sub


    '*************************************************************************************************************************************
    Private Sub CheckBox39_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox39.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox40_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox40.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox41_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox41.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox42_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox42.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox43_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox43.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox44_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox44.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox45_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox45.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
    Private Sub CheckBox46_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox46.Click
        If CheckBox38.Checked = False Then : CheckBox38.Checked = True : End If
    End Sub
End Class