Dim bd1 As New GroupTableBuilder("统计表1",DataTables("进货明细"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("产品代码") '根据产品代码分组
bd1.Groups.AddDef("产品名称") '根据产品代码分组
bd1.Totals.AddDef("箱","进货_件") '对数量进行统计
bd1.Filter = " 进货日期 >= #" & e.Form.Controls("StartDate").Value & "# And 进货日期 <= #" & e.Form.Controls("EedDate").Value & "# And [进货类别] = '购进'"
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表2",DataTables("销售明细"))
Dim dt2 As fxDataSource
bd2.Groups.AddDef("产品代码") '根据产品代码分组
bd2.Groups.AddDef("产品名称") '根据产品代码分组
bd2.Totals.AddDef("整件","销售_件") '对数量进行统计
bd2.Filter = " 发货日期 >= #" & e.Form.Controls("StartDate").Value & "# And 发货日期 <= #" & e.Form.Controls("EedDate").Value & "# "
dt2 = bd2.BuildDataSource()
Dim bd3 As New GroupTableBuilder("统计表3",DataTables("退货明细"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("产品代码") '根据产品代码分组
bd3.Groups.AddDef("产品名称") '根据产品代码分组
bd3.Totals.AddDef("箱","退货_件") '对数量进行统计
bd3.Filter = " 退货日期 >= #" & e.Form.Controls("StartDate").Value & "# And 退货日期 <= #" & e.Form.Controls("EedDate").Value & "# "
dt3 = bd3.BuildDataSource()
Dim bd4 As New GroupTableBuilder("统计表1",DataTables("进货明细"))
Dim dt4 As fxDataSource
bd4.Groups.AddDef("产品代码") '根据产品代码分组
bd4.Groups.AddDef("产品名称") '根据产品代码分组
bd4.Totals.AddDef("箱","进货_退厂件") '对数量进行统计
bd4.Filter = " 进货日期 >= #" & e.Form.Controls("StartDate").Value & "# And 进货日期 <= #" & e.Form.Controls("EedDate").Value & "# And [进货类别] = '退货'"
dt4 = bd4.BuildDataSource()
dt1.Combine("产品代码",dt2,"产品代码") '将销售统计数据组合到进货统计数据
dt1.Combine("产品代码",dt3,"产品代码") '将退货统计数据组合到进货统计数据
dt1.Combine("产品代码",dt4,"产品代码") '将厂家退货统计数据组合到进货统计数据
Tables("销售统计_Table1").DataSource = dt1 '将统计结果绑定到Table
With DataTables("销售统计_Table1").DataCols '用表达式列计算库存数据
.Add("库存",Gettype(Integer), "IsNull([进货_件],0) - ISNULL([销售_件],0) - ISNULL([退货_件],0)- ISNULL([进货_退厂件],0)")
End With