Dim dt As DataTable = DataTables("收入分类")
Dim dic As New Dictionary(of Integer, Integer)
Dim prevLevel As Integer = 0
Dim idxs As String = "-1,"
For Each nd As WinForm.TreeNode In e.Form.Controls("srflTreeView").AllNodes
If nd.Level = 0 AndAlso dic.count > 0 Then
Dim temp = dic(0)
dic.Clear
dic.Add(0, temp)
End If
If dic.ContainsKey(nd.Level) = False Then
dic.Add(nd.Level, 1)
Else
dic(nd.Level) = dic(nd.Level) + 1
End If
For i As Integer = nd.level + 1 To prevLevel
dic(i) = 0
Next
prevLevel = nd.Level
Dim ndr As DataRow
If nd.DataRow IsNot Nothing Then
ndr = dt.Find("SRID = " & nd.DataRow("SRID"))
Else
ndr = dt.AddNew
End If
idxs &= ndr("SRID") & ","
Dim str As String = ""
For i As Integer = 0 To nd.Level
str &= format(dic(i), "000") & "."
Next
ndr("收入分类代码") = str.TrimEnd(".")
ndr("收入目录") = nd.Text
Next
dt.DeleteFor("SRID not in (" & idxs & ")")
dt.Save