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


VERSION 5.00 
Begin VB.Form Teacher  
   BorderStyle     =   1  'Fixed Single 
   Caption         =   "阅卷教师信息管理" 
   ClientHeight    =   2625 
   ClientLeft      =   45 
   ClientTop       =   330 
   ClientWidth     =   4830 
   LinkTopic       =   "Form1" 
   MaxButton       =   0   'False 
   MDIChild        =   -1  'True 
   MinButton       =   0   'False 
   ScaleHeight     =   2625 
   ScaleWidth      =   4830 
   Begin VB.TextBox txtSum  
      Height          =   270 
      Left            =   1770 
      MaxLength       =   3 
      TabIndex        =   3 
      Top             =   1335 
      Width           =   2175 
   End 
   Begin VB.TextBox txtPhone  
      Height          =   270 
      Left            =   1748 
      MaxLength       =   11 
      TabIndex        =   2 
      Top             =   1020 
      Width           =   2175 
   End 
   Begin VB.TextBox txtName  
      Height          =   270 
      Left            =   1748 
      MaxLength       =   10 
      TabIndex        =   0 
      Top             =   345 
      Width           =   2175 
   End 
   Begin VB.CommandButton cmdSave  
      Caption         =   "保存" 
      Height          =   300 
      Left            =   2400 
      TabIndex        =   6 
      Top             =   1845 
      Width           =   735 
   End 
   Begin VB.CommandButton cmdExit  
      Cancel          =   -1  'True 
      Caption         =   "退出" 
      Height          =   300 
      Left            =   3135 
      TabIndex        =   7 
      Top             =   1845 
      Width           =   735 
   End 
   Begin VB.CommandButton cmdDelete  
      Caption         =   "删除" 
      Height          =   300 
      Left            =   1680 
      TabIndex        =   5 
      Top             =   1845 
      Width           =   735 
   End 
   Begin VB.CommandButton cmdAdd  
      Caption         =   "添加" 
      Height          =   300 
      Left            =   960 
      TabIndex        =   4 
      Top             =   1845 
      Width           =   735 
   End 
   Begin VB.TextBox txtPwd  
      Height          =   270 
      Left            =   1740 
      MaxLength       =   6 
      TabIndex        =   1 
      Top             =   675 
      Width           =   2175 
   End 
   Begin VB.PictureBox picNavigation  
      AutoSize        =   -1  'True 
      BorderStyle     =   0  'None 
      Height          =   350 
      Left            =   1260 
      ScaleHeight     =   345 
      ScaleWidth      =   2415 
      TabIndex        =   12 
      Top             =   2145 
      Width           =   2410 
      Begin VB.CommandButton cmdMove  
         Height          =   270 
         Index           =   1 
         Left            =   270 
         Picture         =   "frmTeacher.frx":0000 
         Style           =   1  'Graphical 
         TabIndex        =   9 
         Top             =   0 
         Width           =   300 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   270 
         Index           =   0 
         Left            =   -15 
         Picture         =   "frmTeacher.frx":0044 
         Style           =   1  'Graphical 
         TabIndex        =   8 
         Top             =   0 
         Width           =   300 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   270 
         Index           =   3 
         Left            =   2010 
         Picture         =   "frmTeacher.frx":0091 
         Style           =   1  'Graphical 
         TabIndex        =   11 
         Top             =   0 
         Width           =   300 
      End 
      Begin VB.CommandButton cmdMove  
         Height          =   270 
         Index           =   2 
         Left            =   1725 
         Picture         =   "frmTeacher.frx":00DD 
         Style           =   1  'Graphical 
         TabIndex        =   10 
         Top             =   -15 
         Width           =   300 
      End 
      Begin VB.TextBox txtNews  
         Height          =   270 
         Left            =   555 
         Locked          =   -1  'True 
         TabIndex        =   13 
         TabStop         =   0   'False 
         Top             =   0 
         Width           =   1185 
      End 
   End 
   Begin VB.Label Label4  
      AutoSize        =   -1  'True 
      Caption         =   "阅卷数量" 
      Height          =   180 
      Left            =   915 
      TabIndex        =   17 
      Top             =   1395 
      Width           =   720 
   End 
   Begin VB.Label Label3  
      AutoSize        =   -1  'True 
      Caption         =   "联系电话" 
      Height          =   180 
      Left            =   915 
      TabIndex        =   16 
      Top             =   1050 
      Width           =   720 
   End 
   Begin VB.Label Label1  
      AutoSize        =   -1  'True 
      Caption         =   "教师姓名" 
      Height          =   180 
      Left            =   915 
      TabIndex        =   15 
      Top             =   405 
      Width           =   720 
   End 
   Begin VB.Label Label2  
      AutoSize        =   -1  'True 
      Caption         =   "登录口令" 
      Height          =   180 
      Left            =   915 
      TabIndex        =   14 
      Top             =   735 
      Width           =   720 
   End 
End 
Attribute VB_Name = "Teacher" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
Option Explicit 
Dim isAdding As Boolean             '定义操作状态标志 
Dim objTeacher 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 objTeacher = New Recordset                 '实例化objTeacher对象 
    With objTeacher 
        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 objTeacher 
        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 = "" 
            txtPhone = "":   txtSum = "" 
        Else 
            '显示当前记录数据 
            txtName = .Fields("姓名"): txtPwd = .Fields("口令") 
            txtPhone = .Fields("电话"): txtSum = .Fields("数量") 
            '显示当前记录编号和记录总数 
            txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount 
        End If 
    End With 
    If isAdding Then isAdding = False 
End Sub 
 
Private Sub cmdAdd_Click() 
    txtNews = "添加新记录" 
    txtName = "": txtPwd = "" 
    txtPhone = "": txtSum = 100 
    isAdding = True 
    txtName.SetFocus 
End Sub 
 
Private Sub cmdDelete_Click() 
    '根据是否处于添加记录状态执行不同的操作 
    If isAdding Then 
        '退出添加记录状态,显示当前记录 
        isAdding = False 
        If objTeacher.RecordCount <= 0 Then 
            txtNews = "记录:无"    '显示无记录提示 
        Else 
            '显示当前记录数据 
            txtName = objTeacher.Fields("姓名"): txtPwd = objTeacher.Fields("口令") 
            txtPhone = objTeacher.Fields("电话"): txtSum = objTeacher.Fields("数量") 
            '显示当前记录编号和记录总数 
            txtNews = "记录:" & objTeacher.AbsolutePosition & "/" & objTeacher.RecordCount 
        End If 
    Else 
        If objTeacher.RecordCount > 0 Then 
            If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, "阅卷教师管理") = vbYes Then 
                objTeacher.Delete               '执行删除当前记录操作 
                cmdMove(2).Value = True         '显示下一记录数据 
            Else 
                '显示当前记录数据 
                txtName = objTeacher.Fields("姓名"): txtPwd = objTeacher.Fields("口令") 
                txtPhone = objTeacher.Fields("电话"): txtSum = objTeacher.Fields("数量") 
                '显示当前记录编号和记录总数 
                txtNews = "记录:" & objTeacher.AbsolutePosition & "/" & objTeacher.RecordCount 
            End If 
        End If 
    End If 
End Sub 
Private Sub cmdSave_Click() 
    Dim objCopy As New Recordset 
    '在当前表中无数据和不是添加记录时,不执行保存操作 
    If Not isAdding And objTeacher.RecordCount < 1 Then Exit Sub 
    If Trim(txtName) = "" Then 
        MsgBox "教师姓名不能为空!", vbCritical, "阅卷教师管理" 
        txtName.SetFocus 
        txtName = "" 
    ElseIf Trim(txtPwd) = "" Then 
        MsgBox "系统登录口令不能为空!", vbCritical, "阅卷教师管理" 
        txtPwd.SetFocus 
        txtPwd = "" 
     ElseIf Trim(txtPhone) = "" Then 
        MsgBox "联系电话不能为空!", vbCritical, "阅卷教师管理" 
        txtPhone.SetFocus 
        txtPhone = "" 
    ElseIf Val(txtSum) = 0 Then 
        MsgBox "请输入有效的阅卷数量!", vbCritical, "阅卷教师管理" 
        txtSum.SetFocus 
    Else 
        Set objCopy = objTeacher.Clone 
        With objCopy 
            If .RecordCount > 0 Then 
                '检查阅卷教师姓名是否重复 
                .MoveFirst 
                .Find "姓名='" & Trim(txtName) & "'" 
                If (isAdding And Not .EOF) Or _ 
                    (Not isAdding And Not .EOF And _ 
                     .AbsolutePosition <> objTeacher.AbsolutePosition) Then 
                    MsgBox "姓名重复,请修改!", vbCritical, "阅卷教师管理" 
                    txtName.SetFocus 
                    txtName.SelStart = 0 
                    txtName.SelLength = Len(txtName) 
                    Exit Sub 
                End If 
                If isAdding Then objTeacher.AddNew 
            Else 
                If isAdding Then objTeacher.AddNew      '添加新记录 
            End If 
            objTeacher.Fields("姓名") = Trim(txtName) 
            objTeacher.Fields("口令") = Trim(txtPwd) 
            objTeacher.Fields("电话") = Trim(txtPhone) 
            objTeacher.Fields("数量") = Trim(txtSum) 
            objTeacher.Update 
            MsgBox "数据保存成功!", vbInformation, "阅卷教师管理" 
            isAdding = False 
            '显示当前记录编号和记录总数 
            txtNews = "记录:" & objTeacher.AbsolutePosition & "/" & objTeacher.RecordCount 
        End With 
    End If 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    objCn.Close                 '关闭数据联接 
    Set objCn = Nothing         '释放数据库联接 
    Set objTeacher = Nothing      '释放记录集对象 
End Sub 
 
Private Sub txtName_KeyPress(KeyAscii As Integer) 
    '如果敲回车键,使下一控件获得焦点 
    If KeyAscii = vbKeyReturn Then SendKeys "{TAB}" 
End Sub 
 
'限制联系电话输入 
Private Sub txtPhone_KeyPress(KeyAscii As Integer) 
    '如果敲回车键,使下一控件获得焦点 
    If KeyAscii = vbKeyReturn Then SendKeys "{TAB}" 
    If Not (Chr(KeyAscii) Like "[0-9]" Or KeyAscii = vbKeyBack) Then 
        KeyAscii = 0    '输入不是数字或退格键,取消输入 
    End If 
End Sub 
'限制口令输入 
Private Sub txtPwd_KeyPress(KeyAscii As Integer) 
    '如果敲回车键,使下一控件获得焦点 
    If KeyAscii = vbKeyReturn Then SendKeys "{TAB}" 
    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 txtSum_KeyPress(KeyAscii As Integer) 
    '如果敲回车键,使保存按钮获得焦点 
    If KeyAscii = vbKeyReturn Then cmdSave.SetFocus 
End Sub