Agregado nro z inicial y nro z final a tabla ingresos

This commit is contained in:
Daniel Cortes
2019-01-05 18:15:49 -03:00
parent 543ee9ffde
commit 4c087680cd
13 changed files with 636 additions and 344 deletions

View File

@@ -31,7 +31,6 @@ import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.IngresosView;
import danielcortes.xyz.views.components.IngresosTableModel;
import org.jetbrains.annotations.Contract;
import javax.swing.*;
import java.awt.event.*;
@@ -121,11 +120,15 @@ public class IngresosController {
*/
private void setupViewEvents() {
this.view.getValorField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroZInicialField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroZFinalField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroInicialField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getNroFinalField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getTipoCombo().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getValorField().getActionMap().put("nextField", new NextAction(this.view.getNroInicialField()));
this.view.getValorField().getActionMap().put("nextField", new NextAction(this.view.getNroZInicialField()));
this.view.getNroZInicialField().getActionMap().put("nextField", new NextAction(this.view.getNroZFinalField()));
this.view.getNroZFinalField().getActionMap().put("nextField", new NextAction(this.view.getNroInicialField()));
this.view.getNroInicialField().getActionMap().put("nextField", new NextAction(this.view.getNroFinalField()));
this.view.getNroFinalField().getActionMap().put("nextField", new NextAction(this.view.getTipoCombo()));
this.view.getTipoCombo().getActionMap().put("save", new GuardarAction(this));
@@ -156,14 +159,16 @@ public class IngresosController {
this.hideErrorMessages();
String valor = this.view.getValorField().getText();
String nroZInicial = this.view.getNroZInicialField().getText();
String nroZFinal = this.view.getNroZFinalField().getText();
String nroInicial = this.view.getNroInicialField().getText();
String nroFinal = this.view.getNroFinalField().getText();
TipoIngreso tipoIngreso = (TipoIngreso) this.view.getTipoCombo().getSelectedItem();
if(editing) {
this.editarIngreso(valor, nroInicial, nroFinal, tipoIngreso, this.caja);
this.editarIngreso(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, this.caja);
} else {
this.guardarIngreso(valor, nroInicial, nroFinal, tipoIngreso, this.caja);
this.guardarIngreso(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, this.caja);
}
this.resetFocus();
}
@@ -204,6 +209,8 @@ public class IngresosController {
this.view.getTipoCombo().setSelectedItem(ingreso.getTipoIngreso());
this.view.getValorField().setText(String.valueOf(ingreso.getValor()));
this.view.getNroZInicialField().setText(String.valueOf(ingreso.getNroZInicial()));
this.view.getNroZFinalField().setText(String.valueOf(ingreso.getNroZFinal()));
this.view.getNroInicialField().setText(String.valueOf(ingreso.getNroInicial()));
this.view.getNroFinalField().setText(String.valueOf(ingreso.getNroFinal()));
}
@@ -236,12 +243,14 @@ public class IngresosController {
* Guarda un ingreso tras llamar a validar el input
* Luego de guardar agrega a la tabla el ingreso, llama a limpiar los campos de input y a actualizar el total de ingresos
*/
private void guardarIngreso(String valor, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
if(this.validateInput(valor, nroInicial, nroFinal, tipoIngreso, caja)){
private void guardarIngreso(String valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
if(this.validateInput(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
Ingreso ingreso = new Ingreso();
ingreso.setTipoIngreso(tipoIngreso);
ingreso.setCaja(caja);
ingreso.setValor(Integer.valueOf(valor));
ingreso.setNroZInicial(nroZInicial);
ingreso.setNroZFinal(nroZFinal);
ingreso.setNroInicial(nroInicial);
ingreso.setNroFinal(nroFinal);
@@ -258,10 +267,12 @@ public class IngresosController {
* Tras esto actualiza el ingreso en la tabla, llama a actualizar el total de ingresos, a limpiar los campos de input y a desactivar la flag de editing.
*
*/
private void editarIngreso(String valor, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
if(this.validateInput(valor, nroInicial, nroFinal, tipoIngreso, caja)){
private void editarIngreso(String valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
if(this.validateInput(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
this.editingIngreso.setTipoIngreso(tipoIngreso);
this.editingIngreso.setValor(Integer.valueOf(valor));
this.editingIngreso.setNroZInicial(nroZInicial);
this.editingIngreso.setNroZFinal(nroZFinal);
this.editingIngreso.setNroInicial(nroInicial);
this.editingIngreso.setNroFinal(nroFinal);
this.ingresoDAO.updateIngreso(this.editingIngreso);
@@ -276,10 +287,12 @@ public class IngresosController {
* Llama a los metodos necesarios para validar el input
* @return true cuando todas las validaciones retoran true, si no, false
*/
private boolean validateInput(String valor, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) {
private boolean validateInput(String valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) {
this.hideErrorMessages();
boolean valorValidation = this.validateValor(valor);
boolean nroZInicialValidation = this.validateNroZInicial(nroZInicial);
boolean nroZFinalValidation = this.validateNroZFinal(nroZFinal);
boolean nroInicialValidation = this.validateNroInicial(nroInicial);
boolean nroFinalValidation = this.validateNroFinal(nroFinal);
boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso);
@@ -335,6 +348,50 @@ public class IngresosController {
}
/**
* Valida la variable nroInicial contra los casos
* - Es null
* - Esta vacio
* Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente
* @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true
*/
private boolean validateNroZInicial(String nroZInicial){
if (nroZInicial == null) {
this.view.getErrorNroInicial().setText("Hubo un problema con los datos");
this.view.getErrorNroInicial().setVisible(true);
return false;
}
if (nroZInicial.isEmpty()) {
this.view.getErrorNroInicial().setText("El campo esta vacio");
this.view.getErrorNroInicial().setVisible(true);
return false;
}
return true;
}
/**
* Valida la variable nroFinal contra los casos
* - Es null
* - Esta vacio
* Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente
* @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true
*/
private boolean validateNroZFinal(String nroZFinal){
if (nroZFinal == null) {
this.view.getErrorNroFinal().setText("Hubo un problema con los datos");
this.view.getErrorNroFinal().setVisible(true);
return false;
}
if (nroZFinal.isEmpty()) {
this.view.getErrorNroFinal().setText("El campo esta vacio");
this.view.getErrorNroFinal().setVisible(true);
return false;
}
return true;
}
/**
* Valida la variable nroInicial contra los casos
* - Es null
@@ -400,6 +457,8 @@ public class IngresosController {
private void hideErrorMessages() {
this.view.getErrorTipoIngreso().setVisible(false);
this.view.getErrorValor().setVisible(false);
this.view.getErrorNroZInicial().setVisible(false);
this.view.getErrorNroZFinal().setVisible(false);
this.view.getErrorNroInicial().setVisible(false);
this.view.getErrorNroFinal().setVisible(false);
}
@@ -410,6 +469,8 @@ public class IngresosController {
private void clearInputs() {
this.view.getTipoCombo().setSelectedIndex(0);
this.view.getValorField().setText("");
this.view.getNroZInicialField().setText("");
this.view.getNroZFinalField().setText("");
this.view.getNroInicialField().setText("");
this.view.getNroFinalField().setText("");
}
@@ -419,6 +480,8 @@ public class IngresosController {
*/
private void normalizeInputs(){
this.view.getValorField().setText(this.view.getValorField().getText().trim());
this.view.getNroZInicialField().setText(this.view.getNroZInicialField().getText().trim());
this.view.getNroZFinalField().setText(this.view.getNroZFinalField().getText().trim());
this.view.getNroInicialField().setText(this.view.getNroInicialField().getText().trim());
this.view.getNroFinalField().setText(this.view.getNroFinalField().getText().trim());
}