Foxtable(狐表)用户栏目专家坐堂 → [求助] 请教目录树代码简化


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

主题:[求助] 请教目录树代码简化

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


加好友 发短信
等级:三尾狐 帖子:746 积分:6673 威望:0 精华:1 注册:2008/9/1 11:46:00
[求助] 请教目录树代码简化  发帖心情 Post By:2011/10/19 7:34:00 [只看该作者]

                这段代码是不同用户显示不同目录树,如果登录用户多时,这样代码就太长,不知是否能更简化一点,请大家帮忙,谢谢!

'下面代码是限定目录树中显示的表名(节点)

Select Case User.name
   Case "开发者"
Dim  Ls As String() = {"表A","表B","表C"}
Dim s,sql As String
For Each s In Ls
    sql+ = " UNION Select '表' As 表,'" & s & "' As 表名 ,年,月 From{" & s & "} "
Next
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = sql.Substring(7) 

dt = cmd.ExecuteReader()
'生成目录树
Dim tv As WinForm.TreeView
tv =e.Form.Controls("TreeView1")
tv.BuildTree(dt,"表|表名|年|月")


    Case "张三"
Dim  Ls As String() = {"表A","表B"}
Dim s,sql As String
For Each s In Ls
    sql+ = " UNION Select '表' As 表,'" & s & "' As 表名 ,年,月 From{" & s & "} "
Next
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = sql.Substring(7) 

dt = cmd.ExecuteReader()
'生成目录树
Dim tv As WinForm.TreeView
tv =e.Form.Controls("TreeView1")
tv.BuildTree(dt,"表|表名|年|月")

 Case "李四"
Dim  Ls As String() = {"表C","表B"}
Dim s,sql As String
For Each s In Ls
    sql+ = " UNION Select '表' As 表,'" & s & "' As 表名 ,年,月 From{" & s & "} "
Next
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = sql.Substring(7) 
dt = cmd.ExecuteReader()
'生成目录树
Dim tv As WinForm.TreeView
tv =e.Form.Controls("TreeView1")
tv.BuildTree(dt,"表|表名|年|月")
End Select


'

[此贴子已经被作者于2011-10-19 7:34:53编辑过]

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


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/10/19 7:49:00 [只看该作者]

Dim  Ls As String()
Select Case User.name
    Case "开发者"
        ls = new String () {"表A","表B","表C"}
    Case "张三"
        ls = new String () {"表A","表B"}
    Case "李四"
        ls = new String () {"表B","表C"}
End Select
Dim s,sql As String
For Each s In Ls
    sql+ = " UNION Select '表' As 表,'" & s & "' As 表名 ,年,月 From{" & s & "} "
Next
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = sql.Substring(7)
dt = cmd.ExecuteReader()
'生成目录树
Dim tv As WinForm.TreeView
tv =e.Form.Controls("TreeView1")
tv.BuildTree(dt,"表|表名|年|月")
 
[此贴子已经被作者于2011-10-19 8:13:20编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
老有所乐
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:746 积分:6673 威望:0 精华:1 注册:2008/9/1 11:46:00
[求助] 请教目录树代码简化  发帖心情 Post By:2011/10/19 8:12:00 [只看该作者]

谢谢贺老师

 回到顶部