Пример #1
0
        private void refreshActivateRoles()
        {
            this.checkedListBox_Roles.Items.Clear();
            this.listBox_Activating_Permissions.Items.Clear();

            LinkedList <string> DirectRole = Security_Officer.Get_User_Direct_Roles(GetUserName);//获取用户拥有 的所有角色

            while (DirectRole.Count != 0)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(this.View_RolesData);
                r.Cells[0].Value = DirectRole.First.Value;

                LinkedList <string> DirectFatherRoles = Security_Officer.GetDirectFatherRoles(DirectRole.First.Value);
                LinkedList <string> FatherRoles       = Security_Officer.GetFatherRoles(DirectRole.First.Value);

                LinkedList <string> DirectChildRoles = Security_Officer.GetDirectChildRoles(DirectRole.First.Value);
                LinkedList <string> ChildRoles       = Security_Officer.GetChildRoles(DirectRole.First.Value);

                while (FatherRoles.Count != 0)
                {
                    if (DirectFatherRoles.Find(FatherRoles.First.Value) == null)
                    {
                        r.Cells[3].Value += FatherRoles.First.Value + " ";
                    }
                    FatherRoles.RemoveFirst();
                }

                while (ChildRoles.Count != 0)
                {
                    if (DirectChildRoles.Find(ChildRoles.First.Value) == null)
                    {
                        r.Cells[4].Value += ChildRoles.First.Value + " ";
                    }
                    ChildRoles.RemoveFirst();
                }
                while (DirectFatherRoles.Count != 0)
                {
                    r.Cells[1].Value += DirectFatherRoles.First.Value + " ";
                    DirectFatherRoles.RemoveFirst();
                }
                while (DirectChildRoles.Count != 0)
                {
                    r.Cells[2].Value += DirectChildRoles.First.Value + " ";
                    DirectChildRoles.RemoveFirst();
                }

                DirectRole.RemoveFirst();

                this.View_RolesData.Rows.Add(r);
            }
        }
Пример #2
0
        private void Refresh_Permission()
        {
            this.ListBox_Permissions.Items.Clear();
            LinkedList <string> Direct_Roles = Security_Officer.Get_User_Direct_Roles(GetUserName); //获取用户的指派角色
            LinkedList <string> Roles        = new LinkedList <string>();                           //获取用户拥有的所有角色(包括继承的);

            int i = 0;

            for (LinkedListNode <string> L = Direct_Roles.First; i < Direct_Roles.Count; i++, L = L.Next)
            {
                LinkedList <string> ChildRole = Security_Officer.GetChildRoles(L.Value);//获取指定角色的所有下级角色,添加到授权列表中


                if (Roles.Find(L.Value) == null)
                {
                    Roles.AddLast(L.Value);
                }
                while (ChildRole.Count != 0)
                {
                    if (Roles.Find(ChildRole.First.Value) == null)
                    {
                        Roles.AddLast(ChildRole.First.Value);
                    }
                    ChildRole.RemoveFirst();
                }
            }


            while (Roles.Count != 0)
            {
                LinkedList <string> permisssion = Security_Officer.Get_Role_Direct_Permissions(Roles.First.Value);
                while (permisssion.Count != 0)
                {
                    if (this.ListBox_Permissions.Items.IndexOf((permisssion.First.Value)) == -1)
                    {
                        this.ListBox_Permissions.Items.Add(permisssion.First.Value);
                    }
                    permisssion.RemoveFirst();
                }
                Roles.RemoveFirst();
            }
        }
Пример #3
0
        //更新用户表的代码
        private void Refresh_UserTable()
        {
            this.View_UsersData.Rows.Clear();
            OleDbConnection oleDB = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dac.accdb");

            oleDB.Open();
            OleDbCommand cmd = new OleDbCommand();

            cmd.Connection  = oleDB;
            cmd.CommandText = "select * from [主体信息表]";
            OleDbDataReader dr = cmd.ExecuteReader();

            LinkedList <string> RoleName = new LinkedList <string>();//用于记录在角色信息表中出现的角色名称

            if (dr.HasRows == true)
            {
                while (dr.Read())
                {
                    if (string.Equals(dr["主体名称"].ToString().ToLower(), "admin") == false &&
                        string.Equals(dr["主体名称"].ToString().ToLower(), "security_officer") == false)//管理员和安全员不必添加
                    {
                        DataGridViewRow r = new DataGridViewRow();
                        r.CreateCells(this.View_UsersData);

                        r.Cells[0].Value = dr["主体名称"];
                        r.Cells[4].Value = dr["注册时间"];

                        LinkedList <string> Direct_Roles = Security_Officer.Get_User_Direct_Roles(dr["主体名称"].ToString()); //获取用户的指派角色
                        int i = 0;
                        LinkedList <string> Author_Roles = new LinkedList <string>();                                     //获取用户的授权角色



                        for (LinkedListNode <string> L = Direct_Roles.First; i < Direct_Roles.Count; i++, L = L.Next)
                        {
                            LinkedList <string> ChildRole = Security_Officer.GetChildRoles(L.Value);
                            while (ChildRole.Count != 0)
                            {
                                if (Direct_Roles.Find(ChildRole.First.Value) == null)
                                {
                                    Author_Roles.AddLast(ChildRole.First.Value);
                                }
                                ChildRole.RemoveFirst();
                            }
                        }
                        LinkedList <string> Permission = new LinkedList <string>();//获取用户的授权角色
                        while (Direct_Roles.Count != 0)
                        {
                            r.Cells[1].Value += Direct_Roles.First.Value + " ";
                            LinkedList <string> P = Security_Officer.Get_Role_Direct_Permissions(Direct_Roles.First.Value);
                            while (P.Count != 0)
                            {
                                if (Permission.Find(P.First.Value) == null)
                                {
                                    Permission.AddLast(P.First.Value);
                                }
                                P.RemoveFirst();
                            }
                            Direct_Roles.RemoveFirst();
                        }
                        while (Author_Roles.Count != 0)
                        {
                            r.Cells[2].Value += Author_Roles.First.Value + " ";
                            LinkedList <string> P = Security_Officer.Get_Role_Direct_Permissions(Author_Roles.First.Value);
                            while (P.Count != 0)
                            {
                                if (Permission.Find(P.First.Value) == null)
                                {
                                    Permission.AddLast(P.First.Value);
                                }
                                P.RemoveFirst();
                            }
                            Author_Roles.RemoveFirst();
                        }
                        while (Permission.Count != 0)
                        {
                            r.Cells[3].Value += Permission.First.Value + " ";
                            Permission.RemoveFirst();
                        }
                        this.View_UsersData.Rows.Add(r);
                    }
                }
            }
            dr.Close();
            oleDB.Close();
        }
Пример #4
0
        private void ComboBox_UserName_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ListBox_AssignRole.Items.Clear();
            //    this.ListBox_AssignRoleAdd.Items.Clear();
            this.ListBox_AuthorizeRole.Items.Clear();
            this.ListBox_Permissions.Items.Clear();
            this.Label_Time.Text = GetUserCreatTime(this.ComboBox_UserName.Text);



            LinkedList <string> Direct_Roles = Security_Officer.Get_User_Direct_Roles(this.ComboBox_UserName.Text); //获取用户的指派角色
            LinkedList <string> Roles        = new LinkedList <string>();                                           //获取用户拥有的所有角色(包括继承的);

            int i = 0;

            for (LinkedListNode <string> L = Direct_Roles.First; i < Direct_Roles.Count; i++, L = L.Next)
            {
                LinkedList <string> ChildRole = Security_Officer.GetChildRoles(L.Value);//获取指定角色的所有下级角色,添加到授权列表中


                if (Roles.Find(L.Value) == null)
                {
                    Roles.AddLast(L.Value);
                }
                while (ChildRole.Count != 0)
                {
                    if (this.ListBox_AuthorizeRole.Items.IndexOf(ChildRole.First.Value) == -1)//授权列表中没有该角色时,再添加
                    {
                        this.ListBox_AuthorizeRole.Items.Add(ChildRole.First.Value);
                    }
                    if (Roles.Find(ChildRole.First.Value) == null)
                    {
                        Roles.AddLast(ChildRole.First.Value);
                    }
                    ChildRole.RemoveFirst();
                }
            }

            while (Direct_Roles.Count != 0)
            {
                this.ListBox_AssignRole.Items.Add(Direct_Roles.First.Value);
                //从可指派的角色列表中删除对应已指派的角色
                // this.CheckedListBox_AssignRoleAdd.Items.Remove(Direct_Roles.First.Value);
                this.ListBox_AuthorizeRole.Items.Remove(Direct_Roles.First.Value);

                Direct_Roles.RemoveFirst();
            }
            while (Roles.Count != 0)
            {
                LinkedList <string> permisssion = Security_Officer.Get_Role_Direct_Permissions(Roles.First.Value);
                while (permisssion.Count != 0)
                {
                    if (this.ListBox_Permissions.Items.IndexOf((permisssion.First.Value)) == -1)
                    {
                        this.ListBox_Permissions.Items.Add(permisssion.First.Value);
                    }
                    permisssion.RemoveFirst();
                }
                Roles.RemoveFirst();
            }
        }