form_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_form_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.            // top.location.href = "login.aspx";
  21.     //    }
  22.        
  23.             if (!IsPostBack)
  24.             {
  25.                 LoginDAO.CheckLogin(Session, Response, "/web/", 2);
  26.                 if (Session["user_id"] != null)
  27.                 {
  28.                     BindTree();
  29.                 }
  30.             }
  31.         
  32.     }
  33.     public void BindTree()
  34.     {
  35.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["oaconnection"].ConnectionString);
  36.         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=24 and c.id="+Session["user_id"], con);
  37.         DataSet ds = new DataSet();
  38.         sda.Fill(ds, "1");
  39.         TreeNode parentnode;
  40.         TreeNode childnode;
  41.         TreeNode townnode;
  42.         TreeNode townnode1;
  43.         //TreeView1.ShowLines = true;
  44.         foreach (DataRow parentrow in ds.Tables["1"].Rows)
  45.         {
  46.             //绑定第一层节点
  47.             parentnode = new TreeNode(parentrow["name"].ToString(), parentrow["id"].ToString(), "../Images/tree/folder.gif");
  48.             //运行时候先不展开子节点
  49.             parentnode.Expanded = true;
  50.             parentnode.NavigateUrl = (parentrow["menu_url"]).ToString();
  51.             parentnode.Target = (parentrow["target"]).ToString();
  52.             TreeView1.Nodes.Add(parentnode);
  53.             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);
  54.             adapter.Fill(ds, "2");
  55.             if (ds.Tables["2"].Rows.Count > 0)
  56.             {
  57.                 //绑定第二层节点
  58.                 foreach (DataRow childrow in ds.Tables["2"].Rows)
  59.                 {
  60.                     childnode = new TreeNode(childrow["name"].ToString(), childrow["id"].ToString(), "../Images/tree/folder.gif");
  61.                     parentnode.ChildNodes.Add(childnode);
  62.                     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);
  63.                     adapter2.Fill(ds, "3");
  64.                     childnode.Expanded = false;
  65.                     childnode.NavigateUrl = childrow["menu_url"].ToString();
  66.                     childnode.Target = childrow["menu_url"].ToString();
  67.                     if (ds.Tables["3"].Rows.Count > 0)
  68.                     {
  69.                         //绑定第三层节点
  70.                         foreach (DataRow townrow in ds.Tables["3"].Rows)
  71.                         {
  72.                             townnode = new TreeNode(townrow["name"].ToString(), townrow["id"].ToString(), "../Images/tree/folder.gif");
  73.                             childnode.ChildNodes.Add(townnode);
  74.                             townnode.NavigateUrl = (townrow["menu_url"]).ToString();
  75.                             townnode.Target = (townrow["target"]).ToString();
  76.                             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);
  77.                             adapter3.Fill(ds, "4");
  78.                             townnode.Expanded = false;
  79.                             townnode.NavigateUrl = (townrow["menu_url"]).ToString();
  80.                             townnode.Target = (townrow["target"]).ToString();
  81.                             if (ds.Tables["4"].Rows.Count > 0)
  82.                             {
  83.                                 foreach (DataRow townrow1 in ds.Tables["4"].Rows)
  84.                                 {
  85.                                     townnode1 = new TreeNode(townrow1["name"].ToString(), townrow1["id"].ToString(), "../Images/tree/folder.gif");
  86.                                     townnode.ChildNodes.Add(townnode1);
  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. }