resource_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_resource_left_menu : 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.     public void BindTree()
  29.     {
  30.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["oaconnection"].ConnectionString);
  31.         SqlDataAdapter sda = new SqlDataAdapter("select a.id,name,menu_url,parent_id,target,is_open,is_dir from oa_sys_child_menu" +
  32.             " 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" +
  33.             " a.id=16 and c.id=" + Session["user_id"], con);
  34.         DataSet ds = new DataSet();
  35.         sda.Fill(ds, "1");
  36.         TreeNode parentnode;
  37.         TreeNode childnode;
  38.         TreeNode townnode;
  39.         TreeNode townnode1;
  40.         //TreeView1.ShowLines = true;
  41.         foreach (DataRow parentrow in ds.Tables["1"].Rows)
  42.         {
  43.             //绑定第一层节点
  44.             parentnode = new TreeNode(parentrow["name"].ToString(), parentrow["id"].ToString(), "../Images/tree/folder.gif");
  45.             //运行时候先不展开子节点
  46.             parentnode.Expanded = true;
  47.             parentnode.NavigateUrl = (parentrow["menu_url"]).ToString();
  48.             parentnode.Target = (parentrow["target"]).ToString();
  49.             TreeView1.Nodes.Add(parentnode);
  50.             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 " +
  51.                 "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);
  52.             adapter.Fill(ds, "2");
  53.             if (ds.Tables["2"].Rows.Count > 0)
  54.             {
  55.                 //绑定第二层节点
  56.                 foreach (DataRow childrow in ds.Tables["2"].Rows)
  57.                 {
  58.                     childnode = new TreeNode(childrow["name"].ToString(), childrow["id"].ToString(), "../Images/tree/folder.gif");
  59.                     parentnode.ChildNodes.Add(childnode);
  60.                     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" +
  61.                         " 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() , con);
  62.                     adapter2.Fill(ds, "3");
  63.                     childnode.Expanded = true;
  64.                     childnode.NavigateUrl = childrow["menu_url"].ToString();
  65.                     childnode.Target = (childrow["target"]).ToString();
  66.                     if (ds.Tables["3"].Rows.Count > 0)
  67.                     {
  68.                         //绑定第三层节点
  69.                         foreach (DataRow townrow in ds.Tables["3"].Rows)
  70.                         {
  71.                             townnode = new TreeNode(townrow["name"].ToString(), townrow["id"].ToString(), "../Images/tree/folder.gif");
  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" +
  73.                                 " 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() , con);
  74.                             adapter3.Fill(ds, "4");
  75.                             townnode.Expanded = false;
  76.                             childnode.ChildNodes.Add(townnode);
  77.                             townnode.NavigateUrl = (townrow["menu_url"]).ToString();
  78.                             townnode.Target = (townrow["target"]).ToString();
  79.                             if (ds.Tables["4"].Rows.Count > 0)
  80.                             {
  81.                                 foreach (DataRow townrow1 in ds.Tables["4"].Rows)
  82.                                 {
  83.                                     townnode1 = new TreeNode(townrow1["name"].ToString(), townrow1["id"].ToString(), "../Images/tree/folder.gif");
  84.                                     townnode.ChildNodes.Add(townnode1);
  85.                                     townnode1.NavigateUrl = (townrow1["menu_url"]).ToString();
  86.                                     townnode1.Target = (townrow1["target"]).ToString();
  87.                                 }
  88.                                 ds.Tables["4"].Clear();
  89.                             }
  90.                         } ds.Tables["3"].Clear();
  91.                     }
  92.                 }
  93.                 ds.Tables["2"].Clear();
  94.             }
  95.         }
  96.         con.Close();
  97.     }
  98. }