📄 登录.frm
字号:
VERSION 5.00
Begin VB.Form 登录
BorderStyle = 3 'Fixed Dialog
Caption = "登录"
ClientHeight = 2250
ClientLeft = 2835
ClientTop = 3465
ClientWidth = 3750
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1329.374
ScaleMode = 0 'User
ScaleWidth = 3521.047
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.OptionButton Option2
Caption = "普通用户"
Height = 180
Left = 2040
TabIndex = 3
Top = 1200
Width = 1215
End
Begin VB.OptionButton Option1
Caption = "系统管理员"
Height = 180
Left = 600
TabIndex = 2
Top = 1200
Width = 1215
End
Begin VB.Frame Frame1
Height = 615
Left = 240
TabIndex = 8
Top = 960
Width = 3255
End
Begin VB.TextBox txtUserName
Height = 255
Left = 1290
TabIndex = 0
Top = 135
Width = 2325
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Default = -1 'True
Height = 390
Left = 495
TabIndex = 4
Top = 1680
Width = 1140
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 390
Left = 2100
TabIndex = 5
Top = 1680
Width = 1140
End
Begin VB.TextBox txtPassword
Height = 270
IMEMode = 3 'DISABLE
Left = 1290
PasswordChar = "*"
TabIndex = 1
Top = 525
Width = 2325
End
Begin VB.Label lblLabels
Caption = "用户名称(&U):"
Height = 270
Index = 0
Left = 105
TabIndex = 6
Top = 150
Width = 1080
End
Begin VB.Label lblLabels
Caption = "密码(&P):"
Height = 270
Index = 1
Left = 105
TabIndex = 7
Top = 540
Width = 1080
End
End
Attribute VB_Name = "登录"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit '强制声明变量
Dim miCount As Integer '变量miCount用来记录单击“确定”按钮的次数
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOK_Click()
miCount = miCount + 1
If Option2.Value Then
Identify = 1
End If
If Option1.Value Then
Identify = 0
End If
Dim Sc As String
Sc = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\tradeunion.mdb"
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open Sc
UserName = ""
If Trim(txtUserName.Text) = "" Then '如果用户没有输入用户名时执行的代码
MsgBox "用户名不能为空,请输入你的用户名,谢谢!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus '使Text1得到焦点
Else
Dim OneQuerySql As String
OneQuerySql = "select* from 用户表 where 用户名='" & Trim(txtUserName.Text) & "'"
Dim AdoRsTradeMem As New ADODB.Recordset
If AdoRsTradeMem.State = adStateOpen Then
AdoRsTradeMem.Close
End If
AdoRsTradeMem.Open OneQuerySql, cn, adOpenKeyset, adLockOptimistic
If AdoRsTradeMem.EOF = True Then
MsgBox "该用户不存在,请重新确认后输入!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Identify = 3 Then
MsgBox "请确认用户级别!!!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Trim(AdoRsTradeMem.Fields(2)) <> Identify Then
MsgBox "该用户不存在,请确认用户名或用户级别!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Trim(AdoRsTradeMem.Fields(1)) = Trim(txtPassword.Text) Then
AdoRsTradeMem.Close
Me.Hide
UserName = Trim(txtUserName.Text)
Call LogPlug("系统", "用户 " + UserName + " 登录") '记录日志
主窗体.Show
Exit Sub
Else
MsgBox "密码不正确,请重新确认后输入!", vbOKOnly + vbExclamation, "警告"
txtPassword.SetFocus
txtPassword.Text = ""
End If
End If
End If
End If
End If
If miCount = 3 Then '如果有3次登录失败,则退出程序
MsgBox "登录错误超过限制次数,请重新启动程序!", vbOKOnly + vbExclamation, "警告"
End
End If
Exit Sub
End Sub
Private Sub Form_Load() '窗体载入时执行的代码
miCount = 0
Identify = 3
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -