Exemple #1
0
        /// <summary>
        /// 用于子窗体的排除权限
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        internal static bool DisableForUser(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)
                {
                    menu.Enabled = true;
                    string formName         = owner.Name;
                    string controlName      = menu.Name;
                    PermissionCollection ps = user.GetAllPermissions(false);
                    if (ps.ExceptControl(formName, controlName))
                    {
                        menu.Enabled = false;
                        return(true);
                    }
                    else
                    {
                        ToolStripDropDownItem dropmenu = menu as ToolStripDropDownItem;
                        if (dropmenu != null)
                        {
                            ToolStripItemCollection items = dropmenu.DropDownItems;
                            if (items != null)
                            {
                                foreach (ToolStripItem c in items)
                                {
                                    controlName = c.Name;
                                    if (ps.ExceptControl(formName, dropmenu.Name, controlName))
                                    {
                                        c.Enabled = false;
                                    }
                                    else
                                    {
                                        c.DisableForUser(user);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        private static bool Disable(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;
                    string formName         = owner.Name;
                    string controlName      = control.Name;
                    PermissionCollection ps = user.GetAllPermissions(false);
                    if (ps.ExceptControl(formName, controlName))
                    {
                        control.Enabled = false;
                        return(true);
                    }
                    else
                    {
                        foreach (Control c in control.Controls)
                        {
                            controlName = c.Name;
                            if (ps.ExceptControl(formName, control.Name, controlName))
                            {
                                c.Enabled = false;
                            }
                            else
                            {
                                ToolStrip ms = c as ToolStrip;
                                if (ms != null)
                                {
                                    ms.DisableForUser(user);
                                }
                                else
                                {
                                    c.DisableForUser(user);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #3
0
        private static bool Disable(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;
                    string formName         = owner.Name;
                    string controlName      = menuStrip.Name;
                    PermissionCollection ps = user.GetAllPermissions(false);
                    if (ps.ExceptControl(formName, controlName))
                    {
                        menuStrip.Enabled = false;
                        return(true);
                    }
                    else
                    {
                        foreach (ToolStripItem c in menuStrip.Items)
                        {
                            controlName = c.Name;
                            if (ps.ExceptControl(formName, menuStrip.Name, controlName))
                            {
                                c.Enabled = false;
                            }
                            else
                            {
                                c.DisableForUser(user);
                            }
                        }
                    }
                }
            }
            return(false);
        }