📄 frmscorebrowse.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx"
Begin VB.Form frmScoreBrowse
BorderStyle = 1 'Fixed Single
Caption = "成绩浏览"
ClientHeight = 5730
ClientLeft = 45
ClientTop = 330
ClientWidth = 10290
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 5730
ScaleWidth = 10290
Begin VB.ComboBox comScoreBrowse
BackColor = &H80000018&
Height = 300
Index = 3
Left = 8160
Style = 2 'Dropdown List
TabIndex = 10
Top = 480
Width = 1935
End
Begin VB.ComboBox comScoreBrowse
BackColor = &H80000018&
Height = 300
Index = 2
Left = 4560
Style = 2 'Dropdown List
TabIndex = 9
Top = 480
Width = 3375
End
Begin VB.ComboBox comScoreBrowse
BackColor = &H80000018&
Height = 300
Index = 1
Left = 2400
Style = 2 'Dropdown List
TabIndex = 5
Top = 480
Width = 1935
End
Begin VB.ComboBox comScoreBrowse
BackColor = &H80000018&
Height = 300
Index = 0
Left = 240
Style = 2 'Dropdown List
TabIndex = 3
Top = 480
Width = 1935
End
Begin VB.CommandButton Command1
Caption = "修 改"
Height = 375
Left = 3960
TabIndex = 1
Top = 5160
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "删 除"
Height = 375
Left = 5280
TabIndex = 0
Top = 5160
Width = 1095
End
Begin MSFlexGridLib.MSFlexGrid flgScores
Height = 3975
Left = 240
TabIndex = 2
Top = 960
Width = 9885
_ExtentX = 17436
_ExtentY = 7011
_Version = 393216
Cols = 1
BackColor = -2147483624
BackColorFixed = 12632256
ForeColorFixed = 0
BackColorSel = 16777215
ForeColorSel = 255
BackColorBkg = -2147483624
AllowBigSelection= -1 'True
SelectionMode = 1
AllowUserResizing= 3
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "类型:"
Height = 180
Index = 3
Left = 8160
TabIndex = 8
Top = 240
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "班级:"
Height = 180
Index = 2
Left = 2400
TabIndex = 7
Top = 240
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "学期:"
Height = 180
Index = 1
Left = 4560
TabIndex = 6
Top = 240
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "年级:"
Height = 180
Index = 0
Left = 240
TabIndex = 4
Top = 240
Width = 540
End
End
Attribute VB_Name = "frmScoreBrowse"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'----------------------------------frmScoreBrowse.frm----------------------------------
Option Explicit
'选择年级
Private Sub comScoreBrowse_Click(Index As Integer)
Dim objRecordset As ADODB.Recordset
If Index = 0 Then
strSQL = "select DISTINCT 班级 from Classes where 年级='" & Trim(comScoreBrowse(0).Text) & "'"
Set objRecordset = ExecuteSQL(strSQL)
If objRecordset.EOF = True Then
comScoreBrowse(1).Text = ""
comScoreBrowse(2).Text = ""
Exit Sub
End If
comScoreBrowse(1).Clear
objRecordset.MoveFirst
'将班级信息显示到控件中
Do Until objRecordset.EOF
comScoreBrowse(1).AddItem objRecordset.Fields(0)
objRecordset.MoveNext
Loop
comScoreBrowse(1).ListIndex = 0
End If
Set objRecordset = Nothing
flgScores.Clear
ShowScores
End Sub
Private Sub Form_Activate()
ShowScores
End Sub
Private Sub Form_Load()
Dim objRecordset As ADODB.Recordset
'查询年级
strSQL = "select DISTINCT 年级 from Classes "
Set objRecordset = ExecuteSQL(strSQL)
objRecordset.MoveFirst
comScoreBrowse(0).Clear
Do While Not objRecordset.EOF
comScoreBrowse(0).AddItem objRecordset.Fields(0)
objRecordset.MoveNext
Loop
comScoreBrowse(0).ListIndex = 0
'查询班级
strSQL = "select DISTINCT 班级 from Classes where 年级='" & Trim(comScoreBrowse(0).Text) & "'"
Set objRecordset = ExecuteSQL(strSQL)
comScoreBrowse(1).Clear
objRecordset.MoveFirst
Do While Not objRecordset.EOF
comScoreBrowse(1).AddItem objRecordset.Fields(0)
objRecordset.MoveNext
Loop
comScoreBrowse(1).ListIndex = 0
'初始化学期控件
comScoreBrowse(2).AddItem Val(Format(Date, "yyyy")) - 1 & "---" & Val(Format(Date, "yyyy")) & "年级第一学期"
comScoreBrowse(2).AddItem Val(Format(Date, "yyyy")) - 1 & "---" & Val(Format(Date, "yyyy")) & "年级第二学期"
comScoreBrowse(2).AddItem Format(Date, "yyyy") & "---" & Val(Format(Date, "yyyy")) + 1 & "年级第一学期"
comScoreBrowse(2).AddItem Format(Date, "yyyy") & "---" & Val(Format(Date, "yyyy")) + 1 & "年级第二学期"
comScoreBrowse(2).AddItem Val(Format(Date, "yyyy")) + 1 & "---" & Val(Format(Date, "yyyy")) + 2 & "年级第一学期"
comScoreBrowse(2).AddItem Val(Format(Date, "yyyy")) + 1 & "---" & Val(Format(Date, "yyyy")) + 2 & "年级第二学期"
If Val(Format(Date, "mm")) > 8 Then
comScoreBrowse(2).ListIndex = 2
Else
comScoreBrowse(2).ListIndex = 1
End If
'查询考试类型
strSQL = "select * from ExamType"
Set objRecordset = ExecuteSQL(strSQL)
comScoreBrowse(3).Clear
objRecordset.MoveFirst
Do While Not objRecordset.EOF
comScoreBrowse(3).AddItem objRecordset.Fields(0)
objRecordset.MoveNext
Loop
comScoreBrowse(3).ListIndex = 0
Set objRecordset = Nothing
ShowScores
End Sub
'显示成绩
Public Sub ShowScores()
Dim objRecordset As ADODB.Recordset
Dim objSubRecordset As ADODB.Recordset
Dim i As Integer
Dim j As Integer
Dim r As Integer
Dim intCol As Integer
'成绩和,用于计算平均成绩
Dim sngSum As Single
Dim sngAve As Single
strSQL = "select distinct 学号 from Scores where 学号 in(select 学号 from Documents where 班级='" & Trim(comScoreBrowse(1).Text) & "') and 学期='" & Trim(comScoreBrowse(2).Text) & "' and 类型='" & Trim(comScoreBrowse(3).Text) & "'order by Scores.学号"
Set objRecordset = ExecuteSQL(strSQL)
If objRecordset.EOF = True Then
Exit Sub
End If
sngSum = 0
For i = 1 To objRecordset.RecordCount
strSQL = "select Scores.学号,Documents.姓名,Scores.学期,Scores.类型,Scores.课程名称,Scores.分数 from Scores inner join Documents on Scores.学号=Documents.学号 where Scores.学期='" & Trim(comScoreBrowse(2).Text) & "' and Scores.学号='" & Trim(objRecordset.Fields(0)) & "'and Scores.类型='" & Trim(comScoreBrowse(3).Text) & "'"
Set objSubRecordset = ExecuteSQL(strSQL)
'显示表格标题
If i = 1 Then
flgScores.Cols = objSubRecordset.RecordCount + 7
flgScores.TextMatrix(0, 1) = "学号"
flgScores.TextMatrix(0, 2) = "姓名"
flgScores.TextMatrix(0, 3) = "学期"
flgScores.TextMatrix(0, 4) = "类型"
'显示课程名
intCol = 5
For j = 1 To objSubRecordset.RecordCount
flgScores.TextMatrix(0, intCol) = objSubRecordset.Fields("课程名称")
intCol = intCol + 1
objSubRecordset.MoveNext
Next j
flgScores.TextMatrix(0, intCol) = "总分"
flgScores.TextMatrix(0, intCol + 1) = "平均分"
flgScores.ColWidth(0) = 150
flgScores.ColWidth(3) = 2300
'设置表格样式和行代大小
For j = 1 To objSubRecordset.RecordCount + 6
flgScores.ColAlignment(j) = 0
Next j
objSubRecordset.MoveFirst
flgScores.Rows = 30
flgScores.Row = 1
End If
'将学生信息显示在表格中
flgScores.Rows = flgScores.Rows + 1
flgScores.TextMatrix(flgScores.Row, 1) = objSubRecordset.Fields(0)
flgScores.TextMatrix(flgScores.Row, 2) = objSubRecordset.Fields(1)
flgScores.TextMatrix(flgScores.Row, 3) = objSubRecordset.Fields(2)
flgScores.TextMatrix(flgScores.Row, 4) = objSubRecordset.Fields(3)
'将学生成绩显示在表格中
intCol = 5
sngSum = 0
For j = 1 To objSubRecordset.RecordCount
flgScores.Col = intCol
'不及格用红色显示
If Val(objSubRecordset.Fields("分数")) < 60 Then
flgScores.CellForeColor = vbRed
End If
flgScores.TextMatrix(flgScores.Row, intCol) = objSubRecordset.Fields("分数")
sngSum = sngSum + objSubRecordset.Fields("分数")
intCol = intCol + 1
objSubRecordset.MoveNext
Next j
flgScores.TextMatrix(flgScores.Row, intCol) = sngSum
'计算平均值
sngAve = Int(sngSum / (objSubRecordset.RecordCount) * 10 + 0.5) / 10
flgScores.Col = intCol + 1
'不及格用红色显示
If sngAve < 60 Then
flgScores.CellForeColor = vbRed
End If
flgScores.TextMatrix(flgScores.Row, intCol + 1) = sngAve
flgScores.Row = flgScores.Row + 1
objRecordset.MoveNext
Next i
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -