⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmlogin.frm

📁 适用一般于毕业设计! VB代码源加SQL 数据库 ··
💻 FRM
字号:
VERSION 5.00
Begin VB.Form FrmLogin 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "身份验证"
   ClientHeight    =   2595
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3975
   ControlBox      =   0   'False
   Icon            =   "FrmLogin.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2595
   ScaleWidth      =   3975
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  '屏幕中心
   Begin VB.Frame Frame1 
      Height          =   1755
      Left            =   240
      TabIndex        =   4
      Top             =   60
      Width           =   3495
      Begin VB.TextBox txtUser 
         Height          =   375
         Left            =   1080
         MaxLength       =   20
         TabIndex        =   0
         Text            =   "User"
         Top             =   315
         Width           =   2175
      End
      Begin VB.TextBox txtPwd 
         Height          =   375
         IMEMode         =   3  'DISABLE
         Left            =   1080
         MaxLength       =   20
         PasswordChar    =   "*"
         TabIndex        =   1
         Text            =   "Pwd"
         Top             =   795
         Width           =   2175
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "默认用户编号:Admin, 密码:000000"
         ForeColor       =   &H00000080&
         Height          =   180
         Left            =   240
         TabIndex        =   7
         Top             =   1380
         Width           =   3060
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "密   码"
         Height          =   180
         Left            =   240
         TabIndex        =   6
         Top             =   900
         Width           =   720
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "用户编号"
         Height          =   180
         Left            =   240
         TabIndex        =   5
         Top             =   420
         Width           =   720
      End
   End
   Begin VB.CommandButton cmdOk 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   400
      Left            =   540
      TabIndex        =   2
      Top             =   1980
      Width           =   1125
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   400
      Left            =   2237
      TabIndex        =   3
      Top             =   1980
      Width           =   1125
   End
End
Attribute VB_Name = "FrmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'初始化窗体上控件
Private Sub Form_Load()
  txtUser.Text = ""     '清空用户编号输入框
  txtPwd.Text = ""      '清空密码输入框
End Sub

'登录身份验证,若通过验证,调用frmMain窗体;未通过,结束程序
Private Sub cmdOk_Click()
  Dim Rs As New ADODB.Recordset   '用户信息查询记录集
  Dim strSql As String        '查询字符串
  Static Try_times As Integer     '尝试登录次数计数。注意:Static关键字

  '数据有效性检查(未输入用户编号,重新输)
  If txtUser.Text = "" Then
    MsgBox "请输入用户名", vbExclamation + vbOKOnly, "操作提示"
    txtUser.SetFocus
    Exit Sub
  End If
   
  '从Users表查询指定用户编号的用户信息
  strSql = "SELECT * FROM Users WHERE UserNo='" & txtUser.Text & "'"
  Rs.Open strSql, Conn, adOpenStatic, adLockReadOnly
  If Rs.RecordCount = 0 Then    '不存在指定编号的用户信息
    MsgBox "用户编号不存在", vbExclamation + vbOKOnly, "操作提示"
    txtUser.SetFocus        '用户编号输入框获得焦点
    Try_times = Try_times + 1   '尝试计数 + 1
    If Try_times >= 3 Then      '如果尝试计数满3次,结束程序
      MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭", _
                vbExclamation + vbOKOnly, "操作提示"
      Conn.Close          '关闭连接
      Set Conn = Nothing      '释放Conn
      End           '结束整个应用程序
    Else              '如果尝试计数未满3次,可以重新输入用户编号
      Exit Sub
    End If
  End If
  
  '如果用户编号正确,再判断密码是否正确
  If txtPwd.Text <> IIf(IsNull(Rs!UserPwd), "", Rs!UserPwd) Then    '如果密码错误
    MsgBox "密码错误", vbExclamation + vbOKOnly, "操作提示"
    txtPwd.SetFocus       '密码输入框获得焦点
    Try_times = Try_times + 1   '尝试计数 + 1
    If Try_times >= 3 Then      '如果尝试计数(包括前面计数)满3次,结束程序
      MsgBox "您已经三次尝试进入本系统,均不成功,系统将关闭", _
                vbExclamation + vbOKOnly, "操作提示"
      Conn.Close          '关闭连接
      Set Conn = Nothing      '释放Conn
      End           '结束整个应用程序
    Else              '如果总的尝试计数未满3次,可以重新输入密码
      Exit Sub
    End If
  End If

  '验证通过后,保存当前登录的用户编号
  CurLoginUserNo = txtUser.Text
  '保存当前登录的用户名称
  CurLoginUserName = IIf(IsNull(Rs!UserName), "", Rs!UserName)
  Rs.Close            '关闭记录集
  Set Rs = Nothing          '释放记录集
  Unload Me           '关闭登录窗体
  FrmMain.Show          '调用主窗体
End Sub

'放弃身份验证,结束程序
Private Sub cmdCancel_Click()
  Conn.Close        '关闭连接
  Set Conn = Nothing    '释放Conn
  End         '结束整个应用程序
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set FrmLogin = Nothing
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -