参考代码
Dim lbl3,lbl4 As WinForm.DateTimePicker
lbl3 = e.Form.Controls("DateTimePicker3")
lbl4 = e.Form.Controls("DateTimePicker4")
e.Form.Controls("打印预览").Enabled = False
e.Form.Controls("直接打印").Enabled = False
Dim bd1 As New GroupTableBuilder("统计表1",DataTables("商品库存"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("Item") '根据型号分组
bd1.Groups.AddDef("EnglishDescription") '根据型号分组
bd1.Groups.AddDef("ChineseDescription") '根据型号分组
bd1.Groups.AddDef("EnglishBrand") '根据型号分组
bd1.Groups.AddDef("ChineseBrand") '根据型号分组
bd1.Groups.AddDef("ItemCategory") '根据型号分组
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表2",DataTables("出入记录"))
bd2.Filter = "[作业时间] >= # " & lbl3.value & "# and [作业时间] <= # " & lbl4.value & " # and 操作类型 = '入库'"
Dim dt2 As fxDataSource
bd2.Groups.AddDef("货品编号") '根据型号分组
bd2.Totals.AddDef("数量","入库_数量") '对数量进行统计
dt2 = bd2.BuildDataSource()
Dim bd3 As New GroupTableBuilder("统计表3",DataTables("出入记录"))
bd3.Filter = "[作业时间] >= # " & lbl3.value & "# and [作业时间] <= # " & lbl4.value & " # and 操作类型 = '出库'"
Dim dt3 As fxDataSource
bd3.Groups.AddDef("货品编号") '根据型号分组
bd3.Totals.AddDef("数量","出库_数量") '对数量进行统计
dt3 = bd3.BuildDataSource()
dt1.Combine("Item",dt2,"货品编号") '将销售统计数据组合到进货统计数据
dt1.Combine("Item",dt3,"货品编号") '将退货统计数据组合到进货统计数据
e.Form.Controls("提示").text = "日报表统计"
Tables("报表统计_Table1").DataSource = dt1 '将统计结果绑定到Table
Dim t As Table = Tables("报表统计_Table1")
Dim d As Date = lbl3.Value
t.StopRedraw
Do While d <= lbl4.Value
t.DataTable.DataCols.Add(d & "_in", Gettype(Double))
t.DataTable.DataCols.Add(d & "_out", Gettype(Double))
For Each r As Row In t.Rows
Dim filter As String = "作业时间 = #" & d & "# and 货品编号 = '" & r("item") & "'"
r(d & "_in") = DataTables("出入记录").Compute("sum(数量)", filter & " and 操作类型 = '入库'")
r(d & "_out") = DataTables("出入记录").Compute("sum(数量)", filter & " and 操作类型 = '出库'")
Next
d = d.AddDays(1)
Loop
t.ResumeRedraw