📄 login.frm
字号:
VERSION 5.00
Begin VB.Form login
Caption = "用户登录"
ClientHeight = 3615
ClientLeft = 60
ClientTop = 345
ClientWidth = 5340
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "login.frx":0000
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 3615
ScaleWidth = 5340
WindowState = 2 'Maximized
Begin VB.TextBox Text1
Height = 375
Left = 1920
TabIndex = 0
Top = 1320
Width = 1695
End
Begin VB.TextBox Text2
Height = 375
IMEMode = 3 'DISABLE
Left = 1920
MaxLength = 10
PasswordChar = "*"
TabIndex = 1
Top = 1800
Width = 1695
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "stu.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 375
Left = 240
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "UserID"
Top = 3000
Visible = 0 'False
Width = 2775
End
Begin VB.CommandButton Command1
Caption = "确 定"
Height = 495
Left = 3360
TabIndex = 2
Top = 2880
Width = 1095
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "口 令"
Height = 240
Left = 960
TabIndex = 5
Top = 1920
Width = 795
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "用户名"
Height = 240
Left = 960
TabIndex = 4
Top = 1320
Width = 780
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "用户登录"
Height = 240
Left = 2040
TabIndex = 3
Top = 720
Width = 1035
End
End
Attribute VB_Name = "login"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'===================================================
'判断用户输入的名称和口令是否合法
'首先判断输入的用户名是否存在,如果不存在,给出提示
'如果用户名存在,判断输入口令是否正确,如果错误,给出提示
'如果用户名和口令输入正确,卸载本窗体,
'否则,判断是否用完三次机会,并给出相应提示。
'===================================================
Dim IsUser As Boolean '用户是否存在
Dim Pwd As String
Dim Uname As String
Static count As Integer '记录输入口令次数
Pwd = Trim(Text2.Text)
Uname = Trim(Text1.Text)
IsUser = False
'比对用户名称和口令的正确与否
Do While Not Data1.Recordset.EOF
If Uname = Data1.Recordset.Fields(0) Then
'当用户名和当前记录名称相同时的处理:
If Pwd = Data1.Recordset.Fields("password") Then
'如果口令输入正确,卸载本窗体
Unload Me
mainfrm.Toolbar1.Buttons(2).Enabled = True
mainfrm.Toolbar1.Buttons(1).Enabled = False
Exit Sub
Else
'如果口令输入错误,给出提示信息
If count < 2 Then
MsgBox "口令错误,请重新输入"
Text2.Text = ""
Text2.SetFocus
End If
IsUser = True '标志为合法用户
Exit Do
End If
End If
Data1.Recordset.MoveNext '移动到下一条记录
Loop
count = count + 1 '输入口令次数加1
'输入三次口令,且口令错误,退出程序
If count = 3 Then
MsgBox "非法用户,不能使用本系统"
End
End If
'如果没有此用户,显示提示信息
If Not IsUser Then
MsgBox "无此用户,请重新登录"
Text1.Text = ""
Text1.SetFocus
End If
Data1.Recordset.MoveFirst
End Sub
Private Sub Form_Load()
Dim DBStr As String
DBStr = App.Path
If Right(App.Path, 1) <> "\" Then DBStr = App.Path & "\"
DBStr = DBStr & "stu.mdb"
Data1.DatabaseName = DBStr
Text1.Text = ""
Text2.Text = ""
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -