Dim Filter ,f3 As String
With e.Form.Controls("仓库名称")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "仓库名称 = '" & .Value & "'"
f3 = "仓库名称 = '" & .Value & "'"
End If
End With
With e.Form.Controls("产品编码")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "编号 = '" & .Value & "'"
End If
End With
Dim m1 As String = DataTables("库存").Compute("max(月)",Filter )
Dim dict As new Dictionary(of String,Date)
For Each y As String In DataTables("月结记录表").GetValues("仓库名称",f3 )
Dim d As Date = DataTables("月结记录表").Compute("max(结束时间)","仓库名称='" & y & "'")
dict.Add(y,d)
Next
Dim f2 As String = "1=2 "
For Each key As String In dict.Keys
f2 = f2 & "or ( 仓库名称 ='" & key & "' and 单据日期 > #" & dict(key) & "#)"
Next
With e.Form.Controls("产品编码")
If .Value IsNot Nothing Then
If f2>"" Then
f2= f2 & " And "
End If
f2= f2 & "编号 = '" & .Value & "'"
End If
End With
Dim bd1 As New GroupTableBuilder("统计表1",DataTables("出入库明细"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("编号") '根据编号分组
bd1.Groups.AddDef("仓库名称") '根据编号分组
bd1.Totals.AddDef("入库数","入库数量") '对数量进行统计
bd1.Filter = f2
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 = f2
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 = "月='" & m1 & "'" & iif(filter > ""," and ","") & filter
dt3 = bd3.BuildDataSource()
Dim nms() As String = {"编号","仓库名称"}
dt3 = bd3.BuildDataSource()
dt1.Combine(nms,dt2,nms) '将销售统计数据组合到进货统计数据
dt1.Combine(nms,dt3,nms) '将退货统计数据组合到进货统计数据
Tables("窗口1_Table1").DataSource = dt1
With DataTables("窗口1_Table1").DataCols '用表达式列计算库存数据
.Add("库存数量",Gettype(Integer), "IsNull([上月结存],0) + ISNULL([入库数量],0) - ISNULL([出库数量],0)")
End With