老师您好!
我设计了第一个计算库存的模式,运行正常,但是缺陷是分别从期初表,入库表中的ylggddm中分别取不同值,形成一个字段然后再取不同值形成规格表再参加计算,目的是将原料的规格取值取完全后形成规格表,再依此计算出库表,最终形成库存表。我感到很麻烦。我又用帮助中的形成组合统计结果的方式,又设计一个计算库存的模式,运行也正常,但缺陷是只能显示ylggddm一个分组列,其他内容如供应商、原料名称等字段不知道怎么显示到统计结果中,再就是只能在窗口的table表中显示,怎么形成第一个模式的统计表?我的想法将两种模式的优点组合起来,不知道怎么才能实现?我将代码给您,请指教!
第一个模式
Dim dtb As New DataTableBuilder("原料库存")
dtb.AddDef("ylggddm", Gettype(String), 26)
dtb.AddDef("供应商", Gettype(String), 8)
dtb.AddDef("原料名称", Gettype(String), 12)
'dtb.AddDef("原料类别", Gettype(String), 4)
dtb.AddDef("原料规格", Gettype(String), 22)
dtb.AddDef("长", Gettype(String), 6)
dtb.AddDef("宽", Gettype(String), 6)
dtb.AddDef("厚", Gettype(String),6)
dtb.AddDef("期初_数量", Gettype(Double))
dtb.AddDef("期初_重量", Gettype(Double))
dtb.AddDef("期初_含税额", Gettype(Double))
dtb.AddDef("入库_数量", Gettype(Double))
dtb.AddDef("入库_重量", Gettype(Double))
dtb.AddDef("入库_含税额", Gettype(Double))
dtb.AddDef("出库_数量", Gettype(Double))
dtb.AddDef("出库_重量", Gettype(Double))
dtb.AddDef("出库_含税额", Gettype(Double))
dtb.Build()
'计算原料期初数据
For Each nm As String In DataTables("规格表").GetValues("ylggddm")
Dim dr As DataRow = DataTables("原料库存").AddNew()
Dim pr As DataRow = DataTables("规格表").find("ylggddm='" & nm & "'")
dr("ylggddm") = nm
dr("供应商") = pr("供应商")
dr("原料名称") = pr("ylmc")
' dr("原料类别") = pr("yllb")
dr("原料规格") = pr("原料规格")
dr("长") = pr("长")
dr("宽") = pr("宽")
dr("厚") = pr("厚")
dr("期初_数量") = DataTables("ylqcb").Compute("Sum(期初_数量)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("期初_重量") = DataTables("ylqcb").Compute("Sum(期初_重量)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("期初_含税额") = DataTables("ylqcb").Compute("Sum(期初_含税额)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("入库_数量") = DataTables("ylrkb").Compute("Sum(入库_数量)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("入库_重量") = DataTables("ylrkb").Compute("Sum(入库_重量)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("入库_含税额") = DataTables("ylrkb").Compute("Sum(入库_含税额)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("出库_数量") = DataTables("ylckb").Compute("Sum(出库_数量)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("出库_重量") = DataTables("ylckb").Compute("Sum(出库_重量)","[ylggddm] = '" & dr("ylggddm") & "'")
dr("出库_含税额") = DataTables("ylckb").Compute("Sum(出库_含税额)","[ylggddm] = '" & dr("ylggddm") & "'")
Next
With DataTables("原料库存").DataCols '用表达式列计算库存数据
.Add("库存_数量",Gettype(Double), "IsNull([期初_数量],0)+isnull([入库_数量],0)-ISNULL([出库_数量],0)")
.Add("库存_重量",Gettype(Double), "IsNull([期初_重量],0)+isnull([入库_重量],0)-ISNULL([出库_重量],0)")
.Add("库存_含税额",Gettype(Double), "IsNull([期初_含税额],0)+isnull([入库_含税额],0)-ISNULL([出库_含税额],0)")
End With
MainTable= Tables("原料库存")
Tables("新原料库存计算_table1").datasource=DataTables("原料库存")
第二个模式
Dim bd1 As New GroupTableBuilder("库存统计表1",DataTables("ylqcb"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("ylggddm") '根据ylggddm分组
'bd1.Groups.AddDef("供应商")
'bd1.Groups.AddDef("ylmc")
'bd1.Groups.AddDef("原料规格")
bd1.Totals.AddDef("期初_数量","期初_数量")
bd1.Totals.AddDef("期初_重量","期初_重量")
bd1.Totals.AddDef("期初_含税额","期初_含税额")
'bd1.Subtotal = True
dt1 = bd1.BuildDataSource()
'MainTable = Tables("库存统计表1") '打开生成的统计表
Dim bd2 As New GroupTableBuilder("库存统计表2",DataTables("ylrkb"))
Dim dt2 As fxDataSource
bd2.Groups.AddDef("ylggddm")
'bd1.Groups.AddDef("供应商")
'bd1.Groups.AddDef("ylmc")
'bd1.Groups.AddDef("原料规格")
bd2.Totals.AddDef("入库_数量","入库_数量")
bd2.Totals.AddDef("入库_重量","入库_重量")
bd2.Totals.AddDef("入库_含税额","入库_含税额")
bd2.Subtotal = True
dt2 = bd2.BuildDataSource()
'MainTable = Tables("库存统计表2") '打开生成的统计表
Dim bd3 As New GroupTableBuilder("库存统计表3",DataTables("ylckb"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("ylggddm")
'bd1.Groups.AddDef("供应商")
'bd1.Groups.AddDef("ylmc")
'bd1.Groups.AddDef("原料规格")
bd3.Totals.AddDef("出库_数量","出库_数量")
bd3.Totals.AddDef("出库_重量","出库_重量") '
bd3.Totals.AddDef("出库_含税额","出库_含税额")
bd3.Subtotal = True
dt3 = bd3.BuildDataSource()
'MainTable = Tables("库存统计表3") '打开生成的统计表
dt1.Combine("ylggddm",dt2,"ylggddm") '将入库统计数据组合到期初统计数据
'dt1.Combine("供应商",dt2,"供应商") '将入库统计数据组合到期初统计数据
'dt1.Combine("ylmc",dt2,"ylmc") '将入库统计数据组合到期初统计数据
'dt1.Combine("原料规格",dt2,"原料规格") '将入库统计数据组合到期初统计数据
dt1.Combine("ylggddm",dt3,"ylggddm") '将出库统计数据组合到期初统计数据
'dt1.Combine("供应商",dt3,"供应商") '将入库统计数据组合到期初统计数据
'dt1.Combine("ylmc",dt3,"ylmc") '将入库统计数据组合到期初统计数据
'dt1.Combine("原料规格",dt3,"原料规格") '将入库统计数据组合到期初统计数据
Tables("库存新计算_Table1").DataSource = dt1 '将统计结果绑定到Table
With DataTables("库存新计算_Table1").DataCols
.Add("库存_数量",Gettype(Double), "IsNull([期初_数量],0) +ISNULL([入库_数量],0) - ISNULL([出库_数量],0)")
.Add("库存_重量",Gettype(Double), "IsNull([期初_重量],0) +ISNULL([入库_重量],0) - ISNULL([出库_重量],0)")
.Add("库存_含税额",Gettype(Double), "IsNull([期初_含税额],0) +ISNULL([入库_含税额],0) - ISNULL([出库_含税额],0)")
End With