Option Strict Off
Public Class 人員ID卡系統配置設定
    Dim 對話框(7) As String
    ReadOnly QRCODE As DotNetBarcode = New DotNetBarcode
    Private Sub Set_人員清單()
        Dim ds1 As New DataSet : 清單_dgv.DataSource = Nothing : ds1.Clear()
        清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單_dgv.ColumnHeadersHeight = 25 : 清單_dgv.AllowUserToAddRows = False
        If 小間距1_ch.Checked = False And 中間距1_ch.Checked = False And 大間距1_ch.Checked = True Then : 清單_dgv.RowTemplate.Height = 75
        ElseIf 小間距1_ch.Checked = False And 中間距1_ch.Checked = True And 大間距1_ch.Checked = False Then : 清單_dgv.RowTemplate.Height = 45
        ElseIf 小間距1_ch.Checked = True And 中間距1_ch.Checked = False And 大間距1_ch.Checked = False Then : 清單_dgv.RowTemplate.Height = 25 : End If

        SQL_人員ID卡系統配置設定_清單()
        ds1.Reset() : da.Fill(ds1) : 清單_dgv.DataSource = ds1.Tables(0) : conn.Close()

        清單_dgv.Columns(0).FillWeight = 135 : 清單_dgv.Columns(1).FillWeight = 60 : 清單_dgv.Columns(2).FillWeight = 115 : 清單_dgv.Columns(3).FillWeight = 140
        清單_dgv.Columns(4).FillWeight = 55 : 清單_dgv.Columns(5).FillWeight = 190 : 清單_dgv.Columns(6).FillWeight = 50

        For i As Integer = 0 To 清單_dgv.Rows.Count - 1
            清單_dgv(0, i).Value = 清單_dgv(0, i).Value.ToString.ToUpper : 清單_dgv(1, i).Value = 清單_dgv(1, i).Value.ToString.ToUpper
            Dim 驗證 As String = "" : Dim 取變數 As String
            取變數 = 清單_dgv.Rows(i).Cells("部門").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 : 清單_dgv.Rows(i).Cells("部門").Value = 驗證

            取變數 = 清單_dgv.Rows(i).Cells("課別").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 : 清單_dgv.Rows(i).Cells("課別").Value = 驗證

            取變數 = 清單_dgv.Rows(i).Cells("職稱").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 : 清單_dgv.Rows(i).Cells("職稱").Value = 驗證
        Next
    End Sub
    Private Sub 清除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 清除_bt.MouseEnter
        ToolTip1.SetToolTip(Me.清除_bt, 對話框(3))
    End Sub
    Private Sub 卡片配對_bt_MouseEnter(sender As Object, e As EventArgs) Handles 卡片配對_bt.MouseEnter
        ToolTip1.SetToolTip(Me.卡片配對_bt, 對話框(4))
    End Sub
    Private Sub 導成圖片_bt_MouseEnter(sender As Object, e As EventArgs) Handles 導成圖片_bt.MouseEnter
        ToolTip1.SetToolTip(Me.導成圖片_bt, 對話框(5))
    End Sub
    Private Sub 人員ID卡系統配置設定_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = FH_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Set_人員清單() : ID卡號_tb.Focus()
        清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
    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 DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 清單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            姓名_tb.Text = 清單_dgv("姓名", e.RowIndex).Value.ToString : 帳號_tb.Text = 清單_dgv("帳號", e.RowIndex).Value.ToString
            ID卡號_tb.Text = 清單_dgv("ID卡號", e.RowIndex).Value.ToString
            ID卡號_tb.Focus()
            '----------QRCode-------------------------------------------------------------------------------------------------------
            If ID卡號_tb.Text = "" Then
                QRCode_pb.Image = Nothing : QRCode2_pb.Image = Nothing
            Else
                QRCode_pb.Image = Nothing : QRCode2_pb.Image = Nothing
                QRCode_pb.Image = New Bitmap(QRCode_pb.Width, QRCode_pb.Height)
                QRCode2_pb.Image = New Bitmap(QRCode2_pb.Width, QRCode2_pb.Height)
                Dim GP As Graphics = Graphics.FromImage(QRCode_pb.Image)
                Dim GP2 As Graphics = Graphics.FromImage(QRCode2_pb.Image)
                QRCODE.Type = DotNetBarcode.Types.QRCode : QRCODE.QRQuitZone = 0 : QRCODE.QRWriteBar(ID卡號_tb.Text, 45, 45, 14, GP)
                QRCODE.Type = DotNetBarcode.Types.QRCode : QRCODE.QRQuitZone = 0 : QRCODE.QRWriteBar(ID卡號_tb.Text, 1, 1, 4.7, GP2)
                QRCode_pb.SizeMode = 4 : QRCode2_pb.SizeMode = 4
            End If
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 卡片配對_bt.Click
        If 姓名_tb.Text = "" Or 帳號_tb.Text = "" Or ID卡號_tb.Text = "" Then : MsgBox("資料選擇有誤，請重新確認!!") : Else
            PA42 = ID卡號_tb.Text : PA43 = 帳號_tb.Text : PA44 = 姓名_tb.Text
            SQL_人員ID卡系統配置設定_驗證()
            If dr.Read Then : MsgBox("該ID卡號已經被使用，無法重複設定!!") : Else
                SQL_人員ID卡系統配置設定_配卡() : conn.Close() : MsgBox("ID卡設定完成!!") : ID卡號_tb.Text = ""
            End If
        End If : Set_人員清單() : ID卡號_tb.Focus()
    End Sub
    Private Sub 清除_bt_Click(sender As Object, e As EventArgs) Handles 清除_bt.Click
        If 姓名_tb.Text = "" Or 帳號_tb.Text = "" Then : MsgBox("資料選擇有誤，請重新確認!!") : Else
            PA42 = ID卡號_tb.Text : PA43 = 帳號_tb.Text : ID卡號_tb.Text = "" : SQL_人員ID卡系統配置設定_配卡() : conn.Close()
            MsgBox("ID卡號刪除成功!!") : ID卡號_tb.Text = ""
        End If : Set_人員清單() : ID卡號_tb.Focus()
    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 導成圖片_bt_Click(sender As Object, e As EventArgs) Handles 導成圖片_bt.Click
        If 姓名_tb.Text = "" Then : MsgBox("資料選擇有誤，請重新確認!!") : Else
            SaveFileDialog1.Filter = "JPEG Image|*.jpg|Bitmap Image|*.bmp|PNG Image|*.png"
            SaveFileDialog1.FileName = 姓名_tb.Text
            If SaveFileDialog1.ShowDialog() = DialogResult.OK Then   ' 如果使用者按下 OK 按鈕，則存檔
                Dim fileName As String = SaveFileDialog1.FileName    ' 取得使用者選擇的檔案名稱
                QRCode_pb.Image.Save(fileName)  ' 把 PictureBox 的圖片存檔到使用者選擇的位置
            End If
        End If
    End Sub
End Class