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

📄 frmprofill.frm

📁 上机考试系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form ProgramFilling 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "程序填空题题库管理"
   ClientHeight    =   6150
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11025
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6150
   ScaleWidth      =   11025
   Begin VB.Frame Frame1 
      Caption         =   "参考答案"
      Height          =   1785
      Left            =   6060
      TabIndex        =   20
      Top             =   330
      Width           =   4470
      Begin VB.TextBox txtA 
         Height          =   270
         Left            =   690
         MaxLength       =   50
         TabIndex        =   1
         Top             =   270
         Width           =   3375
      End
      Begin VB.TextBox txtB 
         Height          =   270
         Left            =   690
         MaxLength       =   50
         TabIndex        =   2
         Top             =   645
         Width           =   3375
      End
      Begin VB.TextBox txtC 
         Height          =   270
         Left            =   690
         MaxLength       =   50
         TabIndex        =   3
         Top             =   990
         Width           =   3375
      End
      Begin VB.TextBox txtD 
         Height          =   270
         Left            =   690
         MaxLength       =   50
         TabIndex        =   4
         Top             =   1350
         Width           =   3375
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "空1"
         Height          =   180
         Left            =   345
         TabIndex        =   24
         Top             =   315
         Width           =   270
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         Caption         =   "空3"
         Height          =   180
         Left            =   360
         TabIndex        =   23
         Top             =   1020
         Width           =   270
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "空2"
         Height          =   180
         Left            =   345
         TabIndex        =   22
         Top             =   675
         Width           =   270
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         Caption         =   "空4"
         Height          =   180
         Left            =   360
         TabIndex        =   21
         Top             =   1395
         Width           =   270
      End
   End
   Begin VB.TextBox txtPoint 
      Height          =   270
      Left            =   6930
      MaxLength       =   1
      TabIndex        =   5
      Text            =   "2"
      Top             =   2250
      Width           =   630
   End
   Begin VB.TextBox txtParse 
      Height          =   2160
      Left            =   6060
      MaxLength       =   300
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   6
      Top             =   2910
      Width           =   4470
   End
   Begin VB.TextBox txtQuestion 
      Height          =   4545
      Left            =   495
      MaxLength       =   800
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   0
      Top             =   525
      Width           =   5055
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "保存"
      Height          =   300
      Left            =   5460
      TabIndex        =   9
      Top             =   5400
      Width           =   735
   End
   Begin VB.CommandButton cmdExit 
      Cancel          =   -1  'True
      Caption         =   "退出"
      Height          =   300
      Left            =   6210
      TabIndex        =   10
      Top             =   5400
      Width           =   735
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "删除"
      Height          =   300
      Left            =   4710
      TabIndex        =   8
      Top             =   5400
      Width           =   735
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "添加"
      Height          =   300
      Left            =   3975
      TabIndex        =   7
      Top             =   5400
      Width           =   735
   End
   Begin VB.PictureBox picNavigation 
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   350
      Left            =   4380
      ScaleHeight     =   345
      ScaleWidth      =   2415
      TabIndex        =   15
      Top             =   5715
      Width           =   2410
      Begin VB.CommandButton cmdMove 
         Height          =   270
         Index           =   1
         Left            =   270
         Picture         =   "frmProFill.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   12
         Top             =   0
         Width           =   300
      End
      Begin VB.CommandButton cmdMove 
         Height          =   270
         Index           =   0
         Left            =   -15
         Picture         =   "frmProFill.frx":0044
         Style           =   1  'Graphical
         TabIndex        =   11
         Top             =   0
         Width           =   300
      End
      Begin VB.CommandButton cmdMove 
         Height          =   270
         Index           =   3
         Left            =   2010
         Picture         =   "frmProFill.frx":0091
         Style           =   1  'Graphical
         TabIndex        =   14
         Top             =   -15
         Width           =   300
      End
      Begin VB.CommandButton cmdMove 
         Height          =   270
         Index           =   2
         Left            =   1725
         Picture         =   "frmProFill.frx":00DD
         Style           =   1  'Graphical
         TabIndex        =   13
         Top             =   -15
         Width           =   300
      End
      Begin VB.TextBox txtNews 
         Height          =   270
         Left            =   555
         Locked          =   -1  'True
         TabIndex        =   16
         TabStop         =   0   'False
         Top             =   0
         Width           =   1185
      End
   End
   Begin VB.Label Label8 
      AutoSize        =   -1  'True
      Caption         =   "试题解析"
      Height          =   180
      Left            =   6060
      TabIndex        =   19
      Top             =   2640
      Width           =   720
   End
   Begin VB.Label Label7 
      AutoSize        =   -1  'True
      Caption         =   "参考分数"
      Height          =   180
      Left            =   6060
      TabIndex        =   18
      Top             =   2295
      Width           =   720
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "题干内容"
      Height          =   180
      Left            =   540
      TabIndex        =   17
      Top             =   330
      Width           =   720
   End
End
Attribute VB_Name = "ProgramFilling"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim isAdding As Boolean             '定义操作状态标志
Dim objBlank 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 objBlank = New Recordset                 '实例化objBlank对象
    With objBlank
        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 objBlank
        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
        Show_Data
    End With
    If isAdding Then isAdding = False
End Sub

Private Sub cmdAdd_Click()
    txtNews = "添加新记录"
    txtQuestion = ""
    txtA = "": txtB = "": txtC = ""
    txtD = "": txtPoint = "2": txtParse = ""
    isAdding = True
    txtQuestion.SetFocus
End Sub

Private Sub cmdDelete_Click()
    '根据是否处于添加记录状态执行不同的操作
    If isAdding Then
        '退出添加记录状态,显示当前记录
        isAdding = False
        If objBlank.RecordCount <= 0 Then
            txtNews = "记录:无"    '显示无记录提示
        Else
            Show_Data                   '显示当前记录数据
        End If
    Else
        If objBlank.RecordCount > 0 Then
            If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, _
                       "程序填空题管理") = vbYes Then
                objBlank.Delete                 '执行删除当前记录操作
                cmdMove(2).Value = True         '显示下一记录数据
            Else
                Show_Data                       '显示当前记录数据
            End If
        End If
    End If
End Sub
Private Sub cmdSave_Click()
    Dim objCopy As New Recordset
    '在当前表中无数据和不是添加记录时,不执行保存操作
    If Not isAdding And objBlank.RecordCount < 1 Then Exit Sub
    If Trim(txtQuestion) = "" Then
        MsgBox "题干不能为空!", vbCritical, "程序填空题管理"
        txtQuestion.SetFocus
        txtQuestion = ""
    ElseIf Trim(txtA) = "" Then
        MsgBox "请输入空1参考答案!", vbCritical, "程序填空题管理"
        txtA.SetFocus
        txtA = ""
    ElseIf Trim(txtB) = "" Then
        MsgBox "请输入空2参考答案!", vbCritical, "程序填空题管理"
        txtB.SetFocus
        txtB = ""
    ElseIf Not txtPoint Like "[1-9]" Then
        MsgBox "请输入有效的分数!", vbCritical, "程序填空题管理"
        txtPoint.SetFocus
        txtPoint.SelStart = 0
        txtPoint.SelLength = Len(txtPoint)
    Else
        Set objCopy = objBlank.Clone
        With objCopy
            If .RecordCount > 0 Then
                '检查题干是否重复
                .MoveFirst
                .Find "题干='" & Trim(txtQuestion) & "'"
                If (isAdding And Not .EOF) Or _
                    (Not isAdding And Not .EOF And _
                     .AbsolutePosition <> objBlank.AbsolutePosition) Then
                    MsgBox "试题重复,请修改!", vbCritical, "程序填空题管理"
                    txtQuestion.SetFocus
                    txtQuestion.SelStart = 0
                    txtQuestion.SelLength = Len(txtQuestion)
                    Exit Sub
                End If
            End If
            If isAdding Then objBlank.AddNew        '添加新记录
            objBlank.Fields("题干") = Trim(txtQuestion)
            objBlank.Fields("空a") = Trim(txtA)
            objBlank.Fields("空b") = Trim(txtB)
            objBlank.Fields("空c") = Trim(txtC)
            objBlank.Fields("空d") = Trim(txtD)
            objBlank.Fields("分数") = Trim(txtPoint)
            objBlank.Fields("解析") = Trim(txtParse)
            objBlank.Update
            MsgBox "数据保存成功!", vbInformation, "程序填空题管理"
            isAdding = False
            '显示当前记录编号和记录总数
            txtNews = "记录:" & objBlank.AbsolutePosition & "/" & objBlank.RecordCount
        End With
    End If
End Sub

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

'限制分数输入
Private Sub txtPoint_KeyPress(KeyAscii As Integer)
    If Not (Chr(KeyAscii) Like "[1-9]" Or KeyAscii = vbKeyBack) Then
        KeyAscii = 0    '输入不是数字或退格键,取消输入
    End If
End Sub

Private Sub Show_Data()
    Dim i%
    With objBlank
        If .RecordCount < 1 Then
            txtNews = "记录:无"    '显示无记录提示
            '清除显示数据
            txtQuestion = "": txtPoint = "": txtParse = ""
            txtA = "": txtB = "": txtC = "": txtD = ""
        Else
            '显示当前记录数据
            txtQuestion = .Fields("题干"): txtPoint = .Fields("分数")
            txtParse = .Fields("解析"): txtA = .Fields("空a")
            txtB = .Fields("空b"): txtC = .Fields("空c"): txtD = .Fields("空d")
            '显示当前记录编号和记录总数
            txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
        End If
    End With
End Sub

⌨️ 快捷键说明

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