以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]统计不正确  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=97747)

--  作者:紫色幽魂
--  发布时间:2017/3/17 17:52:00
--  [求助]统计不正确

请问下下面代码中的属于返修检测的统计列为什么统计出来的结果不正确,大于实际的结果

 

DataTables("检测项目").LoadFilter = ""
DataTables("检测项目").Load
Dim lsb As DataTable = DataTables("检测项目")
Dim ryz() As String = {"A","B","C","D"}
Dim dtb As New DataTableBuilder("统计表")
dtb.AddDef("检测性质", Gettype(String), 32)
For Each ry As String In ryz
    dtb.AddDef(ry, Gettype(Double), 32)
Next
dtb.AddDef("总计", Gettype(Double))
dtb.Build()
Dim rq As Date
With RibbonTabs("自定义1")("无损日统计表")
    rq = .Items("rq").value
End With
Dim filter As String
Dim filter1 As String
Dim filter2 As String
If rq <> Nothing Then
    filter &= " [首次检测_检测时间] = #" & rq & "#"
    filter1 &= " [返修_返修时间] = #" & rq & "#"
    filter2 &= " [二次返修_返修时间] = #" & rq & "#"
End If
Dim dr As DataRow = DataTables("统计表").AddNew()
Dim dr1 As DataRow = DataTables("统计表").AddNew()
Dim dr2 As DataRow = DataTables("统计表").AddNew()
Dim dr3 As DataRow = DataTables("统计表").AddNew()
For Each ry As String In ryz
    dr("检测性质") = "首次检测"
    dr(ry) = lsb.Compute("sum(检测人员_" & ry & ")", filter)
    dr1("检测性质") = "返修检测"
    dr1(ry) = lsb.Compute("sum(返修_" & ry & ")", filter1)
    dr2("检测性质") = "二次返修检测"
    dr2(ry) = lsb.Compute("sum(二次返修_" & ry & ")", filter2)
    dr3("检测性质") = "合计:"
    dr3(ry) = dr(ry) + dr1(ry) + dr2(ry)
    Dim sum As Double
    Dim sum1 As Double
    Dim sum2 As Double
    Dim sum3 As Double
    sum = sum + dr(ry)
    dr("总计") = sum
    sum1 = sum1 + dr1(ry)
    dr1("总计") = sum1 + dr1(ry)
    sum2 = sum2 + dr2(ry)
    dr2("总计") = sum2 + dr2(ry)
    dr3("总计") = sum + sum1 + sum2
Next
filter = "1=1"
For Each ry As String In ryz
    filter &= " and " & ry & " is null "
    If DataTables("统计表").Compute("Sum(" & ry & ")") = 0 Then DataTables("统计表").DataCols.Delete(ry)
Next
\'DataTables("统计表").DeleteFor(filter)
MainTable = Tables("统计表")

 


--  作者:有点色
--  发布时间:2017/3/17 18:27:00
--  
 上传实例说明。
--  作者:紫色幽魂
--  发布时间:2017/3/18 9:45:00
--  回复:(有点色) 上传实例说明。
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目2.table


图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看
这个第二排数据加起来和总和计算的不正确,还有最后第二排的删除空行的代码如果执行的话会提示不存在某些被删除的列
--  作者:有点蓝
--  发布时间:2017/3/18 10:42:00
--  

......

 

    sum = sum + dr(ry)
    dr("总计") = sum
    sum1 = sum1 + dr1(ry)
    dr1("总计") = sum1
    sum2 = sum2 + dr2(ry)
    dr2("总计") = sum2

 

......


--  作者:紫色幽魂
--  发布时间:2017/3/18 13:44:00
--  回复:(有点蓝)......    ...
请问下最后倒数第二排的删除没有数据的这行应该怎么改
--  作者:有点蓝
--  发布时间:2017/3/18 15:17:00
--  
filter = "1=1"
For Each ry As String In ryz
   
    If DataTables("统计表").Compute("Sum(" & ry & ")") = 0 Then
        DataTables("统计表").DataCols.Delete(ry)
    Else
        filter &= " and " & ry & " is null "
    End If
Next
Output.Show(filter )
DataTables("统计表").DeleteFor(filter)
MainTable = Tables("统计表")