Compare commits

..

2 Commits

Author SHA1 Message Date
Rafa Muñoz
7dbbed7984 fix(ch 9): ex 1 comp error solved 2025-03-13 12:47:50 +01:00
Rafa Muñoz
738c42f160 feat(ch 9): ex 1 finished - Gestión Fabricante 2025-03-13 12:45:15 +01:00
2 changed files with 75 additions and 1 deletions

View File

@@ -95,7 +95,11 @@ public class ControladorFabricante {
return 1;
}
/**
*
* @param f
* @return
*/
public static int insertaFabricante(Fabricante f) {
try {
Connection conn = ConnectionManager.getConnection();
@@ -115,6 +119,28 @@ public class ControladorFabricante {
return 0;
}
/**
*
* @param f
* @return
*/
public static int eliminaFabricante(int idFabricante) {
try {
Connection conn = ConnectionManager.getConnection();
String sql = "delete from fabricante where id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, idFabricante);
return ps.executeUpdate();
}
catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
}

View File

@@ -203,6 +203,11 @@ public class VentanaGestionFabricante extends JFrame {
panel_1.add(btnNewButton_5);
JButton btnNewButton_6 = new JButton("Eliminar");
btnNewButton_6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eliminar();
}
});
panel_1.add(btnNewButton_6);
@@ -277,6 +282,49 @@ public class VentanaGestionFabricante extends JFrame {
this.jtfCif.setText("");
}
/**
*
*/
private void eliminar() {
String [] opciones ={"","No"};
int eleccion = JOptionPane.showOptionDialog(null,"¿Desea eliminar el registro?",
"Confirmación",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, opciones, "No");
if (eleccion == JOptionPane.YES_OPTION) {
// Realmente elimino
int idFabricante = Integer.parseInt(this.jtfId.getText());
if (ControladorFabricante.eliminaFabricante(idFabricante) > 0) {
// Navego al anterior, si existe
Fabricante anterior =
ControladorFabricante.getAnterior(idFabricante);
if (anterior != null) { // Existe un anterior
mostrarFabricanteEnPantalla(anterior);
}
else { // No existe anterior
Fabricante siguiente =
ControladorFabricante.getSiguiente(idFabricante);
if (siguiente != null) { // Existe un siguiente
mostrarFabricanteEnPantalla(siguiente);
}
else { // No existe siguiente ni anterior, no queda na
nuevo();
}
}
JOptionPane.showMessageDialog(null, "Registro eliminado");
}
else {
JOptionPane.showMessageDialog(null, "Error en la eliminación");
}
}
}
}