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

📄 frmlogon.frm

📁 所在类别: 随书资源/T 工业技术/TP 自动化技术、计算机技术/TP31 计算机软件 其他题名: 作者: 夏邦贵, 刘凡馨等编著 出版者: 机械工业出版社 出版年: 2006 I
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmLogon 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "系统登录"
   ClientHeight    =   2325
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4185
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2325
   ScaleWidth      =   4185
   StartUpPosition =   2  '屏幕中心
   Begin VB.ComboBox cmbType 
      Height          =   300
      ItemData        =   "frmLogon.frx":0000
      Left            =   1462
      List            =   "frmLogon.frx":0002
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   1125
      Width           =   1935
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   315
      Left            =   2197
      TabIndex        =   4
      Top             =   1695
      Width           =   945
   End
   Begin VB.CommandButton cmdOk 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   315
      Left            =   1042
      TabIndex        =   3
      Top             =   1680
      Width           =   945
   End
   Begin VB.TextBox txtPwd 
      Height          =   315
      IMEMode         =   3  'DISABLE
      Left            =   1462
      PasswordChar    =   "*"
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   720
      Width           =   1935
   End
   Begin VB.TextBox txtName 
      Height          =   315
      Left            =   1462
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   315
      Width           =   1935
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "身  份"
      Height          =   180
      Left            =   787
      TabIndex        =   7
      Top             =   1185
      Width           =   540
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "口  令"
      Height          =   180
      Left            =   787
      TabIndex        =   6
      Top             =   780
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "用户名"
      Height          =   180
      Left            =   787
      TabIndex        =   5
      Top             =   375
      Width           =   540
   End
End
Attribute VB_Name = "frmLogon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const MaxLogTimes As Integer = 3    '定义允许尝试登录的最大次数
Private Sub Form_Load()
    '清空用户名和口令文本框
    txtName = ""
    txtPwd = ""
    '创建身份列表
    cmbType.AddItem "学生"
    cmbType.AddItem "教师"
    cmbType.AddItem "系统管理员"
    cmbType.ListIndex = 0                        '设置默认身份
End Sub
Private Sub cmdCancel_Click()
    '请求用户确认是否真的退出系统登录
    If MsgBox("你选择了退出系统登录,退出将不能启动管理系统!" & vbCrLf _
              & "是否真的退出?", vbYesNo + vbQuestion, "登录验证") = vbYes Then
        Unload Me               '卸载登录窗体
    End If
End Sub
Private Sub cmdOk_Click()
    Dim objCn As Connection, objRs As Recordset, strSQL$
    If Trim(txtName) = "" Then              '检验是否输入用户名
        MsgBox "请输入用户名!", vbExclamation, "登录验证"
        txtName = ""
        txtName.SetFocus
        Exit Sub
    End If
    If Trim(txtPwd) = "" Then   '检验是否输入登录口令
        MsgBox "请输入登录口令!", vbExclamation, "登录验证"
        txtPwd = ""
        txtPwd.SetFocus
        Exit Sub
    End If
    '静态常量intLogTimes用于保存用户请求验证的次数
    Static intLogTimes As Integer
    intLogTimes = intLogTimes + 1     '保存当前登录次数
    If intLogTimes > MaxLogTimes Then
        '超过允许的登录次数,显示提示信息
        MsgBox "你已经超过允许的登录验证次数!" & vbCr _
               & "应用程序将结束!", vbCritical, "登录验证"
        End         '结束应用程序
    End If
    '输入合法,进一步检验正确性
    '创建与数据库的联接
    Set objCn = New Connection                  '实例化联接对象
    With objCn                                  '建立数据库联接
        .Provider = "SQLOLEDB"
        .ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
                            "Initial Catalog=学分制选课"
        .Open
    End With
    
    '根据用户身份创建SQL Select命令
    Dim objLog As New Recordset
    Select Case cmbType
        Case "学生"
            strSQL = "select 学号 as 密码 from 学生信息 where 姓名='" & Trim(txtName) & "'"
        Case "教师"
            strSQL = "select 编号 as 密码 from 教师信息  where 姓名='" & Trim(txtName) & "'"
        Case "系统管理员"
            strSQL = "select 口令 as 密码 from 系统管理员 where 用户名='" & Trim(txtName) & "'"
    End Select
    '执行查询获得用户登陆密码
    Set objRs = New Recordset
    With objRs
        Set .ActiveConnection = objCn
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .Open strSQL
        If .RecordCount < 1 Then
            MsgBox "用户名输入错误!", vbCritical, "登录验证"
            txtName.SetFocus
            txtName.SelStart = 0
            txtName.SelLength = Len(txtName)
        Else
            If .Fields("密码") <> Trim(txtPwd) Then
                MsgBox "口令错误,请重新输入!", vbCritical, "登录验证"
                txtPwd.SetFocus
                txtPwd = ""
            Else
                '保存当前用户信息
                CurrentUserName = Trim(txtName)
                CurrentUserPwd = Trim(txtPwd)
                CurrentUserType = cmbType
                '显示登录成功信息
                MsgBox "欢迎使用学分制选课系统!", vbInformation, "登录成功"
                Unload Me               '关闭登录窗体
                frmSysMain.Show         '显示系统主窗体
            End If
        End If
     End With
    objCn.Close             '关闭数据库连接
    Set objCn = Nothing     '释放数据库连接
    Set objRs = Nothing
End Sub

⌨️ 快捷键说明

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