完全无法理解你到底要做什么
Dim g As New GroupTableBuilder("统计表2", DataTables("排名升降分析"))
g.Groups.AddDef("期数")
g.Groups.AddDef("班级")
g.Groups.AddDef("学号")
g.Groups.AddDef("姓名")
g.Groups.AddDef("语文")
g.Groups.AddDef("数学")
g.Groups.AddDef("英语")
g.Groups.AddDef("物理")
g.Groups.AddDef("化学")
g.Groups.AddDef("总分")
g.Build()
MainTable = Tables("统计表2")
DataTables("统计表2").GlobalHandler.drawcell= True
DataTables("统计表2").AddUserStyle("降", Color.Green, Color.White)
DataTables("统计表2").AddUserStyle("升", Color.Red, Color.White)
Dim str,str1 As String
str = e.Form.Controls("ComboBox1").value
str1 = e.Form.Controls("ComboBox2").value
If str Is Nothing Then
MessageBox.Show("请选择上一期的比较参数","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
ElseIf str1 Is Nothing
MessageBox.Show("请选择下一期的比较参数","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
ElseIf str = str1
MessageBox.Show("比较的两期数据不能相同","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
Else
e.Form.Controls("Label3").text="正在分析,请稍候..."
Application.Doevents
Dim Time,Time1 As Date
Time = Date.now
Vars("qs") = str
'加载指定期数的数据
DataTables("成绩表").LoadFilter = "[期数] = '"& str & "' or [期数] = '"& str1 & "'"
DataTables("成绩表").Load()
DataTables("成绩排名").DataRows.Clear() '清除成绩排名表所有数据
Dim f As New Filler '以下是数据填充
f.SourceTable = DataTables("成绩表")
f.SourceCols = "期数,班级,学号,姓名,语文,数学,英语,物理,化学"
f.DataTable = DataTables("成绩排名")
f.DataCols = "期数,班级,学号,姓名,语文,数学,英语,物理,化学"
f.Fill
'下面对成绩排名表中进行排名
Dim pm As List(Of String) = Tables("成绩排名").DataTable.GetUniqueValues("","期数")
Dim pmc As Integer
Dim ColNames() As String = {"语文","数学","英语","化学","物理","总分"}
Dim TotalName As String
For Each ColName As String In ColNames
For i As Integer = 0 To pm.Count -1
If pm(i) = "" Then
Continue For
End If
Dim drs As List(Of DataRow) = Tables("成绩排名").DataTable.Select("[期数] = " & pm(i), ColName & " DESC")
pmc = 0
TotalName = ColName & "排名"
For n As Integer = 0 To drs.Count - 1
pmc = pmc +1
If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
drs(n)(TotalName ) = drs(n-1)(TotalName )
Else
drs(n)(TotalName ) = pmc
End If
Next
Next
Next
Tables("成绩排名").Sort = "总分 DESC"
DataTables("统计表2").DataRows.Clear()
CurrentTable.Focus() '移动焦点到Table
Dim h As New Filler
h.SourceTable = DataTables("成绩排名")
h.SourceCols = "期数,班级,学号,姓名,语文排名,数学排名,英语排名,物理排名,化学排名,总分排名"
h.DataTable = DataTables("统计表2")
h.DataCols = "期数,班级,学号,姓名,语文,数学,英语,物理,化学,总分"
h.Filter = "[期数] = '"& str1 & "'"
h.ExcludeExistValue = True
h.Fill
'以下进行排名分析
Dim dt As Table = Tables("统计表2")
Dim dt1 As DataTable = DataTables("成绩排名")
Dim ColNames1() As String = {"语文","数学","英语","化学","物理","总分"}
For Each Name As String In ColNames1
Dim ColName1 As String = Name & "排名"
For i As Integer = 0 to dt.rows.count -1
Dim Value As Integer
Value = dt1.Compute("sum(" & ColName1 & ")","[学号] = '" & dt.Rows(i)("学号") & "' And [期数] = '" & vars("qs") & "'" )
Dim n As Integer = dt.Rows(i)(Name) - Value
Dim Symbol As String
If n = 0 Then '如果等于下面的不同值,赋于不同的字符
Symbol = "←"
ElseIf n < 0 Then
Symbol = "↑"
Else
Symbol = "↓"
End If
dt.Rows(i)(Name) = Symbol & Math.abs(dt.Rows(i)(Name) - Value ) & "(" & dt.Rows(i)(Name) & "/" & Value & ")"
Next
Next
Time1 = Date.Now
e.Form.Controls("Label3").text="耗时 " & (Time1-Time).TotalSeconds & " 秒"
End If