frmteacher.frm

来自「自测考试系统」· FRM 代码 · 共 404 行

FRM
404
字号
VERSION 5.00
Begin VB.Form frmteacher 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "教师信息管理"
   ClientHeight    =   3375
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5295
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3375
   ScaleWidth      =   5295
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdadd 
      Caption         =   "添加"
      Height          =   375
      Left            =   960
      TabIndex        =   15
      Top             =   1920
      Width           =   855
   End
   Begin VB.CommandButton cmddelete 
      Caption         =   "删除"
      Height          =   375
      Left            =   1800
      TabIndex        =   14
      Top             =   1920
      Width           =   855
   End
   Begin VB.CommandButton cmdsave 
      Caption         =   "保存"
      Height          =   375
      Left            =   2640
      TabIndex        =   13
      Top             =   1920
      Width           =   855
   End
   Begin VB.CommandButton cmdexit 
      Caption         =   "退出"
      Height          =   375
      Left            =   3480
      TabIndex        =   12
      Top             =   1920
      Width           =   855
   End
   Begin VB.PictureBox Picnavigation 
      BackColor       =   &H80000009&
      Height          =   255
      Left            =   1440
      ScaleHeight     =   195
      ScaleWidth      =   2355
      TabIndex        =   10
      Top             =   2520
      Width           =   2415
      Begin VB.TextBox txtnews 
         Height          =   270
         Left            =   0
         TabIndex        =   11
         Text            =   "Text4"
         Top             =   0
         Width           =   3135
      End
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   0
      Left            =   960
      Picture         =   "frmteacher.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   2520
      Width           =   255
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   1
      Left            =   1200
      Picture         =   "frmteacher.frx":0482
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   2520
      Width           =   255
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   2
      Left            =   3840
      Picture         =   "frmteacher.frx":0948
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   2520
      Width           =   255
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   3
      Left            =   4080
      Picture         =   "frmteacher.frx":0E0E
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   2520
      Width           =   255
   End
   Begin VB.TextBox txtphone 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   5
      Text            =   "Text3"
      Top             =   1320
      Width           =   2415
   End
   Begin VB.TextBox txtpwd 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   4
      Text            =   "Text2"
      Top             =   840
      Width           =   2415
   End
   Begin VB.TextBox txtname 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   1920
      TabIndex        =   3
      Text            =   "Text1"
      Top             =   360
      Width           =   2415
   End
   Begin VB.Label Label3 
      Caption         =   "联系电话"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   960
      TabIndex        =   2
      Top             =   1440
      Width           =   855
   End
   Begin VB.Label Label2 
      Caption         =   "登陆口令"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   960
      TabIndex        =   1
      Top             =   960
      Width           =   855
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      Caption         =   "教师姓名"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   960
      TabIndex        =   0
      Top             =   360
      Width           =   855
   End
End
Attribute VB_Name = "frmteacher"
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 cmdadd_Click()
txtnews = "添加新记录"
txtname = ""
txtpwd = ""
txtphone = ""
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("电话")
            '显示当前记录编号和记录总数
      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("电话")
      '显示当前记录和记录总数
      txtnews = "记录" & objTeacher.AbsolutePosition & "/" & objTeacher.RecordCount
      End If
    End If
End If
End Sub

Private Sub cmdexit_Click()
Unload Me
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 = ""
Else
'显示当前记录数据
txtname = .Fields("姓名")
txtpwd = .Fields("口令")
txtphone = .Fields("电话")
'显示当前记录数和记录总数
txtnews = "记录" & .AbsolutePosition & "/" & .RecordCount
End If
End With
If isadding Then isadding = False
End Sub

Private Sub cmdsave_Click()
Dim objcopy As New Recordset
     If Trim(txtname) = "" Then
        MsgBox "教师姓名不能为空!", vbCritical, "阅卷教师信息管理"
        txtname.SetFocus
        txtname = ""
        ElseIf Trim(txtpwd) = "" Then
        MsgBox "登陆口令不能为空!", vbCritical, "阅卷教师信息管理"
        txtpwd.SetFocus
        txtpwd = ""
    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 "教师姓名:" & Trim(txtname) & "已被使用,请使用其他用户名!", vbCritical, "阅卷教师信息管理"
        txtname.SetFocus
        txtname.SelStart = 0
        txtname.SelLength = Len(txtname)
        Exit Sub
        Else
       '保存记录
        If isadding Then objTeacher.AddNew
        objTeacher.Fields("姓名") = Trim(txtname)
        objTeacher.Fields("口令") = Trim(txtpwd)
        objTeacher.Fields("电话") = Trim(txtphone)
        objTeacher.Update
        MsgBox "数据保存成功!", vbInformation, "阅卷教师信息管理"
        isadding = False
        '显示记录编号和记录总数
        txtnews = "记录:" & objTeacher.AbsolutePosition & "/" & objTeacher.RecordCount
        End If
        '添加新记录
    Else
        If isadding Then
    objTeacher.AddNew
    objTeacher.Fields("姓名") = Trim(txtname)
    objTeacher.Fields("口令") = Trim(txtpwd)
    objTeacher.Fields("电话") = Trim(txtphone)
    objTeacher.Update
    MsgBox "数据保存成功!", vbInformation, "阅卷教师信息管理"
    txtnews = "记录:" & objTeacher.AbsolutePosition & "/" & objTeacher.RecordCount
    End If
End If
End With
End If
End Sub

Private Sub Form_Load()
'建立数据库连接
Set objCn = New Connection '定义并实例化连接对象
With objCn '建立连接
           .Provider = "SQLOLEDB"
           .ConnectionString = "user id=sa;data source=(local);" & _
           "initial catalog=自测考试"
           .Open
End With
'获取教师信息记录
Set objTeacher = New Recordset
With objTeacher
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "select * from 阅卷教师"
End With
cmdmove(0) = True
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 txtpwd.SetFocus
'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 KeyAscii = vbKeyReturn Then cmdsave.SetFocus
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 txtphone_KeyPress(KeyAscii As Integer)
'如果敲击回车键则是联系电话输入框获得焦点
If KeyAscii = vbKeyReturn Then txtphone.SetFocus
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 + =
减小字号Ctrl + -
显示快捷键?