Option Explicit On
Option Strict On
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing.Drawing2D
Public Class frmLogin
Dim Conn As New SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim isfind As Boolean = False
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Windows.Forms.Cursor.Current = Cursors.WaitCursor
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.Focus()
txtUsername.SelectAll()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Windows.Forms.Cursor.Current = Cursors.Default
End Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
If txtUsername.Text = "" Then
MessageBox.Show("กรุณากรอก Username ก่อนครับ", "ผลการทำงาน !!!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtUsername.Focus()
txtUsername.SelectAll()
Exit Sub
End If
If txtPassword.Text = "" Then
MessageBox.Show("กรุณากรอก Password ก่อนครับ", "ผลการทำงาน !!!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtPassword.Focus()
txtPassword.SelectAll()
Exit Sub
End If
Dim sqlUser As String = ""
sqlUser = "select * from tb_user"
sqlUser &= " where (username = '" & txtUsername.Text & "') "
sqlUser &= " and (password = '" & txtPassword.Text & "')"
'sqlUser &= " and (isNormal = '1')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
da = New SqlDataAdapter(sqlUser, Conn)
da.Fill(ds, "tb_user")
If isfind = True Then
ds.Tables("tb_user").Clear()
End If
If ds.Tables("tb_user").Rows.Count <> 0 Then
UserSystem = txtUsername.Text
frmMain1.Show()
Me.Close()
Else
MessageBox.Show("Username และ Password ไม่ถูกต้อง", "ผลการทำงาน !!!", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtUsername.Text = ""
txtUsername.Focus()
txtPassword.Text = ""
End If
End Sub
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
If MessageBox.Show("คุณต้องการยกเลิกการเข้าสู่ระบบใช่หรือไม่", "ยืนยัน !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
txtUsername.Text = ""
txtUsername.Focus()
txtUsername.SelectAll()
txtPassword.Text = ""
End
End If
End Sub
End Class