以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  运行效率太慢,求帮忙优化,提升效率  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=50292)

--  作者:阆子天涯
--  发布时间:2014/5/4 10:54:00
--  运行效率太慢,求帮忙优化,提升效率

以下为产生库存报表窗口代码,运行一次要1个多小时,请各位高手帮忙看下,如何优化下,提高效率,谢谢!

 

Dim Filter   As   String
With e.Form.Controls("品牌")
    If .Value   IsNot   Nothing  Then
        Filter =   "品牌 = \'" & .Value &   "\'"
    End   If
End   With

With e.Form.Controls("门店")
    If .Value   IsNot   Nothing   Then
        If Filter >""   Then
            Filter = Filter &   " And "
        End   If
        Filter = Filter &   "门店 = \'" & .Value &   "\'"
    End   If
End   With

With e.Form.Controls("年份")
    If .Value   IsNot   Nothing   Then
        If Filter > ""   Then
            Filter = Filter &   " And "
        End   If
        Filter = Filter &   "年份 = \'" & .Value &   "\'"
    End   If
End   With
With e.Form.Controls("季节")
    If .Value   IsNot   Nothing   Then
        If Filter >""   Then
            Filter = Filter &   " And "
        End   If
        Filter = Filter &   "季节 = \'" & .Value &   "\'"
    End   If
End   With

With e.Form.Controls("开始日期")
    If .Value   IsNot   Nothing   Then
        If Filter >""   Then
            Filter = Filter &   " And "
        End   If
        Filter = Filter &   "单据日期 >= #" & .Value &   "#"
    End   If
End   With
With e.Form.Controls("截止日期")
    If .Value   IsNot   Nothing   Then
        If Filter >""   Then
            Filter = Filter &   " And "
        End   If
        Filter = Filter &   "单据日期 <= #" & .Value &   "#"
    End   If
End   With

If   Filter >   "" Then
    Tables("出入库明细").Filter =   Filter
End If


DataTables("库存报表").DataRows.clear
Tables("库存报表").StopRedraw
Dim dt1,dt2 As DataTable
dt1=DataTables("出入库明细")
dt2=DataTables("库调明细表_主表")
Dim Arys As List(Of String())
Dim dr As  DataRow
Arys = DataTables("出入库明细").GetValues("编码|名称|颜色|尺码|年份|季节|零售价|款号|大类",Filter)
For Each Ary As String() In Arys
    dr= DataTables("库存报表").addnew
    dr("编码")=Ary(0)
    dr("名称")=Ary(1)
    dr("颜色")=Ary(2)
    dr("尺码")=Ary(3)
    dr("年份")=Ary(4)
    dr("季节")=Ary(5)
    dr("零售价")=Ary(6)
   
   
    dr("库房_调拨出库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  业务单号首位 = \'D\' and 收发类型= \'调拨出库\'")
    dr("库房_收货入库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  业务单号首位 = \'F\' and 收发类型= \'收货入库\'")
    dr("库房_返货出库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  业务单号首位 = \'T\' and 收发类型= \'返货出库\'")
    dr("店铺_调拨出库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  业务单号首位 = \'R\' and 收发类型= \'调拨出库\'")
    dr("店铺_调拨入库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  业务单号首位 = \'R\' and 收发类型= \'调拨入库\'")
    dr("店铺_零售出库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  收发类型= \'零售出库\'")
    dr("店铺_零退入库")=dt1.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  收发类型= \'零退入库\'")
   
    dr("店铺_库调")=dt2.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  收发类型= \'库调\'")
    dr("店铺_退货入库")=dt2.Compute("sum(数量)",Filter & " and 编码 = \'"& dr("编码") & "\' and  收发类型= \'退货入库\'")
   
    dr("库房_合计")=dr("库房_收货入库") +dr("店铺_退货入库")+dr("库房_返货出库")-dr("店铺_库调")+dr("库房_调拨出库")
    dr("店铺_合计")=dr("店铺_库调")+dr("店铺_调拨入库")+dr("店铺_调拨出库")-dr("店铺_零售出库")+dr("店铺_零退入库")-dr("店铺_退货入库")
    dr("店库_合计")=dr("库房_合计")+dr("库房_合计")
   
Next

Tables("库存报表").ResumeRedraw

 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:进销存.rar


--  作者:有点甜
--  发布时间:2014/5/4 11:17:00
--  

 测试了一下,没有取巧的方法,只能自己去编写代码统计结果了。

 

 暂时没有时间帮你,你先参考帮助做一下,比较繁琐。

 

 参考帮助来做一下 http://www.foxtable.com/help/topics/2219.htm

 


--  作者:Bin
--  发布时间:2014/5/4 11:21:00
--  
改了一下,测试只需要1-2秒.

.
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:进销存.rar


--  作者:有点甜
--  发布时间:2014/5/4 11:31:00
--  

 咦,怎么这么奇怪......图片点击可在新窗口打开查看


--  作者:Bin
--  发布时间:2014/5/4 11:36:00
--  
以下是引用有点甜在2014-5-4 11:31:00的发言:

 咦,怎么这么奇怪......图片点击可在新窗口打开查看

GEtValues 数据量太大,效率非常低! 所以这样改一下就好了.

可能直接用SQLGETVALUES更加简便

--  作者:ybil
--  发布时间:2014/5/4 11:38:00
--  
試試用分組統計及組合的方法,應該高效些
--  作者:阆子天涯
--  发布时间:2014/5/4 11:52:00
--  
谢谢各位版主了,你们给到我太大的帮助了!我再来改写下!
--  作者:阆子天涯
--  发布时间:2014/5/4 12:11:00
--  
各位版主,是不是试用版的问题,你们的开发版比我用的试用版快些,我把Bin版主的下载下来运行了20多分钟都还没出来
--  作者:ybil
--  发布时间:2014/5/4 13:27:00
--  
試試:窗口表改為查詢表

Dim  Filter,s1,s2,s3 ,flt1,ep1,ep2,ep3 As  String
Dim fdt1,fdt2,fdt3,fdt4,fdt5,fdt6,fdt7,fdt8,fdt9 As fxDataSource
Dim fxdts As fxDataSource() ={fdt1,fdt2,fdt3,fdt4,fdt5,fdt6,fdt7,fdt8,fdt9}
Dim nms1 As String() = {"编码","名称","颜色","尺码","年份","季节","零售价"}  \'分組列
Dim nms2 As String() = {"编码","名称","颜色","尺码","年份","季节"}  \'分組列
Dim nms() As String
Dim bd1 As  GroupTableBuilder
Dim t3 As Table = e.Form.Controls("库存报表").Table
Dim dt3,dt1,dt2 As DataTable
dt1=DataTables("出入库明细")
dt2=DataTables("库调明细表_主表")

s1 = "库房_调拨出库|库房_收货入库|库房_返货出库|店铺_调拨出库|店铺_调拨入库|店铺_零售出库|店铺_零退入库|店铺_库调|店铺_退货入库"      \'統計標題
flt1= "业务单号首位 = \'D\' and 收发类型= \'调拨出库\'@业务单号首位 = \'F\' and 收发类型= \'收货入库\'@业务单号首位 = \'T\' and 收发类型= \'返货出库\'@"   \'條件組合
flt1+= "业务单号首位 = \'R\' and 收发类型= \'调拨出库\'@业务单号首位 = \'R\' and 收发类型= \'调拨入库\'@"
flt1+= "收发类型= \'零售出库\'@收发类型= \'零退入库\'@收发类型= \'库调\'@收发类型= \'退货入库\'"

ep1 = "IsNull([库房_收货入库],0) +IsNull([库房_返货出库],0)+IsNull([库房_调拨出库],0)+IsNull([店铺_退货入库],0)-Isnull([店铺_库调],0)"
ep2 = "IsNull([店铺_库调],0) +IsNull([店铺_调拨入库],0)+IsNull([店铺_调拨出库],0)+IsNull([店铺_零退入库],0)"
ep2+="-Isnull([店铺_零售出库],0)-Isnull([店铺_退货入库],0)"
ep3 = "IsNull([库房_合计],0) +IsNull([库房_合计],0)"

s3 ="品牌,门店,年份,季节,开始日期,截止日期"
For Each s2 In  s3.split(",")   
    With e.Form.Controls(s2)
        If .Value  IsNot  Nothing   Then
            If Filter > ""   Then
                Filter+ = " And "
            End  If
            If s2 = "开始日期" Then
                Filter+ =  "单据日期 >= #" & .Value &   "#"
            ElseIf s2 = "截止日期"  Then
                Filter+ =  "单据日期 <= #" & .Value &   "#"
            Else
                Filter+ =   s2 & " = \'" & .Value &   "\'"
            End  If
        End  If
    End   With 
Next



If   Filter >  "" Then
    Tables("出入库明细").Filter =  Filter
    
    For n1 As Integer = 0 To fxdts.Length-1
        If n1 > 6 Then
            dt3 = dt2
        Else
            dt3 = dt1
        End If
        bd1 = New GroupTableBuilder("报表",dt3)
        For Each s2 In nms1
            If dt3.DataCols.Contains(s2) Then
                bd1.Groups.AddDef(s2) \'分组
            End If
        Next
        
        bd1.Totals.AddDef("数量",s1.split("|")(n1)) \'对数量进行统计
        bd1.Filter = flt1.split("@")(n1) & " and " & Filter
        fxdts(n1) = bd1.BuildDataSource()
        nms = iif(n1 < 7,nms1,nms2)
        If  n1  > 0 Then  fxdts(0).Combine(nms,fxdts(n1),nms)
    Next
    
    
    t3.StopRedraw
    t3.DataSource = fxdts(0)
    With t3.DataTable.DataCols
        .Add("库房_合计", Gettype(Integer),ep1)
        .Add("店铺_合计", Gettype(Integer),ep2)
        .Add("店库_合计", Gettype(Integer),ep3)
    End With
    t3.ResumeRedraw
End If

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:进销存.rar


[此贴子已经被作者于2014-5-4 15:07:20编辑过]

--  作者:有点甜
--  发布时间:2014/5/4 14:23:00
--  

 测试3楼,好像是挺快的。

 

 如果不行,就看看2楼和9楼的代码,改一下。