没有看懂,避免出错的方法:
Public Function GenProductBom(ByVal rootid As Integer,ByVal goid As Integer,ByVal formatstr As String,ByVal NeedTotal As Double,ByVal onetotal As Double) As Boolean
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText ="Select goid,singletotal,comgoid,sf_nonstock,ord From {cp_singlebom} Inner JOIN {product} ON {product}.[_Identify] = {cp_singlebom}.[goid] where {cp_singlebom}.[goid]=" & Cstr(goid)
dt = cmd.ExecuteReader()
Dim r2 As Row = Tables("bomdata").AddNew()
r2("goid") = rootid
r2("nodegoid") = goid
r2("sortkey") = Formatstr
r2("total") = NeedTotal
r2("Singletotal") = onetotal
If dt.DataRows.Count > 0 Then
For Each dr As DataRow In dt.DataRows
Dim r As Row = Tables("tempbom").AddNew()
r("goid")=dr("comgoid")
r("singletotal") = dr("singletotal")
r("total") = dr("singletotal") * NeedTotal
r("sortkey")= Formatstr + "/" + Format(dr("ord"),"000")
Next
End If
Dim cnt As Integer = DataTables("tempbom").DataRows.Count -1
Do While DataTables("tempbom").DataRows.Count > 0
Dim r As DataRow = DataTables("tempbom").DataRows(0)
Dim dt1 As DataTable
Dim cmd1 As New SQLCommand
Dim curgoid As Integer
Dim fstr As String
Dim curSingletotal As Double = r("singletotal")
Dim curTotal As Double = r("total")
curgoid = r("goid")
fstr = r("sortkey")
'MessageBox.Show(cstr(curgoid),"info",MessageBoxButtons.OK,MessageBoxIcon.Information)
r.Delete
cmd1.CommandText = "Select goid,singletotal,comgoid,sf_nonstock,ord From {cp_singlebom} Inner JOIN {product} ON {product}.[_Identify] = {cp_singlebom}.[goid] where {cp_singlebom}.[goid]=" & CSTR(curgoid)
dt1 = cmd1.ExecuteReader()
If dt1.DataRows.Count > 0 Then
GenProductBom(rootid,curgoid,fstr,curtotal,cursingletotal)
Else
'追加到数据表中
Dim r1 As Row = Tables("bomdata").AddNew()
r1("goid") = rootid
r1("nodegoid") = curgoid
r1("sortkey") = fstr
r1("singletotal")=cursingletotal
'r1("sf_summy")= dr("sf_nonstock")
r1("total")= curtotal
End If
Loop
Return True
End Function
[此贴子已经被作者于2011-11-30 11:55:28编辑过]