Dim t1 As Date = Date.Now
Dim tj As new DataTableBuilder("统计")
'第1步:增加与测评表一致的各列
For Each c As Col In Tables("测评表").Cols
If c.Name <> "pg" AndAlso c.Name <> "备注" Then
If c.Name = "姓名" Then
tj.AddDef(c.Name,Gettype(String),20)
Else
tj.AddDef(c.Name,Gettype(Integer))
End If
End If
Next
'第2步:增加总评列
Dim djs As List(of String) = DataTables("设置").GetValues("等级","等级>''","_Identify")
For Each dj As String In djs
tj.AddDef("总评_" & dj,Gettype(Integer))
Next
tj.Build()
Tables("统计结果_统计表").DataSource = DataTables("统计")
Dim Ww As String
For Each c As Col In Tables("统计结果_统计表").ColS
If c.Name <> "姓名" Then
ww = ww & c.Name & "|35|"
End If
Next
ww = "姓名|80|" & ww '隐藏备注列
Tables("统计结果_统计表").SetColVisibleWidth(Ww)
'第3步:增加人员表姓名并统计各等级的测评结果
Dim t As Table = Tables("统计结果_统计表")
t.StopRedraw
Dim xms As List(of String) = DataTables("人员表").GetValues("姓名","姓名>''","_Identify")
For Each xm As String In xms
Dim r As Row = t.AddNew
r("姓名") = xm
For Each c As Col In Tables("测评表").cols
If c.Name <> "姓名" AndAlso c.Name <> "PG" AndAlso c.Name<> "备注" AndAlso c.Name.Contains("总评") = False Then
r(c.Name) = DataTables("测评表").SQLCompute("count(姓名)","姓名 = '" & xm & "' and " & c.Name & " = True")
End If
Next
Next
'第4步:统计总评
For Each r As Row In t.Rows
Dim djj As List(of String) = DataTables("设置").GetValues("等级","等级>''","_Identify") '定义等级
Dim xmm As List(of String) = DataTables("设置").GetValues("项目","项目>''","_Identify") '定义项目
For Each dj As String In djj
Dim sum As Integer = 0 '必须定义为0,否则为累计以一下行的计算
For Each xm As String In xmm
sum = sum + r(xm & "_" & dj)
Next
r("总评_" & dj) = sum
Next
Next
'第5步:对统计结果进行排序,设置表样式
t.Sort = "总评_" & djs(0) & " desc," & "总评_" & djs(1) & " desc," & "总评_" & djs(2) & " desc"
Functions.Execute("表样式","统计")
t.grid.styles.Normal.Border.Color = Color.SlateBlue '风格线设置成深颜色
t.AllowEdit = False
t.DataTable.Save
t.ResumeRedraw
'Forms("主窗口").Controls("lab-提示").text = Nothing
e.Form.Controls("Label1").text = "计算结束, 耗时: " & (Date.Now - t1).TotalSeconds & "秒"