📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
BorderStyle = 3 'Fixed Dialog
Caption = "用户登录"
ClientHeight = 3150
ClientLeft = 3555
ClientTop = 3840
ClientWidth = 5565
ControlBox = 0 'False
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3150
ScaleMode = 0 'User
ScaleWidth = 5565
ShowInTaskbar = 0 'False
Begin VB.TextBox txtUserName
Height = 345
Left = 2250
TabIndex = 1
Top = 975
Width = 2325
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Height = 330
Left = 1515
TabIndex = 4
Top = 2160
Width = 1020
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 330
Left = 3120
TabIndex = 5
Top = 2160
Width = 1020
End
Begin VB.TextBox txtPassword
Height = 345
IMEMode = 3 'DISABLE
Left = 2250
PasswordChar = "*"
TabIndex = 3
Top = 1485
Width = 2325
End
Begin VB.Label Label2
Caption = "Visual Basic编程及实例分析教程综合实例 开发者:郑海春 2006年"
ForeColor = &H00008000&
Height = 255
Left = 120
TabIndex = 7
Top = 2820
Width = 5355
End
Begin VB.Line Line1
BorderColor = &H00808080&
X1 = 120
X2 = 5385
Y1 = 2700
Y2 = 2700
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "学生信息管理系统"
BeginProperty Font
Name = "楷体_GB2312"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00C00000&
Height = 495
Left = 420
TabIndex = 6
Top = 240
Width = 4755
End
Begin VB.Label lblLabels
Caption = "用户名(&U):"
Height = 270
Index = 0
Left = 1065
TabIndex = 0
Top = 990
Width = 1080
End
Begin VB.Label lblLabels
Caption = "密 码(&P):"
Height = 270
Index = 1
Left = 1065
TabIndex = 2
Top = 1500
Width = 1080
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim try_times As Integer '尝试登陆次数
Private Sub Form_Load()
'设置数据库路径
StudentDBfile = App.Path & "\StudentMIS.mdb"
'窗体中心定位
Call ScreenCenter(Me)
End Sub
Private Sub cmdCancel_Click()
'结束应用程序
If MsgBox("你选择了退出登陆,是否退出?", _
vbYesNo + vbInformation, "用户登陆") = vbYes Then
End
Else
Exit Sub
End If
End Sub
Private Sub cmdOK_Click()
Dim sName As String, sPas As String
Dim mrs As ADODB.Recordset, strSQL As String
sName = Trim(txtUserName.Text): sPas = Trim(txtPassword.Text)
'数据有效性检查
If sName = "" Then
MsgBox "请输入用户名!", vbCritical, "用户登陆验证"
txtUserName.SetFocus
Exit Sub
End If
If sPas = "" Then
MsgBox "请输入密码!", vbCritical, "用户登陆验证"
txtPassword.SetFocus
Exit Sub
End If
'检查用户名是否正确
strSQL = "select * from login where user='" & sName & "'"
Set mrs = ExecuteSQL(strSQL)
If mrs.EOF = True Then
MsgBox "用户名不存在!", vbCritical, "用户登陆验证"
try_times = try_times + 1
If try_times >= 3 Then
MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭!", _
vbCritical, "用户登陆验证"
End
Else
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
End If
strSQL = "select * from login where user='" & sName & "'" & _
"and password='" & sPas & "'"
Set mrs = ExecuteSQL(strSQL)
If mrs.EOF = True Then
MsgBox " 密码错误!", vbCritical, "用户登陆验证"
try_times = try_times + 1
If try_times >= 3 Then
MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭!", _
vbCritical, "用户登陆验证"
End
Else
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If
End If
MsgBox "登陆成功!", vbInformation, "用户登陆验证"
'保存当前登陆的权限
bolAuthority = mrs.Fields("admin")
'加载MDI主窗体
StudentMIS.Show
'卸载登陆窗体
Unload Me
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
'用于在输入完用户名后并按回车键后跳到输入密码文本框
If KeyAscii = 13 Then txtPassword.SetFocus
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'用于在输入完密码后并按回车键后跳到确定命令按钮
If KeyAscii = 13 Then cmdOK.SetFocus
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -