Movida la necesidad de pasaar los objetos dao atravez de los constructores de las clases y se consiguen a travez de una clase estatica la que los crea previamente y simplemente los entrega a la clase que lo pide.
Supongo que dara mayor flexibilidad a cuando se quiera cambiar a un orm o cambiar la conexion a otra base de datos
This commit is contained in:
@@ -24,11 +24,10 @@
|
||||
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.data.DAOManager;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.ingreso.Ingreso;
|
||||
import danielcortes.xyz.models.ingreso.IngresoDAO;
|
||||
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;
|
||||
|
||||
@@ -43,8 +42,6 @@ import java.awt.event.MouseEvent;
|
||||
*/
|
||||
public class IngresosController {
|
||||
private IngresosView view;
|
||||
private IngresoDAO ingresoDAO;
|
||||
private TipoIngresoDAO tipoIngresoDAO;
|
||||
private Caja caja;
|
||||
|
||||
private int editingId;
|
||||
@@ -58,30 +55,13 @@ public class IngresosController {
|
||||
* - Metodo que genera los eventos para la vista
|
||||
* - Metodo que actualiza el estado de los botones
|
||||
*/
|
||||
public IngresosController(IngresosView view, IngresoDAO ingresoDAO, TipoIngresoDAO tipoIngresoDAO) {
|
||||
public IngresosController(IngresosView view) {
|
||||
this.view = view;
|
||||
this.ingresoDAO = ingresoDAO;
|
||||
this.tipoIngresoDAO = tipoIngresoDAO;
|
||||
this.fillTipoIngresoCombo();
|
||||
this.setupViewEvents();
|
||||
this.updateButtonsEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter!!
|
||||
*/
|
||||
public IngresoDAO getIngresoDAO() {
|
||||
return ingresoDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter!!!
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TipoIngresoDAO getTipoIngresoDAO() {
|
||||
return tipoIngresoDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarda la caja ingresada y actualiza el contenido de la tabla de ingresos y el campo de total de ingresos
|
||||
@@ -97,7 +77,7 @@ public class IngresosController {
|
||||
*/
|
||||
private void fillTipoIngresoCombo() {
|
||||
JComboBox<TipoIngreso> tipoCombo = this.view.getTipoCombo();
|
||||
for (TipoIngreso tipo : this.tipoIngresoDAO.findAll()) {
|
||||
for (TipoIngreso tipo : DAOManager.getTipoIngresoDAO().findAll()) {
|
||||
tipoCombo.addItem(tipo);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +88,7 @@ public class IngresosController {
|
||||
private void fillIngresosTable() {
|
||||
IngresosTableModel ingresosTableModel = this.view.getIngresosTableModel();
|
||||
ingresosTableModel.removeRows();
|
||||
for (Ingreso ingreso : this.ingresoDAO.findByCaja(this.caja)) {
|
||||
for (Ingreso ingreso : DAOManager.getIngresoDAO().findByCaja(this.caja)) {
|
||||
ingresosTableModel.addRow(ingreso);
|
||||
}
|
||||
}
|
||||
@@ -186,7 +166,7 @@ public class IngresosController {
|
||||
if (selectedId >= 0) {
|
||||
Ingreso ingreso = this.view.getIngresosTableModel().getIngreso(selectedId);
|
||||
this.view.getIngresosTableModel().removeRow(selectedId);
|
||||
this.ingresoDAO.deleteIngreso(ingreso);
|
||||
DAOManager.getIngresoDAO().deleteIngreso(ingreso);
|
||||
this.updateTotalIngresos();
|
||||
this.updateButtonsEnabled();
|
||||
}
|
||||
@@ -223,7 +203,7 @@ public class IngresosController {
|
||||
* Obtiene el total de ingresos de la caja y lo coloca en el el field totalingresos
|
||||
*/
|
||||
private void updateTotalIngresos() {
|
||||
int total = this.ingresoDAO.getTotalIngreso(this.caja);
|
||||
int total = DAOManager.getIngresoDAO().getTotalIngreso(this.caja);
|
||||
this.view.getTotalIngresoField().setValue(total);
|
||||
}
|
||||
|
||||
@@ -257,7 +237,7 @@ public class IngresosController {
|
||||
ingreso.setNroInicial(nroInicial);
|
||||
ingreso.setNroFinal(nroFinal);
|
||||
|
||||
this.ingresoDAO.insertIngreso(ingreso);
|
||||
DAOManager.getIngresoDAO().insertIngreso(ingreso);
|
||||
this.view.getIngresosTableModel().addRow(ingreso);
|
||||
|
||||
this.clearInputs();
|
||||
@@ -277,7 +257,7 @@ public class IngresosController {
|
||||
this.editingIngreso.setNroZFinal(nroZFinal);
|
||||
this.editingIngreso.setNroInicial(nroInicial);
|
||||
this.editingIngreso.setNroFinal(nroFinal);
|
||||
this.ingresoDAO.updateIngreso(this.editingIngreso);
|
||||
DAOManager.getIngresoDAO().updateIngreso(this.editingIngreso);
|
||||
this.view.getIngresosTableModel().setIngreso(this.editingId, this.editingIngreso);
|
||||
this.updateTotalIngresos();
|
||||
this.clearInputs();
|
||||
|
||||
Reference in New Issue
Block a user