protected void Page_Load(object sender, EventArgs e) { base.OnInit(e); //获取用户的权限 if (Session["user_name"] != null) { //admin不进行权限检查,拥有所哟权限 if (Session["user_name"].ToString() == "admin") { //管理员拥有所有权限,不进行权限判断 //获取所有菜单信息 list_menu_one = bll_menu.GetModelList("1=1 and pid=0 and isDeleted = 0"); if (list_menu_one.Count > 0) { foreach (Model.T_Menu t_menu in list_menu_one) { // map_one.Add(t_menu.name, t_menu); list_menu_two = bll_menu.GetModelList("1=1 and pid=" + t_menu.id + " and isDeleted = 0"); map_menu.Add(t_menu.name, list_menu_two); } } } else { //非admin用户进行权限检查,根据权限动态生成菜单 if (Session["user_id"] != null) { //获取用户所有角色 List <Model.T_User_Role> list_user_role = bll_user_role.GetModelList(" id_user='******'"); foreach (Model.T_User_Role t_user_role in list_user_role) { Model.T_Role t_role = bll_role.GetModel(Convert.ToInt32(t_user_role.id_role)); //获取role的权限content String menuContent = AuthorityValidation.GetMenusByRoleId(Convert.ToInt32(t_role.id)); //获取角色的一级菜单权限 list_menu_one = AuthorityValidation.GetMenuListOfMenusByPid(0, menuContent); if (list_menu_one.Count > 0) { foreach (Model.T_Menu t_menu in list_menu_one) { map_one.Add(t_menu.name, t_menu); //获取角色pid下面的菜单权限 list_menu_two = AuthorityValidation.GetMenuListOfMenusByPid(t_menu.id, menuContent); map_menu.Add(t_menu.name, list_menu_two); } } } } } } }
protected override void OnInit(EventArgs e) { //Session失效,跳到登录页面 if (Session["user_id"] == null) { Response.Write("<script>top.location='/View/Sys/login.aspx';</script>"); //Response.Redirect("/View/Sys/login.html"); } else { //获取用户的角色 if (Session["user_name"].ToString() == "admin") { for (int i = 100; i <= 1300; i += 100) { list_privilege_cur_page.Add(i + ""); } } else { //获取用户的权限 if (Session["role_id"] != null) { Model.T_Role t_role = bll_role.GetModel(Convert.ToInt32(Session["role_id"].ToString())); //获取role的权限content String menuContent = AuthorityValidation.GetMenusByRoleId(Convert.ToInt32(t_role.id)); String curPageName = this.GetType().Name; //view_business_planmng_planlist_aspx view_sys_noticemng_noticelist_aspx if (curPageName.Contains("main") || curPageName.Contains("west") || curPageName.Contains("center") || curPageName.Contains("north") || curPageName.Contains("south")) { } else { //获取角色的一级菜单权限 List <Model.T_Menu> list_menu_one = new List <Model.T_Menu>(); List <Model.T_Menu> list_menu_two = new List <Model.T_Menu>(); list_menu_one = AuthorityValidation.GetMenuListOfMenusByPid(0, menuContent); if (list_menu_one.Count > 0) { bool flag = false; foreach (Model.T_Menu t_menu in list_menu_one) { if (flag) { break; } else { //获取角色pid下面的菜单权限 "view_business_planmng_planlist_aspx" list_menu_two = AuthorityValidation.GetMenuListOfMenusByPid(t_menu.id, menuContent); //判断当前页是否在权限范围内 foreach (Model.T_Menu menuTwo in list_menu_two) { if (menuTwo.url != "") { String pageName = menuTwo.url.Substring(menuTwo.url.LastIndexOf('/') + 1); if (curPageName.Contains(pageName.Substring(0, pageName.IndexOf('.')).ToLower())) { //获取该页面对应的几个权限 list_privilege_cur_page = AuthorityValidation.GetMethodByMenuId(menuTwo.id, menuContent); flag = true; break; } } } } } } } } } } base.OnInit(e); }
private void Query(HttpContext context) { string name, order, sort, oderby; //=============================================================== //获取查询条件:【用户名】 name = order = sort = oderby = ""; //获取前台传来的值 if (null != context.Request.QueryString["name"]) {//获取前台传来的值 name = context.Request.QueryString["name"].ToString().Trim(); } //================================================================ //获取分页和排序信息:页大小,页码,排序方式,排序字段 int pageRows, page; pageRows = 10; page = 1; if (null != context.Request.QueryString["rows"]) { pageRows = int.Parse(context.Request.QueryString["rows"].ToString().Trim()); } if (null != context.Request.QueryString["page"]) { page = int.Parse(context.Request.QueryString["page"].ToString().Trim()); } if (null != context.Request.QueryString["sort"]) { order = context.Request.QueryString["sort"].ToString().Trim(); } if (null != context.Request.QueryString["order"]) { sort = context.Request.QueryString["order"].ToString().Trim(); } //=================================================================== //组合查询语句:条件+排序 StringBuilder strWhere = new StringBuilder(); strWhere.Append(" 1=1 and"); if (name != "") { strWhere.AppendFormat(" name like '%{0}%' and ", name); } //删除多余的and int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置 if (startindex >= 0) { strWhere.Remove(startindex, 3);//删除多余的and关键字 } if (sort != "" && order != "") { //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序 oderby = order + " " + sort; } //调用分页的GetList方法 DataSet ds = bll_role.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows); //向ds中插入contentname(上级名称) ds.Tables[0].Columns.Add("contentname", typeof(System.String)); foreach (DataRow dr in ds.Tables[0].Rows) { StringBuilder sbconent = new StringBuilder(); //根据Menu id获取name if (dr["content"] != null && dr["content"] != DBNull.Value && dr["content"].ToString() != "") { //1,2,3,5 分割 String[] ids = dr["content"].ToString().Split(','); if (ids.Length > 0) { foreach (String id in ids) { int id_int = Convert.ToInt32(id); T_Menu t_menu = bll_menu.GetModel(id_int); if (t_menu != null) { sbconent.Append(t_menu.name + ","); } else { //是否是增删改查 if (AuthorityValidation.IsInCRUD(id_int)) { String _name = AuthorityValidation.GetMethodCRUD(id_int); sbconent.Append(_name + ","); } else { sbconent.Append(id + ","); } } } dr["contentname"] = sbconent.ToString().Substring(0, sbconent.ToString().Length - 1); } else { dr["contentname"] = ""; } } else { dr["contentname"] = ""; } } int count = bll_role.GetRecordCount(strWhere.ToString()); //获取条数 string strJson = JsonHelper.Dataset2Json(ds, count); //DataSet数据转化为Json数据 context.Response.Write(strJson); //返回给前台页面 }