Public strusername As String
Public struserpass As String
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
strusername = Trim(txtUserName.Text)
struserpass = Trim(txtPassword.Text)
'用户密码不能为空
If txtPassword.Text = "" Then
MsgBox "用户密码不能为空", , "提示!"
Exit Sub
End If
'用户编号不能为空
If txtUserName.Text = "" Then
MsgBox "用户编号不能为空", , "提示!"
Exit Sub
End If
'打开数据库
Call openmycon
Call openmyres("select YGID from dbo.YuanGong where YGmima='" + Trim(txtPassword.Text) + "'")
'判断用户编号是否存在
If myres.EOF Then
If num > 1 Then
MsgBox "用户编号不存在,请重新输入。" & Chr(13) & "你还有" & num - 1 & "次机会", vbOKOnly, "提示信息"
txtUserName.Text = ""
txtPassword.Text = ""
txtUserName.SetFocus
num = num - 1
Exit Sub
Else
MsgBox "对不起,您已经多次尝试进入本系统,均不成功。" & Chr(13) & "系统将自动关闭,请与管理员联系!", vbOKOnly, "警告信息"
Unload Me
Exit Sub
End If
End If
'判断密码是否正确
Call openmyres("select * from YuanGong where YGID='" + Trim(txtUserName.Text) + "'and YGmima ='" + Trim(txtPassword.Text) + "'")
If myres.EOF Then
If num > 1 Then
MsgBox "您输入的密码不存在,请重新输入。" & Chr(13) & "你还有" & num - 1 & "次机会", vbOKOnly, "提示信息"
txtPassword.Text = ""
txtUserName.Text = ""
num = num - 1
Exit Sub
Else
MsgBox "对不起,您已经多次尝试进入本系统,均不成功。" & Chr(13) & "系统将自动关闭,请与管理员联系!", vbOKOnly, "警告信息"
Unload Me
Exit Sub
End If
End If
MsgBox "用户名密码正确,登录成功!"
frm_MJZCT.Show
Unload Me
End Sub
Private Sub Form_Load()
Me.Top = 4000
Me.Left = 4000
num = 3
txtUserName.Text = ""
txtPassword.Text = ""
End Sub
Private Sub txtPassword_GotFocus()
'获得焦点时改变底色
txtPassword.BackColor = vbCyan
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'只允许输入数字
If KeyAscii <> 8 And (KeyAscii < 47 Or KeyAscii > 58) Then
KeyAscii = 0
End If
'判断输入长度是不是符合要求
If Len(txtPassword.Text) > 10 Then
MsgBox "密码输入不合法", vbOKOnly, "提示"
End If
'当按回车键是当成是按TAB键
If KeyAscii = 13 Then
SendKeys "{tab}"
End If
End Sub
Private Sub txtPassword_LostFocus()
'失去焦点时改变底色
txtPassword.BackColor = vbWhite
End Sub
Private Sub txtUserName_GotFocus()
'获得焦点时改变底色
txtUserName.BackColor = vbCyan
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
'判断输入长度是不是符合要求
If Len(txtUserName.Text) > 20 Then
MsgBox "员工编号输入不合法", vbOKOnly, "提示"
End If
'当按回车键是当成是按TAB键
If KeyAscii = 13 Then
SendKeys "{tab}"
End If
End Sub
Private Sub txtUserName_LostFocus()
'失去焦点时改变底色
txtUserName.BackColor = vbWhite
End Sub