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
        SQL_系統使用者管理清單()
        da.Fill(ds) : 使用者清單_dgv.DataSource = ds.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_grid()
        使用者清單_dgv.Columns(0).FillWeight = 60 : 使用者清單_dgv.Columns(1).FillWeight = 90 : 使用者清單_dgv.Columns(2).FillWeight = 100 : 使用者清單_dgv.Columns(3).FillWeight = 60
        For i As Integer = 1 To 權限數量
            使用者清單_dgv.Columns(i + 3).Visible = False
        Next
        For i As Integer = 0 To 使用者清單_dgv.Rows.Count - 1
            If IsDBNull(使用者清單_dgv.Rows(i).Cells("CC17").Value) Then
                使用者清單_dgv.Rows(i).Cells("CC17").Value = False
            End If
            If 使用者清單_dgv.Rows(i).Cells("CC17").Value = True Then
                使用者清單_dgv.Rows(i).Cells("Password").Value = "******"
            End If
        Next
    End Sub
    Private Sub 系統使用者管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        首次開啟 = False : Set_使用者清單() : Set_grid() : 首次開啟 = True
        修改_bt.Enabled = False : 新增_bt.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("UserName").Value : 密碼_tb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("Password").Value
                編號_tb.Text = 使用者清單_dgv.Rows(e.RowIndex).Cells("DIN_O").Value
                If IsDBNull(使用者清單_dgv.Rows(e.RowIndex).Cells("DIN").Value) Then
                    修改_bt.Enabled = False : 新增_bt.Enabled = True
                    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 = False
                    Next
                Else
                    修改_bt.Enabled = True : 新增_bt.Enabled = False
                End If
                '---------同時控制所有具有一定命名規則的控件---------------------------------------------------------------------------------------------------------------------------------------------
                For no As Integer = 1 To 權限數量
                    If IsDBNull(使用者清單_dgv.Rows(e.RowIndex).Cells("DIN").Value) Then : Else
                        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
                    End If
                Next
            End If
        End If
    End Sub
    Private Sub 顯示密碼_bt_Click(sender As Object, e As EventArgs) Handles 顯示密碼_bt.Click
        SQL_系統使用者密碼顯示()
        If dr.Read() Then : 密碼_tb.Text = dr("Password") : End If : conn.Close()
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        SQL_系統使用者權限新增() : MsgBox("新增完成") : Set_使用者清單() : Set_grid()
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If 姓名_tb.Text = "" Or 密碼_tb.Text = "" Then
            MsgBox("輸入資料有誤")
        Else
            SQL_系統使用者權限修改() : MsgBox("新增完成")
        End If
        Set_使用者清單() : Set_grid() : conn.Close()
    End Sub
    '-------------------------------------------------------------------------------------------------------------
    Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.Click
        If CheckBox7.Checked = False Then : CheckBox7.Checked = True : End If
    End Sub
    Private Sub CheckBox9_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox9.Click
        If CheckBox7.Checked = False Then : CheckBox7.Checked = True : End If
    End Sub
    Private Sub CheckBox10_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox10.Click
        If CheckBox7.Checked = False Then : CheckBox7.Checked = True : End If
    End Sub
    Private Sub CheckBox24_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox24.Click
        If CheckBox7.Checked = False Then : CheckBox7.Checked = True : End If
    End Sub
    '-------------------------------------------------------------------------------------------------------------
    Private Sub CheckBox12_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox12.Click
        If CheckBox11.Checked = False Then : CheckBox11.Checked = True : End If
    End Sub
    Private Sub CheckBox13_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox13.Click
        If CheckBox11.Checked = False Then : CheckBox11.Checked = True : End If
    End Sub
    Private Sub CheckBox25_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox25.Click
        If CheckBox11.Checked = False Then : CheckBox11.Checked = True : End If
    End Sub
    Private Sub CheckBox15_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox15.Click
        If CheckBox11.Checked = False Then : CheckBox11.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 CheckBox16_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox16.Click
        If CheckBox14.Checked = False Then : CheckBox14.Checked = True : End If
    End Sub
    Private Sub CheckBox26_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox26.Click
        If CheckBox14.Checked = False Then : CheckBox14.Checked = True : End If
    End Sub
    Private Sub CheckBox27_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox27.Click
        If CheckBox14.Checked = False Then : CheckBox14.Checked = True : End If
    End Sub

    '-------------------------------------------------------------------------------------------------------------
    Private Sub CheckBox17_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox17.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
    Private Sub CheckBox18_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox18.Click
        If CheckBox6.Checked = False Then : CheckBox6.Checked = True : End If
    End Sub
End Class