下面这段代码功能是在当前节点,添加下级节点!
Dim trv As WinForm.TreeView = Forms("ERP界面").Controls("综合部物品分类设置TreeView1")
If trv.SelectedNode.Text <> "全部" Then
Dim t As Integer = trv.SelectedNode.Text.LastIndexOf(" ")
Dim s As String = trv.SelectedNode.Text.SubString(0,t)
Dim i As Integer = s.Length - 2
Dim s2,s3,s4 As String
Dim dr,dr1,dr2 As DataRow
Dim n,n1 As Integer
Dim dt As DataTable = Tables("综合部物品分类设置_综合部物品分类设置Table1").DataTable
dr = dt.AddNew
s2 = "SubString(分类编号, 1, " & t & ") = '" & s & "' And len(分类编号) = " & t+2
dr1 = dt.Find(s2)
If dt.DataRows.count =1 OrElse dr1 Is Nothing Then 'dt.DataRows.count =1 是因为有dr = dt.AddNew,增加了一行
dr("分类编号") = s & "01"
Else
For Each dr2 In dt.Select(s2)
n = right(dr2("分类编号"),2)
n1= iif(n1<n,n,n1)
Next
For n = 1 To n1
If dt.Find("分类编号 = '" & s & Functions.Execute("数值转换2",n) & "'") Is Nothing Then
dr("分类编号") = s & Functions.Execute("数值转换2",n)
Exit For Else
dr("分类编号") = s & Functions.Execute("数值转换2",n+1)
End If
Next
End If
End If
With Tables("综合部物品分类设置_综合部物品分类设置Table1")
.Position = .Rows.Count - 1
End With
此主题相关图片如下:未命名.jpg
按道理1004的下级节点中 100402 没有此编号 因此会执行代码中的红色部分 也就是 n=2,
dr("分类编号") = s & Functions.Execute("数值转换2",n) dr("分类编号") = “100402”,结果却是执行的else下的代码 变成了 100411..... 调试了半天不知道为什么~~~~
[此贴子已经被作者于2013-1-3 16:11:00编辑过]