以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请老师,帮助修正,谢谢  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=145311)

--  作者:lgz518
--  发布时间:2020/1/15 17:29:00
--  请老师,帮助修正,谢谢
Dim dic As new Dictionary(of String,Integer)
DataTables("材料需求").DataRows.Clear()                                                          
For Each dr1 As DataRow In DataTables("生产工单").DataRows                                       
    For Each dr2 As DataRow In DataTables("产品BOM明细").Select("[产品名称] = \'" & dr1("产品名称") & "\'")   \'
        Dim nd As String = dr2("物料号")
        Dim nm As String = dr2("材料名称")                                                            
        Dim vl As Integer = dr1("下单数量") * dr2("材料用量")                           
        If dic.ContainsKey(nm) = False
            dic.Add(nm,vl)
        Else
            dic(nd) = dic(nd)+ vl
            dic(nm) = dic(nm)+ vl
        End If
    Next
Next
For Each key As String In dic.keys
    Dim dr As DataRow = DataTables("材料需求").AddNew()   \' 
    dr("物料号") = key                                          
    dr("品名") = key                                          
    dr("订单用量") = dic(key)                                                                
Next

--  作者:y2287958
--  发布时间:2020/1/16 8:16:00
--  
If dic.ContainsKey(nm) = False
    dic.Add(nm,vl)
Else
    dic(nm) = dic(nm)+ vl
End If
If dic.ContainsKey(nd) = False
    dic.Add(nd,vl)
Else
    dic(nd) = dic(nd)+ vl
End If

--  作者:有点蓝
--  发布时间:2020/1/16 9:12:00
--  
Dim dic As new Dictionary(of String,Integer)
DataTables("材料需求").DataRows.Clear()
For Each dr1 As DataRow In DataTables("生产工单").DataRows
    For Each dr2 As DataRow In DataTables("产品BOM明细").Select("[产品名称] = \'" & dr1("产品名称") & "\'")   \'
        Dim nd As String = dr2("物料号") & "|" & dr2("材料名称")
        Dim vl As Integer = dr1("下单数量") * dr2("材料用量")
        If dic.ContainsKey(nd) = False
            dic.Add(nd,vl)
        Else
            dic(nd) = dic(nd)+ vl
        End If
    Next
Next
For Each key As String In dic.keys
    Dim dr As DataRow = DataTables("材料需求").AddNew()   \'
    Dim ar() As String = key.Split("|")
    dr("物料号") = ar(0)
    dr("品名") = ar(1)
    dr("订单用量") = dic(key)
Next