Foxtable(狐表)用户栏目专家坐堂 → 目录树生成报错


  共有926人关注过本帖树形打印复制链接

主题:目录树生成报错

帅哥哟,离线,有人找我吗?
weibu
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:659 积分:5363 威望:0 精华:0 注册:2018/5/19 22:27:00
目录树生成报错  发帖心情 Post By:2024/10/11 11:05:00 [只看该作者]

Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.GenerateTree("Departments", "Path", "DepartmentName", ".")
以上是生成目录树的代码,path数据如下:
001
001.001
001.001.001
001.001.001.001
001.001.001.002
001.001.002
001.001.002.003
001.001.002.002
001.001.003
001.001.002.001

以下是添加子部门的代码:
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
If trv.SelectedNode IsNot Nothing Then
    
    Dim pd As WinForm.TreeNode = trv.SelectedNode
    Dim Index As Integer = 1
    If pd.Nodes.count >= 1 Then
        Index = CInt(pd.Nodes(pd.nodes.count - 1).name) + 1
    End If

        
    Dim nd As WinForm.TreeNode = pd.Nodes.Add(index, "请输入")
    trv.SelectedNode = nd
    trv.Select
    trv.BeginEdit
    下方代码的目的是存储新增子节点的信息:
        Dim ndr As Row = Tables("Departments").AddNew() 
        Dim p As DataRow = pd.DataRow 
        ndr("ParentDepartmentID") = p("DepartmentID")
        ndr("Level") = p("Level") + 1
        ndr("UpdateDate") = Date.Today
        ndr("UpdatedBy") = rsuser
        ndr("CompanyId") = 1
   
End If

下方代码是保存数据的代码:执行下方代码后,会删除上面新增的行,并把赋值存储到新增行上一条数据中。    这个代码哪里错误了
Dim dt As DataTable = DataTables("Departments")
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("TreeView1").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("_Identify = " & nd.DataRow("_Identify"))
    Else
       ' ndr = dt.AddNew

    End If
    idxs &= ndr("_Identify") & ","
    Dim str As String = ""
    For i As Integer = 0 To nd.Level
        str &= format(dic(i), "000") & "."
    Next
    ndr("Path") = str.TrimEnd(".")
    ndr("DepartmentName") = nd.Text
Next
dt.DeleteFor("_Identify not in (" & idxs & ")")
DataTables("Departments").Save()

同时在部门表的DataRowAdded有如下代码:
e.DataRow.save
e.DataRow("DepartmentID") = e.DataRow("_Identify")

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111393 积分:567029 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2024/10/11 11:43:00 [只看该作者]

请上传实例测试

 回到顶部