您目前尚未登陆,请选择【登陆】或【注册
首页->新闻文章->破竹CMS4.0免安装版源码>>admin/Security/Permissions.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:破竹CMS4.0免安装版源码
当前文件:文件类型 PozhuCMS/admin/Security/Permissions.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using Pozhu.CMS.Permissions; 12using Pozhu.Sites; 13using Pozhu.Security.Permissions; 14using Pozhu.Security.Roles; 15using Pozhu.UI.Utilities; 16using Pozhu.Common.Utilities; 17using Pozhu.CMS.Web; 18using Pozhu.CMS.Categories; 19 20public partial class admin_Security_Permissions : AdminPageBase 21{ 22 protected void Page_Load(object sender, EventArgs e) 23 { 24 if (!Page.IsPostBack) 25 { 26 rptPermissions.DataSource = RolesPermissions(); 27 rptPermissions.DataBind(); 28 } 29 } 30 31 //获取角色列表的所有权限 32 ArrayList RolesPermissions() 33 { 34 string path = Request.QueryString["path"]; 35 PermissionController objPermissions = new PermissionController(); 36 ArrayList permissions = objPermissions.GetPermissions(CurrentCategory.CategoryID); 37 ArrayList permissionRoles = new ArrayList(); 38 foreach (Permission p in permissions) 39 { 40 bool isExist = false; 41 foreach (Permission rolePermission in permissionRoles) 42 { 43 if (rolePermission.RoleID == p.RoleID) 44 isExist = true; 45 } 46 if (!isExist) 47 { 48 permissionRoles.Add(p); 49 } 50 } 51 return permissionRoles; 52 } 53 54 protected void rptPermissions_ItemDataBound(object sender, RepeaterItemEventArgs e) 55 { 56 PermissionController objPermissions = new PermissionController(); 57 PermissionEntryCollection permissionEntries = objPermissions.GetPermissionEntries(SiteController.GetCurrentSite().SiteID); 58 59 if ((e.Item.ItemType == ListItemType.Header) || (e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) 60 { 61 Repeater rptEntries = (Repeater)e.Item.FindControl("rptEntries"); 62 rptEntries.DataSource = permissionEntries; 63 rptEntries.DataBind(); 64 } 65 66 // 67 if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) 68 { 69 Permission p = (Permission)(e.Item.DataItem); 70 LinkButton lbtnDelete = ((LinkButton)e.Item.FindControl("lbtnDelete")); 71 if (CategoryController.GetCategory(p.CategoryID).Path == "/") 72 { 73 lbtnDelete.Enabled = false; 74 } 75 else 76 { 77 ClientAPI.AddButtonConfirm(lbtnDelete, string.Format("确定移除该角色在些栏目的权限吗?移除后该角色的权限将继承自上级栏目的权限。")); 78 } 79 } 80 81 if (e.Item.ItemType == ListItemType.Header) 82 { 83 //权限项 84 Repeater rptAddEntries = (Repeater)e.Item.FindControl("rptAddEntries"); 85 rptAddEntries.DataSource = permissionEntries; 86 rptAddEntries.DataBind(); 87 88 // 89 RoleController objRoles = new RoleController(); 90 ArrayList allRoles = objRoles.GetSiteRoles(SiteController.GetCurrentSite().SiteID); 91 ArrayList roles = (ArrayList)allRoles.Clone(); 92 93 foreach (RoleInfo role in allRoles) 94 { 95 foreach (Permission pr in RolesPermissions()) 96 { 97 if (role.RoleID == pr.RoleID) 98 { 99 if (roles.Contains(role)) 100 { 101 roles.Remove(role); 102 } 103 } 104 } 105 } 106 107 //邦定到角色下拉框 108 DropDownList ddlRoles = (DropDownList)e.Item.FindControl("ddlRoles"); 109 ddlRoles.DataTextField = "roleName"; 110 ddlRoles.DataValueField = "roleID"; 111 ddlRoles.DataSource = roles; 112 ddlRoles.DataBind(); 113 114 if (ddlRoles.Items.Count == 0) 115 { 116 ddlRoles.Items.Add(new ListItem("没有可选的角色", "")); 117 } 118 } 119 } 120 121 protected bool AllowAccess(int roleID, int permissionEntryID) 122 { 123 string path = Request.QueryString["path"]; 124 PermissionController objPermissions = new PermissionController(); 125 ArrayList permissions = objPermissions.GetPermissions(CurrentCategory.CategoryID); 126 127 foreach (Permission p in permissions) 128 { 129 if ((p.RoleID == roleID) && (p.PermissionEntryID == permissionEntryID)) 130 { 131 return p.AllowAccess; 132 } 133 } 134 135 return false; 136 } 137 protected void rptPermissions_ItemCommand(object source, RepeaterCommandEventArgs e) 138 { 139 140 string commandName = e.CommandName; 141 if (commandName == "add") 142 { 143 if (e.Item.ItemType == ListItemType.Header) 144 { 145 Label lblPath = (Label)e.Item.FindControl("lblPath"); 146 Repeater rptEntries = (Repeater)e.Item.FindControl("rptAddEntries"); 147 DropDownList ddlRoles = (DropDownList)e.Item.FindControl("ddlRoles"); 148 149 // 150 PermissionController objPermissions = new PermissionController(); 151 foreach (RepeaterItem item in rptEntries.Items) 152 { 153 if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) 154 { 155 int ltlPermissionEntryID = int.Parse(((Literal)item.FindControl("ltlPermissionEntryID")).Text); 156 CheckBox cbAllowAccess = (CheckBox)item.FindControl("cbAllowAccess"); 157 158 Permission p = new Permission(); 159 p.RoleID = int.Parse(ddlRoles.SelectedValue); 160 p.CategoryID = CategoryController.GetCategory(CurrentSite.SiteID, lblPath.Text).CategoryID; 161 p.PermissionEntryID = ltlPermissionEntryID; 162 p.AllowAccess = cbAllowAccess.Checked; 163 164 objPermissions.AddPermission(p); 165 166 } 167 } 168 } 169 // 170 Response.Redirect(Request.RawUrl); 171 } 172 else if (commandName == "edit") 173 { 174 if ((e.Item.ItemType == ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) 175 { 176 LinkButton lbtnEdit = (LinkButton)e.Item.FindControl("lbtnEdit"); 177 LinkButton lbtnUpdate = (LinkButton)e.Item.FindControl("lbtnUpdate"); 178 LinkButton lbtnCancel = (LinkButton)e.Item.FindControl("lbtnCancel"); 179 LinkButton lbtnDelete = (LinkButton)e.Item.FindControl("lbtnDelete"); 180 Label lblPath = (Label)e.Item.FindControl("lblPath"); 181 Repeater rptEntries = (Repeater)e.Item.FindControl("rptEntries"); 182 183 // 184 lbtnEdit.Visible = false; 185 lbtnUpdate.Visible = true; 186 lbtnCancel.Visible = true; 187 lbtnDelete.Visible = false; 188 lblPath.Text = Request.QueryString["path"]; 189 190 foreach (RepeaterItem item in rptEntries.Items) 191 { 192 if((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) 193 { 194 Label lblAllowAccess = (Label)item.FindControl("lblAllowAccess"); 195 CheckBox cbAllowAccess = (CheckBox)item.FindControl("cbAllowAccess"); 196 197 lblAllowAccess.Visible = false; 198 cbAllowAccess.Visible = true; 199 } 200 } 201 } 202 } 203 else if (commandName == "update") 204 { 205 if ((e.Item.ItemType == ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) 206 { 207 Label lblPath = (Label)e.Item.FindControl("lblPath"); 208 Repeater rptEntries = (Repeater)e.Item.FindControl("rptEntries"); 209 int roleID = int.Parse(e.CommandArgument.ToString()); 210 211 PermissionController objPermissions = new PermissionController(); 212 int permissionCategoryID = CategoryController.GetCategory(CurrentSite.SiteID, lblPath.Text).CategoryID; 213 ArrayList permissions = objPermissions.GetPermissions(permissionCategoryID); 214 foreach (Permission p in permissions) 215 { 216 if (p.RoleID == roleID) 217 { 218 CheckBox cbAllowAccess = null; 219 int ltlPermissionEntryID = Null.NullInteger; 220 bool isExist = false; 221 foreach (RepeaterItem item in rptEntries.Items) 222 { 223 if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) 224 { 225 ltlPermissionEntryID = int.Parse(((Literal)item.FindControl("ltlPermissionEntryID")).Text); 226 cbAllowAccess = (CheckBox)item.FindControl("cbAllowAccess"); 227 228 // 229 if (p.PermissionEntryID == ltlPermissionEntryID) 230 { 231 isExist = true; 232 break; 233 } 234 } 235 } 236 237 // 238 if (isExist && p.CategoryID == permissionCategoryID) 239 { 240 p.AllowAccess = cbAllowAccess.Checked; 241 p.CategoryID = permissionCategoryID; 242 objPermissions.UpdatePermission(p); 243 } 244 else 245 { 246 p.PermissionEntryID = ltlPermissionEntryID; 247 p.AllowAccess = cbAllowAccess.Checked; 248 p.CategoryID = permissionCategoryID; 249 objPermissions.AddPermission(p); 250 } 251 } 252 } 253 } 254 255 Response.Redirect(Request.RawUrl); 256 } 257 else if (commandName == "cancel") 258 { 259 // 260 rptPermissions.DataSource = RolesPermissions(); 261 rptPermissions.DataBind(); 262 } 263 else if (commandName == "delete") 264 { 265 if ((e.Item.ItemType == ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) 266 { 267 Label lblPath = (Label)e.Item.FindControl("lblPath"); 268 Repeater rptEntries = (Repeater)e.Item.FindControl("rptEntries"); 269 int roleID = int.Parse(e.CommandArgument.ToString()); 270 271 //如果path的值为"/",则返回 272 if (lblPath.Text == "/") 273 return; 274 275 // 276 PermissionController objPermissions = new PermissionController(); 277 ArrayList permissions = objPermissions.GetPermissions(CategoryController.GetCategory(CurrentSite.SiteID, lblPath.Text).CategoryID); 278 foreach (Permission p in permissions) 279 { 280 if (p.RoleID == roleID) 281 { 282 foreach (RepeaterItem item in rptEntries.Items) 283 { 284 if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) 285 { 286 int ltlPermissionEntryID = int.Parse(((Literal)item.FindControl("ltlPermissionEntryID")).Text); 287 288 // 289