查询系统所有存储过程,并以树形结构显示

HTML:
 1    <style type="text/css">
 2        body{font-size:9pt;}
 3        a{margin-top:1px;width:100px;float:left;clear:both;cursor:hand;border:1px solid gray;margin-left:5px;color:black;text-decoration:none;padding-left:3px;}
 4        b{margin-top:1px;width:100px;float:left;clear:both;cursor:pointer;border:1px solid gray;padding-left:3px;}
 5    
</style>
 6
 7<%=treeHtml %>
 8<script type="text/javascript">
 9    var B_tag=document.getElementsByTagName("B");
10    for(var i=0;i<B_tag.length;i++)
11    {
12        B_tag[i].onclick=function (){
13            change(event.srcElement);
14        }

15    }

16    
17    var A_tag=document.getElementsByTagName("A");
18    for(var i=0;i<A_tag.length;i++)
19    {
20        A_tag[i].href="";
21        A_tag[i].target="";    
22        A_tag[i].style.display="none"   ;
23    }

24    function change(obj)
25    {        
26        
27        var myObj=obj.nextSibling;        
28        while(myObj.tagName!="B" && myObj.tagName!="SCRIPT")
29        {       
30            if(myObj.tagName=="A")
31            {                  
32                myObj.style.display=(myObj.style.display=="none" || myObj.style.display=="")?"block":"none";
33            }

34            myObj=myObj.nextSibling;
35        }

36    }

37
</script>

C#:
        SqlConnection conn = new SqlConnection(@"server=192.168.1.102;uid=sa;pwd=123;database=test;");//

        
protected string treeHtml = string.Empty;

        
protected void Page_Load(object sender, EventArgs e)
        
{
            CreateDivTree();
        }


        
protected void CreateDivTree()
        
{
            List
<string> leftNames = new List<string>();

            
string sql = "select [name] from [sysObjects] where [xtype] = 'p' order by [name]";

            DataTable dt 
= SqlHelper.ExecuteDataset(conn,CommandType.Text,sql).Tables[0];

            
int rowCount = dt.Rows.Count;

            
if (rowCount > 0)
            
{
                
string leftName=string.Empty;

                
string name=string.Empty;

                
string nameUpper = string.Empty;

                
foreach (DataRow row in dt.Rows)
                
{
                    name 
= row["name"].ToString();

                    nameUpper 
= name.ToUpper();

                    
if (name.IndexOf("_"> 0)
                    
{
                        leftName 
= nameUpper.Substring(0, nameUpper.IndexOf("_"));
                    }

                    
else
                    
{
                        leftName 
= nameUpper.Substring(01);
                    }


                    
if (leftName == "DT" || leftName == "SP")
                    
{
                        
continue;
                    }


                    
if (!leftNames.Contains(leftName))
                    
{
                        leftNames.Add(leftName);
                        treeHtml 
+= string.Format("<B>{0}</B>", leftName);
                        treeHtml 
+= string.Format("<A>{0}</A>", name);
                    }

                    
else
                    
{
                        treeHtml 
+= string.Format("<A>{0}</A>", name);
                    }

                }

            }


        }


以前也做过类似的程序,但代码较多,加载速度较慢.

这次进行了优化,代码很少,速度很快.

posted on 2007-10-18 15:47  小子好黑  阅读(446)  评论(0编辑  收藏  举报

导航