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

📄 frmstudent.frm

📁 自测考试系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form student 
   Caption         =   "Form1"
   ClientHeight    =   2910
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4485
   LinkTopic       =   "Form1"
   ScaleHeight     =   2910
   ScaleWidth      =   4485
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   3
      Left            =   3360
      Picture         =   "frmstudent.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   15
      Top             =   1800
      Width           =   255
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   2
      Left            =   3120
      Picture         =   "frmstudent.frx":0482
      Style           =   1  'Graphical
      TabIndex        =   14
      Top             =   1800
      Width           =   255
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   1
      Left            =   960
      Picture         =   "frmstudent.frx":0948
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   1800
      Width           =   255
   End
   Begin VB.CommandButton cmdmove 
      Height          =   255
      Index           =   0
      Left            =   720
      Picture         =   "frmstudent.frx":0E0E
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   1800
      Width           =   255
   End
   Begin VB.PictureBox Picnavigation 
      BackColor       =   &H80000009&
      Height          =   300
      Left            =   1200
      ScaleHeight     =   240
      ScaleWidth      =   1875
      TabIndex        =   10
      Top             =   1800
      Width           =   1935
      Begin VB.TextBox txtnews 
         Height          =   300
         Left            =   0
         TabIndex        =   11
         Text            =   "Text4"
         Top             =   0
         Width           =   1935
      End
   End
   Begin VB.CommandButton cmdexit 
      Caption         =   "退出"
      Height          =   255
      Left            =   2880
      TabIndex        =   9
      Top             =   1440
      Width           =   700
   End
   Begin VB.CommandButton cmdsave 
      Caption         =   "保存"
      Height          =   255
      Left            =   2160
      TabIndex        =   8
      Top             =   1440
      Width           =   700
   End
   Begin VB.CommandButton cmddelete 
      Caption         =   "删除"
      Height          =   255
      Left            =   1440
      TabIndex        =   7
      Top             =   1440
      Width           =   700
   End
   Begin VB.CommandButton cmdadd 
      Caption         =   "添加"
      Height          =   255
      Left            =   720
      TabIndex        =   6
      Top             =   1440
      Width           =   700
   End
   Begin VB.TextBox txtName 
      Height          =   270
      Left            =   1170
      MaxLength       =   15
      TabIndex        =   2
      Top             =   255
      Width           =   2415
   End
   Begin VB.TextBox txtCode 
      Height          =   270
      Left            =   1170
      MaxLength       =   8
      TabIndex        =   1
      Top             =   975
      Width           =   2415
   End
   Begin VB.TextBox txtNum 
      Height          =   270
      Left            =   1170
      MaxLength       =   8
      TabIndex        =   0
      Top             =   615
      Width           =   2415
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "学号"
      Height          =   180
      Left            =   720
      TabIndex        =   5
      Top             =   660
      Width           =   360
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "姓名"
      Height          =   180
      Left            =   720
      TabIndex        =   4
      Top             =   300
      Width           =   360
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "考号"
      Height          =   180
      Left            =   720
      TabIndex        =   3
      Top             =   1020
      Width           =   360
   End
End
Attribute VB_Name = "student"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim isadding As Boolean
Dim objstudent As Recordset
Dim objCn As Connection

Private Sub cmdadd_Click()
txtnews = "添加新记录"
txtname = ""
txtNum = ""
txtCode = ""
isadding = True
txtname.SetFocus
End Sub

Private Sub cmddelete_Click()
'根据是否处于添加状态,执行不同的操作
If isadding Then
   isadding = False
   If objstudent.RecordCount <= 0 Then
      txtnews = "记录:无" '显示无记录提示
   Else
      '显示当前录数据
      txtname = objstudent.Fields("姓名")
      txtNum = objstudent.Fields("学号")
      txtCode = objstudent.Fields("考号")
            '显示当前记录编号和记录总数
      txtnews = "记录" & objstudent.AbsolutePosition & "/" & objstudent.RecordCount
  End If
Else
      If objstudent.RecordCount > 0 Then
      If MsgBox("是否删除记录?", vbYesNo + vbQuestion, "学生信息管理") = vbYes Then
      '执行删除当前记录操作
      objstudent.Delete
     '显示下一条记录
      cmdmove(2).Value = True
      Else
      '显示当前记录数据
      txtname = objstudent.Fields("姓名")
      txtNum = objstudent.Fields("学号")
      txtCode = objstudent.Fields("考号")
      '显示当前记录和记录总数
      txtnews = "记录" & objstudent.AbsolutePosition & "/" & objstudent.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 objstudent
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 = ""
txtNum = ""
txtCode = ""
Else
'显示当前记录数据
txtname = .Fields("姓名")
txtNum = .Fields("学号")
txtCode = .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(txtNum) = "" Then
        MsgBox "学号不能为空!", vbCritical, "学生信息管理"
        txtNum.SetFocus
        txtNum = ""
        ElseIf Trim(txtCode) = "" Then
        MsgBox "考号不能为空", vbCritical, "学生信息管理"
    Else
    Set objcopy = objstudent.Clone
    With objcopy
    If .RecordCount > 0 Then
        '检验用户是否已用
        .MoveFirst
        .Find "姓名='" & Trim(txtname) & "'"
        If (isadding And Not .EOF) Or (Not isadding And Not .EOF And .AbsolutePosition <> objstudent.AbsolutePosition) Then
        MsgBox "学生姓名:" & Trim(txtname) & "已被使用,请使用其他用户名!", vbCritical, "学生信息管理"
        txtname.SetFocus
        txtname.SelStart = 0
        txtname.SelLength = Len(txtname)
        Exit Sub
        Else
       '保存记录
        If isadding Then objstudent.AddNew
        objstudent.Fields("姓名") = Trim(txtname)
        objstudent.Fields("学号") = Trim(txtNum)
        objstudent.Fields("考号") = Trim(txtCode)
        objstudent.Update
        MsgBox "数据保存成功!", vbInformation, "学生信息管理"
        isadding = False
        '显示记录编号和记录总数
        txtnews = "记录:" & objstudent.AbsolutePosition & "/" & objstudent.RecordCount
        End If
        '添加新记录
    Else
        If isadding Then
    objstudent.AddNew
    objstudent.Fields("姓名") = Trim(txtname)
    objstudent.Fields("学号") = Trim(txtNum)
    objstudent.Fields("考号") = Trim(txtCode)
    objstudent.Update
    MsgBox "数据保存成功!", vbInformation, "阅卷教师信息管理"
    txtnews = "记录:" & objstudent.AbsolutePosition & "/" & objstudent.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 objstudent = New Recordset
With objstudent
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 objstudent = Nothing
End Sub


'Private Sub txtname_KeyPress(KeyAscii As Integer)
'如果敲击回车键则是口令输入框获得焦点
'If KeyAscii = vbKeyReturn Then txtnum.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 txtnum_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 txtcode_KeyPress(KeyAscii As Integer)
'如果敲击回车键则是联系电话输入框获得焦点
If KeyAscii = vbKeyReturn Then txtCode.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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -