Public Class 系統使用者管理
    Dim 資料長度, 資料寬度, BBNN1, FG As Integer
    Dim 權限代號, QQW(11), 權限名稱, HH As String
    Dim 權限選取 As Boolean = False
    Dim file_name As String = ""
    Dim RI As Integer = -1
    Dim SK As String = "要查找的 KEY"
    Dim Str As String = Application.StartupPath
    Dim 對話框(36) As String
    Private Sub Set_權限清單()
        Dim ds1 As New DataSet
        預設權限_dgv.DataSource = Nothing : ds1.Clear()
        預設權限_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        預設權限_dgv.ColumnHeadersHeight = 25 : 預設權限_dgv.AllowUserToAddRows = False : 預設權限_dgv.RowTemplate.Height = 35
        PA40 = 職稱_cb.Text : SQL_系統權限預設表_單一讀取()
        da.Fill(ds1) : 預設權限_dgv.DataSource = ds1.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_使用者清單()
        Dim ds, ds1 As New DataSet
        清單_dgv.DataSource = Nothing : ds.Clear() : ds1.Clear()
        清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單_dgv.ColumnHeadersHeight = 25 : 清單_dgv.AllowUserToAddRows = False : 清單_dgv.RowTemplate.Height = 35
        清單1_dgv.DataSource = Nothing
        清單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單1_dgv.ColumnHeadersHeight = 25 : 清單1_dgv.AllowUserToAddRows = False : 清單1_dgv.RowTemplate.Height = 35
        If 小間距1_ch.Checked = False And 中間距1_ch.Checked = False And 大間距1_ch.Checked = True Then : 清單1_dgv.RowTemplate.Height = 75
        ElseIf 小間距1_ch.Checked = False And 中間距1_ch.Checked = True And 大間距1_ch.Checked = False Then : 清單1_dgv.RowTemplate.Height = 45
        ElseIf 小間距1_ch.Checked = True And 中間距1_ch.Checked = False And 大間距1_ch.Checked = False Then : 清單1_dgv.RowTemplate.Height = 25 : End If

        SQL_系統使用者管理_使用者清單()
        da.Fill(ds) : 清單_dgv.DataSource = ds.Tables(0) : da.Fill(ds1) : 清單1_dgv.DataSource = ds1.Tables(0) : conn.Close() : Set_grid()
        清單1_dgv.Columns(6).Visible = True
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            Dim 驗證 As String = "" : Dim 取變數 As String
            取變數 = 清單1_dgv.Rows(i).Cells(3).Value.ToString : NN1 = 0
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = " " Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            清單1_dgv.Rows(i).Cells(3).Value = 驗證

            取變數 = 清單1_dgv.Rows(i).Cells(4).Value.ToString : NN1 = 0
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = " " Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            清單1_dgv.Rows(i).Cells(4).Value = 驗證

            取變數 = 清單1_dgv.Rows(i).Cells(5).Value.ToString : NN1 = 0
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = " " Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            清單1_dgv.Rows(i).Cells(5).Value = 驗證

            取變數 = 清單1_dgv.Rows(i).Cells(7).Value.ToString : NN1 = 0
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = "/" Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            清單1_dgv.Rows(i).Cells(7).Value = 驗證
        Next
    End Sub
    Private Sub Set_grid()
        清單1_dgv.Columns(0).FillWeight = 90 : 清單1_dgv.Columns(1).Visible = False : 清單1_dgv.Columns(2).Visible = False : 清單1_dgv.Columns(3).FillWeight = 70
        清單1_dgv.Columns(4).FillWeight = 80 : 清單1_dgv.Columns(5).FillWeight = 80 : 清單1_dgv.Columns(6).FillWeight = 50 : 清單1_dgv.Columns(7).FillWeight = 90
        清單1_dgv.Columns(8).Visible = False : 清單1_dgv.Columns(9).FillWeight = 25 : 清單1_dgv.Columns(10).FillWeight = 55 : 清單1_dgv.Columns(11).FillWeight = 35
        For i As Integer = 0 To 權限數量 - 1
            清單1_dgv.Columns(i + 12).Visible = False
        Next
        If 顯示密碼_bt.Enabled = True And 隱藏密碼_bt.Enabled = False Then
            For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
                清單_dgv(2, i).Value = "**********"
            Next
        End If
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            If 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "01" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "02" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "03" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "04" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "05" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue : End If
        Next
        If 登入人級別 = "00" Then : 清單1_dgv.Columns("CC63").Visible = True : 清單1_dgv.Columns("CC63").FillWeight = 10 : End If
    End Sub
    Private Sub Set_格式設定()
        隱藏密碼_bt.Enabled = False
        For no As Integer = 1 To 權限數量
            Dim 選擇 As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
            選擇.Checked = False
        Next
    End Sub
    Private Sub 下拉清單_職稱()
        PA47 = 部門_cb.Text : PA48 = 處別_cb.Text : SQL_系統使用者管理_下拉清單_職稱()
        級別_cb.Items.Clear() : 職稱_cb.Items.Clear() : 職稱1_cb.Items.Clear()
        While (dr.Read()) : 職稱_cb.Items.Add(dr("職稱")) : 級別_cb.Items.Add(dr("級別"))
            Dim 驗證 As String = "" : Dim 取變數 As String : NN1 = 0
            取變數 = dr("職稱")
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = "/" Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            職稱1_cb.Items.Add(驗證)
        End While : conn.Close()
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        SQL_系統使用者管理_下拉清單_部門() : 部門_cb.Items.Clear() : 部門_cb.Items.Add("") : 部門1_cb.Items.Clear() : 部門1_cb.Items.Add("")
        While (dr.Read()) : 部門_cb.Items.Add(dr("部門"))
            Dim 驗證 As String = "" : Dim 取變數 As String : NN1 = 0
            取變數 = dr("部門")
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = " " Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            部門1_cb.Items.Add(驗證)
        End While : conn.Close()
    End Sub
    Private Sub ComboBox5下拉表單資料載入()
        PA20 = Strings.Left(部門_cb.Text, 1) : SQL_系統使用者管理_下拉清單_處別()
        處別_cb.Items.Clear() : 處別_cb.Items.Add("") : 處別1_cb.Items.Clear() : 處別1_cb.Items.Add("")
        While (dr.Read()) : 處別_cb.Items.Add(dr("處"))
            Dim 驗證 As String = "" : Dim 取變數 As String : NN1 = 0
            取變數 = dr("處")
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = " " Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            處別1_cb.Items.Add(驗證)
        End While : conn.Close()
    End Sub
    Private Sub ComboBox3下拉表單資料載入()
        PA20 = Strings.Left(處別_cb.Text, 2) : SQL_系統使用者管理_下拉清單_課別()
        課別_cb.Items.Clear() : 課別_cb.Items.Add("") : 課別1_cb.Items.Clear() : 課別1_cb.Items.Add("")
        While (dr.Read()) : 課別_cb.Items.Add(dr("課別"))
            Dim 驗證 As String = "" : Dim 取變數 As String : NN1 = 0
            取變數 = dr("課別")
            For ii As Integer = 1 To 20
                If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : NN1 += 1 : Else
                    If Strings.Mid(取變數, ii, 1) = " " Then : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : NN1 += 1 : End If
                End If
            Next
            課別1_cb.Items.Add(驗證)
        End While : conn.Close()
    End Sub
    Private Sub ComboBox4下拉表單資料載入()
        PA20 = Strings.Left(課別_cb.Text, 3) : SQL_系統使用者管理_下拉清單_組別()
        組別_cb.Items.Clear() : 組別_cb.Items.Add("") : 組別1_cb.Items.Clear() : 組別1_cb.Items.Add("")
        While (dr.Read()) : 組別_cb.Items.Add(dr("組別")) : 組別1_cb.Items.Add(dr("組別")) : End While : conn.Close()
    End Sub
    Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.新增_bt, "新增")
    End Sub
    Private Sub 確認新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 確認新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.確認新增_bt, "新增存檔")
    End Sub
    Private Sub 修改1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改1_bt, "修改")
    End Sub
    Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改_bt, "修改存檔")
    End Sub
    Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
    End Sub
    Private Sub 顯示密碼_bt_MouseEnter(sender As Object, e As EventArgs) Handles 顯示密碼_bt.MouseEnter
        ToolTip1.SetToolTip(Me.顯示密碼_bt, "顯示密碼")
    End Sub
    Private Sub 隱藏密碼_bt_MouseEnter(sender As Object, e As EventArgs) Handles 隱藏密碼_bt.MouseEnter
        ToolTip1.SetToolTip(Me.隱藏密碼_bt, "隱藏密碼")
    End Sub
    Private Sub 查詢_bt_MouseEnter(sender As Object, e As EventArgs) Handles 查詢_bt.MouseEnter
        ToolTip1.SetToolTip(Me.查詢_bt, "查詢")
    End Sub
    Private Sub 指定預設權限_bt_MouseEnter(sender As Object, e As EventArgs) Handles 指定預設權限_bt.MouseEnter
        ToolTip1.SetToolTip(Me.指定預設權限_bt, "指定預設權限")
    End Sub
    Private Sub 系統使用者管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = FH_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        PA = "" : 預設權限_dgv.Visible = False : 修改_bt.Enabled = False : 確認新增_bt.Enabled = False
        Panel1.Visible = False : 在職 = True
        清單1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
    End Sub
    Private Sub 系統使用者管理_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        ComboBox1下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox4下拉表單資料載入() : ComboBox5下拉表單資料載入() : 下拉清單_職稱()
        Set_格式設定() : 小間距1_ch.Checked = True : 中間距1_ch.Checked = False : 大間距1_ch.Checked = False : Set_使用者清單() : Set_grid()
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 部門_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 部門_cb.SelectedIndexChanged
        部門1_cb.SelectedIndex = 部門_cb.SelectedIndex : ComboBox5下拉表單資料載入() : 下拉清單_職稱()
    End Sub
    Private Sub 處別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 處別_cb.SelectedIndexChanged
        處別1_cb.SelectedIndex = 處別_cb.SelectedIndex : ComboBox3下拉表單資料載入() : 下拉清單_職稱()
    End Sub
    Private Sub 課別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 課別_cb.SelectedIndexChanged
        課別1_cb.SelectedIndex = 課別_cb.SelectedIndex : ComboBox4下拉表單資料載入()
    End Sub
    Private Sub 職稱_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 職稱_cb.SelectedIndexChanged
        職稱1_cb.SelectedIndex = 職稱_cb.SelectedIndex : 級別_cb.SelectedIndex = 職稱_cb.SelectedIndex : Set_權限清單() : Dim S1, S2, S3, S4 As String
        PA = 職稱_cb.Text : SQL_系統使用者管理_組織帶入() : PA = ""
        If dr.Read() Then : S1 = dr("部") : S2 = dr("處") : S3 = dr("課") : S4 = dr("組") : End If : conn.Close()
        部門_cb.Text = S1 : 處別_cb.Text = S2 : 課別_cb.Text = S3 : 組別_cb.Text = S4
    End Sub
    Private Sub 級別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 級別_cb.SelectedIndexChanged
        職稱_cb.SelectedIndex = 級別_cb.SelectedIndex : Set_權限清單()
    End Sub
    Private Sub 清單1_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 清單1_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 清單1_dgv.Rows.Count - 1 Then
            Exit Sub
        Else
            If 清單1_dgv("級別", e.RowIndex).Value.ToString <> 清單1_dgv("級別", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(清單1_dgv.RowHeadersVisible, 清單1_dgv.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 清單1_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 清單1_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
        For i As Integer = 0 To 清單1_dgv.Rows.Count - 1
            If 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "01" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "02" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "03" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "04" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
            ElseIf 清單1_dgv.Rows(i).Cells("級別").Value.ToString = "05" Then : 清單1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue : End If
        Next
    End Sub
    Private Sub 清單1_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 清單1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            部門_cb.Text = "" : 處別_cb.Text = ""
            姓名_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString : 帳號_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("帳號").Value.ToString
            密碼_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("密碼").Value.ToString : 職稱_cb.Text = 清單_dgv.Rows(e.RowIndex).Cells("職稱").Value.ToString
            NAS帳號_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("NAS帳號").Value.ToString : NAS密碼_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("NAS密碼").Value.ToString
            If 顯示密碼_bt.Enabled = False Then
                PA39 = 姓名_tb.Text : PA38 = 帳號_tb.Text : SQL_系統使用者密碼顯示()
                If dr.Read() Then : 密碼_tb.Text = dr("密碼") : End If : conn.Close()
            End If

            For no As Integer = 1 To 權限數量
                If no < 10 Then : HH = "0" & no : ElseIf no >= 10 Then : HH = no : End If
                Dim 選擇 As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
                選擇.Checked = 清單_dgv.Rows(e.RowIndex).Cells("CC" & HH).Value
            Next
            Set_權限清單() : 職稱_cb.Text = 清單_dgv.Rows(e.RowIndex).Cells("職稱").Value.ToString
        End If
    End Sub
    Private Sub 指定預設權限_bt_Click_1(sender As Object, e As EventArgs) Handles 指定預設權限_bt.Click
        If 姓名_tb.Text = "" Or 帳號_tb.Text = "" Or 密碼_tb.Text = "" Then : MsgBox("基本資料有誤，請重新確認!!") : Else
            For no As Integer = 1 To 權限數量
                If no < 10 Then : HH = "0" & no : ElseIf no >= 10 Then : HH = no : End If
                Dim 選擇 As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
                If HH = 63 Then : Else
                    選擇.Checked = 預設權限_dgv.Rows(0).Cells("CC" & HH).Value
                End If
            Next
        End If
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        If 級別_cb.Text = "00" Or 級別_cb.Text = "01" Or 級別_cb.Text = "02" Or 級別_cb.Text = "03" Or 級別_cb.Text = "04" Then
            If 登入人級別 = "00" Then
                姓名_tb.Text = "" : 帳號_tb.Text = "" : 密碼_tb.Text = "" : 新增_bt.Enabled = False : 確認新增_bt.Enabled = True
                Set_格式設定()
            Else : MsgBox("00~04級人員的帳號新增請找系統管理員!!") : End If
        Else
            姓名_tb.Text = "" : 帳號_tb.Text = "" : 密碼_tb.Text = "" : 新增_bt.Enabled = False : 確認新增_bt.Enabled = True
            Set_格式設定()
        End If
    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 級別_cb.Text = "00" Or 級別_cb.Text = "01" Or 級別_cb.Text = "02" Or 級別_cb.Text = "03" Or 級別_cb.Text = "04" Then
                If 登入人級別 = "00" Then
                    Dim result As DialogResult = MessageBox.Show("是否載入 [系統預設權限] ?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    If result = DialogResult.Yes Then : 指定預設權限_bt.PerformClick() : End If
                    DTP = Strings.Format(Today().AddMonths(2), "yyyy/MM/dd") : SQL_系統使用者新增() : SQL_系統使用者修改() : conn.Close()
                    MsgBox("新增完成!!")
                    Set_使用者清單() : Set_grid()
                    確認新增_bt.Enabled = False : 新增_bt.Enabled = True : 顯示密碼_bt.Enabled = True : 隱藏密碼_bt.Enabled = False
                Else : MsgBox("00~04級人員的帳號新增請找系統管理員!!") : End If
            Else
                Dim result As DialogResult = MessageBox.Show("是否載入 [系統預設權限] ?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then : 指定預設權限_bt.PerformClick() : End If
                DTP = Strings.Format(Today().AddMonths(2), "yyyy/MM/dd") : SQL_系統使用者新增() : SQL_系統使用者修改() : conn.Close()
                MsgBox("新增完成!!")
                Set_使用者清單() : Set_grid()
                確認新增_bt.Enabled = False : 新增_bt.Enabled = True : 顯示密碼_bt.Enabled = True : 隱藏密碼_bt.Enabled = False
            End If
        End If
    End Sub
    Private Sub 修改1_bt_Click(sender As Object, e As EventArgs) Handles 修改1_bt.Click
        If 姓名_tb.Text = "" Or 帳號_tb.Text = "" Or 密碼_tb.Text = "" Then : MsgBox("基本資料有誤，請重新確認!!") : Else
            修改_bt.Enabled = True
        End If
    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
            Dim result As DialogResult = MessageBox.Show("是否載入 [系統預設權限] ?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If result = DialogResult.Yes Then : 指定預設權限_bt.PerformClick() : End If
            If 密碼_tb.Text = "**********" Then : PA9 = "" : Else : PA9 = ", 密碼 = '" & 密碼_tb.Text & "'" : End If
            SQL_系統使用者修改() : conn.Close() : MsgBox("修改完成!!")
            修改_bt.Enabled = False
        End If : PA = "" : Set_使用者清單() : Set_grid()
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If 姓名_tb.Text = "" And 帳號_tb.Text = "" And 密碼_tb.Text = "" Then : MsgBox("基本資料有誤，請重新確認!!") : Else
            If 登入人級別 = "00" Then
                Dim result As DialogResult = MessageBox.Show("是否將該人員的在職狀態修變更成離職?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then
                    CheckBox63.Checked = True : SQL_系統使用者修改() : conn.Close() : MsgBox("人員狀態已經改成離職!!")
                Else
                    PA37 = 帳號_tb.Text : SQL_系統使用者刪除() : conn.Close() : MsgBox("該使用者資料已經刪除!!")
                End If
                姓名_tb.Text = "" : 帳號_tb.Text = "" : 帳號_tb.Text = "" : 修改_bt.Enabled = False : 確認新增_bt.Enabled = False
            Else
                Dim result As DialogResult = MessageBox.Show("是否將該人員的在職狀態修變更成離職?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then
                    CheckBox63.Checked = True : SQL_系統使用者修改() : conn.Close() : MsgBox("人員狀態已經改成離職!!")
                End If
                修改_bt.Enabled = False : 確認新增_bt.Enabled = False
            End If : PA = "" : Set_使用者清單() : Set_grid()
        End If
    End Sub
    Private Sub 隱藏密碼_bt_Click(sender As Object, e As EventArgs) Handles 隱藏密碼_bt.Click
        顯示密碼_bt.Enabled = True : 隱藏密碼_bt.Enabled = False : 密碼_tb.Text = "**********"
    End Sub
    Private Sub 顯示密碼_bt_Click(sender As Object, e As EventArgs) Handles 顯示密碼_bt.Click
        顯示密碼_bt.Enabled = False : 隱藏密碼_bt.Enabled = True
        PA39 = 姓名_tb.Text : PA38 = 帳號_tb.Text : SQL_系統使用者密碼顯示()
        If dr.Read() Then : 密碼_tb.Text = dr("密碼") : End If : conn.Close()
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        PA = InputBox(對話框(13)) : Set_使用者清單() : PA = ""
    End Sub
    Private Sub 權限名稱取得()
        Dim 選擇 As CheckBox = CType(Me.Controls.Find("CheckBox" + 權限代號.ToString(), True)(0), CheckBox) : 權限名稱 = 選擇.Text : 權限選取 = 選擇.Checked
    End Sub
    Private Sub 自動生成_bt_Click(sender As Object, e As EventArgs) Handles 自動生成_bt.Click
        Dim random As New Random() : Dim randomNumber As Integer = random.Next(10, 99)
        Dim rando As New Random() : Dim randomNum As Integer = rando.Next(0, 9)
        Dim rand As New Random() : Dim randomNu As Integer = rand.Next(0, 9)
        Dim DFG As String
        For QAZ = 0 To 999
            QQW(0) = randomNumber : QQW(1) = Strings.Right(Year(Today), 2) : QQW(2) = Strings.Left(Year(Today), 2) : QQW(3) = Month(Today) + 9
            QQW(4) = Strings.Right(QQW(0), 1) : QQW(5) = Strings.Left(QQW(0), 1) : QQW(6) = Strings.Right(QQW(1), 1) : QQW(7) = Strings.Left(QQW(1), 1) : QQW(8) = Strings.Right(QQW(2), 1)
            QQW(9) = Strings.Left(QQW(2), 1) : QQW(10) = Strings.Right(QQW(3), 1) : QQW(11) = Strings.Left(QQW(3), 1)
            For RT = 4 To 11 : If RT = 9 Or RT = 5 Or RT = 4 Or RT = 8 Then : FG = RT : 轉換() : End If : Next
            Dim ran1 = New Random(DateTime.Now.Millisecond) : Dim NUM2 As Integer = ran1.Next(1, 4096)
            For I = 0 To 4096 : If NUM2 > 99 Then : NUM2 -= 49 : ElseIf NUM2 < 99 Then : I = 4096 : End If : Next
            DFG = QQW(9) & QQW(7) & QQW(5) & QQW(11) & QQW(4) & QQW(6) & QQW(8) & QQW(10) & NUM2
            PA41 = DFG : SQL_系統使用者ID卡號()
            If dr.Read() = True Then : Else : QAZ = 999 : End If : conn.Close()
        Next
        If 密碼_tb.Text = "" Then : 密碼_tb.Text = Strings.Left(DFG, 9) & randomNu : End If
    End Sub
    Private Sub 轉換()
        If QQW(FG) = "1" Then : QQW(FG) = "A" : ElseIf QQW(FG) = "2" Then : QQW(FG) = "B"
        ElseIf QQW(FG) = "3" Then : QQW(FG) = "C" : ElseIf QQW(FG) = "4" Then : QQW(FG) = "D"
        ElseIf QQW(FG) = "5" Then : QQW(FG) = "E" : ElseIf QQW(FG) = "6" Then : QQW(FG) = "F"
        ElseIf QQW(FG) = "7" Then : QQW(FG) = "G" : ElseIf QQW(FG) = "8" Then : QQW(FG) = "H"
        ElseIf QQW(FG) = "9" Then : QQW(FG) = "I" : ElseIf QQW(FG) = "0" Then : QQW(FG) = "J" : End If
    End Sub
    Private Sub 小間距1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距1_ch.Click
        小間距1_ch.Checked = True : 中間距1_ch.Checked = False : 大間距1_ch.Checked = False : Set_使用者清單()
    End Sub
    Private Sub 中間距1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距1_ch.Click
        小間距1_ch.Checked = False : 中間距1_ch.Checked = True : 大間距1_ch.Checked = False : Set_使用者清單()
    End Sub
    Private Sub 大間距1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距1_ch.Click
        小間距1_ch.Checked = False : 中間距1_ch.Checked = False : 大間距1_ch.Checked = True : Set_使用者清單()
    End Sub
    Private Sub 部門1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 部門1_cb.SelectedIndexChanged
        部門_cb.SelectedIndex = 部門1_cb.SelectedIndex
    End Sub
    Private Sub 處別1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 處別1_cb.SelectedIndexChanged
        處別_cb.SelectedIndex = 處別1_cb.SelectedIndex
    End Sub
    Private Sub 課別1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 課別1_cb.SelectedIndexChanged
        課別_cb.SelectedIndex = 課別1_cb.SelectedIndex
    End Sub
    Private Sub 組別1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 組別1_cb.SelectedIndexChanged
        組別_cb.SelectedIndex = 組別1_cb.SelectedIndex
    End Sub
    Private Sub 職稱1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 職稱1_cb.SelectedIndexChanged
        職稱_cb.SelectedIndex = 職稱1_cb.SelectedIndex
        If 確認新增_bt.Enabled = True Or 修改_bt.Enabled = True Then : 指定預設權限_bt.PerformClick() : End If
    End Sub
    Private Sub 組別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 組別_cb.SelectedIndexChanged
        組別1_cb.SelectedIndex = 組別_cb.SelectedIndex
    End Sub
    Private Sub 工人_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 工人_ch.Click
        If 工人_ch.Checked = True Then : 工人 = True : Else : 工人 = False : End If : Set_使用者清單()
    End Sub
End Class