private void aceptar_Click(object sender, EventArgs e) { //Se validan los campos NotificadorErrores errores = new NotificadorErrores(); if (textBox1.TextLength == 0) { errores.agregarError("El rol no puede contener un nombre vacío"); } if (textBox1.TextLength > 50) { errores.agregarError("El nombre del rol no puede superar los 50 caracteres"); } if (elegidas.Items.Count == 0) { errores.agregarError("Debe elegir al menos una funcionalidad"); } if (errores.hayError()) { errores.mostrarErrores(); return; } //Se agrega el ROL int resultado = UtilesSQL.ejecutarComandoNonQuery("INSERT INTO DERROCHADORES_DE_PAPEL.Rol (rol_nombre, rol_activo)" + " VALUES (\'" + textBox1.Text + "\'," + (habilitado.Checked ? "1":"0") + ")"); if (resultado <= 0) { MessageBox.Show("Hubo un error al intentar agregar el rol, elija otro nombre"); return; } //Se agregan las funcionalidades elegidas para el ROL resultado = UtilesSQL.ejecutarComandoNonQuery("INSERT INTO DERROCHADORES_DE_PAPEL.FuncionalidadXRol (fxro_funcionalidad, fxro_rol)" + " SELECT func_id, rol_id" + " FROM DERROCHADORES_DE_PAPEL.Funcionalidad, DERROCHADORES_DE_PAPEL.Rol" + " WHERE rol_nombre = \'" + textBox1.Text + "\' AND func_detalle IN (" + stringFuncionalidades() + ")"); if (resultado <= 0) { MessageBox.Show("Hubo un error al intentar agregar funcionalidades"); return; } MessageBox.Show("Se agregó el rol con éxito"); this.Close(); }
private void aceptar_Click(object sender, EventArgs e) { //Se validan los campos NotificadorErrores errores = new NotificadorErrores(); if (textBox1.TextLength == 0) { errores.agregarError("El rol no puede contener un nombre vacío"); } if (textBox1.TextLength > 50) { errores.agregarError("El nombre del rol no puede superar los 50 caracteres"); } if (actuales_dt.Rows.Count == 0) { errores.agregarError("Debe elegir al menos una funcionalidad"); } if (errores.hayError()) { errores.mostrarErrores(); return; } int resultado; //Se actualiza el nombre if (!textBox1.Text.Equals(nombre_inicial)) { resultado = UtilesSQL.ejecutarComandoNonQuery("UPDATE DERROCHADORES_DE_PAPEL.Rol SET rol_nombre = \'" + textBox1.Text + "\'" + "WHERE rol_id = " + id_inicial); if (resultado <= 0) { MessageBox.Show("Hubo un error al intentar modificar el rol, elija otro nombre"); return; } } //Se actualiza el estado if (habilitado.Checked != estado_inicial.Equals("Habilitado")) { resultado = UtilesSQL.ejecutarComandoNonQuery("UPDATE DERROCHADORES_DE_PAPEL.Rol SET rol_activo = " + (habilitado.Checked ? "1":"0") + "WHERE rol_id = " + id_inicial); if (resultado <= 0) { MessageBox.Show("Hubo un error al intentar modificar el estado del rol"); return; } } //Se agregan las funcionalidades elegidas para el ROL y se borran las removidas. foreach (DataRow fila in funcionalidades.Rows) { if (!dataTableContiene(fila, funcionalidades_inicial) && dataTableContiene(fila, actuales_dt)) { // Es una funcionalidad nueva resultado = UtilesSQL.ejecutarComandoNonQuery("INSERT INTO DERROCHADORES_DE_PAPEL.FuncionalidadXRol (fxro_funcionalidad, fxro_rol) VALUES (" + fila["func_id"].ToString() + "," + id_inicial + ")"); if (resultado <= 0) { MessageBox.Show("Hubo un error al intentar agregar la funcionalidad " + fila["func_detalle"].ToString()); return; } } else if (dataTableContiene(fila, funcionalidades_inicial) && !dataTableContiene(fila, actuales_dt)) { // Es una funcionalidad removida resultado = UtilesSQL.ejecutarComandoNonQuery("DELETE FROM DERROCHADORES_DE_PAPEL.FuncionalidadXRol WHERE fxro_rol = " + id_inicial + " AND fxro_funcionalidad = " + fila["func_id"].ToString()); if (resultado <= 0) { MessageBox.Show("Hubo un error al intentar quitar la funcionalidad " + fila["func_detalle"].ToString()); return; } } } MessageBox.Show("Se modificó el rol con éxito"); this.Close(); }