代码没错,绝对是你手工计算有问题。
StatusBar.Message1= "正在统计"
StatusBar.ProgressBar.Visible =True
StatusBar.ProgressBar.Minimum = 0
StatusBar.ProgressBar.Maximum =DataTables("答案2").datarows.count
Dim dtb As New DataTableBuilder("督学测评统计表")
dtb.AddDef("单位",Gettype(String),8)
dtb.AddDef("单位代码",Gettype(String),8)
dtb.AddDef("教职工数",Gettype(Double))
dtb.AddDef("类别",Gettype(String),8)
dtb.AddDef("调查人数",Gettype(Double))
dtb.AddDef("得分",Gettype(Decimal))
Dim djs() As String = {"是或好","否或不好"}
For i As Integer = 1 To 7
For Each dj As String In djs
dtb.AddDef("内容"& i & dj & "人",Gettype(Decimal),"","内容" & i & "_"& dj &"_人数")
dtb.AddDef("内容"& i & dj & "%",Gettype(Decimal),"","内容" & i & "_"& dj &"_%")
Next
Next
dtb.Build()
Tables("督学测评统计表").ResumeRedraw
Tables("督学测评统计表").StopRedraw
Dim lbs() As String = {"A","B"}
For Each lb As String In lbs
Dim dr As DataRow
For Each dw As String In DataTables("答案2").GetValues("单位", "")
dr = DataTables( "督学测评统计表" ).datarows.addnew()
dr("单位") = dw
Dim ddr As DataRow = DataTables("校名设置").Find("单位 = '" & dw & "'")
dr("单位代码") = ddr("单位代码")
Dim jdr As DataRow = DataTables("教职工数").Find("单位 = '" & dw & "'")
dr("教职工数") = jdr("教职工数")
dr("类别") = lb
dr("调查人数") = DataTables("答案2").Compute("count(单位)", "[单位] = '" & dw & "'And 类别 = '" & lb & "'And 备注 <> '0' ")
Dim XXs() As String = {"内容1","内容2","内容3","内容4","内容5","内容6","内容7"}
Dim rdr As DataRow = DataTables("分值").Find("表名 = '责任督学' And 类别 = '" & lb & "'")
For Each XX As String In XXs
dr( XX &"是或好人") = DataTables("答案2").Compute("Count(单位)", "[单位] = '" & dw & "'And 类别 = '" & lb & "'And " & XX & "= 'A'")
dr( XX &"是或好%") = dr( XX &"是或好人")/dr("调查人数")*100
dr( XX &"否或不好人") = DataTables("答案2").Compute("Count(单位)", "[单位] = '" & dw & "'And 类别 = '" & lb & "'And " & XX & "= 'B'")
dr( XX &"否或不好%") = dr( XX &"否或不好人")/dr("调查人数")*100
dr("得分") += dr( XX &"是或好人")*rdr("A") + dr( XX &"否或不好人")* rdr("B")
Dim Nms() As String = {XX &"是或好%",XX &"否或不好%","得分"}
For Each nm As String In nms
If dr.IsNull(Nm) = False Then
dr(Nm) = Format(dr(Nm),"0.00") '确定小数位数
End If
Next
Next
dr("得分") = Format(dr("得分")/dr("调查人数")/7, "0.00")
Next
Next
For Each zdr As DataRow In DataTables("督学测评统计表").DataRows
For Each dc As DataCol In DataTables("督学测评统计表").datacols
If dc.IsNumeric Then
If zdr(dc.name) = 0 Then
zdr(dc.name) = Nothing
End If
End If
Next
Next
Dim lms() As String = {"单位","单位代码","教职工数","调查人数","教职工数","类别"}
For Each lm As String In lms
Tables("督学测评统计表").Cols(""& lm &"").TextAlign = TextAlignEnum.Center
Next
Tables("督学测评统计表").Sort = "单位"
Tables("督学测评统计表").AutoSizeCols() '默认自动列宽
e.Form.Controls("Label1").text ="统计结束,请导出数据!否则数据会丢失!"
Tables("督学测评统计表").ResumeRedraw