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

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. public partial class web_data_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.         con.Open();
  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='161' 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.         foreach (DataRow parentrow in ds.Tables["1"].Rows)
  40.         {
  41.             //绑定第一层节点
  42.             parentnode = new TreeNode(parentrow["name"].ToString(), parentrow["id"].ToString(), "../Images/tree/folder.gif");
  43.             //运行时候先不展开子节点
  44.             parentnode.Expanded = true;
  45.             parentnode.NavigateUrl = (parentrow["menu_url"]).ToString();
  46.             parentnode.Target = (parentrow["target"]).ToString();
  47.             TreeView1.Nodes.Add(parentnode);
  48.             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);
  49.             adapter.Fill(ds, "2");
  50.             if (ds.Tables["2"].Rows.Count > 0)
  51.             {
  52.                 //绑定第二层节点
  53.                 foreach (DataRow childrow in ds.Tables["2"].Rows)
  54.                 {
  55.                     childnode = new TreeNode(childrow["name"].ToString(), childrow["id"].ToString(), "../Images/tree/folder.gif");
  56.                     parentnode.ChildNodes.Add(childnode);
  57.                     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);
  58.                     adapter2.Fill(ds, "3");
  59.                     childnode.Expanded = false;
  60.                     childnode.NavigateUrl = childrow["menu_url"].ToString();
  61.                     childnode.Target = childrow["target"].ToString();
  62.                     if (ds.Tables["3"].Rows.Count > 0)
  63.                     {
  64.                         //绑定第三层节点
  65.                         foreach (DataRow townrow in ds.Tables["3"].Rows)
  66.                         {
  67.                             townnode = new TreeNode(townrow["name"].ToString(), townrow["id"].ToString(), "../Images/tree/folder.gif");
  68.                             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);
  69.                             adapter3.Fill(ds, "4");
  70.                             townnode.Expanded = false;
  71.                             childnode.ChildNodes.Add(townnode);
  72.                             townnode.NavigateUrl = (townrow["menu_url"]).ToString();
  73.                             townnode.Target = (townrow["target"]).ToString();
  74.                             if (ds.Tables["4"].Rows.Count > 0)
  75.                             {
  76.                                 foreach (DataRow townrow1 in ds.Tables["4"].Rows)
  77.                                 {
  78.                                     townnode1 = new TreeNode(townrow1["name"].ToString(), townrow1["id"].ToString(), "../Images/tree/folder.gif");
  79.                                     townnode.ChildNodes.Add(townnode1);
  80.                                     townnode1.NavigateUrl = (townrow1["menu_url"]).ToString();
  81.                                     townnode1.Target = (townrow1["target"]).ToString();
  82.                                 }
  83.                                 ds.Tables["4"].Clear();
  84.                             }
  85.                         } ds.Tables["3"].Clear();
  86.                     }
  87.                 }
  88.                 ds.Tables["2"].Clear();
  89.             }
  90.         }
  91.         con.Close();
  92.     }
  93. }