Private Sub cmdok_Click()
Dim txtsql As String '用来存放SQL语句
Dim txtsql1 As String
Dim txtsql2 As String
Dim mrc As ADODB.Recordset '连接USER表
Dim mrc1 As ADODB.Recordset '连接onwork表
Dim mrc2 As ADODB.Recordset '连接worklog表
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='" & Trim(txtusername.Text) & "'"
'查询指定用户名的记录
Set mrc = executeSQL(txtsql, msgtext) '执行查询语句
If mrc.EOF Then
MsgBox "用户名和密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtusername.SetFocus
txtusername.Text = ""
Exit Sub
Else
If Trim(mrc.Fields(1)) = Trim(txtpassword.Text) Then
ok = True
username = Trim(txtusername.Text) '判断密码是否输入正确
If Trim(mrc.Fields(2)) = "一般用户" Then '判断用户级别
MsgBox "您是一般用户!"
MDIForm1.Operator.Enabled = False
MDIForm1.Admin.Enabled = True
MDIForm1.Show
End If
If Trim(mrc.Fields(2)) = "操作员" Then
MsgBox "您是操作员!"
MDIForm1.Admin.Enabled = False
MDIForm1.Show
End If
If Trim(mrc.Fields(2)) = "管理员" Then
MsgBox "您是管理员!"
MDIForm1.Show
End If
'把信息写入Onwork表
txtsql1 = "select * from OnWork_Info where UserID ='" & txtusername.Text & "'"
Set mrc1 = executeSQL(txtsql1, msgtext1)
mrc1.AddNew
mrc1.Fields(0) = Trim(txtusername.Text)
mrc1.Fields(1) = Trim(mrc.Fields(2))
mrc1.Fields(2) = Date
mrc1.Fields(3) = Trim(Time)
mrc1.Fields(4) = VBA.Environ("computername")
mrc1.Update
'把信息写入worklog表
txtsql2 = "select * from worklog_Info where userID = '" & txtusername.Text & "'"
Set mrc2 = executeSQL(txtsql2, msgtext2)
mrc2.AddNew
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
micount = micount + 1
If micount = 1 Then
MsgBox "密码输入错误,请重新输入,您还有两次机会!", vbOKOnly + vbExclamation, "警告"
txtpassword.SetFocus
txtpassword.Text = ""
Exit Sub
Else
If micount = 2 Then
MsgBox "密码输入错误,请重新输入,您还有一次机会!", vbOKOnly + vbExclamation, "警告"
txtpassword.SetFocus
txtpassword.Text = ""
Exit Sub
Else
If micount = 3 Then
MsgBox "密码输入错误,没有计划,即将退出系统!", vbOKOnly + vbExclamation, "警告"
End
Exit Sub
End If
End If
End If
End If
End If
End If
End If '结束条件语句
End Sub