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

📄 studentmanage.frm

📁 用VB编写的简单的学生成绩管理系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      TabIndex        =   2
      Text            =   " "
      Top             =   1200
      Width           =   1935
   End
   Begin VB.TextBox txtSex 
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4320
      TabIndex        =   1
      Text            =   " "
      Top             =   480
      Width           =   1935
   End
   Begin VB.TextBox txtNum 
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1080
      TabIndex        =   0
      Text            =   " "
      Top             =   480
      Width           =   1935
   End
   Begin VB.Label Label5 
      Caption         =   "出生日期"
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   3240
      TabIndex        =   9
      Top             =   1200
      Width           =   975
   End
   Begin VB.Label Label4 
      Caption         =   "性别"
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   3240
      TabIndex        =   8
      Top             =   480
      Width           =   855
   End
   Begin VB.Label Label3 
      Caption         =   "班级"
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   7
      Top             =   1920
      Width           =   735
   End
   Begin VB.Label Label2 
      Caption         =   "姓名"
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   120
      TabIndex        =   6
      Top             =   1200
      Width           =   735
   End
   Begin VB.Label Label1 
      Caption         =   "学号"
      BeginProperty Font 
         Name            =   "微软雅黑"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   5
      Top             =   480
      Width           =   735
   End
End
Attribute VB_Name = "studentmanage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim isadding As Boolean     '定义操作状态,为真时才可修改数据库
Dim objStudent As Recordset     '用于保存学生名单数据表记录
Dim objCn As Connection     '用于建立数据库连接
Private Sub cmdAdd_Click()
    txtRecNo = "添加新记录"
    txtNum = ""
    txtName = ""
    txtSex = ""
    txtBirth = ""
    txtClass = ""
    txtNum.SetFocus
    isadding = True
End Sub
Private Sub cmdDelete_Click()
    If isadding Then
        isadding = False
        If objStudent.BOF = objStudent.EOF Then
            txtRecNo = "记录:无"
        Else
            ShowData
        End If
    Else
        If objStudent.RecordCount > 0 Then
            If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, "学生名单管理") = vbYes Then
                objStudent.Delete       '用Recordset的方法来删除数据
                cmdMove(2).Value = True     '显示下一记录数据
            Else
                ShowData        '显示当前记录数据
            End If
        End If
    End If
End Sub
Private Sub cmdExit_Click()
    Unload Me
End Sub
Private Sub cmdSave_Click()
    Dim objCopy As New Recordset
    Set objCopy = objStudent.Clone
    With objCopy
        If .RecordCount > 0 Then    '检查学号是否重复
            .MoveFirst
            .Find "学号='" & Trim(txtNum) & "'"
            If (isadding And Not .EOF) Or _
            (Not isadding And Not .EOF And .AbsolutePosition <> objStudent.AbsolutePosition) Then
            MsgBox "学号:" & Trim(txtNum) & "已被使用,请修改。", vbCritical, "学生名单管理"
            txtNum.SetFocus
            txtNum.SelStart = 0
            txtNum.SelLength = Len(txtNum)
            Else
                If isadding Then objStudent.AddNew      'Recordset的AddNew方法为记录集添加数据
                End If
        Else
            If isadding Then objStudent.AddNew
        End If
        objStudent.Fields("学号") = Trim(txtNum)    '使用Recordset对象时,Fields方法用来访问字段。
        objStudent.Fields("姓名") = Trim(txtName)   '使用字段名称的访问
        objStudent.Fields("性别") = Trim(txtSex)
        objStudent.Fields("出生日期") = Trim(txtBirth)
        objStudent.Fields("班级") = Trim(txtClass)
        objStudent.Update       'Update将对记录的修改保存到数据库
        MsgBox "数据保存成功", vbInformation, "学生名单管理"
        isadding = False
        txtRecNo = "当前记录:共" & objStudent.AbsolutePosition & "条/第" & objStudent.RecordCount & "条"
    End With
End Sub
Private Sub cmdSea_Click()
    studentmanage.Hide
    frmQStudent.Show
    frmQStudent.txtNum.SetFocus
End Sub
Private Sub Form_Load()
    Set objCn = New Connection      '实例化连接对象
    With objCn      '建立数据库连接
        .Provider = "SQLOLEDB"
        .ConnectionString = "User ID=db4;PWD=lsc;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).Value = True     '触发按钮单击事件
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
            txtRecNo = "记录:No"
            txtNum = ""
            txtName = ""
            txtSex = ""
            txtBirth = ""
            txtClass = ""
        Else
            ShowData
        End If
    End With
    If isadding Then isadding = False
End Sub
Private Sub ShowData()
    With objStudent
        txtNum = .Fields("学号")
        txtName = .Fields("姓名")
        txtSex = .Fields("性别")
        txtBirth = .Fields("出生日期")
        txtClass = .Fields("班级")
        txtRecNo = "当前记录:第" & .AbsolutePosition & "条/共" & .RecordCount & "条"
    End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
    objCn.Close     '关闭数据库连接
    Set objCn = Nothing     '释放数据库连接
    Set objStudent = Nothing       '释放记录集对象
End Sub

⌨️ 快捷键说明

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