📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form DlgLogin
BorderStyle = 3 'Fixed Dialog
Caption = "登陆"
ClientHeight = 2040
ClientLeft = 3630
ClientTop = 2355
ClientWidth = 3615
Icon = "frmLogin.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1205.299
ScaleMode = 0 'User
ScaleWidth = 3394.289
ShowInTaskbar = 0 'False
Begin VB.TextBox txtUserName
BackColor = &H8000000B&
Height = 288
Left = 1200
TabIndex = 1
Top = 695
Width = 2325
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Default = -1 'True
Height = 390
Left = 1200
TabIndex = 4
Top = 1560
Width = 1140
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 390
Left = 2400
TabIndex = 5
Top = 1560
Width = 1140
End
Begin VB.TextBox txtPassword
BackColor = &H8000000B&
Height = 288
IMEMode = 3 'DISABLE
Left = 1200
PasswordChar = "*"
TabIndex = 3
Top = 1080
Width = 2325
End
Begin VB.Label lblLabels
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "密码:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 180
Index = 3
Left = 135
TabIndex = 8
Top = 1125
Width = 600
End
Begin VB.Label lblLabels
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "用户名:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 180
Index = 2
Left = 120
TabIndex = 7
Top = 735
Width = 795
End
Begin VB.Label lblLabels
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "用户名:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 180
Index = 0
Left = 120
TabIndex = 0
Top = 720
Width = 795
End
Begin VB.Label lblLabels
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "密码:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 180
Index = 1
Left = 120
TabIndex = 2
Top = 1110
Width = 600
End
Begin VB.Image Image1
Height = 480
Left = 240
Picture = "frmLogin.frx":058A
Top = 120
Width = 480
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "请输入用户名及密码."
ForeColor = &H00808080&
Height = 180
Left = 1080
TabIndex = 6
Top = 120
Width = 1710
End
Begin VB.Shape Shape1
BorderColor = &H00808080&
FillColor = &H00FFFFFF&
FillStyle = 0 'Solid
Height = 495
Left = 0
Top = 0
Width = 3615
End
End
Attribute VB_Name = "DlgLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Unload Me
End Sub
Private Sub cmdOK_Click()
On Error GoTo errh:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set rs = cn.Execute("SELECT UserName , Password FROM 超级用户 ")
If rs.EOF Then
rs.Close
Set rs = Nothing
Unload Me
Load FrmMain
Exit Sub
End If
rs.MoveFirst
Dim i As Integer
'校验是否为超级用户
Do
If rs.Fields("UserName") = txtUserName.Text Then
If rs.Fields("Password") = txtPassword.Text Then
UserType = True
LoginSucceeded = True
rs.Close
If txtPassword.Text = "Admin" Then IsAdmin = True
Unload Me
Load FrmMain
Exit Sub
Exit Do
End If
End If
rs.MoveNext
Loop Until rs.EOF
'校验是否为普通用户
Set rs = cn.Execute("SELECT 学号 FROM 学生 WHERE 学号 =" & "'" & txtPassword.Text & "'")
If rs.EOF Then
MsgBox "无效密码或用户名请重试!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
Else
rs.Close
UserType = False
LoginSucceeded = True
Unload Me
Load FrmMain
End If
Exit Sub
errh:
MsgBox Err.Description
End Sub
Private Sub Form_Load()
Dim s As String
MakeCenter DlgLogin
s = MakeConnection() '创建全局ADO连接
If s <> "OK" Then
MsgBox s, , "错误!"
Unload Me
LoginSucceeded = False
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not LoginSucceeded Then '如果登陆失败
cn.Close '释放连接
Set cn = Nothing
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -