📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
BorderStyle = 1 'Fixed Single
Caption = "用户登录"
ClientHeight = 3075
ClientLeft = 45
ClientTop = 330
ClientWidth = 5175
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 3075
ScaleWidth = 5175
Begin VB.CommandButton cmdCancel
Caption = "取消重填"
Height = 495
Left = 2640
TabIndex = 6
Top = 2280
Width = 1215
End
Begin VB.CommandButton cmdLogin
Caption = "登 录"
Height = 495
Left = 960
TabIndex = 5
Top = 2280
Width = 1215
End
Begin VB.Frame Frame1
Height = 1815
Left = 120
TabIndex = 0
Top = 120
Width = 4575
Begin VB.TextBox txtPwd
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
IMEMode = 3 'DISABLE
Left = 1560
PasswordChar = "*"
TabIndex = 4
Top = 1080
Width = 2415
End
Begin VB.TextBox txtUser
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1560
TabIndex = 3
Top = 360
Width = 2415
End
Begin VB.Label Label2
Caption = "密 码:"
Height = 375
Left = 480
TabIndex = 2
Top = 1080
Width = 975
End
Begin VB.Label Label1
Caption = "用户名:"
Height = 375
Left = 480
TabIndex = 1
Top = 600
Width = 975
End
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rs_user As New ADODB.Recordset
Private Sub cmdCancel_Click()
txtUser.Text = ""
txtPwd.Text = ""
End Sub
Private Sub cmdLogin_Click()
'首先检查用户是否输入了用户名和密码
If txtUser.Text = "" Then
MsgBox "请输入用户名!", vbOKOnly + vbInformation, "注意"
txtUser.SetFocus
Exit Sub
ElseIf txtPwd.Text = "" Then
MsgBox "请输入密码!", vbOKOnly + vbInformation, "注意"
txtPwd.SetFocus
Exit Sub
End If
Dim sqluser As String
'构造查询该用户名和密码的sql语句
sqluser = "select * from 用户表 where 用户名 = '" & txtUser.Text _
& "' and 密码 = '" & txtPwd.Text & "'"
rs_user.CursorLocation = adUseClient
'打开数据游标
rs_user.Open sqluser, conn, adOpenKeyset, adLockPessimistic
If rs_user.EOF = True Then
MsgBox "用户名和密码不正确!", vbOKOnly + vbInformation, "注意"
rs_user.Close
Exit Sub
ElseIf rs_user.Fields(3) = "超级用户" Then
admin_user = True
' 如果是超级用户则使添加新用户子菜单为可用
MDIfrmMain.mnAddNew.Enabled = True
'还需使其他菜单可用
MDIfrmMain.mnStu.Enabled = True
MDIfrmMain.mnPlan.Enabled = True
MDIfrmMain.mnAdmit.Enabled = True
'提示用户登录成功并关闭游标和登录窗口
MsgBox "登录成功!", vbOKOnly + vbInformation, "注意"
rs_user.Close
Unload Me
Else
admin_user = False
'如果为普通用户则,添加新用户子菜单不可用,其他菜单可用
MDIfrmMain.mnStu.Enabled = True
MDIfrmMain.mnPlan.Enabled = True
MDIfrmMain.mnAdmit.Enabled = True
MsgBox "登录成功!", vbOKOnly + vbInformation, "注意"
rs_user.Close
Unload Me
End If
End Sub
Private Sub Form_Load()
Dim X0 As Long
Dim Y0 As Long
'让窗体居中
X0 = Screen.Width
Y0 = Screen.Height
X0 = (X0 - Me.Width) / 2
Y0 = (Y0 - Me.Height) / 2
Me.Move X0, Y0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -