这段代码是不同用户显示不同目录树,如果登录用户多时,这样代码就太长,不知是否能更简化一点,请大家帮忙,谢谢!
'下面代码是限定目录树中显示的表名(节点)
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编辑过]