Dim filter1 As String
filter1="日期 >= #" & e.Form.Controls("startdate").value & "# " & " And 日期 <= #" & e.Form.Controls("enddate").value & "#"
Dim bd1 As New SQLGroupTableBuilder("统计表1","销售单")
bd1.ConnectionName = "wjhansdata"
Dim dt1 As fxDataSource
bd1.Groups.AddDef("客户编码") '根据型号分组
bd1.Groups.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.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("期初金额","期初金额") '对数量进行统计
dt5 = bd5.BuildDataSource()
Dim nms1 As String() = {"客户编码","客户名称"} '指定连接列
Dim nms2 As String() = {"客户编码","客户名称"} '指定连接列
dt5.Combine(nms1,dt1,nms1) '将销售统计数据组合到进货统计数据
dt5.Combine(nms1,dt2,nms2) '将退货统计数据组合到进货统计数据
dt5.Show("统计表5")
'Tables(e.form.Name & "_Table1").DataSource = dt5 '将统计结果绑定到Table
msgbox("3")
'''
DataTables("销售单").LoadFilter = ""
DataTables("销售单").Load
DataTables("资金收付明细单").LoadFilter = ""
DataTables("资金收付明细单").Load
'msgbox(1)
Dim dt As DataTable = DataTables("统计表5")
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 日期 < #" & e.Form.Controls("startdate").value & "#"
Dim drs As List(Of DataRow) = DataTables("销售单").Select(filter2)
Dim s5 As Double = 0
For Each cdr As DataRow In drs
If cdr("日期") < e.Form.Controls("startdate").value Then
s5 += cdr("金额")
End If
Next
filter2="单位编码 = '" & dr("客户编码") & "' And 日期 < #" & e.Form.Controls("startdate").value & "#"
drs = DataTables("资金收付明细单").Select(filter2)
Dim s6 As Double = 0
For Each cdr As DataRow In drs
If cdr("日期") < e.Form.Controls("startdate").value Then
s6 += cdr("借方金额")
End If
Next
dr("期初金额") += s5-s6
Next
'
'msgbox(2)
'''''
With DataTables("统计表5").DataCols '用表达式列计算库存数据
.Add("余额",Gettype(Double), "IsNull([期初金额],0)+ IsNull([销售金额],0)-ISNULL([收款金额],0)")
End With
'用表达式列计算库存数据
Forms("2").open()
[此贴子已经被作者于2016/8/4 14:14:01编辑过]