k_left_menu.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:5k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class web_Default : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (Session["user_id"] == null)
  17.         {
  18.             Response.Write("<script>window.open('login.aspx','_top');</script>");
  19.         }
  20.         if (!IsPostBack)
  21.         {
  22.             if (Session["user_id"] != null)
  23.             {
  24.                 BindTree();
  25.             }
  26.             
  27.         }
  28.     }
  29.     public void BindTree()
  30.     {
  31.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["oaconnection"].ConnectionString);
  32.         SqlDataAdapter sda = new SqlDataAdapter("select a.id,name,menu_url,parent_id,target,is_open,is_dir from oa_sys_child_menu as a left join oa_user_group_detail as b on a.id=b.menu_id left join oa_employee as c on b.main_id=c.user_group where a.id=8 and c.id="+Session["user_id"] , con);
  33.         DataSet ds = new DataSet();
  34.         sda.Fill(ds, "1");
  35.         TreeNode parentnode;
  36.         TreeNode childnode;
  37.         TreeNode townnode;
  38.         TreeNode townnode1;
  39.         //TreeView1.ShowLines = true;
  40.         foreach (DataRow parentrow in ds.Tables["1"].Rows)
  41.         {
  42.             //绑定第一层节点
  43.             parentnode = new TreeNode(parentrow["name"].ToString(), parentrow["id"].ToString(), "../Images/tree/folder.gif");
  44.             //运行时候先不展开子节点
  45.             parentnode.Expanded = true;
  46.             parentnode.NavigateUrl = (parentrow["menu_url"]).ToString();
  47.             parentnode.Target = (parentrow["target"]).ToString();
  48.             TreeView1.Nodes.Add(parentnode);
  49.             SqlDataAdapter adapter = new SqlDataAdapter("select a.id,name,menu_url,parent_id,target,is_open,is_dir from oa_sys_child_menu as a left join oa_user_group_detail as b on a.id=b.menu_id left join oa_employee as c on b.main_id=c.user_group where parent_id =" + parentrow["id"].ToString()+"and c.id="+Session["user_id"], con);
  50.             adapter.Fill(ds, "2");
  51.             if (ds.Tables["2"].Rows.Count > 0)
  52.             {
  53.                 //绑定第二层节点
  54.                 foreach (DataRow childrow in ds.Tables["2"].Rows)
  55.                 {
  56.                     childnode = new TreeNode(childrow["name"].ToString(), childrow["id"].ToString(), "../Images/tree/folder.gif");
  57.                     parentnode.ChildNodes.Add(childnode);
  58.                     SqlDataAdapter adapter2 = new SqlDataAdapter("select a.id,name,menu_url,parent_id,target,is_open,is_dir from oa_sys_child_menu as a left join oa_user_group_detail as b on a.id=b.menu_id left join oa_employee as c on b.main_id=c.user_group where parent_id=" + childrow["id"].ToString()+"and c.id="+Session["user_id"], con);
  59.                     adapter2.Fill(ds, "3");
  60.                     childnode.Expanded = false;
  61.                     childnode.NavigateUrl = childrow["menu_url"].ToString();
  62.                     childnode.Target = childrow["menu_url"].ToString();
  63.                     if (ds.Tables["3"].Rows.Count > 0)
  64.                     {
  65.                         //绑定第三层节点
  66.                         foreach (DataRow townrow in ds.Tables["3"].Rows)
  67.                         {
  68.                             townnode = new TreeNode(townrow["name"].ToString(), townrow["id"].ToString(), "../Images/tree/folder.gif");
  69.                             childnode.ChildNodes.Add(townnode);
  70.                             townnode.NavigateUrl = (townrow["menu_url"]).ToString();
  71.                             townnode.Target = (townrow["target"]).ToString();
  72.                             SqlDataAdapter adapter3 = new SqlDataAdapter("select a.id,name,menu_url,parent_id,target,is_open,is_dir from oa_sys_child_menu as a left join oa_user_group_detail as b on a.id=b.menu_id left join oa_employee as c on b.main_id=c.user_group where parent_id=" + townrow["id"].ToString()+"and c.id="+Session["user_id"], con);
  73.                             adapter3.Fill(ds, "4");
  74.                             townnode.Expanded = false;
  75.                             townnode.NavigateUrl = (townrow["menu_url"]).ToString();
  76.                             townnode.Target = (townrow["target"]).ToString();
  77.                             
  78.                             if (ds.Tables["4"].Rows.Count > 0)
  79.                             {
  80.                                 foreach (DataRow townrow1 in ds.Tables["4"].Rows)
  81.                                 {
  82.                                     townnode1 = new TreeNode(townrow1["name"].ToString(), townrow1["id"].ToString(), "../Images/tree/folder.gif");
  83.                                     townnode.ChildNodes.Add(townnode1);
  84.                                    
  85.                                 }
  86.                                 ds.Tables["4"].Clear();
  87.                             }
  88.                         } ds.Tables["3"].Clear();
  89.                     }
  90.                 }
  91.                 ds.Tables["2"].Clear();
  92.             }
  93.         }
  94.         con.Close();
  95.     }
  96. }