Foxtable(狐表)用户栏目专家坐堂 → 目录树不限级生成优化,如果不生产多余行


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

主题:目录树不限级生成优化,如果不生产多余行

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


加好友 发短信
等级:三尾狐 帖子:659 积分:5357 威望:0 精华:0 注册:2018/5/19 22:27:00
目录树不限级生成优化,如果不生产多余行  发帖心情 Post By:2020/5/29 18:58:00 [只看该作者]

老师这段代码如何优化,不是生成多行再删除,而是仅生成一条数据
Dim dt As DataTable = DataTables("department")
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("departno") = str.TrimEnd(".")
    ndr("department") = nd.Text
Next
 dt.DeleteFor("_Identify not in (" & idxs & ")")

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110744 积分:563646 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/5/30 8:42:00 [只看该作者]

http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=122759

 回到顶部