sys_left_menu.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:5k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class web_sys_left_menu : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Session["user_id"] == null)
- {
- Response.Write("<script>window.open('login.aspx','_top');</script>");
- }
- if (!IsPostBack)
- {
- if (Session["user_id"] != null)
- {
- BindTree();
- }
- }
- }
- public void BindTree()
- {
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["oaconnection"].ConnectionString);
- 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=22 and c.id=" + Session["user_id"], con);
- DataSet ds = new DataSet();
- sda.Fill(ds, "1");
- TreeNode parentnode;
- TreeNode childnode;
- TreeNode townnode;
- TreeNode townnode1;
- //TreeView1.ShowLines = true;
- foreach (DataRow parentrow in ds.Tables["1"].Rows)
- {
- //绑定第一层节点
- parentnode = new TreeNode(parentrow["name"].ToString(), parentrow["id"].ToString(), "../Images/tree/folder.gif");
- //运行时候先不展开子节点
- parentnode.Expanded = true;
- parentnode.NavigateUrl = (parentrow["menu_url"]).ToString();
- parentnode.Target = (parentrow["target"]).ToString();
- TreeView1.Nodes.Add(parentnode);
- 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);
- adapter.Fill(ds, "2");
- if (ds.Tables["2"].Rows.Count > 0)
- {
- //绑定第二层节点
- foreach (DataRow childrow in ds.Tables["2"].Rows)
- {
- childnode = new TreeNode(childrow["name"].ToString(), childrow["id"].ToString(), "../Images/tree/folder.gif");
- parentnode.ChildNodes.Add(childnode);
- 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);
- adapter2.Fill(ds, "3");
- childnode.Expanded = false;
- childnode.NavigateUrl = childrow["menu_url"].ToString();
- childnode.Target = childrow["target"].ToString();
- if (ds.Tables["3"].Rows.Count > 0)
- {
- //绑定第三层节点
- foreach (DataRow townrow in ds.Tables["3"].Rows)
- {
- townnode = new TreeNode(townrow["name"].ToString(), townrow["id"].ToString(), "../Images/tree/folder.gif");
- 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);
- adapter3.Fill(ds, "4");
- townnode.Expanded = false;
- childnode.ChildNodes.Add(townnode);
- townnode.NavigateUrl = (townrow["menu_url"]).ToString();
- townnode.Target = (townrow["target"]).ToString();
- if (ds.Tables["4"].Rows.Count > 0)
- {
- foreach (DataRow townrow1 in ds.Tables["4"].Rows)
- {
- townnode1 = new TreeNode(townrow1["name"].ToString(), townrow1["id"].ToString(), "../Images/tree/folder.gif");
- townnode.ChildNodes.Add(townnode1);
- townnode1.NavigateUrl = (townrow1["menu_url"]).ToString();
- townnode1.Target = (townrow1["target"]).ToString();
- }
- ds.Tables["4"].Clear();
- }
- } ds.Tables["3"].Clear();
- }
- }
- ds.Tables["2"].Clear();
- }
- }
- con.Close();
- }
- }