示例#1
0
        private void FillUsersInRollsTree()
        {
            string queryString = "select u.Name, r.RoleName from userstoRoles utr " +
                                 " join users u on u.userID = utr.FKUserID " +
                                 " join Roles r on r.roleID = utr.FKRoleID ";

            if (rbName.Checked)
            {
                queryString += "order by Name";
            }
            else
            {
                queryString += "order by RoleName";
            }

            UsersInRoles.BeginUpdate();
            UsersInRoles.Nodes.Clear();
            TreeNode parentNode = null;
            TreeNode subNode    = null;


            DataTable dt          = GuardarDatos.GetRoles(queryString);
            string    currentName = string.Empty;

            foreach (DataRow row in dt.Rows)
            {
                if (rbName.Checked)
                {
                    subNode = new TreeNode(row["roleName"].ToString());
                    if (currentName != row["Name"].ToString())
                    {
                        parentNode  = new TreeNode(row["Name"].ToString());
                        currentName = row["Name"].ToString();
                        UsersInRoles.Nodes.Add(parentNode);
                    }
                }
                else
                {
                    subNode = new TreeNode(row["Name"].ToString());
                    if (currentName != row["RoleName"].ToString())
                    {
                        parentNode  = new TreeNode(row["RoleName"].ToString());
                        currentName = row["RoleName"].ToString();
                        UsersInRoles.Nodes.Add(parentNode);
                    }
                }

                if (parentNode != null)
                {
                    parentNode.Nodes.Add(subNode);
                }
            }
            UsersInRoles.EndUpdate();
        }
示例#2
0
        private void FillUsersInRollsTree()
        {
            string queryString = @"select SH.SEC_HDR_USR_NAME,RW.ROLE_NAME, UTRW_CREATE, UTRW_UPDATE, UTRW_DELETE
            from USER_TO_ROLE_WFMS as UTRW inner join USERS_WFMS as UW on UTRW.FK_USER_ID=UW.UserID inner join
            ROLES_WFMS as RW on UTRW.FK_ROLE_ID=RW.ROLE_ID inner join SECURITY_HEADER as SH on UW.SecqHeaderID = SH.SEC_HDR_CODE";

            if (rbName.Checked)
            {
                queryString += " order by SH.SEC_HDR_USR_NAME";
            }
            else
            {
                queryString += " order by RW.ROLE_NAME";
            }

            UsersInRoles.BeginUpdate();
            UsersInRoles.Nodes.Clear();

            TreeNode parentNode      = null;
            TreeNode subNode         = null;
            TreeNode childNodeCreate = null;
            TreeNode childNodeUpdate = null;
            TreeNode childNodeDelete = null;


            DataSet   ds = db.SelectRolesToUSERS(queryString);
            DataTable dt = ds.Tables[0];

            string currentName = string.Empty;

            foreach (DataRow row in dt.Rows)
            {
                string create, updatetxt, deleteTxt;
                create          = Convert.ToInt32(row["UTRW_CREATE"]) == 1 ? "Create" : "Cannot Create";
                updatetxt       = Convert.ToInt32(row["UTRW_UPDATE"]) == 1 ? "Update" : "Cannot Update";
                deleteTxt       = Convert.ToInt32(row["UTRW_DELETE"]) == 1 ? "Delete" : "Cannot Delete";
                childNodeCreate = new TreeNode(create);
                childNodeUpdate = new TreeNode(updatetxt);
                childNodeDelete = new TreeNode(deleteTxt);
                if (rbName.Checked)
                {
                    subNode = new TreeNode(row["ROLE_NAME"].ToString());
                    if (currentName != row["SEC_HDR_USR_NAME"].ToString())
                    {
                        parentNode  = new TreeNode(row["SEC_HDR_USR_NAME"].ToString());
                        currentName = row["SEC_HDR_USR_NAME"].ToString();
                        UsersInRoles.Nodes.Add(parentNode);
                    }
                }
                else
                {
                    subNode = new TreeNode(row["SEC_HDR_USR_NAME"].ToString());
                    if (currentName != row["ROLE_NAME"].ToString())
                    {
                        parentNode  = new TreeNode(row["ROLE_NAME"].ToString());
                        currentName = row["ROLE_NAME"].ToString();
                        UsersInRoles.Nodes.Add(parentNode);
                    }
                }

                if (parentNode != null)
                {
                    parentNode.Nodes.Add(subNode);
                    if (chkBoCollExpan.Checked == true)
                    {
                        parentNode.ExpandAll();
                        chkBoCollExpan.Text = "Collapse";
                    }
                    else
                    {
                        parentNode.Collapse();
                        chkBoCollExpan.Text = "Expand";
                    }
                }
                if (subNode != null)
                {
                    subNode.Nodes.Add(childNodeCreate);
                    subNode.Nodes.Add(childNodeUpdate);
                    subNode.Nodes.Add(childNodeDelete);
                    if (chkBoCollExpan.Checked == true)
                    {
                        parentNode.ExpandAll();
                        chkBoCollExpan.Text = "Collapse";
                    }
                    else
                    {
                        parentNode.Collapse();
                        chkBoCollExpan.Text = "Expand";
                    }
                }
            }
            UsersInRoles.EndUpdate();
        }
示例#3
0
        private void FillUsersInRollsTree()
        {
            ConnectionStringSettingsCollection connectionStrings =
                ConfigurationManager.ConnectionStrings;

            string        connString = connectionStrings["ControlBasedSecurity.Properties.Settings.ControlSecurityConnectionString"].ToString();
            SqlConnection conn       = new SqlConnection(connString);

            conn.Open();

            string queryString = "select u.Name, r.RoleName from userstoRoles utr " +
                                 " join users u on u.userID = utr.FKUserID " +
                                 " join Roles r on r.roleID = utr.FKRoleID ";

            if (rbName.Checked)
            {
                queryString += "order by Name";
            }
            else
            {
                queryString += "order by RoleName";
            }

            UsersInRoles.BeginUpdate();
            UsersInRoles.Nodes.Clear();
            TreeNode parentNode = null;
            TreeNode subNode    = null;

            DataSet        ds          = new DataSet();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(queryString, conn);

            dataAdapter.Fill(ds, "usersInRoles");
            DataTable dt          = ds.Tables[0];
            string    currentName = string.Empty;

            foreach (DataRow row in dt.Rows)
            {
                if (rbName.Checked)
                {
                    subNode = new TreeNode(row["roleName"].ToString());
                    if (currentName != row["Name"].ToString())
                    {
                        parentNode  = new TreeNode(row["Name"].ToString());
                        currentName = row["Name"].ToString();
                        UsersInRoles.Nodes.Add(parentNode);
                    }
                }
                else
                {
                    subNode = new TreeNode(row["Name"].ToString());
                    if (currentName != row["RoleName"].ToString())
                    {
                        parentNode  = new TreeNode(row["RoleName"].ToString());
                        currentName = row["RoleName"].ToString();
                        UsersInRoles.Nodes.Add(parentNode);
                    }
                }

                if (parentNode != null)
                {
                    parentNode.Nodes.Add(subNode);
                }
            }
            UsersInRoles.EndUpdate();
        }