private static bool Enable10(Control control, User user) { Form owner = control.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { control.Enabled = true; int nofinded = 0; string formName = owner.Name; PermissionCollection ps = user.GetAllPermissions(false); foreach (Control c in control.Controls) { string controlName = c.Name; if (ps.ContainsControl(formName, control.Name, controlName)) { c.Enabled = true; } else { c.Enabled = false; nofinded++; ToolStrip ms = c as ToolStrip; if (ms != null) { if (ms.EnableChildrenForUser(user)) { nofinded--; } } else { if (c.EnableChildrenForUser(user)) { nofinded--; } } } } if (nofinded == control.Controls.Count) { control.Enabled = false; return(false); } else { return(true); } } } return(false); }
private static bool Enable20(ToolStrip menuStrip, User user) { Form owner = menuStrip.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { menuStrip.Enabled = true; int nofinded = 0; string formName = owner.Name; PermissionCollection ps = user.GetAllPermissions(false); foreach (ToolStripItem c in menuStrip.Items) { string controlName = c.Name; if (ps.ContainsControl(formName, menuStrip.Name, controlName)) { c.Enabled = true; } else { c.Enabled = false; nofinded++; if (c.EnableChildrenForUser2(user)) { nofinded--; } } } if (nofinded == menuStrip.Items.Count) { menuStrip.Enabled = false; return(false); } else { return(true); } } } return(false); }
/// <summary> /// 用于主窗体的包含权限 /// </summary> /// <param name="menu"></param> /// <param name="user"></param> /// <returns></returns> internal static bool EnableChildrenForUser2(this ToolStripItem menu, User user = null) { Form owner = null; if (menu.Owner != null) { if (menu.Owner.Parent != null) { owner = menu.Owner.Parent.FindForm(); } } if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { ToolStripDropDownItem dropmenu = menu as ToolStripDropDownItem; if (dropmenu != null) { ToolStripItemCollection items = dropmenu.DropDownItems; if (items != null) { dropmenu.Enabled = true; int nofinded = 0; string formName = owner.Name; PermissionCollection ps = user.GetAllPermissions(false); foreach (ToolStripItem c in items) { string controlName = c.Name; if (ps.ContainsControl(formName, dropmenu.Name, controlName)) { c.Enabled = true; } else { c.Enabled = false; nofinded++; if (c.EnableChildrenForUser2(user)) { nofinded--; } } } if (nofinded == items.Count) { dropmenu.Enabled = false; return(false); } else { return(true); } } } } } return(false); }