示例#1
0
        private static bool Enable(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);
        }