Imports System.Data.SqlClient
Public Class LoginForm1
    ' TODO: 插入程式碼，利用提供的使用者名稱和密碼執行自訂驗證
    ' (請參閱 https://go.microsoft.com/fwlink/?LinkId=35339)。
    ' 如此便可將自訂主體附加到目前執行緒的主體，如下所示: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' 其中 CustomPrincipal 是用來執行驗證的 IPrincipal 實作。
    ' 接著，My.User 便會傳回封裝在 CustomPrincipal 物件中的識別資訊，
    ' 例如使用者名稱、顯示名稱等。
    Dim da As Object
    Dim ds As Object
    Private Property MYSQL As String
    Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Visible = False
        Label1.Text = "版本 : " & 版本
    End Sub
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim dr As SqlDataReader
        Dim cmd As New SqlCommand
        Dim conn As New SqlConnection
        If UsernameTextBox.Text = "" Then
            MsgBox("請輸入帳號!")
        ElseIf UsernameTextBox.Text <> "" Then
            ConString = "Data Source=192.168.1.10;Initial Catalog=楠晉社保考勤資料庫;Persist Security Info=True;User ID=b70340;Password=0911274990;Max pool size = 200;Connection Timeout=0"
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            MYSQL = "SELECT * FROM 使用者 WHERE (帳號 = '" & UsernameTextBox.Text & "')"
            cmd.Connection = conn : cmd.CommandText = MYSQL : dr = cmd.ExecuteReader
            If dr.Read() Then
                TextBox1.Text = dr("密碼").ToString
                gUserName = dr("姓名").ToString
                'CC(0) = dr.Item(3) : CC(1) = dr.Item(4) : CC(2) = dr.Item(5) : CC(3) = dr.Item(6) : CC(4) = dr.Item(7) : CC(5) = dr.Item(8) : CC(6) = dr.Item(9)
                'CC(7) = dr.Item(10) : CC(8) = dr.Item(11) : CC(9) = dr.Item(12) : CC(10) = dr.Item(13) : CC(11) = dr.Item(14) : CC(12) = dr.Item(15) : CC(13) = dr.Item(16)
                'CC(14) = dr.Item(17) : CC(15) = dr.Item(18) : CC(16) = dr.Item(19) : CC(17) = dr.Item(20) : CC(18) = dr.Item(21) : CC(19) = dr.Item(22) : CC(20) = dr.Item(23)
                'CC(21) = dr.Item(24) : CC(22) = dr.Item(25) : CC(23) = dr.Item(26) : CC(24) = dr.Item(27) : CC(25) = dr.Item(28) : CC(26) = dr.Item(29) : CC(27) = dr.Item(30)
                'CC(28) = dr.Item(31) : CC(29) = dr.Item(32) : CC(30) = dr.Item(33) : CC(31) = dr.Item(34) : CC(32) = dr.Item(35) : CC(33) = dr.Item(36) : CC(34) = dr.Item(37)
                'CC(35) = dr.Item(38) : CC(36) = dr.Item(39) : CC(37) = dr.Item(40) : CC(38) = dr.Item(41) : CC(39) = dr.Item(42) : CC(40) = dr.Item(43) : CC(41) = dr.Item(44)
                'CC(42) = dr.Item(45) : CC(43) = dr.Item(46) : CC(44) = dr.Item(47) : CC(45) = dr.Item(48) : CC(46) = dr.Item(49) : CC(47) = dr.Item(50) : CC(48) = dr.Item(51)
                'CC(49) = dr.Item(52) : CC(50) = dr.Item(53) : CC(51) = dr.Item(54) : CC(52) = dr.Item(55) : CC(53) = dr.Item(56) : CC(54) = dr.Item(57) : CC(55) = dr.Item(58)
                'CC(56) = dr.Item(59) : CC(57) = dr.Item(60) : CC(58) = dr.Item(61) : CC(59) = dr.Item(62) : CC(60) = dr.Item(63) : CC(61) = dr.Item(64) : CC(62) = dr.Item(65)
                'CC(63) = dr.Item(66) : CC(64) = dr.Item(67) : CC(65) = dr.Item(68) : CC(66) = dr.Item(69) : CC(67) = dr.Item(70) : CC(68) = dr.Item(71) : CC(69) = dr.Item(72)
                'CC(70) = dr.Item(73) : CC(71) = dr.Item(74) : CC(72) = dr.Item(75) : CC(73) = dr.Item(76) : CC(74) = dr.Item(77) : CC(75) = dr.Item(78) : CC(76) = dr.Item(79)
                'CC(77) = dr.Item(80) : CC(78) = dr.Item(81) : CC(79) = dr.Item(82) : CC(80) = dr.Item(83) : CC(81) = dr.Item(84) : CC(82) = dr.Item(85) : CC(83) = dr.Item(86)
            End If
            If PasswordTextBox.Text = TextBox1.Text Then
                If TextBox1.Text = "" Then
                    MsgBox("帳號或密碼錯誤，請重新輸入!")
                Else
                    Me.Hide()
                    楠晉鞋業AAS.Show() : OK.Enabled = False : Cancel.Enabled = False
                End If
            ElseIf PasswordTextBox.Text <> TextBox1.Text Then
                MsgBox("帳號或密碼錯誤，請重新輸入!")
            End If
            dr.Close()
        End If
        conn.Close()
    End Sub
End Class
