Correcciones varias... se me fue la onda

Le puse una columna de inserted_at a todas las tablas de la base de
datos excepto las de join

El resto son bugs.. no se, muchas cosas
This commit is contained in:
Daniel Cortés
2019-05-28 23:36:52 -04:00
parent 50ae40449b
commit e4c7e8f282
7 changed files with 114 additions and 70 deletions

View File

@@ -2,53 +2,56 @@
#-----------------------------Eliminar todas las tablas--------------------------# #-----------------------------Eliminar todas las tablas--------------------------#
#--------------------------------------------------------------------------------# #--------------------------------------------------------------------------------#
set foreign_key_checks = 0; set foreign_key_checks = 0;
drop table if exists usuario;
drop table if exists libro_arriendo; drop table if exists editorial;
drop table if exists libro_venta; drop table if exists estado;
drop table if exists libro_compra; drop table if exists autor;
drop table if exists arriendo; drop table if exists categoria;
drop table if exists venta; drop table if exists idioma;
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 libro; drop table if exists libro;
drop table if exists ejemplar; drop table if exists ejemplar;
drop table if exists editorial; drop table if exists libro_autor;
drop table if exists idioma; drop table if exists libro_categoria;
drop table if exists categoria; drop table if exists libro_idioma;
drop table if exists autor; drop table if exists direccion;
drop table if exists estado; drop table if exists telefono;
set foreign_key_checks = 1; 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----------------# #--------------Definicion de las tablas relacionadas a los libros----------------#
#--------------------------------------------------------------------------------# #--------------------------------------------------------------------------------#
create table editorial create table editorial
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table estado create table estado
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table autor create table autor
@@ -56,19 +59,22 @@ create table autor
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null, nombre varchar(255) not null,
apellido_paterno 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 create table categoria
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table idioma create table idioma
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table libro create table libro
@@ -80,18 +86,20 @@ create table libro
precio_referencia int not null, precio_referencia int not null,
ano_publicacion int default null, ano_publicacion int default null,
editorial_id int unsigned not 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 create table ejemplar
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
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), unique key serie_libro (serie, libro_id),
foreign key (libro_id) references libro (id) on delete cascade on update cascade, 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 create table libro_autor
@@ -124,29 +132,33 @@ create table libro_idioma
#--------------------------------------------------------------------------------# #--------------------------------------------------------------------------------#
create table direccion create table direccion
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
calle varchar(255) not null, calle varchar(255) not null,
numero varchar(255) not null numero varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table telefono create table telefono
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
numero varchar(255) not null numero varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table empresa create table empresa
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
nombre varchar(255) not null nombre varchar(255) not null,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table distribuidor create table distribuidor
( (
id int unsigned primary key auto_increment, id int unsigned primary key auto_increment,
rut varchar(255) not null, rut varchar(255) not null,
empresa_id int unsigned not null, empresa_id int unsigned not null,
foreign key (empresa_id) references empresa (id) on delete restrict on update cascade foreign key (empresa_id) references empresa (id) on delete restrict on update cascade,
inserted_at timestamp default CURRENT_TIMESTAMP
); );
create table cliente create table cliente
@@ -156,7 +168,8 @@ create table cliente
nombre varchar(255) not null, nombre varchar(255) not null,
apellido_paterno varchar(255) not null, apellido_paterno varchar(255) not null,
apellido_materno 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 create table trabajador
@@ -166,7 +179,8 @@ create table trabajador
nombre varchar(255) not null, nombre varchar(255) not null,
apellido_paterno varchar(255) not null, apellido_paterno varchar(255) not null,
apellido_materno 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 create table distribuidor_direccion
@@ -228,7 +242,8 @@ create table factura
precio_neto int not null, precio_neto int not null,
precio_iva int not null, precio_iva int not null,
costo_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 create table boleta
@@ -238,7 +253,8 @@ create table boleta
precio_neto int not null, precio_neto int not null,
precio_iva int not null, precio_iva int not null,
costo_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 create table compra
@@ -247,7 +263,8 @@ create table compra
factura_id int unsigned not null, factura_id int unsigned not null,
distribuidor_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 (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 create table venta
@@ -258,7 +275,8 @@ create table venta
boleta_id int unsigned not null, boleta_id int unsigned not null,
foreign key (cliente_id) references cliente (id) on delete restrict on update cascade, 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 (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 create table arriendo
@@ -271,7 +289,8 @@ create table arriendo
fecha_devolucion_estimada date not null, fecha_devolucion_estimada date not null,
fecha_devolucion_real date, fecha_devolucion_real date,
trabajador_id int unsigned not null, 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 create table libro_compra
@@ -308,7 +327,8 @@ create table usuario
nombre varchar(255) not null, nombre varchar(255) not null,
password varbinary(2000) not null, password varbinary(2000) not null,
trabajador_id int unsigned 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
); );
#--------------------------------------------------------------------------------# #--------------------------------------------------------------------------------#

View File

@@ -7,7 +7,6 @@ import javax.swing.UnsupportedLookAndFeelException;
import xyz.danielcortes.controllers.LaunchController; import xyz.danielcortes.controllers.LaunchController;
import xyz.danielcortes.login.LoginController; import xyz.danielcortes.login.LoginController;
import xyz.danielcortes.login.LoginPanel; import xyz.danielcortes.login.LoginPanel;
import xyz.danielcortes.models.Usuario;
public class App { public class App {
@@ -15,7 +14,7 @@ public class App {
setupLookAndFeel(); setupLookAndFeel();
LoginController loginController = new LoginController(new LoginPanel()); LoginController loginController = new LoginController(new LoginPanel());
loginController.setLoggedListener(e -> { loginController.setLoggedListener(e -> {
LaunchController launchController = new LaunchController(new Usuario()); LaunchController launchController = new LaunchController(e.getUser());
launchController.run(); launchController.run();
}); });
} }
@@ -31,7 +30,7 @@ public class App {
String metal = "javax.swing.plaf.metal.MetalLookAndFeel"; String metal = "javax.swing.plaf.metal.MetalLookAndFeel";
String gtk = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; String gtk = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
UIManager.setLookAndFeel(gtk); UIManager.setLookAndFeel(nimbus);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -72,7 +72,7 @@ public class TrabajadorUpdateController extends BaseController {
return; return;
} }
String apellidoMaterno = this.view.getApellidoPaternoField().getText(); String apellidoMaterno = this.view.getApellidoMaternoField().getText();
ValidationResult apellidoMaternoValidation = this.trabajadorValidator.validateApellidoMaterno(apellidoMaterno); ValidationResult apellidoMaternoValidation = this.trabajadorValidator.validateApellidoMaterno(apellidoMaterno);
if(apellidoMaternoValidation.hasError()){ if(apellidoMaternoValidation.hasError()){
apellidoMaternoValidation.showErrorDialog(); apellidoMaternoValidation.showErrorDialog();

View File

@@ -39,6 +39,7 @@ public class TrabajadorViewController extends BaseController {
this.view.getApellidoPaternoField().setText(this.trabajador.getApellidoPaterno()); this.view.getApellidoPaternoField().setText(this.trabajador.getApellidoPaterno());
this.view.getApellidoMaternoField().setText(this.trabajador.getApellidoMaterno()); this.view.getApellidoMaternoField().setText(this.trabajador.getApellidoMaterno());
this.view.getFechaContratoPicker().setDate(this.trabajador.getFechaContrato()); this.view.getFechaContratoPicker().setDate(this.trabajador.getFechaContrato());
this.view.getUsernameField().setText(this.trabajador.getUsuario().getNombre());
} }
public BasePanel getView() { public BasePanel getView() {

View File

@@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
import xyz.danielcortes.framework.Hash; import xyz.danielcortes.framework.Hash;
import xyz.danielcortes.framework.LoggedEvent; import xyz.danielcortes.framework.LoggedEvent;
@@ -44,6 +45,13 @@ public class LoginController {
if (Arrays.equals(pass, user.getPassword())) { if (Arrays.equals(pass, user.getPassword())) {
this.frame.dispose(); this.frame.dispose();
loggedListener.loginTry(new LoggedEvent(this, user)); loggedListener.loginTry(new LoggedEvent(this, user));
}else{
JOptionPane.showMessageDialog(
null,
"El usuario o contraseña son incorrectos",
"Error",
JOptionPane.ERROR_MESSAGE
);
} }
} }

View File

@@ -7,6 +7,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
@Entity @Entity
@@ -31,6 +32,9 @@ public class Trabajador {
@Column(name = "fecha_contrato") @Column(name = "fecha_contrato")
private LocalDate fechaContrato; private LocalDate fechaContrato;
@OneToOne(mappedBy = "trabajador")
private Usuario usuario;
public Integer getId() { public Integer getId() {
return id; return id;
} }
@@ -79,6 +83,14 @@ public class Trabajador {
this.fechaContrato = fechaContrato; this.fechaContrato = fechaContrato;
} }
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o)

View File

@@ -112,7 +112,9 @@
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties>
<editable value="false"/>
</properties>
</component> </component>
<component id="c3b00" class="com.github.lgooddatepicker.components.DatePicker" binding="fechaContratoPicker"> <component id="c3b00" class="com.github.lgooddatepicker.components.DatePicker" binding="fechaContratoPicker">
<constraints> <constraints>
@@ -134,7 +136,9 @@
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties>
<editable value="false"/>
</properties>
</component> </component>
</children> </children>
</grid> </grid>