Option Strict Off
Imports System.Data.SqlClient
Public Class 人員ID卡系統配置設定
    Dim conn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    Dim ds As New DataSet : Dim ds1 As New DataSet
    Dim dr As SqlDataReader
    Dim 編號 As String
    Private Sub Set_人員清單()
        DataGridView2.DataSource = Nothing : ds1.Clear()
        DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView2.ColumnHeadersHeight = 25
        DataGridView2.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 姓名, 帳號, 部門, 職稱, 員工編號, ID卡號 FROM 使用者權限管理表 ORDER BY 職稱"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1()
    End Sub
    Private Sub Set_grid1()
        DataGridView2.Columns(0).Width = 150 : DataGridView2.Columns(1).Width = 150 : DataGridView2.Columns(2).Width = 150 : DataGridView2.Columns(3).Width = 150
        DataGridView2.Columns(4).Width = 150 : DataGridView2.Columns(1).Width = 150
    End Sub
    Private Sub 人員ID卡系統配置設定_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Set_人員清單() : TextBox1.Enabled = False : TextBox2.Enabled = False
        TextBox3.Focus()
    End Sub
    Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox1.Text = DataGridView2(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView2(1, e.RowIndex).Value.ToString
            TextBox3.Focus()
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
            MsgBox("輸入資料有誤")
        Else
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "UPDATE 使用者權限管理表 SET ID卡號 = N'" & TextBox3.Text & "' WHERE (帳號 = N'" & TextBox2.Text & "') AND (姓名 = N'" & TextBox1.Text & "')"
            cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() : conn.Close()
            MsgBox("卡片與系統帳號配對完成") : TextBox3.Text = ""
        End If
        Set_人員清單() : TextBox3.Focus()
    End Sub
End Class