If Len(Trim(txtPassword.Text)) = 0 Then
MsgBox "用户密码为空,请重新输入!!", vbOKOnly
Exit Sub
End If
With conlogin
If .State = adStateOpen Then
.Close
End If
.Provider = "microsoft.jet.oledb.4.0"
.ConnectionString = App.Path & "\jinbin.mdb"
.Open
End With
With rstlogin
If .State = adStateOpen Then
.Close
End If
.LockType = adLockReadOnly
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.ActiveConnection = conlogin
.Source = "select * from userinfo"
.Open
If Trim(txtPassword.Text) = flagpassword And Len(Trim(txtPassword.Text)) = Len(flagpassword) Then
If flagadmin = "高级用户" Then
wt.flagnumber = 79802223
Unload Me
mainfrm.Show
ElseIf flagadmin = "一般用户" Then
wt.flagnumber = 32220897
Unload Me
mainfrm.Show
Else
MsgBox "非法人员及权限,请找管理员", vbOKOnly
Exit Sub
End If
Else
MsgBox "密码错误,请重新输入"
Exit Sub
End If
End With
End Sub
Private Sub txtgonghao_LostFocus()
Dim conlogin As New ADODB.Connection
Dim rstlogin As New ADODB.Recordset
If Len(Trim(txtgonghao.Text)) <> 0 Then
With conlogin
If .State = adStateOpen Then
.Close
End If
.Provider = "microsoft.jet.oledb.4.0"
.ConnectionString = App.Path & "\jinbin.mdb"
.Open
End With
With rstlogin
If .State = adStateOpen Then
.Close
End If
.LockType = adLockReadOnly
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.ActiveConnection = conlogin
.Source = "select userid,username,userpassword,userjibie from userinfo where userid='" & Trim(txtgonghao.Text) & "'"
.Open
If .RecordCount <> 0 Then
Do Until .EOF
txtusername.Text = Trim(.Fields!UserName.Value)
flagpassword = Trim(.Fields!userpassword.Value)
flagadmin = Trim(.Fields!userjibie.Value)
.MoveNext
Loop
Else
MsgBox "输入的工号非法,请重新输入", vbOKOnly
txtgonghao.Text = ""
txtgonghao.SetFocus
Exit Sub
End If
End With
End If
End Sub
2:添加用户界面设计:
代码设计:
Private Sub cmdadd_Click()
Dim conuser As New ADODB.Connection
Dim cmduser As New ADODB.Command
Dim rstuser As New ADODB.Recordset
Dim strcnn As String
'输入数据进行验证
If Len(Trim(txtuser.Text)) = 0 Then
MsgBox "用户名没有输入,请输入!", vbOKOnly
Exit Sub
Else
txtuser.Text = CStr(Trim(txtuser.Text))
End If
If Len(Trim(txtgonghao.Text)) = 0 Then
MsgBox "工号没有输入,请输入!", vbOKOnly
Exit Sub
Else
txtgonghao.Text = CStr(Trim(txtgonghao.Text))
End If
If Len(Trim(txtpassword.Text)) = 0 Then
MsgBox "密码没有输入,请输入!", vbOKOnly
Exit Sub
Else
txtpassword.Text = CStr(Trim(txtpassword.Text))
End If
If Len(Trim(txtpassword2.Text)) = 0 Then
MsgBox "请输入确认密码!", vbOKOnly
Exit Sub
Else
txtpassword2.Text = CStr(Trim(txtpassword2.Text))
End If
If txtpassword.Text <> txtpassword2.Text Then
MsgBox "确认密码和第一次输入的密码不同,请重新输入!", vbOKOnly
Exit Sub
End If