www.pudn.com > cjg2.rar > frmOldTests.frm


VERSION 5.00 
Begin VB.Form OldTests  
   BorderStyle     =   1  'Fixed Single 
   Caption         =   "历届试题管理" 
   ClientHeight    =   1905 
   ClientLeft      =   45 
   ClientTop       =   330 
   ClientWidth     =   4455 
   LinkTopic       =   "Form1" 
   MaxButton       =   0   'False 
   MDIChild        =   -1  'True 
   MinButton       =   0   'False 
   ScaleHeight     =   1905 
   ScaleWidth      =   4455 
   Begin VB.TextBox txtNum  
      Height          =   270 
      Left            =   1635 
      Locked          =   -1  'True 
      MaxLength       =   8 
      TabIndex        =   9 
      Top             =   195 
      Width           =   1995 
   End 
   Begin VB.TextBox txtName  
      Height          =   270 
      Left            =   1620 
      Locked          =   -1  'True 
      MaxLength       =   20 
      TabIndex        =   8 
      Top             =   607 
      Width           =   1995 
   End 
   Begin VB.PictureBox picNavigation  
      AutoSize        =   -1  'True 
      BorderStyle     =   0  'None 
      Height          =   360 
      Left            =   885 
      ScaleHeight     =   360 
      ScaleWidth      =   2685 
      TabIndex        =   6 
      Top             =   1312 
      Width           =   2685 
      Begin VB.TextBox txtNews  
         Height          =   300 
         Left            =   690 
         Locked          =   -1  'True 
         TabIndex        =   7 
         TabStop         =   0   'False 
         Top             =   15 
         Width           =   1275 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   300 
         Index           =   2 
         Left            =   1950 
         Picture         =   "frmOldTests.frx":0000 
         Style           =   1  'Graphical 
         TabIndex        =   4 
         Top             =   15 
         Width           =   345 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   300 
         Index           =   3 
         Left            =   2280 
         Picture         =   "frmOldTests.frx":0044 
         Style           =   1  'Graphical 
         TabIndex        =   5 
         Top             =   15 
         Width           =   345 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   300 
         Index           =   0 
         Left            =   30 
         Picture         =   "frmOldTests.frx":0093 
         Style           =   1  'Graphical 
         TabIndex        =   2 
         Top             =   15 
         Width           =   345 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   300 
         Index           =   1 
         Left            =   360 
         Picture         =   "frmOldTests.frx":00E0 
         Style           =   1  'Graphical 
         TabIndex        =   3 
         Top             =   15 
         Width           =   345 
      End 
   End 
   Begin VB.CommandButton cmdDelete  
      Caption         =   "删除" 
      Height          =   300 
      Left            =   1440 
      TabIndex        =   0 
      Top             =   997 
      Width           =   735 
   End 
   Begin VB.CommandButton cmdExit  
      Cancel          =   -1  'True 
      Caption         =   "退出" 
      Height          =   315 
      Left            =   2280 
      TabIndex        =   1 
      Top             =   990 
      Width           =   735 
   End 
   Begin VB.Label Label1  
      AutoSize        =   -1  'True 
      Caption         =   "试题编号" 
      Height          =   180 
      Left            =   825 
      TabIndex        =   11 
      Top             =   240 
      Width           =   720 
   End 
   Begin VB.Label Label2  
      AutoSize        =   -1  'True 
      Caption         =   "试题名称" 
      Height          =   180 
      Left            =   825 
      TabIndex        =   10 
      Top             =   652 
      Width           =   720 
   End 
End 
Attribute VB_Name = "OldTests" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Option Explicit 
Dim objOldTests 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 objOldTests = New Recordset               '实例化objOldTests对象 
    With objOldTests 
        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 objOldTests 
        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 = "记录:无"    '显示无记录提示 
            txtNum = "" 
            txtName = "" 
        Else 
            '显示当前记录数据 
            txtNum = .Fields("编号") 
            txtName = .Fields("表名") 
            '显示当前记录编号和记录总数 
            txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount 
        End If 
    End With 
End Sub 
 
 
Private Sub cmdDelete_Click() 
    Dim strSQL$ 
    '请求确认执行删除操作 
    If objOldTests.RecordCount > 0 Then 
    If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, "历届试题管理") = vbYes Then 
        '执行删除当前记录操作 
        strSQL = "DROP TABLE " & objOldTests.Fields("表名") 
        objOldTests.Delete 
        objCn.Execute strSQL 
        '显示下一记录数据 
        cmdMove(2).Value = True 
    End If 
    End If 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    objCn.Close                 '关闭数据联接 
    Set objCn = Nothing         '释放数据库联接 
    Set objOldTests = Nothing     '释放记录集对象 
End Sub