NumberFormatTextField agregado en el campo value de egresos y el total egresos
This commit is contained in:
@@ -159,7 +159,7 @@ public class EgresosController {
|
||||
|
||||
String nro = this.view.getNroField().getText();
|
||||
String descripcion = this.view.getDescripcionField().getText();
|
||||
String valor = this.view.getValorField().getText();
|
||||
int valor = this.view.getValorField().getValue();
|
||||
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
|
||||
|
||||
if(editing){
|
||||
@@ -182,6 +182,7 @@ public class EgresosController {
|
||||
this.egresoDAO.deleteEgreso(egreso);
|
||||
this.updateTotalEgresos();
|
||||
this.updateButtonsEnabled();
|
||||
this.resetFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ public class EgresosController {
|
||||
|
||||
this.view.getNroField().setText(egreso.getNro());
|
||||
this.view.getDescripcionField().setText(egreso.getDescripcion());
|
||||
this.view.getValorField().setText(String.valueOf(egreso.getValor()));
|
||||
this.view.getValorField().setValue(egreso.getValor());
|
||||
this.view.getTipoCombo().setSelectedItem(egreso.getTipoEgreso());
|
||||
}
|
||||
}
|
||||
@@ -216,7 +217,7 @@ public class EgresosController {
|
||||
*/
|
||||
private void updateTotalEgresos() {
|
||||
int total = this.egresoDAO.getTotalEgreso(this.caja);
|
||||
this.view.getTotalEgresosField().setText(String.valueOf(total));
|
||||
this.view.getTotalEgresosField().setValue(total);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,10 +238,10 @@ public class EgresosController {
|
||||
* Guarda un egreso tras llamar a validar su input
|
||||
* Luego de guardar, agrega el egreso a la tabla, llama a actualizar el total de egresos y llama a limpiar a los inputs
|
||||
*/
|
||||
private void guardarEgreso(String nro, String descripcion, String valor, TipoEgreso tipo, Caja caja) {
|
||||
if (this.validateInput(nro, descripcion, valor, tipo, caja)) {
|
||||
private void guardarEgreso(String nro, String descripcion, int valor, TipoEgreso tipo, Caja caja) {
|
||||
if (this.validateInput(nro, descripcion, tipo, caja)) {
|
||||
Egreso egreso = new Egreso();
|
||||
egreso.setValor(Integer.valueOf(valor));
|
||||
egreso.setValor(valor);
|
||||
egreso.setDescripcion(descripcion);
|
||||
egreso.setNro(nro);
|
||||
egreso.setTipoEgreso(tipo);
|
||||
@@ -257,8 +258,8 @@ public class EgresosController {
|
||||
* Tras esto actualiza el egreso en la tabla, llama a actualizar el total de egresos y a limpiar los inputs
|
||||
* Finalmente setea la flag editing a false
|
||||
*/
|
||||
private void editarEgreso(String nro, String descripcion, String valor, TipoEgreso tipo, Caja caja) {
|
||||
if (this.validateInput(nro, descripcion, valor, tipo, caja)) {
|
||||
private void editarEgreso(String nro, String descripcion, int valor, TipoEgreso tipo, Caja caja) {
|
||||
if (this.validateInput(nro, descripcion, tipo, caja)) {
|
||||
this.editingEgreso.setValor(Integer.valueOf(valor));
|
||||
this.editingEgreso.setDescripcion(descripcion);
|
||||
this.editingEgreso.setNro(nro);
|
||||
@@ -275,15 +276,14 @@ public class EgresosController {
|
||||
* llama a los metodos necesarios para validar los inputs entregados
|
||||
* @return true cuando todas las validaciones retoran true, si no, false
|
||||
*/
|
||||
private boolean validateInput(String nro, String descripcion, String valor, TipoEgreso tipoEgreso, Caja caja) {
|
||||
private boolean validateInput(String nro, String descripcion, TipoEgreso tipoEgreso, Caja caja) {
|
||||
|
||||
boolean nroValidation = this.validateNro(nro);
|
||||
boolean descripcionValidation = this.validateDescripcion(descripcion);
|
||||
boolean valorValidation = this.validateValor(valor);
|
||||
boolean tipoEgresoValidation = this.validateTipoEgreso(tipoEgreso);
|
||||
boolean cajaValidation = this.validateCaja(caja);
|
||||
|
||||
return nroValidation && descripcionValidation && valorValidation && tipoEgresoValidation;
|
||||
return nroValidation && descripcionValidation && tipoEgresoValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,44 +332,6 @@ public class EgresosController {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida la variable valor contra los casos
|
||||
* - Es null
|
||||
* - Esta vacio
|
||||
* - Los caracteres no son todos digitos
|
||||
* - El largo del string es mayot 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 tipoEgreso contra los casos
|
||||
* - Es null
|
||||
@@ -399,7 +361,6 @@ public class EgresosController {
|
||||
*/
|
||||
private void hideErrorMessages() {
|
||||
this.view.getErrorTipoEgreso().setVisible(false);
|
||||
this.view.getErrorValor().setVisible(false);
|
||||
this.view.getErrorDescripcion().setVisible(false);
|
||||
this.view.getErrorNumero().setVisible(false);
|
||||
}
|
||||
@@ -410,6 +371,7 @@ public class EgresosController {
|
||||
private void clearInputs() {
|
||||
this.view.getTipoCombo().setSelectedIndex(0);
|
||||
this.view.getNroField().setText("");
|
||||
this.view.getValorField().setValue(0);
|
||||
this.view.getValorField().setText("");
|
||||
this.view.getDescripcionField().setText("");
|
||||
}
|
||||
@@ -418,7 +380,6 @@ public class EgresosController {
|
||||
* Ejecuta trim sobre todos los campos de texto
|
||||
*/
|
||||
private void normalizeInputs(){
|
||||
this.view.getValorField().setText(this.view.getValorField().getText().trim());
|
||||
this.view.getNroField().setText(this.view.getNroField().getText().trim());
|
||||
this.view.getDescripcionField().setText(this.view.getDescripcionField().getText().trim());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user