use stack to initial a treeview with the data in a database

该博客代码主要实现基于数据库查询的树形数据处理。通过查询用户权限相关数据,利用栈结构对数据进行处理和排序,最终构建树形视图。涉及数据库连接、数据查询、字符串处理和树形节点操作等信息技术操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

try
   {
    if(!Page.IsPostBack)
    {

     Stack s1 = new Stack();
     Stack s2 = new Stack();
     Stack s3 = new Stack();
     s1.Push("00");
     string temp = "";
     string strSql = "select rights.right_code from rights,user_right where rights.right_code=user_right.right_code and user_right.user_code='"+Session["UserCode"].ToString()+"' order by rights.right_code desc";
     mySQL.strConn="server=localhost;database=LIMS;uid=sa;pwd=sa;";
     DataView dv = (DataView)mySQL.ExecuteDataSource(strSql);
     for(int i=0;i<dv.Count;i++)
     {
     
      while(s1.Count>0)
      {
       temp = s1.Pop().ToString();
       if(temp != dv[i]["RIGHT_CODE"].ToString().Substring(0,temp.Length))
        break;
      }
      s1.Push(temp);
      for(int j=dv[i]["RIGHT_CODE"].ToString().Length/2;j>0;j--)
       s1.Push(dv[i]["RIGHT_CODE"].ToString().Substring(0,2*j));
     }
     while(s1.Count>0)
     {
      s2.Push(s1.Pop());
     }
     s2.Pop();
     //È¡Ê÷ÐÍÊý¾ÝÅÅÁÐs2

     strSql = "select right_code,right_name,page_code from rights order by right_code";
     dv.Dispose();
     dv = (DataView)mySQL.ExecuteDataSource(strSql);
     dv.Sort = "right_code";
     DataRowView drv;
     while(s2.Count>0)
     {
      temp = s2.Pop().ToString();
      Microsoft.Web.UI.WebControls.TreeNode cc = new Microsoft.Web.UI.WebControls.TreeNode();     
      drv = dv.FindRows(temp)[0];
      if(drv["Page_Code"].ToString()=="")
      {
       cc.Text = drv["right_name"].ToString();
       while(s3.Count>0)
       {
        temp = s1.Pop().ToString();
        if(temp.Length>drv["right_code"].ToString().Length)
         cc.Nodes.Add((Microsoft.Web.UI.WebControls.TreeNode)s3.Pop());
        else
        {
         s1.Push(temp);
         break;
        }
       }
      }
      else
      {
       cc.Text = drv["right_name"].ToString();

       cc.NavigateUrl = drv["page_code"].ToString().Substring(0,drv["page_code"].ToString().IndexOf(';'));

//as frame used, using following coding to set target of a hyperlink

//       if(cc.Text=="select checkout") //       {
//        cc.Target="_blank";
//       }
//       else
//       {
        cc.Target = "main";
//       }
      }
      s3.Push(cc);
      s1.Push(drv["right_code"].ToString());
     }
     while(s3.Count>0)
      this.TreeView1.Nodes.Add((Microsoft.Web.UI.WebControls.TreeNode)s3.Pop());
     s1.Clear();
    }
   }
   catch
   {return;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值