Dim bd1 As New SQLGroupTableBuilder("统计表1","进货单")
Dim dt1 As fxDataSource
bd1.Groups.AddDef("型号") '根据型号分组
bd1.Totals.AddDef("数量","进货_数量") '对数量进行统计
bd1.Totals.AddExp("进货_金额","数量 * 单价") '对金额进行统计
bd1.Filter = "[日期] >= #" & Vars("开始日期") & "# And [日期] <= #" & Vars("结束日期") & "#"
dt1 = bd1.BuildDataSource()
Dim bd2 As New SQLGroupTableBuilder("统计表2","销售单")
Dim dt2 As fxDataSource
bd2.Groups.AddDef("型号") '根据型号分组
bd2.Totals.AddDef("数量","销售_数量") '对数量进行统计
bd2.Totals.AddExp("销售_金额","数量 * 售价") '对金额进行统计
bd2.Filter = "[日期] >= #" & Vars("开始日期") & "# And [日期] <= #" & Vars("结束日期") & "#"
dt2 = bd2.BuildDataSource()
Dim bd3 As New SQLGroupTableBuilder("统计表3","退货单")
Dim dt3 As fxDataSource
bd3.Groups.AddDef("型号") '根据型号分组
bd3.Totals.AddDef("数量","退货_数量") '对数量进行统计
bd3.Totals.AddExp("退货_金额","数量 * 单价") '对金额进行统计
bd3.Filter = "[日期] >= #" & Vars("开始日期") & "# And [日期] <= #" & Vars("结束日期") & "#"
dt3 = bd3.BuildDataSource()
Dim bd4 As New SQLGroupTableBuilder("统计表1","进货单")
Dim dt4 As fxDataSource
bd4.Groups.AddDef("型号") '根据型号分组
bd4.Totals.AddDef("数量","上期_进货_数量") '对数量进行统计
bd4.Totals.AddExp("上期_进货_金额","数量 * 单价") '对金额进行统计
bd4.Filter = "[日期] < #" & Vars("开始日期") & "#"
dt4 = bd4.BuildDataSource()
Dim bd5 As New SQLGroupTableBuilder("统计表2","销售单")
Dim dt5 As fxDataSource
bd5.Groups.AddDef("型号") '根据型号分组
bd5.Totals.AddDef("数量","上期_销售_数量") '对数量进行统计
bd5.Totals.AddExp("上期_销售_金额","数量 * 售价") '对金额进行统计
bd5.Filter = "[日期] < #" & Vars("开始日期") & "#"
dt5 = bd5.BuildDataSource()
Dim bd6 As New SQLGroupTableBuilder("统计表3","退货单")
Dim dt6 As fxDataSource
bd6.Groups.AddDef("型号") '根据型号分组
bd6.Totals.AddDef("数量","上期_退货_数量") '对数量进行统计
bd6.Totals.AddExp("上期_退货_金额","数量 * 单价") '对金额进行统计
bd6.Filter = "[日期] < #" & Vars("开始日期") & "#"
dt6 = bd6.BuildDataSource()
dt1.Combine("型号",dt2,"型号") '将销售统计数据组合到进货统计数据
dt1.Combine("型号",dt3,"型号") '将退货统计数据组合到进货统计数据
dt1.Combine("型号",dt4,"型号") '将退货统计数据组合到进货统计数据
dt1.Combine("型号",dt5,"型号") '将退货统计数据组合到进货统计数据
dt1.Combine("型号",dt6,"型号") '将退货统计数据组合到进货统计数据
Tables("窗口3_Table1").DataSource = dt1 '将统计结果绑定到Table
With DataTables("窗口3_Table1").DataCols '用表达式列计算库存数据
.Add("库存_数量",Gettype(Integer), "ISNULL([进货_数量],0) - ISNULL([销售_数量],0) - ISNULL([退货_数量],0)")
.Add("库存_金额",Gettype(Double), "[库存_数量] /[进货_数量] * [进货_金额]")
.Add("上期库存_数量",Gettype(Integer), "ISNULL([上期_进货_数量],0) - ISNULL([上期_销售_数量],0) - ISNULL([上期_退货_数量],0)")
.Add("上期库存_金额",Gettype(Double),"[上期库存_数量] /[上期_进货_数量] * [上期_进货_金额]")
End With