private void PopulatePermissionTree() { string queryString = @"select CW.CONRTOL_NAME,INVISIBLE,DISABLED,RW.ROLE_NAME FROM CONTROLS_TO_ROLES_WFMS as CTRW inner join CONTROLS_WFMS as CW on CTRW.FK_CONTROL_NAME=CW.CONRTOL_NAME inner join ROLES_WFMS as RW on CTRW.FK_ROLE_ID=RW.ROLE_ID"; if (ByControlRB.Checked) { queryString += " order by CONRTOL_NAME"; } else { queryString += " order by ROLE_NAME"; } DataTable dt = null; DataSet ds = db.SelectRolesToControls(queryString); dt = ds.Tables[0]; PermissionTree.BeginUpdate(); PermissionTree.Nodes.Clear(); TreeNode parentNode = null; TreeNode subNode = null; string currentName = string.Empty; foreach (DataRow row in dt.Rows) { string subNodeText = ByControlRB.Checked ? row["ROLE_NAME"].ToString() : row["CONRTOL_NAME"].ToString(); subNodeText += ":"; subNodeText += Convert.ToInt32(row["INVISIBLE"]) == 0 ? " Visible " : " Not visible "; subNodeText += " and "; subNodeText += Convert.ToInt32(row["DISABLED"]) == 0 ? " Enabled " : " Disabled "; subNode = new TreeNode(subNodeText); string dataName = ByControlRB.Checked ? row["CONRTOL_NAME"].ToString() : row["ROLE_NAME"].ToString(); if (currentName != dataName) { parentNode = new TreeNode(dataName); currentName = dataName; PermissionTree.Nodes.Add(parentNode); } if (parentNode != null) { parentNode.Nodes.Add(subNode); } } PermissionTree.EndUpdate(); }
private void PopulatePermissionTree() { ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings; string connString = connectionStrings[ "ControlBasedSecurity.Properties.Settings.ControlSecurityConnectionString"]. ToString(); SqlConnection conn = new SqlConnection(connString); conn.Open(); string queryString = "select controlID, Invisible, Disabled, RoleName " + "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"; } DataSet ds = new DataSet(); SqlDataAdapter dataAdapter = null; DataTable dt = null; try { dataAdapter = new SqlDataAdapter(queryString, conn); dataAdapter.Fill(ds, "controlsToRoles"); dt = ds.Tables[0]; } catch (Exception e) { MessageBox.Show("Unable to retrieve permissions: " + e.Message, "Error retrieving permissions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); } PermissionTree.BeginUpdate(); PermissionTree.Nodes.Clear(); TreeNode parentNode = null; TreeNode subNode = null; string currentName = string.Empty; foreach (DataRow row in dt.Rows) { string subNodeText = ByControlRB.Checked ? row["RoleName"].ToString() : row["ControlID"].ToString(); subNodeText += ":"; subNodeText += Convert.ToInt32(row["Invisible"]) == 0 ? " visible " : " not visible "; subNodeText += " and "; subNodeText += Convert.ToInt32(row["Disabled"]) == 0 ? " enabled " : " disabled "; 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(); }
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(); }