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

📄 frmadd_class.frm

📁 用VB开发的一个学生管理系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Frmadmin_class 
   Caption         =   "班级管理"
   ClientHeight    =   3405
   ClientLeft      =   60
   ClientTop       =   420
   ClientWidth     =   6015
   LinkTopic       =   "Form1"
   ScaleHeight     =   3405
   ScaleWidth      =   6015
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cmd_del 
      Caption         =   "删除"
      Height          =   375
      Left            =   3000
      TabIndex        =   7
      Top             =   2400
      Width           =   975
   End
   Begin VB.CommandButton cmd_modify 
      Caption         =   "修改"
      Height          =   375
      Left            =   1680
      TabIndex        =   6
      Top             =   2400
      Width           =   855
   End
   Begin VB.CommandButton cmd_cancel 
      Caption         =   "返回"
      Height          =   375
      Left            =   4560
      TabIndex        =   2
      Top             =   2400
      Width           =   975
   End
   Begin VB.CommandButton cmd_add 
      Caption         =   "添加"
      Height          =   375
      Left            =   360
      TabIndex        =   1
      Top             =   2400
      Width           =   975
   End
   Begin VB.Frame Frame1 
      Caption         =   "班级基本信息"
      Height          =   1695
      Left            =   600
      TabIndex        =   0
      Top             =   360
      Width           =   4575
      Begin VB.ComboBox class_no 
         Height          =   300
         Left            =   1800
         TabIndex        =   8
         Top             =   480
         Width           =   1455
      End
      Begin VB.TextBox class_name 
         Height          =   375
         Left            =   1800
         TabIndex        =   5
         Top             =   1080
         Width           =   1455
      End
      Begin VB.Label Label2 
         Caption         =   "班级名称:"
         Height          =   255
         Left            =   600
         TabIndex        =   4
         Top             =   1080
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "班级编号:"
         Height          =   255
         Left            =   600
         TabIndex        =   3
         Top             =   480
         Width           =   975
      End
   End
End
Attribute VB_Name = "Frmadmin_class"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_cancel_Click()
Unload Me
End Sub
Private Sub cmd_add_Click()
Dim rs As ADODB.Recordset
Dim rstclass As ADODB.Recordset

If Trim(class_no.Text) = "" Or Trim(class_name.Text) = "" Then
MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If

 sqlStr = "select * from classes where classno ='" & class_no.Text & "'"
 Set rs = executesql(sqlStr, msgText)
 If rs.RecordCount = 0 Then
     sqlStr = "select * from classes"
     Set rstclass = executesql(sqlStr, msgText)
     rstclass.AddNew
     rstclass.Fields("classno") = Trim(class_no.Text)
     rstclass.Fields("className") = Trim(class_name.Text)
     rstclass.Update
     rstclass.Close
     rs.Close
     MsgBox "添加成绩信息成功", 48, "提示"
     initform
    
   Else
     MsgBox "您输入的成绩信息已存在!", vbOKOnly + vbExclamation, "警告"
     initform
     Exit Sub
 End If
End Sub

Sub initform()
class_no = ""
class_name = ""
End Sub
Sub initclassno()
Dim rstclass As ADODB.Recordset
sqlStr = "select classno from classes "
Set rstclass = executesql(sqlStr, msgText)
class_no.Clear
If Not rstclass.EOF Then
Do While Not rstclass.EOF
   class_no.AddItem Trim(rstclass.Fields(0))
   rstclass.MoveNext
Loop
class_no.ListIndex = 0
Else
MsgBox "请添加学生编号", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstclass.Close
End Sub
Private Sub class_no_click()
getclassname
End Sub
Sub getclassname()
Dim rs As ADODB.Recordset
sqlStr = "select className from classes where classno ='" & class_no.Text & "'"
Set rs = executesql(sqlStr, msgText)
If Not rs.EOF Then
class_name.Text = rs.Fields(0)
rs.Close
Else
MsgBox "你查找的信息不存在!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
End Sub
Private Sub Form_Load()
initclassno
initform
End Sub
Private Sub cmd_del_Click()
Dim conn As ADODB.Connection
sqlStr = "delete from classes where classno='" & class_no.Text & "'"
On Error GoTo exitsub
Set conn = New ADODB.Connection
conn.Open connStr
conn.Execute sqlStr
MsgBox "成功删除数据!"
exitsub:
conn.Close
initform
End Sub

Private Sub cmd_modify_Click()
Dim rs As ADODB.Recordset

sqlStr = "update classes set [ClassName]='" & class_name.Text & "'  where classno='" & class_no.Text & "'"

On Error GoTo exitsub
Set conn = New ADODB.Connection
conn.Open connStr
conn.Execute sqlStr
MsgBox "修改数据成功!"
exitsub:
conn.Close

initform
End Sub

⌨️ 快捷键说明

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