📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
Caption = "用户登录"
ClientHeight = 3840
ClientLeft = 6390
ClientTop = 4230
ClientWidth = 5475
Icon = "frmLogin.frx":0000
LinkTopic = "Form2"
Picture = "frmLogin.frx":000C
ScaleHeight = 3840
ScaleWidth = 5475
Begin VB.CommandButton cmdExit
Caption = "退出(&X)"
Height = 615
Left = 3000
Style = 1 'Graphical
TabIndex = 5
Top = 2520
Width = 1215
End
Begin VB.CommandButton cmdOk
Caption = "确定(&0)"
Default = -1 'True
Height = 615
Left = 960
Style = 1 'Graphical
TabIndex = 4
Top = 2520
Width = 1215
End
Begin VB.TextBox txtPasswd
Height = 495
IMEMode = 3 'DISABLE
Left = 2400
PasswordChar = "*"
TabIndex = 3
Top = 1320
Width = 1455
End
Begin VB.TextBox txtUser
Height = 495
Left = 2400
TabIndex = 2
Top = 480
Width = 1455
End
Begin VB.Label lblPasswd
BackStyle = 0 'Transparent
Caption = "密码:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1680
TabIndex = 1
Top = 1440
Width = 735
End
Begin VB.Label lblUser
BackStyle = 0 'Transparent
Caption = "用户名:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1440
TabIndex = 0
Top = 600
Width = 975
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public counter As Integer '定义重试次数
Dim SQLSt As String
Dim rs As ADODB.Recordset
Private Sub cmdExit_Click()
DBDisconnect
End
End Sub
'单击“确定”按钮
Private Sub cmdOK_Click()
Dim vUser As String '定义user变量,用于存储用户名
vUser = Trim(txtUser) ' 给user赋值
Dim pwd As String '定义pwd变量,用于存储密码
pwd = Trim(txtPasswd) '给密码赋值
'没有输入用户名
If Trim(vUser) = "" Then
MsgBox "请输入用户名", vbInformation, "警告"
txtUser.SetFocus
Exit Sub
End If
SQLStr = "select * from PasswdInfo where UserName='" + Trim(vUser) + "'"
'rs.Open SQLStr, cnn, adOpenForwardOnly, adLockReadOnly
Set rs = SQLQuery(SQLStr)
'判断用户是否存在
If rs.EOF Then '该用户不存在
counter = counter + 1
If counter < 3 Then
MsgBox "用户名不存在,请重新输入!", vbOKOnly + vbInformation, "用户名错误"
txtUser.Text = ""
txtPasswd.Text = ""
txtUser.SetFocus
Exit Sub
Else
MsgBox "重试了三次,退出系统!", vbOKOnly + vbExclamation, "警告"
DBDisconnect
End
Exit Sub
End If
End If
'判断密码是否正确
If rs.Fields("passwd") <> pwd Then
counter = counter + 1
If counter < 3 Then
MsgBox "用户或密码错误,请重新输入!", vbOKOnly + vbInformation, "密码错误"
txtUser.Text = ""
txtPasswd.Text = ""
txtUser.SetFocus
Exit Sub
Else
MsgBox "重试了三次,退出系统!", vbOKOnly + vbExclamation, "密码错误"
DBDisconnect
End
Exit Sub
End If
End If
'登录成功,保存当前用户的信息
CurUserName = rs.Fields("UserName")
CurUserType = rs.Fields("Usertype")
Unload Me
frmMain.Show
frmMain.Enabled = True
frmMain.mnuUser.Enabled = True
frmMain.mnuSystem.Enabled = True
frmMain.mnuBook.Enabled = True
frmMain.mnuBorrow.Enabled = True
End Sub
'窗体装载事件
Private Sub Form_Load()
counter = 0 '初始化重试次数
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -