Foxtable(狐表)用户栏目专家坐堂 → 组合统计


  共有4032人关注过本帖平板打印复制链接

主题:组合统计

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/6/27 11:03:00 [只看该作者]

这个意思?

 

Dim Filter1 As String

With e.Form.Controls("日期")
    If .Value Is Nothing Then
        Return
    End If
End With

Dim Filter As String

Dim curD As Date=e.Form.Controls("日期").Value '当前日期

Filter = Filter & "日期 <= #" & curD & "#"


Dim bd1 As New GroupTableBuilder("统计表1",DataTables("进货"))

Dim dt1 As fxDataSource
bd1.Groups.AddDef("型号") '根据型号分组
bd1.Totals.AddDef("进货_数量","进货_数量") '对数量进行统计
bd1.Totals.AddDef("进货_金额","进货_金额") '对金额进行统计
bd1.Filter = Filter
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表2",DataTables("销售"))
Dim dt2  As fxDataSource
bd2.Groups.AddDef("型号") '根据型号分组
bd2.Totals.AddDef("销售_数量","销售_数量") '对数量进行统计
bd2.Totals.AddDef("销售_金额","销售_金额") '对金额进行统计
bd2.Filter = Filter
dt2 = bd2.BuildDataSource()


Dim bd3 As New GroupTableBuilder("统计表3",DataTables("退货"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("型号") '根据型号分组
bd3.Totals.AddDef("退货_数量","退货_数量") '对数量进行统计
bd3.Totals.AddDef("退货_金额","退货_金额") '对金额进行统计
bd3.Filter = Filter
dt3 = bd3.BuildDataSource()


dt1.Combine("型号",dt2,"型号") '将销售统计数据组合到进货统计数据
dt1.Combine("型号",dt3,"型号") '将退货统计数据组合到进货统计数据
Tables("统计_Table1").DataSource = dt1 '将统计结果绑定到Table

Dim lastD As Date = curD.AddMonths(-1) '上一个月的日期
Dim lastD2 As New Date(lastD.Year, lastD.Month, Date.DaysInMonth(lastD.Year,lastD.Month)) '上个月的最后一天
Filter = "日期 <= #" & curD & "#" & " And 日期  > #" & lastD & "#"
With DataTables("统计_Table1").DataCols  '用表达式列计算库存数据
    .Add("期初_数量",Gettype(Double),"","信息_期初数量")
    .Add("期初_金额",Gettype(Double),"","信息_期初金额")
End With
For Each r As Row In Tables("统计_Table1").Rows
    r("期初_数量") = DataTables("进货").Compute("sum(进货_数量)", filter) - DataTables("销售").Compute("sum(销售_数量)", filter) - DataTables("退货").Compute("sum(退货_数量)", filter)
    r("期初_金额") = DataTables("进货").Compute("sum(进货_金额)", filter) - DataTables("销售").Compute("sum(销售_金额)", filter) - DataTables("退货").Compute("sum(退货_金额)", filter)
Next

With DataTables("统计_Table1").DataCols  '用表达式列计算库存数据
    .Add("库存_数量",Gettype(Double), "IsNull([期初_数量],0) - IsNull([进货_数量],0) - ISNULL([销售_数量],0) - ISNULL([退货_数量],0)","信息_当期数量")
    .Add("库存_金额",Gettype(Double), "IsNull([期初_金额],0) - IsNull([进货_金额],0) - ISNULL([销售_金额],0) - ISNULL([退货_金额],0)","信息_当期金额")
End With
Tables("统计_Table1").SetColVisibleWidth("型号|80|进货_数量|80|进货_金额|80|销售_数量|80|销售_金额|80|退货_数量|80|退货_金额|80|期初_数量|80|期初_金额|80|库存_数量|80|库存_金额|80")


 回到顶部
总数 21 1 2 3 下一页