📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
Caption = "登录"
ClientHeight = 2850
ClientLeft = 3360
ClientTop = 2880
ClientWidth = 4725
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2850
ScaleWidth = 4725
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdQuit
Caption = "退出"
Height = 420
Left = 2400
Style = 1 'Graphical
TabIndex = 6
Top = 2280
Width = 1095
End
Begin VB.CommandButton cmdLogin
Caption = "登陆"
Height = 420
Left = 1080
Style = 1 'Graphical
TabIndex = 5
Top = 2280
Width = 1095
End
Begin VB.Frame Frame1
Appearance = 0 'Flat
ForeColor = &H80000008&
Height = 1575
Left = 120
TabIndex = 0
Top = 600
Width = 4455
Begin VB.TextBox txtPassword
Appearance = 0 'Flat
BackColor = &H80000018&
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 350
IMEMode = 3 'DISABLE
Left = 1680
PasswordChar = "*"
TabIndex = 4
Top = 960
Width = 2055
End
Begin VB.TextBox txtUserName
Appearance = 0 'Flat
BackColor = &H80000018&
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 350
Left = 1680
TabIndex = 2
Top = 360
Width = 2055
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "密码:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 240
Left = 840
TabIndex = 3
Top = 1015
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "用户名:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 240
Left = 600
TabIndex = 1
Top = 415
Width = 960
End
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "学生信息管理系统"
BeginProperty Font
Name = "华文彩云"
Size = 22.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000002&
Height = 465
Left = 600
TabIndex = 7
Top = 120
Width = 3720
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'----------------------------------frmLogin.frm----------------------------------
Option Explicit
'登陆
Private Sub cmdLogin_Click()
'声明ADODB.Recordset对象变量
Dim objRecordset As ADODB.Recordset
'声明SQL字符串
Dim strSQL As String
'查找用户名
strSQL = "select UserName from Users where UserName='" & Trim(txtUserName.Text) & "'"
'获得符合输入的用户记录集
Set objRecordset = ExecuteSQL(strSQL)
'如果输入的用户不存在
If objRecordset.EOF = True Then
MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
'从数据库中获得用户名
UserName = objRecordset.Fields(0)
'查找用密码
strSQL = "select UserName from Users where Password='" & Trim(txtPassword.Text) & "'"
'获得符合输入的密码记录集
Set objRecordset = ExecuteSQL(strSQL)
'如果输入的密码不存在
If objRecordset.EOF = True Or UserName <> objRecordset.Fields(0) Then
MsgBox "密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If
'显示主界面
mdiMain.Show
'卸载登陆窗体
Unload Me
End Sub
'退出登陆
Private Sub cmdQuit_Click()
Unload Me
End Sub
'输入用户名
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
'输入回车表示输入结束,密码框获得焦点
If KeyAscii = 13 Then
txtPassword.SetFocus
End If
End Sub
'输入密码
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'输入回车表示输入结束,登陆按钮获得焦点
If KeyAscii = 13 Then
cmdLogin.SetFocus
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -