以文本方式查看主题

-  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=24346)

--  作者:blackzhu
--  发布时间:2012/10/11 11:16:00
--  [求助]怎么计算新加的数据
根据帮助的零件计算代码:

Dim dic As new Dictionary(of String,Integer)
For Each dr1 As DataRow In DataTables("生产计划").DataRows
    For
Each dr2 As DataRow In DataTables("零件用量").Select("[产品] = \'" & dr1("产品") & "\'")
        Dim
nm As String = dr2("零件")
        Dim
vl As Integer = dr1("生产数量") * dr2("用量")
        If
dic.ContainsKey(nm) = False
            dic.Add(nm,vl)

        Else

            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(
"需求数量") = dic(key)
Next



  根据这个代码  如果在生产计划再添加新的产品和数量   我怎么执行这个代码?


  前提是不能清除已经计算过的零件了!!!!!!!


--  作者:woiz
--  发布时间:2012/10/11 11:26:00
--  

新增行的时候加判断

For Each key As String In dic.keys
    if datatables("零件需求").find("零件= \'" & key & "\'") is nothing then
       Dim dr As DataRow = DataTables("零件需求").AddNew()
       dr("零件") = key
       dr("需求数量") = dic(key)
     end if
Next


--  作者:blackzhu
--  发布时间:2012/10/11 11:46:00
--  
谢谢!鱼儿 明白,我没有想到.