📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
BorderStyle = 1 'Fixed Single
Caption = "登录"
ClientHeight = 1530
ClientLeft = 45
ClientTop = 330
ClientWidth = 3990
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 1530
ScaleWidth = 3990
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 375
Left = 2520
TabIndex = 3
Top = 1080
Width = 975
End
Begin VB.CommandButton cmdOk
Caption = "登录"
Default = -1 'True
Height = 375
Left = 720
TabIndex = 2
Top = 1080
Width = 975
End
Begin VB.TextBox txtPassword
Height = 300
IMEMode = 3 'DISABLE
Left = 1320
PasswordChar = "*"
TabIndex = 1
Top = 600
Width = 2415
End
Begin VB.TextBox txtUserName
Height = 300
Left = 1320
TabIndex = 0
Top = 240
Width = 2415
End
Begin VB.Label Label2
Caption = "密码"
Height = 255
Left = 480
TabIndex = 5
Top = 645
Width = 735
End
Begin VB.Label Label1
Caption = "用户名"
Height = 255
Left = 480
TabIndex = 4
Top = 285
Width = 855
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private LoginSucceeded As Boolean '记录是否登录成功
Private Sub cmdCancel_Click()
'设置全局变量为 false
'不提示失败的登录
LoginSucceeded = False
Unload Me
End Sub
Private Sub cmdOK_Click()
userName = txtUsername.Text '全局变量:记录当前用户的用户名
userPassword = txtPassword.Text '全局变量:记录当前用户的密码
'检查正确的密码
'在此处要从数据库中检索是否有这个用户,以及密码是否正确
cn.Open
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = cn
rs.LockType = adLockReadOnly
rs.CursorType = adOpenForwardOnly
rs.Open "select * from 用户密码表 where 用户名 = '" & userName & "' and 密码 = '" & userPassword & "'"
If rs.EOF Then
LoginSucceeded = False
Else
userXingMing = rs!姓名 '全局变量:记录当前用户的姓名
LoginSucceeded = True
End If
If LoginSucceeded = False Then
'程序执行到此,说明一定没有登录成功
MsgBox "无效的用户名或密码,请重试!", , "登录"
txtUsername.SetFocus
txtPassword.Text = ""
SendKeys "{Home}+{End}"
Else
Me.Hide
End If
rs.Close
cn.Close
If LoginSucceeded = True Then
Unload Me
frmMain.Show
End If
End Sub
Private Sub Form_Activate()
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.SetFocus
Set cn = New ADODB.Connection
cn.ConnectionString = connectString
End Sub
Private Sub Form_Load()
LoginSucceeded = False
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -