下面代码是逻辑3,根据你产品数量表的产品,平均生成
Dim dt1 As DataTable = DataTables("产品数量")
Dim dt2 As DataTable = DataTables("BOM")
Dim dt3 As DataTable = DataTables("物料库存")
Dim dic_wl As new Dictionary(Of String, Double)
For Each dr As DataRow In dt3.Select("")
dic_wl.add(dr("材料分类") & dr("材料名称") & dr("型号规格"), dr("库存"))
Next
Dim dic_bom As new Dictionary(Of String, List(of DataRow))
Dim canloop As Boolean = False
dt1.ReplaceFor("生产数量", 0)
Do While canloop = False
canloop = True
For Each dr As DataRow In dt1.DataRows
Dim str As String = dr("产品分类") & dr("型号") & dr("规格")
If dic_bom.ContainsKey(str) = False Then
Dim drs As List(Of DataRow) = dt2.Select("产品分类 + 型号 + 规格 = '" & str & "'")
dic_bom.add(str, drs)
End If
Dim cando As Boolean = True
For Each cdr As DataRow In dic_bom(str)
Dim sstr As String = cdr("材料分类") & cdr("材料名称") & cdr("型号规格")
If dic_wl.ContainsKey(sstr) = False Then
cando = False
Exit For
End If
If dic_wl(sstr) < cdr("结构用料") Then
cando = False
Exit For
End If
Next
If cando Then
For Each cdr As DataRow In dic_bom(str)
Dim sstr As String = cdr("材料分类") & cdr("材料名称") & cdr("型号规格")
dic_wl(sstr) -= cdr("结构用料")
Next
dr("生产数量") += 1
canloop = False
End If
Next
Loop