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

📄 frmmanagers.frm

📁 上机考试系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmManagers 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "系统管理员管理"
   ClientHeight    =   2145
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4950
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2145
   ScaleWidth      =   4950
   Begin VB.TextBox txtName 
      Height          =   270
      Left            =   1650
      MaxLength       =   6
      TabIndex        =   0
      Top             =   525
      Width           =   1425
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "保存"
      Height          =   300
      Left            =   3443
      TabIndex        =   4
      Top             =   1020
      Width           =   735
   End
   Begin VB.CommandButton cmdExit 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   315
      Left            =   3443
      TabIndex        =   5
      Top             =   1350
      Width           =   735
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "删除"
      Height          =   300
      Left            =   3443
      TabIndex        =   3
      Top             =   690
      Width           =   735
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "添加"
      Height          =   300
      Left            =   3443
      TabIndex        =   2
      Top             =   360
      Width           =   735
   End
   Begin VB.TextBox txtPwd 
      Height          =   270
      Left            =   1650
      MaxLength       =   6
      TabIndex        =   1
      Top             =   945
      Width           =   1425
   End
   Begin VB.PictureBox picNavigation 
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   360
      Left            =   750
      ScaleHeight     =   360
      ScaleWidth      =   2685
      TabIndex        =   10
      Top             =   1350
      Width           =   2685
      Begin VB.CommandButton cmdMove 
         Height          =   300
         Index           =   1
         Left            =   360
         Picture         =   "frmManagers.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   7
         Top             =   15
         Width           =   345
      End
      Begin VB.CommandButton cmdMove 
         Height          =   300
         Index           =   0
         Left            =   15
         Picture         =   "frmManagers.frx":0045
         Style           =   1  'Graphical
         TabIndex        =   6
         Top             =   15
         Width           =   345
      End
      Begin VB.CommandButton cmdMove 
         Height          =   300
         Index           =   3
         Left            =   2280
         Picture         =   "frmManagers.frx":0092
         Style           =   1  'Graphical
         TabIndex        =   9
         Top             =   15
         Width           =   345
      End
      Begin VB.CommandButton cmdMove 
         Height          =   300
         Index           =   2
         Left            =   1950
         Picture         =   "frmManagers.frx":00E1
         Style           =   1  'Graphical
         TabIndex        =   8
         Top             =   15
         Width           =   345
      End
      Begin VB.TextBox txtNews 
         Height          =   300
         Left            =   675
         Locked          =   -1  'True
         TabIndex        =   11
         TabStop         =   0   'False
         Top             =   15
         Width           =   1275
      End
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "用户名"
      Height          =   180
      Left            =   968
      TabIndex        =   13
      Top             =   570
      Width           =   540
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "口  令"
      Height          =   180
      Left            =   968
      TabIndex        =   12
      Top             =   975
      Width           =   540
   End
End
Attribute VB_Name = "frmManagers"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim isAdding As Boolean             '定义操作状态标志
Dim objAdmin As Recordset           '用于保存管理员数据表记录
Dim objCn As Connection             '用于建立数据库联接

Private Sub cmdExit_Click()
    Unload Me               '关闭系统用户管理窗体
End Sub

Private Sub Form_Load()
    '建立数据库联接
    Set objCn = 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
        Set .ActiveConnection = objCn
        .CursorLocation = adUseClient          '指定使用客户端游标
        .CursorType = adOpenStatic        '指定使用静态游标
        .LockType = adLockOptimistic
        .Open "SELECT * FROM 管理员"     '获取管理员登录信息
    End With
    '触发按钮单击事件,显示第一个记录
    cmdMove(0).Value = True
End Sub

Private Sub cmdMove_Click(Index As Integer)
    With objAdmin
        Select Case Index           '切换当前记录
            Case 0                  '使第一个记录成为当前记录
                If .RecordCount > 0 And Not .BOF Then .MoveFirst
            Case 1                  '使上一个记录成为当前记录
                If .RecordCount > 0 And Not .BOF Then
                    .MovePrevious
                    If .BOF Then .MoveFirst
                End If
            Case 2                  '使下一个记录成为当前记录
                If .RecordCount > 0 And Not .EOF Then
                    .MoveNext
                    If .EOF Then .MoveLast
                End If
            Case 3                  '使最后一个记录成为当前记录
                If .RecordCount > 0 And Not .EOF Then .MoveLast
        End Select
        If .RecordCount < 1 Then
            txtNews = "记录:无"    '显示无记录提示
            txtName = ""
            txtPwd = ""
        Else
            '显示当前记录数据
            txtName = .Fields("用户名")
            txtPwd = .Fields("口令")
            '显示当前记录编号和记录总数
            txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
        End If
    End With
    If isAdding Then isAdding = False
End Sub

Private Sub cmdAdd_Click()
    txtNews = "添加新记录"
    txtName = ""
    txtPwd = ""
    isAdding = True
End Sub

Private Sub cmdDelete_Click()
    '根据是否处于添加记录状态执行不同的操作
    If isAdding Then
        '退出添加记录状态,显示当前记录
        isAdding = False
        If objAdmin.BOF And objAdmin.EOF Then
            txtNews = "记录:无"    '显示无记录提示
        Else
            '显示当前记录数据
            txtName = objAdmin.Fields("用户名")
            txtPwd = objAdmin.Fields("口令")
            '显示当前记录编号和记录总数
            txtNews = "记录:" & objAdmin.AbsolutePosition & "/" & objAdmin.RecordCount
        End If
    Else
        If objAdmin.RecordCount > 0 Then
            If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, "系统用户管理") = vbYes Then
                '执行删除当前记录操作
                objAdmin.Delete
                '显示下一记录数据
                cmdMove(2).Value = True
            Else
                '显示当前记录数据
                txtName = objAdmin.Fields("用户名")
                txtPwd = objAdmin.Fields("口令")
                '显示当前记录编号和记录总数
                txtNews = "记录:" & objAdmin.AbsolutePosition & "/" & objAdmin.RecordCount
            End If
        End If
    End If
End Sub
Private Sub cmdSave_Click()
    Dim objCopy As New Recordset
    If Trim(txtName) = "" Then
        MsgBox "用户名不能为空!", vbCritical, "系统用户管理"
        txtName.SetFocus
        txtName = ""
    ElseIf Len(Trim(txtPwd)) <> 6 Then
        MsgBox "用户口令必须为6位字符串!", vbCritical, "系统用户管理"
        txtPwd.SetFocus
        txtPwd.SelStart = 0
        txtPwd.SelLength = Len(txtPwd)
    Else
        Set objCopy = objAdmin.Clone
        With objCopy
            If .RecordCount > 0 Then
                '检查用户名是否被使用
                .MoveFirst
                .Find "用户名='" & Trim(txtName) & "'"
                If (isAdding And Not .EOF) Or _
                    (Not isAdding And Not .EOF And _
                     .AbsolutePosition <> objAdmin.AbsolutePosition) Then
                    MsgBox "用户名:" & Trim(txtName) _
                    & "已被使用,请使用其他用户名!", _
                    vbCritical, "系统用户管理"
                    txtName.SetFocus
                    txtName.SelStart = 0
                    txtName.SelLength = Len(txtName)
                    Exit Sub
                Else
                    '保存或添加记录
                    If isAdding Then objAdmin.AddNew
                    objAdmin.Fields("用户名") = Trim(txtName)
                    objAdmin.Fields("口令") = Trim(txtPwd)
                    objAdmin.Update
                    MsgBox "数据保存成功!", vbInformation, "系统用户管理"
                    isAdding = False
                    '显示当前记录编号和记录总数
                    txtNews = "记录:" & objAdmin.AbsolutePosition & "/" & objAdmin.RecordCount
                End If
            Else
                '添加新记录
                If isAdding Then
                    objAdmin.AddNew
                    objAdmin.Fields("用户名") = Trim(txtName)
                    objAdmin.Fields("口令") = Trim(txtPwd)
                    objAdmin.Update
                    MsgBox "数据保存成功!", vbInformation, "系统用户管理"
                    isAdding = False
                    '显示当前记录编号和记录总数
                    txtNews = "记录:" & objAdmin.AbsolutePosition & "/" & objAdmin.RecordCount
                End If
            End If
        End With
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    objCn.Close                 '关闭数据联接
    Set objCn = Nothing         '释放数据库联接
    Set objAdmin = Nothing      '释放记录集对象
End Sub

'限制用户名输入
Private Sub txtName_KeyPress(KeyAscii As Integer)
    If Not (Chr(KeyAscii) Like "[0-9]" Or Chr(KeyAscii) Like "[a-z]" _
           Or Chr(KeyAscii) Like "[A-Z]" Or KeyAscii = vbKeyBack) Then
        KeyAscii = 0    '输入不是数字、英文字母或退格键,取消输入
    End If
End Sub
'限制口令输入
Private Sub txtPwd_KeyPress(KeyAscii As Integer)
    If Not (Chr(KeyAscii) Like "[0-9]" Or Chr(KeyAscii) Like "[a-z]" _
           Or Chr(KeyAscii) Like "[A-Z]" Or KeyAscii = vbKeyBack) Then
        KeyAscii = 0    '输入不是数字、英文字母或退格键,取消输入
    End If
End Sub

⌨️ 快捷键说明

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