📄 登录.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
BorderStyle = 1 'Fixed Single
Caption = "用户登录"
ClientHeight = 2970
ClientLeft = 45
ClientTop = 330
ClientWidth = 4530
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
Picture = "登录.frx":0000
ScaleHeight = 2970
ScaleWidth = 4530
Begin VB.Frame Frame1
Height = 1740
Left = 345
TabIndex = 1
Top = 285
Width = 3735
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 = 480
Left = 1470
TabIndex = 0
Top = 360
Width = 1830
End
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 = 480
IMEMode = 3 'DISABLE
Left = 1470
PasswordChar = "*"
TabIndex = 2
Top = 990
Width = 1830
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "用户名:"
Height = 180
Left = 390
TabIndex = 6
Top = 510
Width = 720
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "密 码:"
Height = 180
Left = 390
TabIndex = 5
Top = 1140
Width = 810
End
End
Begin VB.CommandButton cmdLogin
Caption = "登 录(&O)"
Height = 375
Left = 630
TabIndex = 3
Top = 2325
Width = 1290
End
Begin VB.CommandButton cmdCancel
Caption = "取消(&C)"
Height = 375
Left = 2670
TabIndex = 4
Top = 2325
Width = 1275
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 UserTable where Username = '" & txtUser.Text _
& "' and Password = '" & 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
'清空txtUser和txtPwd文本框
txtUser.Text = ""
txtPwd.Text = ""
Exit Sub
Else
'还需使其他菜单可用
MDIfrmMain.mnAddUser.Enabled = True
MDIfrmMain.mnBasicData.Enabled = True
MDIfrmMain.mnWuYe.Enabled = True
MDIfrmMain.mnDataTg.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 + -