Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:目录树生成报错

1楼
weibu 发表于: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楼
有点蓝 发表于:2024/10/11 11:43:00
请上传实例测试
共2 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02734 s, 2 queries.