Ahora el modelo de egreso se autocarga con el objeto de tipo egreso en vez de con su id
This commit is contained in:
@@ -31,6 +31,8 @@ import danielcortes.xyz.models.TipoEgresoDAO;
|
|||||||
import danielcortes.xyz.views.EgresosView;
|
import danielcortes.xyz.views.EgresosView;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
public class CajaController {
|
public class CajaController {
|
||||||
private EgresosView view;
|
private EgresosView view;
|
||||||
@@ -56,21 +58,33 @@ public class CajaController {
|
|||||||
|
|
||||||
private void fillEgresosTable() {
|
private void fillEgresosTable() {
|
||||||
for(Egreso egreso: this.egresoDAO.findAll()){
|
for(Egreso egreso: this.egresoDAO.findAll()){
|
||||||
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(egreso.getTipo()).get(0);
|
|
||||||
view.getEgresosTableModel().addRow(egreso);
|
view.getEgresosTableModel().addRow(egreso);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpViewEvents(){
|
private void setUpViewEvents(){
|
||||||
this.view.getGuardarButton().addActionListener(e -> {
|
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
|
||||||
|
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void guardarActionListener(){
|
||||||
String nro = this.view.getNroField().getText();
|
String nro = this.view.getNroField().getText();
|
||||||
String descripcion = this.view.getDescripcionField().getText();
|
String descripcion = this.view.getDescripcionField().getText();
|
||||||
String valor = this.view.getValorField().getText();
|
String valor = this.view.getValorField().getText();
|
||||||
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
|
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
|
||||||
Egreso egreso = this.createEgreso(nro, descripcion, valor, tipo.getId());
|
Egreso egreso = this.createEgreso(nro, descripcion, valor, tipo);
|
||||||
this.view.getEgresosTableModel().addRow(egreso);
|
this.view.getEgresosTableModel().addRow(egreso);
|
||||||
this.updateTotalEgresos();
|
this.updateTotalEgresos();
|
||||||
});
|
}
|
||||||
|
|
||||||
|
private void eliminarActionListener(){
|
||||||
|
int selectedID = this.view.getEgresosTable().getSelectedRow();
|
||||||
|
System.out.println(selectedID);
|
||||||
|
if(selectedID >= 0) {
|
||||||
|
Egreso egreso = this.view.getEgresosTableModel().getEgreso(selectedID);
|
||||||
|
this.view.getEgresosTableModel().removeRow(selectedID);
|
||||||
|
this.egresoDAO.deleteEgreso(egreso);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTotalEgresos(){
|
private void updateTotalEgresos(){
|
||||||
@@ -78,7 +92,7 @@ public class CajaController {
|
|||||||
this.view.getTotalEgresosField().setText(String.valueOf(total));
|
this.view.getTotalEgresosField().setText(String.valueOf(total));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Egreso createEgreso(String nro, String descripcion, String valor, int tipo){
|
private Egreso createEgreso(String nro, String descripcion, String valor, TipoEgreso tipo){
|
||||||
Egreso egreso = new Egreso();
|
Egreso egreso = new Egreso();
|
||||||
egreso.setValor(Integer.valueOf(valor));
|
egreso.setValor(Integer.valueOf(valor));
|
||||||
egreso.setDescripcion(descripcion);
|
egreso.setDescripcion(descripcion);
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ public class Egreso {
|
|||||||
private String nro;
|
private String nro;
|
||||||
private String descripcion;
|
private String descripcion;
|
||||||
private int valor;
|
private int valor;
|
||||||
private int tipo;
|
private TipoEgreso tipo;
|
||||||
|
|
||||||
public Egreso(int id, String nro, String descripcion, int valor, int tipo) {
|
public Egreso(int id, String nro, String descripcion, int valor, TipoEgreso tipo) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.nro = nro;
|
this.nro = nro;
|
||||||
this.descripcion = descripcion;
|
this.descripcion = descripcion;
|
||||||
@@ -40,7 +40,7 @@ public class Egreso {
|
|||||||
this.tipo = tipo;
|
this.tipo = tipo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Egreso(String nro, String descripcion, int valor, int tipo) {
|
public Egreso(String nro, String descripcion, int valor, TipoEgreso tipo) {
|
||||||
this.nro = nro;
|
this.nro = nro;
|
||||||
this.descripcion = descripcion;
|
this.descripcion = descripcion;
|
||||||
this.valor = valor;
|
this.valor = valor;
|
||||||
@@ -81,11 +81,11 @@ public class Egreso {
|
|||||||
this.valor = valor;
|
this.valor = valor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTipo() {
|
public TipoEgreso getTipo() {
|
||||||
return tipo;
|
return tipo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTipo(int tipo) {
|
public void setTipo(TipoEgreso tipo) {
|
||||||
this.tipo = tipo;
|
this.tipo = tipo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ package danielcortes.xyz.models.mysql;
|
|||||||
import danielcortes.xyz.data.MysqlConnection;
|
import danielcortes.xyz.data.MysqlConnection;
|
||||||
import danielcortes.xyz.models.Egreso;
|
import danielcortes.xyz.models.Egreso;
|
||||||
import danielcortes.xyz.models.EgresoDAO;
|
import danielcortes.xyz.models.EgresoDAO;
|
||||||
|
import danielcortes.xyz.models.TipoEgreso;
|
||||||
|
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -110,7 +112,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
|||||||
ps.setString(1,egreso.getNro());
|
ps.setString(1,egreso.getNro());
|
||||||
ps.setString(2,egreso.getDescripcion());
|
ps.setString(2,egreso.getDescripcion());
|
||||||
ps.setInt(3,egreso.getValor());
|
ps.setInt(3,egreso.getValor());
|
||||||
ps.setInt(4,egreso.getTipo());
|
ps.setInt(4,egreso.getTipo().getId());
|
||||||
updates = ps.executeUpdate();
|
updates = ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
@@ -130,7 +132,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
|||||||
ps.setString(1,egreso.getNro());
|
ps.setString(1,egreso.getNro());
|
||||||
ps.setString(2,egreso.getDescripcion());
|
ps.setString(2,egreso.getDescripcion());
|
||||||
ps.setInt(3,egreso.getValor());
|
ps.setInt(3,egreso.getValor());
|
||||||
ps.setInt(4,egreso.getTipo());
|
ps.setInt(4,egreso.getTipo().getId());
|
||||||
ps.setInt(5, egreso.getId());
|
ps.setInt(5, egreso.getId());
|
||||||
updates = ps.executeUpdate();
|
updates = ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -179,16 +181,20 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<Egreso> EgresosFromResultSet(ResultSet rs) throws SQLException {
|
private List<Egreso> EgresosFromResultSet(ResultSet rs) throws SQLException {
|
||||||
ArrayList<Egreso> egresoList = new ArrayList<>();
|
ArrayList<Egreso> egresoList = new ArrayList<>();
|
||||||
while(rs.next()){
|
while(rs.next()){
|
||||||
|
int tipoEgresoId = rs.getInt("tipo_id");
|
||||||
|
TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
|
||||||
|
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0);
|
||||||
|
|
||||||
Egreso egreso = new Egreso();
|
Egreso egreso = new Egreso();
|
||||||
|
|
||||||
egreso.setId(rs.getInt("id"));
|
egreso.setId(rs.getInt("id"));
|
||||||
egreso.setNro(rs.getString("nro"));
|
egreso.setNro(rs.getString("nro"));
|
||||||
egreso.setDescripcion(rs.getString("descripcion"));
|
egreso.setDescripcion(rs.getString("descripcion"));
|
||||||
egreso.setValor(rs.getInt("valor"));
|
egreso.setValor(rs.getInt("valor"));
|
||||||
egreso.setTipo(rs.getInt("tipo_id"));
|
egreso.setTipo(tipoEgreso);
|
||||||
egresoList.add(egreso);
|
egresoList.add(egreso);
|
||||||
}
|
}
|
||||||
return egresoList;
|
return egresoList;
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="15" left="15" bottom="15" right="15"/>
|
<margin top="15" left="15" bottom="15" right="15"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="20" width="1074" height="403"/>
|
<xy x="20" y="20" width="860" height="487"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<grid id="9047a" binding="egresosPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="9047a" binding="egresosPanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="10" left="10" bottom="10" right="10"/>
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<scrollpane id="65bec">
|
<scrollpane id="65bec">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@@ -95,15 +95,23 @@
|
|||||||
</scrollpane>
|
</scrollpane>
|
||||||
<component id="c5738" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
|
<component id="c5738" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Añadir"/>
|
<text value="&Añadir"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3442d" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Total Egresos:"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="2b8d0" class="javax.swing.JTextField" binding="totalEgresosField">
|
<component id="2b8d0" class="javax.swing.JTextField" binding="totalEgresosField">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
<preferred-size width="150" height="-1"/>
|
<preferred-size width="150" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@@ -111,12 +119,12 @@
|
|||||||
<editable value="false"/>
|
<editable value="false"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="3442d" class="javax.swing.JLabel">
|
<component id="ee598" class="javax.swing.JButton" binding="eliminarButton" default-binding="true">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Total Egresos:"/>
|
<text value="&Eliminar"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
@@ -125,5 +133,7 @@
|
|||||||
</grid>
|
</grid>
|
||||||
<inspectionSuppressions>
|
<inspectionSuppressions>
|
||||||
<suppress inspection="FormSpellChecking"/>
|
<suppress inspection="FormSpellChecking"/>
|
||||||
|
<suppress inspection="I18nForm"/>
|
||||||
|
<suppress inspection="NoLabelFor"/>
|
||||||
</inspectionSuppressions>
|
</inspectionSuppressions>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ public class EgresosView {
|
|||||||
private JTextField totalEgresosField;
|
private JTextField totalEgresosField;
|
||||||
private JComboBox<TipoEgreso> tipoCombo;
|
private JComboBox<TipoEgreso> tipoCombo;
|
||||||
|
|
||||||
|
|
||||||
|
private JButton eliminarButton;
|
||||||
|
|
||||||
private EgresosTableModel egresosTableModel;
|
private EgresosTableModel egresosTableModel;
|
||||||
|
|
||||||
private void createUIComponents() {
|
private void createUIComponents() {
|
||||||
@@ -52,6 +55,7 @@ public class EgresosView {
|
|||||||
egresosTableModel = new EgresosTableModel();
|
egresosTableModel = new EgresosTableModel();
|
||||||
egresosTable = new JTable(egresosTableModel);
|
egresosTable = new JTable(egresosTableModel);
|
||||||
egresosTable.setAutoCreateRowSorter(true);
|
egresosTable.setAutoCreateRowSorter(true);
|
||||||
|
egresosTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getContentPanel() {
|
public JPanel getContentPanel() {
|
||||||
@@ -62,6 +66,10 @@ public class EgresosView {
|
|||||||
return guardarButton;
|
return guardarButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JButton getEliminarButton() {
|
||||||
|
return eliminarButton;
|
||||||
|
}
|
||||||
|
|
||||||
public JTextField getValorField() {
|
public JTextField getValorField() {
|
||||||
return valorField;
|
return valorField;
|
||||||
}
|
}
|
||||||
@@ -82,7 +90,16 @@ public class EgresosView {
|
|||||||
return tipoCombo;
|
return tipoCombo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JTable getEgresosTable() {
|
||||||
|
return egresosTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEgresosTable(JTable egresosTable) {
|
||||||
|
this.egresosTable = egresosTable;
|
||||||
|
}
|
||||||
|
|
||||||
public EgresosTableModel getEgresosTableModel() {
|
public EgresosTableModel getEgresosTableModel() {
|
||||||
return egresosTableModel;
|
return egresosTableModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ public class EgresosTableModel extends AbstractTableModel {
|
|||||||
this.fireTableRowsInserted(0,getRowCount()-1);
|
this.fireTableRowsInserted(0,getRowCount()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeRow(int row){
|
||||||
|
this.rows.remove(row);
|
||||||
|
this.fireTableRowsDeleted(0,getRowCount()-1);
|
||||||
|
}
|
||||||
|
|
||||||
public Object getValueAt(int row, int col) {
|
public Object getValueAt(int row, int col) {
|
||||||
switch (col){
|
switch (col){
|
||||||
case 0:
|
case 0:
|
||||||
@@ -69,4 +74,8 @@ public class EgresosTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Egreso getEgreso(int row){
|
||||||
|
return rows.get(row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user