diff --git a/script.sql b/script.sql index 6fe0e6f..08c27fb 100644 --- a/script.sql +++ b/script.sql @@ -2,53 +2,56 @@ #-----------------------------Eliminar todas las tablas--------------------------# #--------------------------------------------------------------------------------# set foreign_key_checks = 0; -drop table if exists usuario; -drop table if exists libro_arriendo; -drop table if exists libro_venta; -drop table if exists libro_compra; -drop table if exists arriendo; -drop table if exists venta; -drop table if exists compra; -drop table if exists boleta; -drop table if exists factura; -drop table if exists trabajador_telefono; -drop table if exists trabajador_direccion; -drop table if exists cliente_telefono; -drop table if exists cliente_direccion; -drop table if exists distribuidor_telefono; -drop table if exists distribuidor_direccion; -drop table if exists trabajador; -drop table if exists cliente; -drop table if exists distribuidor; -drop table if exists empresa; -drop table if exists telefono; -drop table if exists direccion; -drop table if exists libro_idioma; -drop table if exists libro_categoria; -drop table if exists libro_autor; + +drop table if exists editorial; +drop table if exists estado; +drop table if exists autor; +drop table if exists categoria; +drop table if exists idioma; drop table if exists libro; drop table if exists ejemplar; -drop table if exists editorial; -drop table if exists idioma; -drop table if exists categoria; -drop table if exists autor; -drop table if exists estado; -set foreign_key_checks = 1; +drop table if exists libro_autor; +drop table if exists libro_categoria; +drop table if exists libro_idioma; +drop table if exists direccion; +drop table if exists telefono; +drop table if exists empresa; +drop table if exists distribuidor; +drop table if exists cliente; +drop table if exists trabajador; +drop table if exists distribuidor_direccion; +drop table if exists distribuidor_telefono; +drop table if exists cliente_direccion; +drop table if exists cliente_telefono; +drop table if exists trabajador_direccion; +drop table if exists trabajador_telefono; +drop table if exists factura; +drop table if exists boleta; +drop table if exists compra; +drop table if exists venta; +drop table if exists arriendo; +drop table if exists libro_compra; +drop table if exists libro_venta; +drop table if exists libro_arriendo; +drop table if exists usuario; +set foreign_key_checks = 1; #--------------------------------------------------------------------------------# #--------------Definicion de las tablas relacionadas a los libros----------------# #--------------------------------------------------------------------------------# create table editorial ( - id int unsigned primary key auto_increment, - nombre varchar(255) not null + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table estado ( - id int unsigned primary key auto_increment, - nombre varchar(255) not null + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table autor @@ -56,19 +59,22 @@ create table autor id int unsigned primary key auto_increment, nombre varchar(255) not null, apellido_paterno varchar(255) not null, - apellido_materno varchar(255) not null + apellido_materno varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table categoria ( - id int unsigned primary key auto_increment, - nombre varchar(255) not null + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table idioma ( - id int unsigned primary key auto_increment, - nombre varchar(255) not null + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table libro @@ -80,18 +86,20 @@ create table libro precio_referencia int not null, ano_publicacion int default null, editorial_id int unsigned not null, - foreign key (editorial_id) references editorial (id) on delete restrict on update cascade + foreign key (editorial_id) references editorial (id) on delete restrict on update cascade, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table ejemplar ( - id int unsigned primary key auto_increment, - serie varchar(255) not null, - libro_id int unsigned not null, - estado_id int unsigned default 1, + id int unsigned primary key auto_increment, + serie varchar(255) not null, + libro_id int unsigned not null, + estado_id int unsigned default 1, unique key serie_libro (serie, libro_id), foreign key (libro_id) references libro (id) on delete cascade 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, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table libro_autor @@ -124,29 +132,33 @@ create table libro_idioma #--------------------------------------------------------------------------------# create table direccion ( - id int unsigned primary key auto_increment, - calle varchar(255) not null, - numero varchar(255) not null + id int unsigned primary key auto_increment, + calle varchar(255) not null, + numero varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table telefono ( - id int unsigned primary key auto_increment, - numero varchar(255) not null + id int unsigned primary key auto_increment, + numero varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table empresa ( - id int unsigned primary key auto_increment, - nombre varchar(255) not null + id int unsigned primary key auto_increment, + nombre varchar(255) not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table distribuidor ( - id int unsigned primary key auto_increment, - rut varchar(255) not null, - empresa_id int unsigned not null, - foreign key (empresa_id) references empresa (id) on delete restrict on update cascade + id int unsigned primary key auto_increment, + rut varchar(255) not null, + empresa_id int unsigned not null, + foreign key (empresa_id) references empresa (id) on delete restrict on update cascade, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table cliente @@ -156,7 +168,8 @@ create table cliente nombre varchar(255) not null, apellido_paterno varchar(255) not null, apellido_materno varchar(255) not null, - fecha_nacimiento date not null + fecha_nacimiento date not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table trabajador @@ -166,7 +179,8 @@ create table trabajador nombre varchar(255) not null, apellido_paterno varchar(255) not null, apellido_materno varchar(255) not null, - fecha_contrato date not null + fecha_contrato date not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table distribuidor_direccion @@ -228,7 +242,8 @@ create table factura precio_neto int not null, precio_iva int not null, costo_iva int not null, - fecha_compra datetime not null + fecha_compra datetime not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table boleta @@ -238,7 +253,8 @@ create table boleta precio_neto int not null, precio_iva int not null, costo_iva int not null, - fecha_venta datetime not null + fecha_venta datetime not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table compra @@ -247,7 +263,8 @@ create table compra factura_id int unsigned not null, distribuidor_id int unsigned not null, foreign key (factura_id) references factura (id) on delete restrict on update cascade, - foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade + foreign key (distribuidor_id) references distribuidor (id) on delete restrict on update cascade, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table venta @@ -258,7 +275,8 @@ create table venta boleta_id int unsigned not null, foreign key (cliente_id) references cliente (id) on delete restrict on update cascade, foreign key (trabajador_id) references trabajador (id) on delete restrict on update cascade, - foreign key (boleta_id) references boleta (id) on delete restrict on update cascade + foreign key (boleta_id) references boleta (id) on delete restrict on update cascade, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table arriendo @@ -271,7 +289,8 @@ create table arriendo fecha_devolucion_estimada date not null, fecha_devolucion_real date, trabajador_id int unsigned not null, - cliente_id int unsigned not null + cliente_id int unsigned not null, + inserted_at timestamp default CURRENT_TIMESTAMP ); create table libro_compra @@ -308,7 +327,8 @@ create table usuario nombre varchar(255) not null, password varbinary(2000) not null, trabajador_id int unsigned not null, - foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade + foreign key (trabajador_id) references trabajador (id) on delete cascade on update cascade, + inserted_at timestamp default current_timestamp ); #--------------------------------------------------------------------------------# diff --git a/src/main/java/xyz/danielcortes/App.java b/src/main/java/xyz/danielcortes/App.java index c9b4bdd..087166e 100644 --- a/src/main/java/xyz/danielcortes/App.java +++ b/src/main/java/xyz/danielcortes/App.java @@ -7,7 +7,6 @@ import javax.swing.UnsupportedLookAndFeelException; import xyz.danielcortes.controllers.LaunchController; import xyz.danielcortes.login.LoginController; import xyz.danielcortes.login.LoginPanel; -import xyz.danielcortes.models.Usuario; public class App { @@ -15,7 +14,7 @@ public class App { setupLookAndFeel(); LoginController loginController = new LoginController(new LoginPanel()); loginController.setLoggedListener(e -> { - LaunchController launchController = new LaunchController(new Usuario()); + LaunchController launchController = new LaunchController(e.getUser()); launchController.run(); }); } @@ -31,7 +30,7 @@ public class App { String metal = "javax.swing.plaf.metal.MetalLookAndFeel"; String gtk = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; - UIManager.setLookAndFeel(gtk); + UIManager.setLookAndFeel(nimbus); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { e.printStackTrace(); } diff --git a/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorUpdateController.java b/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorUpdateController.java index 1425892..cfa6018 100644 --- a/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorUpdateController.java +++ b/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorUpdateController.java @@ -72,7 +72,7 @@ public class TrabajadorUpdateController extends BaseController { return; } - String apellidoMaterno = this.view.getApellidoPaternoField().getText(); + String apellidoMaterno = this.view.getApellidoMaternoField().getText(); ValidationResult apellidoMaternoValidation = this.trabajadorValidator.validateApellidoMaterno(apellidoMaterno); if(apellidoMaternoValidation.hasError()){ apellidoMaternoValidation.showErrorDialog(); diff --git a/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorViewController.java b/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorViewController.java index 8083b01..6397326 100644 --- a/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorViewController.java +++ b/src/main/java/xyz/danielcortes/controllers/trabajador/TrabajadorViewController.java @@ -39,6 +39,7 @@ public class TrabajadorViewController extends BaseController { this.view.getApellidoPaternoField().setText(this.trabajador.getApellidoPaterno()); this.view.getApellidoMaternoField().setText(this.trabajador.getApellidoMaterno()); this.view.getFechaContratoPicker().setDate(this.trabajador.getFechaContrato()); + this.view.getUsernameField().setText(this.trabajador.getUsuario().getNombre()); } public BasePanel getView() { diff --git a/src/main/java/xyz/danielcortes/login/LoginController.java b/src/main/java/xyz/danielcortes/login/LoginController.java index e611689..f7c9d31 100644 --- a/src/main/java/xyz/danielcortes/login/LoginController.java +++ b/src/main/java/xyz/danielcortes/login/LoginController.java @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Optional; import javax.swing.JFrame; +import javax.swing.JOptionPane; import javax.swing.WindowConstants; import xyz.danielcortes.framework.Hash; import xyz.danielcortes.framework.LoggedEvent; @@ -44,6 +45,13 @@ public class LoginController { if (Arrays.equals(pass, user.getPassword())) { this.frame.dispose(); loggedListener.loginTry(new LoggedEvent(this, user)); + }else{ + JOptionPane.showMessageDialog( + null, + "El usuario o contraseƱa son incorrectos", + "Error", + JOptionPane.ERROR_MESSAGE + ); } } diff --git a/src/main/java/xyz/danielcortes/models/Trabajador.java b/src/main/java/xyz/danielcortes/models/Trabajador.java index 6e94082..efd24c8 100644 --- a/src/main/java/xyz/danielcortes/models/Trabajador.java +++ b/src/main/java/xyz/danielcortes/models/Trabajador.java @@ -7,6 +7,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @@ -31,6 +32,9 @@ public class Trabajador { @Column(name = "fecha_contrato") private LocalDate fechaContrato; + @OneToOne(mappedBy = "trabajador") + private Usuario usuario; + public Integer getId() { return id; } @@ -79,6 +83,14 @@ public class Trabajador { this.fechaContrato = fechaContrato; } + public Usuario getUsuario() { + return usuario; + } + + public void setUsuario(Usuario usuario) { + this.usuario = usuario; + } + @Override public boolean equals(Object o) { if (this == o) diff --git a/src/main/java/xyz/danielcortes/views/trabajador/TrabajadorViewPanel.form b/src/main/java/xyz/danielcortes/views/trabajador/TrabajadorViewPanel.form index 8ebe293..f296045 100644 --- a/src/main/java/xyz/danielcortes/views/trabajador/TrabajadorViewPanel.form +++ b/src/main/java/xyz/danielcortes/views/trabajador/TrabajadorViewPanel.form @@ -112,7 +112,9 @@ - + + + @@ -134,7 +136,9 @@ - + + +