1、少用sqlcompute等
2、筛选条件,尽量少用日期
Dim filter1 As String
filter1="日期 >= #" & e.Form.Controls("startdate").value & "# " & " And 日期 <= #" & e.Form.Controls("enddate").value & "#"
Dim bd1 As New SQLGroupTableBuilder("统计表1","进货单明细")
Dim b As New SQLGroupTableBuilder("统计表1","订单")
bd1.ConnectionName = "wjhansdata"
Dim dt1 As fxDataSource
bd1.Groups.AddDef("产品名称") '根据型号分组
bd1.Groups.AddDef("仓库") '根据型号分组
bd1.Totals.AddDef("数量","进货_数量") '对数量进行统计
bd1.Totals.AddDef("金额","进货_金额") '对金额进行统计
bd1.Filter = filter1
dt1 = bd1.BuildDataSource()
Dim bd2 As New SqlGroupTableBuilder("统计表2","销售单明细")
bd2.ConnectionName = "wjhansdata"
Dim dt2 As fxDataSource
bd2.Groups.AddDef("产品名称") '根据型号分组
bd2.Groups.AddDef("仓库") '根据型号分组
bd2.Totals.AddDef("数量","销售_数量") '对数量进行统计
bd2.Totals.AddDef("金额","销售_金额") '对金额进行统计
bd2.Totals.AddDef("成本","销售_成本") '对金额进行统计
bd2.Filter = filter1
dt2 = bd2.BuildDataSource()
Dim bd5 As New GroupTableBuilder("统计表5",DataTables("期初库存"))
Dim dt5 As fxDataSource
bd5.Groups.AddDef("产品名称") '根据型号分组
bd5.Groups.AddDef("仓库") '根据型号分组
bd5.Totals.AddDef("期初数量","期初_数量") '对数量进行统计
bd5.Totals.AddDef("期初金额","期初_金额") '对金额进行统计
dt5 = bd5.BuildDataSource()
Dim nms As String() = {"产品名称","仓库"} '指定连接列
dt5.Combine(nms,dt1,nms) '将销售统计数据组合到进货统计数据
dt5.Combine(nms,dt2,nms) '将退货统计数据组合到进货统计数据
Tables("区间进销存_Table1").DataSource = dt5 '将统计结果绑定到Table
DataTables("进货单明细").LoadFilter = ""
DataTables("进货单明细").Load
DataTables("销售单明细").loadFilter = ""
DataTables("销售单明细").load
msgbox(1)
Dim dt As DataTable = DataTables("区间进销存_Table1")
For Each dr As DataRow In dt.DataRows
Dim filter2 As String
' filter2="产品名称 = '" & dr("产品名称") & "' and 颜色 = '" & dr("颜色") & "' and 仓库 = '" & dr("仓库") & "' and 日期 >= #" & e.Form.Controls("startdate").value & "# " & " And 日期 <= #" & e.Form.Controls("enddate").value & "#"
filter2="产品名称 = '" & dr("产品名称") & "' and 仓库 = '" & dr("仓库") & "'" ' And 日期 < #" & e.Form.Controls("startdate").value & "#"
Dim drs As List(Of DataRow) = DataTables("进货单明细").Select(filter2)
Dim s1 As Double = 0
Dim s5 As Double = 0
For Each cdr As DataRow In drs
If cdr("日期") < e.Form.Controls("startdate").value Then
s1 += cdr("数量")
s5 += cdr("金额")
End If
Next
drs = DataTables("销售单明细").Select(filter2)
Dim s2 As Double = 0
Dim s6 As Double = 0
For Each cdr As DataRow In drs
If cdr("日期") < e.Form.Controls("startdate").value Then
s1 += cdr("数量")
s5 += cdr("金额")
End If
Next
dr("期初_数量") += s1 - s2
dr("期初_金额") += s5+s6
Next
'
msgbox(2)
With DataTables("区间进销存_Table1").DataCols '用表达式列计算库存数据
.Add("库存_数量",Gettype(Integer), "IsNull([期初_数量],0)+ IsNull([进货_数量],0) - ISNULL([销售_数量],0) ")
.Add("库存_金额",Gettype(Double), "IsNull([期初_金额],0)+ IsNull([进货_金额],0) - ISNULL([销售_成本],0) ")
End With
'
Tables("区间进销存_table1").Cols("期初_数量").GrandTotal = True '指定要合计的列
Tables("区间进销存_table1").Cols("期初_金额").GrandTotal = True
Tables("区间进销存_table1").Cols("进货_数量").GrandTotal = True
Tables("区间进销存_table1").Cols("进货_金额").GrandTotal = True
Tables("区间进销存_table1").Cols("销售_数量").GrandTotal = True
Tables("区间进销存_table1").Cols("销售_金额").GrandTotal = True
Tables("区间进销存_table1").Cols("销售_成本").GrandTotal = True
Tables("区间进销存_table1").Cols("库存_数量").GrandTotal = True
Tables("区间进销存_table1").Cols("库存_金额").GrandTotal = True
Tables("区间进销存_table1").GrandTotal = True '显示合计模式
[此贴子已经被作者于2016/7/22 13:02:09编辑过]