''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'程 序 员 : 梁 嘉 辉
'编 写 时 间 : 2006-5-17
'模 块 功 能 : 实现多用户登录
'E - Mail : purana@126.com
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim g_Connect As ADODB.Connection
Dim g_Recordset As ADODB.Recordset
Private Sub Command1_Click()
Static userCount As Integer
Dim i As Integer
For i = 0 To 2
If Text1(i).Text = "" Then
MsgBox "內容不能為空,請輸入!", vbExclamation + vbOKOnly
Text1(i).SetFocus
Exit Sub
End If
Next
If Text1(1).Text <> Text1(2).Text Then
MsgBox "兩次密碼不正確,請重新輸入"
Text1(1).SetFocus
Exit Sub
End If
Set g_Recordset = CreateObject("ADODB.Recordset")
Dim sql As String
sql = "SELECT * FROM user_info WHERE 用戶名='" & Text1(0).Text & "'"
g_Recordset.Open sql, g_Connect, adOpenKeyset, adLockPessimistic
If g_Recordset.RecordCount <= 0 Then
MsgBox "沒有此用戶,請重新輸入!", vbCritical + vbOKOnly
userCount = userCount + 1
g_Recordset.Close
'Exit Sub
Else
If Text1(1).Text = g_Recordset.Fields("密碼").Value Then
MsgBox "密碼正確,登錄成功!", vbOKCancel
Form2.Show
g_Recordset.Close
Unload Me
Else
MsgBox "密碼不正確,請確定密碼!"
Text1(1).SetFocus
userCount = userCount + 1
'Exit Sub
End If
End If
If userCount >= 3 Then
MsgBox "你已經超出使用權限了,不能再使用本軟件!"
End
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim iConnstr As String
Set g_Connect = CreateObject("ADODB.Connection")
iConnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\student.mdb;Persist Security Info=False"
g_Connect.Open iConnstr
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set g_Connect = Nothing
Set g_Recordset = Nothing
End Sub