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

📄 frmsyslogon.frm

📁 上机考试系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form SystemLogon 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "大学计算机基础课上机考试评分系统用户登录"
   ClientHeight    =   8520
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9240
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   8520
   ScaleWidth      =   9240
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  '屏幕中心
   Begin VB.TextBox txtName 
      Height          =   315
      Left            =   1582
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   240
      Width           =   1935
   End
   Begin VB.TextBox txtPwd 
      Height          =   315
      IMEMode         =   3  'DISABLE
      Left            =   1582
      PasswordChar    =   "*"
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   645
      Width           =   1935
   End
   Begin VB.CommandButton cmdOk 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   315
      Left            =   1159
      TabIndex        =   3
      Top             =   1620
      Width           =   945
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "退出"
      Height          =   315
      Left            =   2321
      TabIndex        =   4
      Top             =   1620
      Width           =   945
   End
   Begin VB.ComboBox cmbType 
      Height          =   300
      ItemData        =   "frmSysLogon.frx":0000
      Left            =   1582
      List            =   "frmSysLogon.frx":0002
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   1080
      Width           =   1935
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "用户名"
      Height          =   180
      Left            =   907
      TabIndex        =   7
      Top             =   300
      Width           =   540
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "口  令"
      Height          =   180
      Left            =   907
      TabIndex        =   6
      Top             =   705
      Width           =   540
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "身  份"
      Height          =   180
      Left            =   907
      TabIndex        =   5
      Top             =   1110
      Width           =   540
   End
End
Attribute VB_Name = "SystemLogon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const MaxLogTimes As Integer = 3    '定义允许尝试登录的最大次数
Dim objAdmin As Recordset           '用于保存管理员登录信息
Dim objStudent As Recordset          '用于保存学生登录信息
Dim objTeacher As Recordset          '用于保存教师登录信息
Private Sub Form_Load()
    '清空用户名和口令文本框
    txtName = ""
    txtPwd = ""
    '创建身份列表
    cmbType.AddItem "学生"
    cmbType.AddItem "阅卷教师"
    cmbType.AddItem "系统管理员"
    cmbType.ListIndex = 2                        '设置默认身份
    '创建与数据库的联接
    Dim objCn As New Connection                  '定义并实例化联接对象
    With objCn                                   '建立数据库联接
        .Provider = "SQLOLEDB"
        .ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
                            "Initial Catalog=自测考试"
        .Open
    End With
    '访问数据库获得管理员登录信息
    Set objAdmin = New Recordset                 '实例化objAdmin对象
    With objAdmin
        .CursorLocation = adUseClient           '指定使用客户端游标
        .CursorType = adOpenStatic              '指定使用静态游标
        .Open "SELECT * FROM 管理员", objCn     '获取管理员登录信息
        Set .ActiveConnection = Nothing         '断开与数据库的联接
    End With
    '访问数据库获得学生登录信息
    Set objStudent = New Recordset              '实例化objstudent对象
    With objStudent
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .Open "SELECT 学号,考号 FROM 学生信息", objCn   '获取学生登录信息
        Set .ActiveConnection = Nothing                 '断开与数据库的联接
    End With
    '访问数据库获得教师登录信息
    Set objTeacher = New Recordset              '实例化objTeacher对象
    With objTeacher
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .Open "SELECT 姓名,口令 FROM 阅卷教师", objCn   '获取教师登录信息
        Set .ActiveConnection = Nothing                 '断开与数据库的联接
    End With
    objCn.Close             '关闭数据库连接
    Set objCn = Nothing     '释放数据库连接
End Sub
Private Sub cmdCancel_Click()
    '请求用户确认是否真的退出系统登录
    If MsgBox("你选择了退出系统登录,退出将不能启动管理系统!" & vbCrLf _
              & "是否真的退出?", vbYesNo + vbQuestion, "登录验证") = vbYes Then
        Unload Me               '卸载登录窗体
    End If
End Sub
Private Sub cmdOk_Click()
    '静态常量intLogTimes用于保存用户请求验证的次数
    Static intLogTimes As Integer
    intLogTimes = intLogTimes + 1     '保存当前登录次数
    If intLogTimes > MaxLogTimes Then
        '超过允许的登录次数,显示提示信息
        MsgBox "你已经超过允许的登录验证次数!" & vbCr _
               & "应用程序将结束!", vbCritical, "登录验证"
        End         '结束应用程序
    End If
    '检验是否输入用户名
    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
    '根据用户身份创建用于检验用户名和口令的合法性的Recorset对象
    Dim objLog As New Recordset
    Select Case cmbType
        Case "学生"
            Set objLog = objStudent.Clone
        Case "阅卷教师"
            Set objLog = objTeacher.Clone
        Case "系统管理员"
            Set objLog = objAdmin.Clone
    End Select
    Dim strPwdField As String
    With objLog      '检验用户名和口令的合法性
        If .RecordCount > 0 Then
            .MoveFirst
            Select Case cmbType
                Case "学生"
                    .Find "学号='" & Trim(txtName) & "'"
                    strPwdField = "考号"
                Case "阅卷教师"
                    .Find "姓名='" & Trim(txtName) & "'"
                    strPwdField = "口令"
                Case "系统管理员"
                    .Find "用户名='" & Trim(txtName) & "'"
                    strPwdField = "口令"
            End Select
            If .EOF Then
                MsgBox "用户名输入错误!请检查输入和登录身份是否正确!", vbCritical, "登录验证"
                txtName.SetFocus
                txtName.SelStart = 0
                txtName.SelLength = Len(txtName)
            ElseIf .Fields(strPwdField) <> Trim(txtPwd) Then
                MsgBox "口令错误!请检查输入和登录身份是否正确!", vbCritical, "登录验证"
                txtPwd.SetFocus
                txtPwd = ""
            Else
                '保存当前用户信息
                CurrentUserName = Trim(txtName)
                CurrentUserStatus = cmbType
                MsgBox "欢迎使用自测考试系统!", vbInformation, "登录成功"
                Unload Me                   '关闭登录窗体
                mdiSystemMain.Show         '显示系统主窗体
            End If
        End If
     End With
     Set objLog = Nothing               '释放objLog对象
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objAdmin = Nothing                  '释放objAdmin对象
    Set objStudent = Nothing                 '释放objstudent对象
    Set objTeacher = Nothing                 '释放objTeacher对象
End Sub


⌨️ 快捷键说明

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