以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  后台统计  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=164204)

--  作者:朱女士
--  发布时间:2021/4/29 14:57:00
--  后台统计

老师您好!

  如对某表用代码进行统计,但不是交叉统计和分组统计,我想要实现:不管事先是否对表中数据做任何筛选,所有数据又要参与计算。怎么写代码加载或统计所有数据?请指教,谢谢!

 


--  作者:y2287958
--  发布时间:2021/4/29 15:37:00
--  
用datatable不用table
--  作者:有点蓝
--  发布时间:2021/4/29 16:07:00
--  
请举例说明
--  作者:朱女士
--  发布时间:2021/4/29 16:38:00
--  

For Each nm As String In DataTables("ylqcb").GetValues("ylggddm")
    Dim dr As DataRow = DataTables("ylkcb").find("ylggddm=\'" & nm & "\'")
   
    If dr Is Nothing Then
        dr =DataTables("ylkcb").AddNew()
        Dim pr As DataRow = DataTables("ylqcb").find("ylggddm=\'" & nm & "\'")
        If pr IsNot Nothing Then
            dr("供应商") = pr("供应商")
            dr("ylmc") = pr("ylmc")
            dr("原料规格") =pr("原料规格")
            dr("ylggddm")=nm
            dr("yldm") = pr("yldm")
            dr("长") = pr("长")
            dr("宽") = pr("宽")
            dr("厚") = pr("厚")
            dr("含税价")=pr("含税价")
        End If
    End If
   
Next

For Each nm As String In DataTables("ylrkb").GetValues("ylggddm")
    Dim dr As DataRow = DataTables("ylkcb").find("ylggddm=\'" & nm & "\'")
   
    If dr Is Nothing Then
        dr =DataTables("ylkcb").AddNew()
        Dim wr As DataRow = DataTables("ylrkb").find("ylggddm=\'" & nm & "\'")
        If wr IsNot Nothing Then
            dr("供应商") = wr("供应商")
            dr("ylmc") = wr("ylmc")
            dr("原料规格") =wr("原料规格")
            dr("ylggddm")=nm
            dr("yldm") = wr("yldm")
            dr("长") = wr("长")
            dr("宽") = wr("宽")
            dr("厚") = wr("厚")
            dr("含税价")=wr("含税价")

        End If
    End If
   
Next


For Each nm As String In DataTables("ylkcb").GetValues("ylggddm")
      Dim dr As DataRow = DataTables("ylkcb").find("ylggddm=\'" & nm & "\'")
       dr("期初_数量") = DataTables("ylqcb").Compute("Sum(期初_数量)","[ylggddm] = \'" & dr("ylggddm") & "\'")
    dr("期初_重量") = DataTables("ylqcb").Compute("Sum(期初_重量)","[ylggddm] = \'" & dr("ylggddm") & "\'")
    dr("期初_含税额") = DataTables("ylqcb").Compute("Sum(期初_含税额)","[ylggddm] = \'" & dr("ylggddm") & "\'")
   
    dr("入库_数量") = DataTables("ylrkb").Compute("Sum(入库_数量)","[ylggddm] = \'" & dr("ylggddm") & "\'")
   
    dr("入库_重量") = DataTables("ylrkb").Compute("Sum(入库_重量)","[ylggddm] = \'" & dr("ylggddm") & "\'")
   
    dr("入库_含税额") = DataTables("ylrkb").Compute("Sum(入库_含税额)","[ylggddm] = \'" & dr("ylggddm") & "\'")
   
    dr("出库_数量") = DataTables("ylckb").Compute("Sum(出库_数量)","[ylggddm] = \'" & dr("ylggddm") & "\'")
   
    dr("出库_重量") = DataTables("ylckb").Compute("Sum(出库_重量)","[ylggddm] = \'" & dr("ylggddm") & "\'")
   
    dr("出库_含税额") = DataTables("ylckb").Compute("Sum(出库_含税额)","[ylggddm] = \'" & dr("ylggddm") & "\'")
      
   
    dr("库存_数量")=dr("期初_数量")+dr("入库_数量")-dr("出库_数量")
    dr("库存_重量")=dr("期初_重量")+dr("入库_重量")-dr("出库_重量")
    dr("库存_含税额")=dr("期初_含税额")+dr("入库_含税额")-dr("出库_含税额")
   
    
Next
messagebox.show("计算完毕")
MainTable= Tables("ylkcb")


--  作者:有点蓝
--  发布时间:2021/4/29 16:58:00
--  
什么地方有问题?上面代码本来就不会受筛选影响的。如果是指数据没有完全加载,参考:http://www.foxtable.com/webhelp/topics/2902.htm,看下面sqlxxx方法