这部分 内容与 学生管理系统十分相似,唯一的一些差别就是在登录类型那里 分为,一般用户,操作员,管理员,再将表更新。
先看一下流程图吧。
注意事项
1.要限制用户控件的字符
2.要限制登录不同类型的人,有不同的权限。
3.密码输错三次,退出程序。
代码
Private Sub cmdOK_Click()
Dim txtSQL As String '用来存放SQL 语句
Dim txtsql1 As String
Dim txtsql2 As String
Dim mrc As ADODB.Recordset '用来存放记录集对象
Dim mrc1 As ADODB.Recordset
Dim mrc2 As ADODB.Recordset
Dim Msgtext As String '用来存放返回消息
Dim MsgText1 As String
Dim MsgText2 As String
UserName = ""
If Trim(txtUserName.Text = "") Then '判断输入用户名是否为空
MsgBox "请输入用户名!", vbOKOnly + vbExclamation, "提示"
txtUserName.SetFocus
txtPassword.Text = ""
Exit Sub
Else
If Trim(txtPassword.Text = "") Then '判断输入用户名是否为空
MsgBox "请输入密码!", vbOKOnly + vbExclamation, "提示"
txtPassword.SetFocus
txtPassword.Text = ""
Exit Sub
Else
'查询指定用户名的记录
txtSQL = "select * from user_Info where userID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
txtsql2 = "select * from worklog_Info where userID = '" & txtUserName.Text & "'"
Set mrc2 = ExecuteSQL(txtsql2, MsgText2)
txtsql1 = "select * from onwork_Info where userID = '" & txtUserName.Text & "'"
Set mrc1 = ExecuteSQL(txtsql1, MsgText1)
If mrc.EOF Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "提示"
txtUserName.SetFocus
txtUserName.Text = ""
Exit Sub
Else
'判断输入密码是否正确
If Trim(mrc.Fields(0)) = txtUserName.Text And Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
OK = True
UserName = Trim(txtUserName.Text)
If Trim(mrc.Fields(2)) = "一般用户" Then '判断用户级别
MsgBox "您是一般用户"
frmMain.Operator.Enabled = False
frmMain.Administrator.Enabled = False
End If
If Trim(mrc.Fields(2)) = "操作员" Then
MsgBox "您是操作员"
MDIForm1.Administrator_Menu.Enabled = False
End If
If Trim(mrc.Fields(2)) = "管理员" Then
MsgBox "您是管理员"
End If
mrc1.AddNew
mrc1.Fields(0) = Trim(txtUserName)
mrc1.Fields(1) = Trim(mrc.Fields(2))
mrc1.Fields(2) = Trim(Date)
mrc1.Fields(3) = Time
mrc1.Update
mrc1.Close
mrc2.AddNew '添加记录到worklog_info表
mrc2.Fields(1) = Trim(txtUserName)
mrc2.Fields(2) = Trim(mrc.Fields(2))
mrc2.Fields(3) = Trim(Date)
mrc2.Fields(4) = Trim(Time)
mrc2.Fields(7) = VBA.Environ("computername")
mrc2.Fields(8) = True
mrc2.Update
mrc2.Close
Me.Hide
Print
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "提示"
txtPassword.SetFocus
txtPassword.Text = ""
End If
'记载输入密码次数
miCount = miCount + 1
If miCount = 3 Then
MsgBox "超过登陆限制"
End
End If
End If
End If
End If
End Sub