没看懂你要统计的东西,截图说明要统计什么。
Dim dt1 As DataTable = DataTables("MRP报表")
Dim dtb As New DataTableBuilder("mrp统计表")
dtb.AddDef("成品代码", Gettype(String), 16)
dtb.AddDef("成品名称及规格", Gettype(String), 16)
dtb.AddDef("可配套数量", Gettype(String))
dtb.AddDef("同类子料个数", Gettype(String))
Dim lbs As List(of String) = dt1.GetValues("子料类别")
For Each lb As String In lbs
dtb.AddDef(lb & "_子料代码", Gettype(String))
dtb.AddDef(lb & "_子料名称", Gettype(String))
dtb.AddDef(lb & "_库存", Gettype(String))
dtb.AddDef(lb & "_在途采购", Gettype(String))
Next
dtb.Build()
Dim dt2 As Table = Tables("mrp统计表")
For Each dm As String() In dt1.GetValues("成品代码|成品名称及规格")
Dim nr As Row = dt2.AddNew
nr("成品代码") = dm(0)
nr("成品名称及规格") = dm(1)
Dim min As Double = 99999
For Each lbei As String In dt1.GetValues("子料类别","成品代码='" & dm(0) & "' And 成品名称及规格='" & dm(1) & "'")
Dim dr As DataRow = dt1.Find("成品代码='" & dm(0) & "' And 成品名称及规格='" & dm(1) & "' and 子料类别='" & lbei & "'","子料库存数量")
If dr IsNot Nothing
nr(lbei & "_子料代码") = dr("子料代码")
nr(lbei & "_子料名称") = dr("子料名称及规格")
nr(lbei & "_库存") = dr("子料库存数量")
nr(lbei & "_在途采购") = dr("子料在途采购")
If min > dr("子料库存数量") Then
min = dr("子料库存数量")
End If
End If
Next
nr("可配套数量") = min
Next
MainTable= dt2