Dim dtb As New DataTableBuilder("原料库存")
dtb.AddDef("ylggdm", 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("ylggb").GetValues("ylggdm")
Dim dr As DataRow = DataTables("原料库存").AddNew()
Dim pr As DataRow = DataTables("ylggb").find("ylggdm='" & nm & "'")
dr("ylggdm") = nm
dr("供应商") = pr("供应商")
'dr("原料名称") = pr("原料名称")
dr("原料类别") = pr("yllb")
dr("原料规格") = pr("原料规格")
dr("长") = pr("长")
dr("宽") = pr("宽")
dr("厚") = pr("厚")
dr("期初_数量") = DataTables("ylqcb").Compute("Sum(期初_数量)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("期初_重量") = DataTables("ylqcb").Compute("Sum(期初_重量)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("期初_含税额") = DataTables("ylqcb").Compute("Sum(期初_含税额)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("入库_数量") = DataTables("ylrkb").Compute("Sum(入库_数量)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("入库_重量") = DataTables("ylrkb").Compute("Sum(入库_重量)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("入库_含税额") = DataTables("ylrkb").Compute("Sum(入库_含税额)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("出库_数量") = DataTables("ylckb").Compute("Sum(出库_数量)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("出库_重量") = DataTables("ylckb").Compute("Sum(出库_重量)","[ylggdm] = '" & dr("ylggdm") & "'")
dr("出库_含税额") = DataTables("ylckb").Compute("Sum(出库_含税额)","[ylggdm] = '" & dr("ylggdm") & "'")
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("原料库存")