NumberFormatTextField agregado en el campo value de ingresos y formateado los campos integer en los tablemodels
This commit is contained in:
@@ -158,7 +158,7 @@ public class IngresosController {
|
||||
this.normalizeInputs();
|
||||
this.hideErrorMessages();
|
||||
|
||||
String valor = this.view.getValorField().getText();
|
||||
int valor = this.view.getValorField().getValue();
|
||||
String nroZInicial = this.view.getNroZInicialField().getText();
|
||||
String nroZFinal = this.view.getNroZFinalField().getText();
|
||||
String nroInicial = this.view.getNroInicialField().getText();
|
||||
@@ -208,7 +208,7 @@ public class IngresosController {
|
||||
this.editing = true;
|
||||
|
||||
this.view.getTipoCombo().setSelectedItem(ingreso.getTipoIngreso());
|
||||
this.view.getValorField().setText(String.valueOf(ingreso.getValor()));
|
||||
this.view.getValorField().setValue(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()));
|
||||
@@ -221,7 +221,7 @@ public class IngresosController {
|
||||
*/
|
||||
private void updateTotalIngresos(){
|
||||
int total = this.ingresoDAO.getTotalIngreso(this.caja);
|
||||
this.view.getTotalIngresoField().setText(String.valueOf(total));
|
||||
this.view.getTotalIngresoField().setValue(total);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,12 +243,12 @@ 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 nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
|
||||
if(this.validateInput(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
|
||||
private void guardarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
|
||||
if(this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
|
||||
Ingreso ingreso = new Ingreso();
|
||||
ingreso.setTipoIngreso(tipoIngreso);
|
||||
ingreso.setCaja(caja);
|
||||
ingreso.setValor(Integer.valueOf(valor));
|
||||
ingreso.setValor(valor);
|
||||
ingreso.setNroZInicial(nroZInicial);
|
||||
ingreso.setNroZFinal(nroZFinal);
|
||||
ingreso.setNroInicial(nroInicial);
|
||||
@@ -267,10 +267,10 @@ 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 nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
|
||||
if(this.validateInput(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
|
||||
private void editarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
|
||||
if(this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
|
||||
this.editingIngreso.setTipoIngreso(tipoIngreso);
|
||||
this.editingIngreso.setValor(Integer.valueOf(valor));
|
||||
this.editingIngreso.setValor(valor);
|
||||
this.editingIngreso.setNroZInicial(nroZInicial);
|
||||
this.editingIngreso.setNroZFinal(nroZFinal);
|
||||
this.editingIngreso.setNroInicial(nroInicial);
|
||||
@@ -287,10 +287,9 @@ 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 nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) {
|
||||
private boolean validateInput(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);
|
||||
@@ -298,7 +297,7 @@ public class IngresosController {
|
||||
boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso);
|
||||
boolean cajaValidation = this.validateCaja(caja);
|
||||
|
||||
return valorValidation && tipoIngresoValidation && cajaValidation;
|
||||
return nroZInicialValidation && nroZFinalValidation && nroInicialValidation && nroFinalValidation && tipoIngresoValidation && cajaValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,44 +309,6 @@ public class IngresosController {
|
||||
return caja != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida la variable valor contra los casos
|
||||
* - Es null
|
||||
* - Esta vacio
|
||||
* - Los caracteres no son solamente digitos
|
||||
* - El largo del string es mayor a 10
|
||||
* 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 validateValor(String valor) {
|
||||
if (valor == null) {
|
||||
this.view.getErrorValor().setText("Hubo un problema con los datos");
|
||||
this.view.getErrorValor().setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valor.isEmpty()) {
|
||||
this.view.getErrorValor().setText("El campo esta vacio");
|
||||
this.view.getErrorValor().setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!valor.chars().allMatch(Character::isDigit)) {
|
||||
this.view.getErrorValor().setText("Deben ser numeros");
|
||||
this.view.getErrorValor().setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(valor.length() > 10){
|
||||
this.view.getErrorValor().setText("El numero ingresado es demasiado largo");
|
||||
this.view.getErrorValor().setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida la variable nroInicial contra los casos
|
||||
* - Es null
|
||||
@@ -456,7 +417,6 @@ 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);
|
||||
@@ -468,6 +428,7 @@ public class IngresosController {
|
||||
*/
|
||||
private void clearInputs() {
|
||||
this.view.getTipoCombo().setSelectedIndex(0);
|
||||
this.view.getValorField().setValue(0);
|
||||
this.view.getValorField().setText("");
|
||||
this.view.getNroZInicialField().setText("");
|
||||
this.view.getNroZFinalField().setText("");
|
||||
@@ -479,7 +440,6 @@ public class IngresosController {
|
||||
* Ejecuta un trim sobre todos los jtextfield
|
||||
*/
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user