📄 test成绩录入.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim SQL As String
Dim msg As String
Dim rs As ADODB.Recordset
Private Sub Form_Load()
'首先需要初始化学院ComboBox、系ComboBox、班级ComboBox和班级课程ComboBox
Dim rst As ADODB.Recordset
Dim strItem As String
'初始化学院ComboBox
SQL = "select 院代码,院名称 from 院信息表 order by 院代码"
Set rst = SelectSQL(SQL, msg)
If rst.RecordCount > 0 Then '如果存在学院信息
Do While Not rst.EOF
strItem = rst.Fields(0) & " " & rst.Fields(1)
CboQuery(0).AddItem (strItem)
rst.MoveNext
Loop
rst.Close
CboQuery(0).ListIndex = 0
Else '如果不存在学院信息
MsgBox ("请先创建院信息!") '如果没有院信息不能使用
CboQuery(0).Enabled = False
CboQuery(1).Enabled = False
CboQuery(2).Enabled = False
Exit Sub
End If
Call SelectData(0) '得到系列表
If CboQuery(1).ListCount > 0 Then
Call SelectData(1) '得到班级列表
End If
End Sub
Private Sub SelectData(Index As Integer)
'初始化系ComboBox、班级ComboBox
Dim rst As ADODB.Recordset
Dim strItem As String
If Index = 0 Then '如果是选择院,初始化系ComboBox
SQL = " select 系代码,系名称 from 系信息表 where 院代码='"
SQL = SQL & Left(Trim(CboQuery(0).Text), 2) & "' order by 系代码"
Set rst = SelectSQL(SQL, msg)
CboQuery(1).Clear
If rst.RecordCount > 0 Then '如果存在系信息,初始化系ComboBox
Do While Not rst.EOF
strItem = rst.Fields(0) & " " & rst.Fields(1)
CboQuery(1).AddItem (strItem)
rst.MoveNext
Loop
rst.Close
CboQuery(1).ListIndex = 0
Else '如果不存在系信息,退出过程
Exit Sub
End If
ElseIf Index = 1 Then '如果是选择系,初始化班级ComboBox
SQL = " select 班号,班级名称 from 班级信息表 where 系代码='"
SQL = SQL & Left(Trim(CboQuery(1).Text), 4) & "' order by 班号"
Set rst = SelectSQL(SQL, msg)
CboQuery(2).Clear
If rst.RecordCount > 0 Then '如果存在班级信息,初始化班级ComboBox
Do While Not rst.EOF
strItem = rst.Fields(0) & " " & rst.Fields(1)
CboQuery(2).AddItem (strItem)
rst.MoveNext
Loop
rst.Close
CboQuery(2).ListIndex = 0
Call FixData '在ComboBox中载入课程列表
Else '如果不存在班级信息,退出过程
Exit Sub
End If
End If
End Sub
Private Sub FixData()
'在ComboBox中载入班级课程列表
Dim rst As ADODB.Recordset
Dim strItem As String
'得到班级课程信息
SQL = "select 课程号,课程名称 from 课程信息表 where 课程号 in("
SQL = SQL & "select 课程号 from 课程分配信息表 where 班号='"
SQL = SQL & Left(Trim(CboQuery(2).Text), 6) & "') order by 课程号"
Set rst = SelectSQL(SQL, msg)
CboQuery(3).Clear
If rst.RecordCount > 0 Then '如果存在班级课程信息,初始化班级课程ComboBox
Do While Not rst.EOF
strItem = rst.Fields(0) & " " & rst.Fields(1)
CboQuery(3).AddItem (strItem)
rst.MoveNext
Loop
rst.Close
CboQuery(3).ListIndex = 0
Else '如果不存在班级课程信息,退出过程
Exit Sub
End If
End Sub
Private Sub LoadData() '显示成绩列表
Dim classNo As String
Dim courseNo As String
Dim rst As ADODB.Recordset
Dim flag As Boolean
If CboQuery(2).ListCount > 0 And CboQuery(3).ListCount > 0 Then
classNo = Left(Trim(CboQuery(2).Text), 6)
courseNo = Left(Trim(CboQuery(3).Text), 5)
'读取成绩信息
DataGrid1.Caption = classNo & "班" & courseNo & "课程成绩信息"
SQL = "select 考试ID,学号,课程号,成绩,考次代码 from 成绩信息表 where学号 like '" & classNo & "%'"
SQL = SQL & " and 课程号='" & courseNo & "'"
Set rs = SelectSQL(SQL, msg)
Set DataGrid1.DataSource = rs
DataGrid1.Columns.Item(1).Locked = False
DataGrid1.Columns.Item(2).Locked = False
DataGrid1.Refresh
Else
MsgBox ("不能生成成绩列表!")
DataGrid1.Caption = "没有成绩单信息"
Exit Sub
End If
End Sub
Private Sub CboQuery_Click(Index As Integer)
'下拉框控件内容更新
Dim strCaption As String
If Index = 0 Then '选择院信息时
Call SelectData(0) '初始化系ComboBox控件
ElseIf Index = 1 Then '选择系信息时
If CboQuery(1).ListCount > 0 Then
Call SelectData(1) '初始化班级ComboBox控件
End If
ElseIf Index = 2 Then '选择班级信息时
If CboQuery(2).ListCount > 0 Then
Call FixData '初始化班级课程ComboBox控件
End If
End If
End Sub
Private Sub CmdQuery_Click()
'显示成绩列表
Dim strCaption As String
If CboQuery(3).ListCount > 0 Then
strCaption = "需要" & Left(Trim(CboQuery(2).Text), 6)
strCaption = strCaption & "班" & Left(Trim(CboQuery(3).Text), 6)
strCaption = strCaption & "课程成绩列表吗?"
msg = MsgBox(strCaption, vbYesNo)
If msg = vbYes Then
Call LoadData '显示成绩列表
End If
End If
End Sub
Private Sub cmdExit_Click()
'退出操作
Set rs = Nothing
Unload Me
Pingfen.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出操作
Unload Me
Pingfen.Enabled = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -