Browse Source

ya se insertan todos los datos del formulario en sus respectivas tablas y ademas se agregaron validaciones y notificaciones de error en caso de que falle alguna insercion

master
mramirezg 9 months ago
parent
commit
638d593f49
2 changed files with 80 additions and 9 deletions
  1. +26
    -2
      src/main/java/mx/gob/jumapacelaya/services/DatabaseService.java
  2. +54
    -7
      src/main/java/mx/gob/jumapacelaya/ui/MantenimientoView.java

+ 26
- 2
src/main/java/mx/gob/jumapacelaya/services/DatabaseService.java View File

@ -1,5 +1,8 @@
package mx.gob.jumapacelaya.services;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
import javax.swing.plaf.PanelUI;
import java.sql.*;
import java.time.LocalDate;
import java.util.ArrayList;
@ -139,8 +142,8 @@ public class DatabaseService {
/* -------------- Metodos para insetar en la BD ---------------- */
// INSERTAR EN TABLA: MANTENIMINETOS
public int insertarMantenimiento(LocalDate fecha, String tipoMantId, String departamentoId, String empleadoId) {
String query = "INSERT INTO MANTENIMIENTOS (fecha, tipoMantId, departamentoId, empleadoId) VALUES (?, ?, ?, ?)";
public int insertarMantenimiento(LocalDate fecha, String tipoMantId, String departamentoId, String empleadoId, String formaMant) {
String query = "INSERT INTO MANTENIMIENTOS (fecha, tipoMantId, departamentoId, empleadoId, formaMant) VALUES (?, ?, ?, ?, ?)";
int nuevoId = -1;
try (Connection connection = getConnection();
@ -150,6 +153,7 @@ public class DatabaseService {
preparedStatement.setString(2, tipoMantId);
preparedStatement.setString(3, departamentoId);
preparedStatement.setString(4, empleadoId);
preparedStatement.setString(5, formaMant);
int rowsAffected = preparedStatement.executeUpdate();
if (rowsAffected > 0) {
@ -203,4 +207,24 @@ public class DatabaseService {
}
return ultimoId;
}
// INSERTAR EN LA TABLA: ACTUALIZACIONESSEG
public boolean insertActualizacionSeg(String descripcion, String otras, int mantenimientoId) {
String query = "INSERT INTO ACTUALIZACIONESSEG (actualizacion, otrasactualizaciones, mantenimientoid) VALUES (?, ?, ?)";
try (Connection connection = getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, descripcion);
preparedStatement.setString(2, otras);
preparedStatement.setInt(3, mantenimientoId);
int rowsInserted = preparedStatement.executeUpdate();
return rowsInserted > 0;
} catch (SQLException e) {
System.err.println("Error al insertar actualizacionSeg: " + e.getMessage());
return false;
}
}
}

+ 54
- 7
src/main/java/mx/gob/jumapacelaya/ui/MantenimientoView.java View File

@ -49,7 +49,11 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
private final ComboBox<String> tipoMantt;
private final ComboBox<String> area;
private final ComboBox<String> usuario;
private RadioButtonGroup<String> formaGroup;
private CheckboxGroup<String> actualizaciones;
private final HorizontalLayout botonesLayout;
private TextArea txtCuales;
private RadioButtonGroup<String> masActualizacionesGroup;
Span userSignSpan = new Span("Nombre Usuario");
@ -242,21 +246,21 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
Span Titulo = new Span("Actualizaciones de Seguridad Informatica:");
etiquetaLayout.add(Titulo);
CheckboxGroup<String> actualizaciones = new CheckboxGroup<>();
this.actualizaciones = new CheckboxGroup<>();
actualizaciones.setLabel("Actualizaciones Necesarias");
actualizaciones.setItems("S.O", "Antivirus", "Firewall");
RadioButtonGroup<String> formaGroup = new RadioButtonGroup<>();
this.formaGroup = new RadioButtonGroup<>();
formaGroup.setRequired(true);
formaGroup.setLabel("Actividad Realizada de Forma:");
formaGroup.setItems("Remota", "Manual");
TextArea txtCuales = new TextArea();
this.txtCuales = new TextArea();
txtCuales.setLabel("¿Cuales?");
txtCuales.setEnabled(false);
txtCuales.setWidthFull();
RadioButtonGroup<String> masActualizacionesGroup = new RadioButtonGroup<>();
this.masActualizacionesGroup= new RadioButtonGroup<>();
masActualizacionesGroup.setRequired(true);
masActualizacionesGroup.setLabel("¿Requiere Más Actualizaciones?");
masActualizacionesGroup.setItems("Si","No");
@ -388,13 +392,27 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
String departamentoId = area.getValue();
String empleadoId = usuario.getValue();
if (fechaSeleccionada == null || tipoMantId == null || departamentoId == null || empleadoId == null) {
// AQUI SE MANEJA LA OPCION SELECIONADA EN LA FORMA DE MANTENIMIENTO (REMOTA o MANUAL)
String formaSeleccionada = formaGroup.getValue();
String formaMantt = null;
if ("Remota".equals(formaSeleccionada)) {
formaMantt = "R";
} else if ("Manual".equals(formaSeleccionada)) {
formaMantt = "M";
}
// VALIDACION PARA QUE TODOS LOS CAMPOS OBLIGATORIOS SEAN LLENADOS
if (fechaSeleccionada == null || tipoMantId == null || departamentoId == null || empleadoId == null || formaMantt == null) {
Notification.show("Por favor, completa todos los campos requeridos", 4000, Notification.Position.MIDDLE);
return;
}
int isInserted = databaseService.insertarMantenimiento(fechaSeleccionada, tipoMantId, departamentoId, empleadoId);
int isInserted = databaseService.insertarMantenimiento(fechaSeleccionada, tipoMantId, departamentoId, empleadoId, formaMantt);
// AQUI SE MANEJA LA INSERCION DE LOS DETALLES DE HARDWARE (TIPO DE HARDWARE, NO. DE SERIE, MODELO, PLACA)
if (isInserted > 0) {
int mantenimientoId = databaseService.getUltimoMantenimientoId();
@ -408,7 +426,7 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
int numSerieInt = noSerie.getValue() != null ? noSerie.getValue().intValue() : 0;
int placaInt = placa.getValue() != null ? placa.getValue().intValue() : 0;
// Validaciones antes de insertar hardware
// Validaciones antes de insertar detalles del hardware
if (tipoHardware.getValue() == null || modelo.getValue() == null || numSerieInt <= 0 || placaInt <= 0) {
Notification.show("Por favor, completa todos los campos de hardware", 4000, Notification.Position.MIDDLE);
return;
@ -430,14 +448,43 @@ public class MantenimientoView extends VerticalLayout implements BeforeEnterObse
Notification.show("Error al insertar detalles del hardware", 4000, Notification.Position.MIDDLE);
return;
}
}
// AQUI MANEJO LA INSERCION DE LOS DATOS DE LOS CHECKBOXES DE ACTUALIZACIONES DE SEGURIDAD!!!
for (String actualizacionSelecionada : actualizaciones.getSelectedItems()) {
boolean isActualizacionInserted = databaseService.insertActualizacionSeg(actualizacionSelecionada, null, mantenimientoId);
if (!isActualizacionInserted) {
Notification.show("Error al insertar actualizacion de seguridad", 4000, Notification.Position.MIDDLE);
return;
}
}
if (masActualizacionesGroup.getValue().equals("Si")) {
String otrasActu = txtCuales.getValue();
String actualizacion = "Otras";
if (otrasActu != null && !otrasActu.trim().isEmpty()){
boolean isOtrasActualizaciones = databaseService.insertActualizacionSeg(actualizacion, otrasActu, mantenimientoId);
if (!isOtrasActualizaciones) {
Notification.show("Error al insertar otras actualizaciones de seguridad", 4000, Notification.Position.MIDDLE);
return;
}
}
}
// NOTIFICACION DE GUARDADO EXITOSO Y LIMPIEZA DE LOS CAMPOS!!!
Notification.show("!!Mantenimiento guardado exitosamente!!", 4000, Notification.Position.MIDDLE);
fecha.clear();
tipoMantt.clear();
area.clear();
usuario.clear();
formaGroup.clear();
actualizaciones.clear();
masActualizacionesGroup.clear();
txtCuales.clear();
} else {
Notification.show("Error al guardar el mantenimeinto", 4000, Notification.Position.MIDDLE);
}


Loading…
Cancel
Save