以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]为什么可以计算,但是会卡很久?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=120285)

--  作者:zhaomeng
--  发布时间:2018/6/12 0:14:00
--  [求助]为什么可以计算,但是会卡很久?
为什么可以计算,但是会卡很久?大概10来分钟,数据就几百行。
Dim d As Date = Date.today
d = new Date(d.year, d.month, 1)
Dim d1 As Date = d.AddMonths(0)
Dim d2 As Date = d.AddMonths(-1)
Dim dr As DataRow = e.DataRow
Dim dt As DataTable = DataTables("销售开单")
If e.DataCol.Name = "编号" Then
   dr("AA") = dt.Compute("Sum(数量)","[编号] = \'" & dr("编号") & "\' And [日期] >=  #" & d2 & "#  And [日期] <  #" & d1 & "#"  )
End If
另外“AA” 能否用列号表示?比如Tables("计算").Cols(3) 如何定义这个变量?

--  作者:有点甜
--  发布时间:2018/6/12 8:50:00
--  

1、不要重置列,如果需要全部重新计算,参考

 

http://www.foxtable.com/webhelp/scr/2219.htm

 

2、如果自己不会调试,上传具体实例测试。


--  作者:zhaomeng
--  发布时间:2018/6/12 8:59:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:成本表.rar


您帮忙看看,谢谢!

--  作者:有点甜
--  发布时间:2018/6/12 9:34:00
--  

1、代码

 

Dim dr As DataRow = e.DataRow
Dim dt As DataTable = DataTables("销售开单")
If e.DataCol.Name = "编号" Then
    Dim ary1() = {"AA","BB","CC","DD","EE","FF","GG","HH","II","JJ","KK","LL"}
    Dim ary2(ary1.length) As Date
    Dim d As Date = Date.today
    d = new Date(d.year, d.month, 1)
    ary2(0) = d
    For i As Integer = 0 To ary1.length-1
        ary2(i+1) = d.AddMonths(-i-1)
    Next
    Dim ary3(ary1.length-1) As Double
    Dim drs = dt.Select("[编号] = \'" & dr("编号") & "\'", "日期 desc")
    For Each cdr As DataRow In drs
        For i As Integer = 0 To ary1.length-1
            If cdr("日期") >= ary2(i+1) AndAlso cdr("日期") < ary2(i) Then
                ary3(i) += cdr("数量")
                Exit For
            End If
        Next
    Next
    For i As Integer = 0 To ary1.length-1
        dr(ary1(i)) = ary3(i)
    Next
End If

 

2、代码

 

If MainTable.Name = "计算" Then
    systemready = False
    Dim f As New Filler
    DataTables("计算").DataRows.Clear() \'清除原有数据
    f.SourceTable = DataTables("销售开单")
    f.SourceCols = "编号"
    f.DataTable = DataTables("计算")
    f.DataCols = "编号"
    f.Fill()
    systemready = True
    DataTables("计算").datacols("编号").RaiseDataColChanged
End If


--  作者:zhaomeng
--  发布时间:2018/6/12 11:00:00
--  
已经可以了,非常感谢!!!