arreglada validacion de serie ejemplar y cosas de la vista
This commit is contained in:
@@ -88,6 +88,7 @@ create table ejemplar
|
|||||||
serie varchar(255) not null,
|
serie varchar(255) not null,
|
||||||
libro_id int unsigned not null,
|
libro_id int unsigned not null,
|
||||||
estado_id int unsigned default 1,
|
estado_id int unsigned default 1,
|
||||||
|
unique key serie_libro (serie, libro_id),
|
||||||
foreign key (libro_id) references libro (id) on delete restrict on update cascade,
|
foreign key (libro_id) references libro (id) on delete restrict on update cascade,
|
||||||
foreign key (estado_id) references estado (id) on delete restrict on update cascade
|
foreign key (estado_id) references estado (id) on delete restrict on update cascade
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package xyz.danielcortes;
|
package xyz.danielcortes;
|
||||||
|
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
import xyz.danielcortes.controllers.LaunchController;
|
import xyz.danielcortes.controllers.LaunchController;
|
||||||
@@ -13,12 +15,27 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void setupLookAndFeel(){
|
private static void setupLookAndFeel(){
|
||||||
|
System.setProperty("awt.useSystemAAFontSettings","lcd");
|
||||||
|
System.setProperty("swing.aatext", "true");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
|
||||||
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
String motif ="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
|
||||||
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
|
String nimbus = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
|
||||||
|
String metal = "javax.swing.plaf.metal.MetalLookAndFeel";
|
||||||
|
|
||||||
|
UIManager.setLookAndFeel(metal);
|
||||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Toolkit xToolkit = Toolkit.getDefaultToolkit();
|
||||||
|
Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
|
||||||
|
awtAppClassNameField.setAccessible(true);
|
||||||
|
awtAppClassNameField.set(xToolkit, "JAVA");
|
||||||
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class LibroSearchController extends BaseController {
|
|||||||
if (serie == null)
|
if (serie == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.ejemplarValidator.validateSerie(serie))
|
if (!this.ejemplarValidator.validateSerie(serie, libro.getId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Ejemplar ejemplar = new Ejemplar();
|
Ejemplar ejemplar = new Ejemplar();
|
||||||
|
|||||||
@@ -67,10 +67,18 @@ public class EjemplarRepository {
|
|||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exists(String serie, Integer id) {
|
public boolean exists(String serie, Integer libro_id) {
|
||||||
Query query = em.createQuery("SELECT count(e) FROM Ejemplar e WHERE serie = :serie and id != :id");
|
Query query = em.createQuery("SELECT count(e) FROM Ejemplar e WHERE serie = :serie and libro.id = :libro_id");
|
||||||
query.setParameter("serie", serie);
|
query.setParameter("serie", serie);
|
||||||
|
query.setParameter("libro_id", libro_id);
|
||||||
|
return (Long) query.getResultList().get(0) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean exists(String serie, Integer libro_id, Integer id) {
|
||||||
|
Query query = em.createQuery("SELECT count(e) FROM Ejemplar e WHERE id != :id and serie = :serie and libro.id = :libro_id");
|
||||||
query.setParameter("id", id);
|
query.setParameter("id", id);
|
||||||
|
query.setParameter("serie", serie);
|
||||||
|
query.setParameter("libro_id", libro_id);
|
||||||
return (Long) query.getResultList().get(0) == 1;
|
return (Long) query.getResultList().get(0) == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package xyz.danielcortes.validator;
|
package xyz.danielcortes.validator;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import xyz.danielcortes.models.Ejemplar;
|
|
||||||
import xyz.danielcortes.repository.EjemplarRepository;
|
import xyz.danielcortes.repository.EjemplarRepository;
|
||||||
|
|
||||||
public class EjemplarValidator {
|
public class EjemplarValidator {
|
||||||
@@ -12,7 +11,7 @@ public class EjemplarValidator {
|
|||||||
this.ejemplarRepository = ejemplarRepository;
|
this.ejemplarRepository = ejemplarRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateSerie(String serie) {
|
public boolean validateSerie(String serie, Integer libro_id) {
|
||||||
if (serie == null) {
|
if (serie == null) {
|
||||||
JOptionPane.showMessageDialog(
|
JOptionPane.showMessageDialog(
|
||||||
null,
|
null,
|
||||||
@@ -29,15 +28,7 @@ public class EjemplarValidator {
|
|||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (ejemplarRepository.exists(serie, libro_id)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validateSerie(String serie, Ejemplar original) {
|
|
||||||
if (!validateSerie(serie))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!ejemplarRepository.exists(serie, original.getId())) {
|
|
||||||
JOptionPane.showMessageDialog(
|
JOptionPane.showMessageDialog(
|
||||||
null,
|
null,
|
||||||
"El numero de serie ya existe",
|
"El numero de serie ya existe",
|
||||||
@@ -48,5 +39,4 @@ public class EjemplarValidator {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user