private void BtnAplicar_Click(object sender, EventArgs e) { try { if ((int?)cboPerfil.SelectedValue > 0) { bool Exclusao = new GRUPO_ACESSO_BLL().Excluir((int)cboPerfil.SelectedValue); if (Exclusao) { int ID_PERFIL = (int)cboPerfil.SelectedValue; foreach (TreeNode itens in trwTelasSelecionadas.Nodes[0].Nodes) { if (lista_telas.Exists(x => x.ID == Convert.ToInt32(itens.Tag))) { SYS_MENU_DTO tela = lista_telas.First(x => x.ID == Convert.ToInt32(itens.Tag)); GRUPO_ACESSO_DTO DTO = new GRUPO_ACESSO_DTO(); DTO.ID_PERFIL = ID_PERFIL; DTO.ID_SYS_MENU = tela.ID; new GRUPO_ACESSO_BLL().Inserir(DTO); } } } cboPerfil.SelectedIndex = -1; tssMSG.Text = "Permissões alteradas"; tssMSG.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro do sistema", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public GRUPO_ACESSO_DTO Listar(int ID_PERFIL) { using (SqlConnection cn = new SqlConnection(strConnection)) { GRUPO_ACESSO_DTO list = new GRUPO_ACESSO_DTO(); try { SqlDataReader dr = null; StringBuilder SQL_ = new StringBuilder(); SQL_.Append("select "); SQL_.Append("X.ID, "); SQL_.Append("X.ID_SYS_MENU, "); SQL_.Append("A.DESCRICAO, "); SQL_.Append("A.NAME, "); SQL_.Append("A.ID AS ID_SYS_MENU "); SQL_.Append("from "); SQL_.Append("GRUPO_ACESSO X "); SQL_.Append("LEFT JOIN SYS_MENU A "); SQL_.Append("ON "); SQL_.Append("X.ID_SYS_MENU = A.ID "); SQL_.Append("WHERE "); SQL_.Append("ID_PERFIL = @ID_PERFIL "); cn.Open(); SqlCommand cmd = new SqlCommand(SQL_.ToString(), cn); cmd.Parameters.AddWithValue("@ID_PERFIL", ID_PERFIL); dr = cmd.ExecuteReader(); while (dr.Read()) { SYS_MENU_DTO menu = new SYS_MENU_DTO(); menu.ID = Convert.ToInt32(dr["ID_SYS_MENU"]); menu.DESCRICAO = Convert.ToString(dr["DESCRICAO"]); menu.NAME = Convert.ToString(dr["NAME"]); list.SYS_MENU.Add(menu); } return(list); } catch (SqlException ex) { throw new Exception(ex.ToString()); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { cn.Close(); } } }
public int?Inserir(GRUPO_ACESSO_DTO DTO) { try { return(DAO.Inserir(DTO)); } catch (Exception ex) { throw ex; } }
public void PopularParametros(GRUPO_ACESSO_DTO DTO, SqlCommand cmd) { cmd.Parameters.AddWithValue("@ID", DTO.ID); cmd.Parameters.AddWithValue("@ID_PERFIL", DTO.ID_PERFIL); cmd.Parameters.AddWithValue("@ID_SYS_MENU", DTO.ID_SYS_MENU); //Substitui o null por DBnull foreach (SqlParameter Parameter in cmd.Parameters) { if (Parameter.Value == null) { Parameter.Value = DBNull.Value; } } }
public int?Inserir(GRUPO_ACESSO_DTO DTO) { using (SqlConnection cn = new SqlConnection(strConnection)) { try { SqlDataReader dr = null; StringBuilder SQL_ = new StringBuilder(); SQL_.Append("INSERT INTO "); SQL_.Append("GRUPO_ACESSO "); SQL_.Append("( "); SQL_.Append("ID_PERFIL, "); SQL_.Append("ID_SYS_MENU "); SQL_.Append(") "); SQL_.Append("VALUES "); SQL_.Append("( "); SQL_.Append("@ID_PERFIL, "); SQL_.Append("@ID_SYS_MENU "); SQL_.Append("); SELECT SCOPE_IDENTITY(); "); cn.Open(); SqlCommand cmd = new SqlCommand(SQL_.ToString(), cn); PopularParametros(DTO, cmd); if ((DTO.ID = Convert.ToInt32(cmd.ExecuteScalar())) > 0) { return(DTO.ID); } return(0); } catch (SqlException ex) { throw new Exception(ex.ToString()); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { cn.Close(); } } }