Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Class LogInFrom
Public pUser_id As String = ""
Public pPassword As String = ""
Dim strConnString As String = ConfigurationManager.GetSection("Project_RFIDConnectionString")
Private Sub logIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles logIn.Click
Dim objDialogResult As New DialogResult()
If CheckBox_admin.Checked Then
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strSQL As String
'strConnString = "Data Source=COMSCI-PC\SQLEXPRESS;Initial Catalog=Project_RFID;Persist Security Info=True;User ID=sa;Password=root"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM ADMIN WHERE ADM_USERNAME = '" & Me.userName.Text & "' AND ADM_PASSWORD = '" & Me.password.Text & "' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
Dim frm As New Form_Admin
frm._strUser = Me.userName.Text
frm.LoadInfor()
frm.Show()
Me.Hide()
Else
objDialogResult = MessageBox.Show("คุณไม่สามารถลงชื่อเข้าใช้ระบบของผู้ดูแลระบบได้ กรุณาตรวจสอบข้อมูลอีกครั้ง", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
userName.Clear()
password.Clear()
userName.Focus()
End If
objConn.Close()
objConn = Nothing
Else
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strSQL As String
'strConnString = "Data Source=COMSCI-PC\SQLEXPRESS;Initial Catalog=Project_RFID;Persist Security Info=True;User ID=sa;Password=root"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM ACCOUNT WHERE USERNAME = '" & Me.userName.Text & "' AND PASSWORD = '" & Me.password.Text & "' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
Dim frm As New Form_User
frm._strUser = Me.userName.Text
frm.LoadInfor()
frm.Show()
Me.Hide()
Else
objDialogResult = MessageBox.Show("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง กรุณาลองใหม่ หรือติดต่อผู้ดูแลระบบ", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
userName.Clear()
password.Clear()
userName.Focus()
End If
objConn.Close()
objConn = Nothing
End If
End Sub
รบกวนด้วยนะครับ แก้ตรงไหนบ้าง
ขอบคุณล่วงหน้าครับ
Tag : .NET, Ms SQL Server 2005, Win (Windows App), VS 2008 (.NET 3.x), Windows