Ejemplo n.º 1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="name"></param>
 /// <param name="permissions"></param>
 public Role(string name, PermissionCollection permissions)
 {
     id = Guid.NewGuid();
     if (name != null && name.Trim() != "")
     {
         this.name = name;
     }
     if (permissions == null)
     {
         this.permissions = new PermissionCollection();
     }
     else
     {
         this.permissions = permissions;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取当前用户拥有的所有权限
        /// </summary>
        public PermissionCollection GetAllPermissions()
        {
            PermissionCollection ps = new PermissionCollection();

            foreach (Role r in roles)
            {
                foreach (Permission p in r.Permissions)
                {
                    ps.Add(p);
                }
            }
            foreach (Department d in departments)
            {
                foreach (Role r in d.Roles)
                {
                    foreach (Permission p in r.Permissions)
                    {
                        ps.Add(p);
                    }
                }
            }
            foreach (Project pr in projects)
            {
                foreach (Role r in pr.Roles)
                {
                    foreach (Permission p in r.Permissions)
                    {
                        ps.Add(p);
                    }
                }
            }
            foreach (UserGroup ug in userGroups)
            {
                foreach (Role r in ug.Roles)
                {
                    foreach (Permission p in r.Permissions)
                    {
                        ps.Add(p);
                    }
                }
            }
            return(ps);
        }
Ejemplo n.º 3
0
        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Control c = contextMenuStrip1.SourceControl;

            if (c is Button)
            {
                string name;
                Button btn = c as Button;
                switch (btn.Name)
                {
                case "btn_Perm":
                    name = textBox11.Text.Trim();
                    string mod = comboBox9.Text;
                    string act = comboBox10.Text;
                    KellPermission.Permission per = perms[selectPerm];
                    per.Name           = name;
                    per.TheModule.Name = mod;
                    per.TheAction.Name = act;
                    listBoxSelecter2.UpdateSourceItem(selectPerm, per);
                    break;

                case "btn_Role":
                    name = textBox10.Text.Trim();
                    KellPermission.PermissionCollection pers = new KellPermission.PermissionCollection();
                    foreach (object obj in listBoxSelecter3.SelectedItems)
                    {
                        KellPermission.Permission perr = (KellPermission.Permission)obj;
                        roles[selectRole].Permissions.Add(perr);
                    }
                    roles[selectRole].Name = name;
                    listBoxSelecter3.UpdateSourceItem(selectRole, roles[selectRole]);
                    break;

                case "btn_User":
                    string userName = textBox1.Text.Trim();
                    string password = textBox2.Text.Trim();
                    if (deps != null)
                    {
                        Department          dep         = deps[comboBox1.SelectedIndex];
                        string              description = textBox3.Text;
                        KellPermission.User user        = users[selectUser];
                        Project             prj         = null;
                        try
                        {
                            if (prjs != null)
                            {
                                prj = prjs[comboBox2.SelectedIndex - 1];
                            }
                        }
                        catch
                        { }
                        if (prj != null)
                        {
                            user.Projects.Clear();
                            user.Projects.Add(prj);
                        }
                        else
                        {
                            user.Projects.Clear();
                        }
                        user.UserName = userName;
                        user.Password = password;
                        user.Departments.Clear();
                        user.Departments.Add(dep);
                        user.Description            = description;
                        comboBox8.Items[selectUser] = userName;
                    }
                    break;

                case "btn_Dept":
                    name = textBox7.Text.Trim();
                    KellPermission.Department parent = null;
                    try
                    {
                        parent = deps[comboBox11.SelectedIndex - 1];
                    }
                    catch
                    { }
                    KellPermission.Department depp = deps[selectDept];
                    if (parent != null)
                    {
                        depp.Parent = parent;
                    }
                    else
                    {
                        depp.Parent = null;
                    }
                    depp.Name = name;
                    comboBox3.Items[selectDept]  = depp.Name;
                    comboBox1.Items[selectDept]  = depp.Name;
                    comboBox6.Items[selectDept]  = depp.Name;
                    comboBox11.Items[selectDept] = depp.Name;
                    break;

                case "btn_Proj":
                    name = textBox6.Text.Trim();
                    prjs[selectProj].Name        = name;
                    comboBox12.Items[selectProj] = name;
                    comboBox2.Items[selectProj]  = name;
                    comboBox5.Items[selectProj]  = name;
                    break;

                case "btn_Modu":
                    name = textBox8.Text.Trim();
                    mods[selectModu].Name       = name;
                    comboBox9.Items[selectModu] = name;
                    break;

                case "btn_Actn":
                    name = textBox9.Text.Trim();
                    acts[selectActn].Name        = name;
                    comboBox10.Items[selectActn] = name;
                    break;
                }
            }
        }