以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  递归函数计算物料成本的问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=64884)

--  作者:able
--  发布时间:2015/3/4 11:35:00
--  递归函数计算物料成本的问题
以下代码是:内部函数
Dim nd As WinForm.TreeNode = args(0)
Dim dt As DataTable = args(1)
Dim je As Double = args(2)
Dim yl As Double = args(3)
Dim drs As List(of DataRow)
drs = dt.Select("[父键] = \'" & nd.name & "\'")
If drs.Count = 0 Then
    nd.Text &= "   成本:" & je
    Return je
Else
    Dim sum As Double = 0
    For Each dr As DataRow In drs
        Dim cd As Winform.TreeNode = nd.Nodes.Add(dr("键"),dr("物料名称"))
        sum += Functions.Execute("bom",cd,dt,dr("金额"),dr("需求数量"))
    Next
    sum = sum*yl
    nd.Text &= "   成本:" & sum
    Return sum
End If

以下代码是在目录树:用来返回物料成本
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
Dim dt As DataTable = DataTables("表A")
tr.StopRedraw()
tr.Nodes.Clear
tr.Nodes.Add("全部")
For Each dr As DataRow In dt.Select("父键 is null")
    nd = tr.Nodes.Add(dr("键"),dr("物料名称"))
    Functions.Execute("bom",nd,dt,0,dr("需求数量"))
Next
tr.ResumeRedraw()

我想问一下:如何用同样的原理,将物料成本输出至数据表对应的行.

--  作者:有点甜
--  发布时间:2015/3/4 11:41:00
--  

以下代码是:内部函数
Dim nd As WinForm.TreeNode = args(0)
Dim dt As DataTable = args(1)
Dim je As Double = args(2)
Dim yl As Double = args(3)
Dim cdr As DataRow = args(4)
Dim drs As List(of DataRow)
drs = dt.Select("[父键] = \'" & nd.name & "\'")
If drs.Count = 0 Then
    nd.Text &= "   成本:" & je
    Return je
Else
    Dim sum As Double = 0
    For Each dr As DataRow In drs
        Dim cd As Winform.TreeNode = nd.Nodes.Add(dr("键"),dr("物料名称"))
        sum += Functions.Execute("bom",cd,dt,dr("金额"),dr("需求数量"),dr)
    Next
    sum = sum*yl
    nd.Text &= "   成本:" & sum
    cdr("成本") = sum
    Return sum
End If


以下代码是在目录树:用来返回物料成本
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
Dim dt As DataTable = DataTables("表A")
tr.StopRedraw()
tr.Nodes.Clear
tr.Nodes.Add("全部")
For Each dr As DataRow In dt.Select("父键 is null")
    nd = tr.Nodes.Add(dr("键"),dr("物料名称"))
    Functions.Execute("bom",nd,dt,0,dr("需求数量"),dr)
Next
tr.ResumeRedraw()