e.Form.Controls("Table3").Visible = True
Dim Filter As String
With e.Form.Controls("StartDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 >= #" & .Value & "# "
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 <= #" & .Value & "# "
End If
End With
DataTables("采购明细表").LoadFilter = ""
DataTables("采购明细表").Load
DataTables("出库明细表").loadFilter = ""
DataTables("出库明细表").load
DataTables("商品名称附表").loadFilter = ""
DataTables("商品名称附表").load
Dim bd1 As New GroupTableBuilder("统计表1",DataTables("商品名称附表"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("仓库名称")
bd1.Groups.AddDef("商品类别")
bd1.Groups.AddDef("商品编号")
bd1.Groups.AddDef("商品名称")
bd1.Groups.AddDef("规格型号")
bd1.Groups.AddDef("单位")
bd1.Totals.AddDef("期初数量","期初_数量")
bd1.Totals.AddDef("期初金额","期初_金额") '对数量进行统计
Dim max As Date = DataTables("商品名称附表").Compute("max(日期)", "日期 <='" & e.Form.Controls("EndDate").value & "'")
bd1.Filter = "日期 = '" & max & "'"
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表2",DataTables("采购明细表"))
Dim dt2 As fxDataSource
bd2.Groups.AddDef("仓库名称")
bd2.Groups.AddDef("商品类别")
bd2.Groups.AddDef("商品编号")
bd2.Groups.AddDef("商品名称")
bd2.Groups.AddDef("规格型号")
bd2.Groups.AddDef("单位")
bd2.Totals.AddDef("数量","采购_数量") '对数量进行统计
bd2.Totals.AddDef("金额","采购_金额")
bd2.Filter = Filter
dt2 = bd2.BuildDataSource()
Dim bd3 As New GroupTableBuilder("统计表3",DataTables("出库明细表"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("仓库名称")
bd3.Groups.AddDef("商品类别")
bd3.Groups.AddDef("商品编号")
bd3.Groups.AddDef("商品名称")
bd3.Groups.AddDef("规格型号")
bd3.Groups.AddDef("单位")
bd3.Totals.AddDef("数量","出库_数量") '对数量进行统计
bd3.Totals.AddDef("金额","出库_金额")
bd3.Filter = Filter
dt3 = bd3.BuildDataSource()
Dim nms As String() = {"仓库名称","商品类别","商品编号","商品名称","规格型号","单位"} '指定连接列
dt1.Combine(nms,dt2,nms) '将销售统计数据组合到进货统计数据
dt1.Combine(nms,dt3,nms)
Tables("库存管理_Table3").DataSource = dt1 '将统计结果绑定到Table
Dim dt As DataTable = DataTables("库存管理_Table3")
For Each dr As DataRow In dt.DataRows
Dim filter2 As String
filter2="商品编号 = '" & dr("商品编号") & "'and 仓库名称 = '" & dr("仓库名称") & "'"
Dim drs As List(Of DataRow) = DataTables("采购明细表").Select(filter2)
Dim s1 As Double = 0
Dim s2 As Double = 0
For Each cdr As DataRow In drs
If cdr("日期") < e.Form.Controls("startdate").value Then
s1 += cdr("数量")
s2 += cdr("金额")
End If
Next
drs = DataTables("出库明细表").Select(filter2)
Dim s3 As Double = 0
Dim s4 As Double = 0
For Each cdr As DataRow In drs
If cdr("日期") < e.Form.Controls("startdate").value Then
s3 += cdr("数量")
s4 += cdr("金额")
End If
Next
dr("期初_数量") += s1 - s3
dr("期初_金额") += s2 - s4
Next
With DataTables("库存管理_Table3").DataCols '用表达式列计算库存数据
.Add("期末_数量",Gettype(Double), "IsNull([期初_数量],0) + ISNULL([采购_数量],0) - ISNULL([出库_数量],0)")
.Add("期末_金额",Gettype(Double), "IsNull([期初_金额],0) + ISNULL([采购_金额],0) - ISNULL([出库_金额],0)")
End With
Tables("库存管理_Table3").SetColVisibleWidth("仓库名称|70|商品类别|70|商品编号|70|商品名称|90|规格型号|90|单位|50|期初_数量|50|期初_金额|70|采购_数量|50|采购_金额|70|出库_数量|50|出库_金额|70|期末_数量|50|期末_金额|70")
Tables("库存管理_Table3").Sort = "商品类别,商品编号"
Tables("库存管理_Table3").Cols("期初_数量").GrandTotal = True
Tables("库存管理_Table3").Cols("期初_金额").GrandTotal = True
Tables("库存管理_Table3").Cols("采购_数量").GrandTotal = True
Tables("库存管理_Table3").Cols("采购_金额").GrandTotal = True
Tables("库存管理_Table3").Cols("出库_数量").GrandTotal = True
Tables("库存管理_Table3").Cols("出库_金额").GrandTotal = True
Tables("库存管理_Table3").Cols("期末_数量").GrandTotal = True
Tables("库存管理_Table3").Cols("期末_金额").GrandTotal = True
Tables("库存管理_Table3").GrandTotal = True
Tables("库存管理_Table3").ExtendLastCol = True