arreglada validacion de serie ejemplar y cosas de la vista

This commit is contained in:
Daniel Cortés
2019-05-14 13:07:47 -04:00
parent 944dfecf08
commit 3c7a120314
5 changed files with 34 additions and 18 deletions

View File

@@ -1,5 +1,7 @@
package xyz.danielcortes;
import java.awt.Toolkit;
import java.lang.reflect.Field;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import xyz.danielcortes.controllers.LaunchController;
@@ -13,12 +15,27 @@ public class App {
}
private static void setupLookAndFeel(){
System.setProperty("awt.useSystemAAFontSettings","lcd");
System.setProperty("swing.aatext", "true");
try {
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
String motif ="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
String nimbus = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
String metal = "javax.swing.plaf.metal.MetalLookAndFeel";
UIManager.setLookAndFeel(metal);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
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();
}
}
}

View File

@@ -110,7 +110,7 @@ public class LibroSearchController extends BaseController {
if (serie == null)
return;
if (!this.ejemplarValidator.validateSerie(serie))
if (!this.ejemplarValidator.validateSerie(serie, libro.getId()))
return;
Ejemplar ejemplar = new Ejemplar();

View File

@@ -67,10 +67,18 @@ public class EjemplarRepository {
em.getTransaction().commit();
}
public boolean exists(String serie, Integer id) {
Query query = em.createQuery("SELECT count(e) FROM Ejemplar e WHERE serie = :serie and id != :id");
public boolean exists(String serie, Integer libro_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("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("serie", serie);
query.setParameter("libro_id", libro_id);
return (Long) query.getResultList().get(0) == 1;
}
}

View File

@@ -1,7 +1,6 @@
package xyz.danielcortes.validator;
import javax.swing.JOptionPane;
import xyz.danielcortes.models.Ejemplar;
import xyz.danielcortes.repository.EjemplarRepository;
public class EjemplarValidator {
@@ -12,7 +11,7 @@ public class EjemplarValidator {
this.ejemplarRepository = ejemplarRepository;
}
public boolean validateSerie(String serie) {
public boolean validateSerie(String serie, Integer libro_id) {
if (serie == null) {
JOptionPane.showMessageDialog(
null,
@@ -29,15 +28,7 @@ public class EjemplarValidator {
JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
public boolean validateSerie(String serie, Ejemplar original) {
if (!validateSerie(serie))
return false;
if (!ejemplarRepository.exists(serie, original.getId())) {
if (ejemplarRepository.exists(serie, libro_id)) {
JOptionPane.showMessageDialog(
null,
"El numero de serie ya existe",
@@ -48,5 +39,4 @@ public class EjemplarValidator {
return true;
}
}