Exemple #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();
        }
        private void PopulatePermissionTree()
        {
            string queryString = "	select usr .Name from ControlsToRoles ctr"+

                                 "  join controls c on c.ControlID = ctr.FKControlID and c.Page = ctr.FKPage" +

                                 "  join roles r on r.RoleID = ctr.FKRole" +

                                 "  join UsersToRoles UsTr on UsTr.FKRoleID = ctr.FKRole" +

                                 "  join Users usr on usr.UserID = UsTr.FKUserID" +

                                 "  group by usr.Name  ";

            DataTable dt = null;

            try
            {
                dt = GuardarDatos.GetRoles(queryString);
                DataRow row = dt.NewRow();
                row[0] = "TODOS";
                dt.Rows.Add(row);
                cboCargaUsuario.DataSource    = dt;
                cboCargaUsuario.DisplayMember = "Name";
                cboCargaUsuario.SelectedIndex = cboCargaUsuario.Items.Count - 1;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error al recuperar " + e.Message,
                                "Error al recuperar",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }


            string currentName = string.Empty;
        }
Exemple #3
0
        private void PopulatePermissionTree()
        {
            string queryString = "select ctr .fkpage, controlID, Invisible, Disabled, RoleName,ContenedorPeqMineria,ContenedorZandor,ContenedorOtros " +
                                 "from ControlsToRoles ctr " +
                                 " join controls c on c.ControlID = ctr.FKControlID and c.Page = ctr.FKPage " +
                                 " join roles r on r.RoleID = ctr.FKRole ";

            if (ByControlRB.Checked)
            {
                queryString += " order by ControlID";
            }
            else
            {
                queryString += " order by RoleName";
            }
            DataTable dt = null;

            try

            {
                dt = GuardarDatos.GetRoles(queryString);
            }
            catch (Exception e)
            {
                MessageBox.Show("Incapaz de recuperar permisos: " + e.Message,
                                "Error al recuperar permisos",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

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

            string currentName = string.Empty;

            foreach (DataRow row in dt.Rows)
            {
                string subNodeText = String.Concat(" Formulario: ", row["fkpage"].ToString(), "-", (ByControlRB.Checked ? row["RoleName"].ToString() : row["ControlID"].ToString()));
                subNodeText += ":";
                subNodeText += Convert.ToInt32(row["Invisible"]) == 0 ? " visible " : " no visible ";
                subNodeText += ", ";
                subNodeText += Convert.ToInt32(row["Disabled"]) == 0 ? " Activo " : " Inactivo ";


                if (workingForm != null && workingForm.Name.Trim().ToUpper().Contains("FRM_MUESTREOPM"))
                {
                    if (!String.IsNullOrEmpty(row["ContenedorPeqMineria"].ToString().Trim()))
                    {
                        subNodeText += ", ";

                        subNodeText += Convert.ToInt32(row["ContenedorPeqMineria"]) == 0 ? " No Grabar Peq Min " : " Grabar Peq Min";
                        subNodeText += ", ";
                        subNodeText += Convert.ToInt32(row["ContenedorZandor"]) == 0 ? " No Grabar Cont Zandor" : " Grabar Cont Zandor";
                        subNodeText += ", ";
                        subNodeText += Convert.ToInt32(row["ContenedorOtros"]) == 0 ? " No Grabar Cont Otros" : " Grabar Cont Otros";
                    }
                }

                subNode = new TreeNode(subNodeText);
                string dataName = ByControlRB.Checked ? row["ControlID"].ToString() : row["RoleName"].ToString();
                if (currentName != dataName)
                {
                    parentNode  = new TreeNode(dataName);
                    currentName = dataName;
                    PermissionTree.Nodes.Add(parentNode);
                }

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