Mas logs y actualizacion de los to string de las clases y por ello ademas se tuvo que cambiar el como se renderizaban los combobox de los tipo egreso y tipo ingreso

This commit is contained in:
Daniel Cortes
2019-01-20 20:11:57 -03:00
parent e6195786b6
commit 68f8dc029e
22 changed files with 168 additions and 345 deletions

BIN
dist/Programa Caja.jar vendored

Binary file not shown.

View File

@@ -6,7 +6,7 @@ import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
import danielcortes.xyz.views.CalcularFondoView;
import danielcortes.xyz.views.components.FondoTableModel;
import danielcortes.xyz.views.components.table_model.FondoTableModel;
import javax.swing.*;
import java.awt.event.ActionEvent;

View File

@@ -30,7 +30,7 @@ import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.egreso.Egreso;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.views.EgresosView;
import danielcortes.xyz.views.components.EgresosTableModel;
import danielcortes.xyz.views.components.table_model.EgresosTableModel;
import javax.swing.*;
import java.awt.event.ActionEvent;

View File

@@ -29,7 +29,7 @@ import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.ingreso.Ingreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.views.IngresosView;
import danielcortes.xyz.views.components.IngresosTableModel;
import danielcortes.xyz.views.components.table_model.IngresosTableModel;
import javax.swing.*;
import java.awt.event.ActionEvent;

View File

@@ -45,4 +45,12 @@ public class Caja {
public void setFecha(LocalDate fecha) {
this.fecha = fecha;
}
@Override
public String toString() {
return "Caja{" +
"id=" + id +
", fecha=" + fecha +
'}';
}
}

View File

@@ -72,4 +72,15 @@ public class Documentos {
public void setCaja(Caja caja) {
this.caja = caja;
}
@Override
public String toString() {
return "Documentos{" +
"id=" + id +
", cheques=" + cheques +
", tarjetas=" + tarjetas +
", retiros=" + retiros +
", caja=" + caja +
'}';
}
}

View File

@@ -126,4 +126,21 @@ public class Efectivo {
public void setCaja(Caja caja) {
this.caja = caja;
}
@Override
public String toString() {
return "Efectivo{" +
"id=" + id +
", veinteMil=" + veinteMil +
", diezMil=" + diezMil +
", cincoMil=" + cincoMil +
", dosMil=" + dosMil +
", mil=" + mil +
", quinientos=" + quinientos +
", cien=" + cien +
", cincuenta=" + cincuenta +
", diez=" + diez +
", caja=" + caja +
'}';
}
}

View File

@@ -24,6 +24,7 @@
package danielcortes.xyz.models.efectivo;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
@@ -33,8 +34,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class EfectivoDAO {
private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName());
protected ConnectionHolder connectionHolder;
public abstract List<Efectivo> findAll();
@@ -72,6 +77,8 @@ public abstract class EfectivoDAO {
efectivo.setCincuenta(rs.getInt("cincuenta"));
efectivo.setDiez(rs.getInt("diez"));
LOGGER.log(Level.FINER, "Se a creo: {0}", efectivo);
efectivoList.add(efectivo);
}
return efectivoList;

View File

@@ -24,6 +24,7 @@
package danielcortes.xyz.models.efectivo;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
@@ -33,8 +34,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SQLiteEfectivoDAO extends EfectivoDAO {
private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName());
public SQLiteEfectivoDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@@ -43,15 +48,18 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public List<Efectivo> findAll() {
List<Efectivo> efectivoList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
String query = "select * from efectivos";
PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0}", query);
efectivoList = this.efectivosFromResultSet(rs);
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return efectivoList;
@@ -61,16 +69,19 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public Efectivo findById(int id) {
Efectivo efectivo = null;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
String query = "select * from efectivos where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
efectivo = this.efectivosFromResultSet(rs).get(0);
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return efectivo;
@@ -80,10 +91,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public Efectivo findByCaja(Caja caja) {
Efectivo efectivo = null;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
String query = "select * from efectivos where caja_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
List<Efectivo> efectivoList = this.efectivosFromResultSet(rs);
if (efectivoList.size() > 0) {
efectivo = efectivoList.get(0);
@@ -92,7 +106,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return efectivo;
@@ -102,7 +116,8 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean insertEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
@@ -113,19 +128,26 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}] | updates: {11}", new Object[]{query, efectivo.getVeinteMil(), efectivo.getDiezMil(), efectivo.getCincoMil(), efectivo.getDosMil(), efectivo.getMil(), efectivo.getQuinientos(), efectivo.getCien(), efectivo.getCincuenta(), efectivo.getDiez(), efectivo.getCaja().getId(), updates});
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
query = "select last_insert_rowid()";
ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0}", query);
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -135,10 +157,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean insertDefaultEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)");
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getCaja().getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}", new Object[]{query, efectivo.getCaja().getId(), updates});
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
@@ -149,7 +174,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -159,7 +184,8 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean updateEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
String query = "update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
@@ -171,12 +197,14 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
ps.setInt(11, efectivo.getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}] | updates: {12}", new Object[]{query, efectivo.getVeinteMil(), efectivo.getDiezMil(), efectivo.getCincoMil(), efectivo.getDosMil(), efectivo.getMil(), efectivo.getQuinientos(), efectivo.getCien(), efectivo.getCincuenta(), efectivo.getDiez(), efectivo.getCaja().getId(), efectivo.getId(), updates});
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -186,14 +214,16 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean deleteEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
String query = "delete from efectivos where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}", new Object[]{query, efectivo.getId(), updates});
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -203,9 +233,12 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public int getTotalEfectivo(Caja caja) {
int total = 0;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?");
String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, caja.getId());
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
ResultSet rs = ps.executeQuery();
rs.next();
total = rs.getInt(1);
@@ -213,7 +246,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}

View File

@@ -83,4 +83,16 @@ public class Egreso {
public void setCaja(Caja caja) {
this.caja = caja;
}
@Override
public String toString() {
return "Egreso{" +
"id=" + id +
", nro='" + nro + '\'' +
", descripcion='" + descripcion + '\'' +
", valor=" + valor +
", tipoEgreso=" + tipoEgreso +
", caja=" + caja +
'}';
}
}

View File

@@ -242,6 +242,7 @@ public class InformeLibroDeVentasContent {
this.total = total;
}
@Override
public String toString() {
return "InformeLibroDeVentasContent{" +

View File

@@ -100,4 +100,18 @@ public class Ingreso {
public void setCaja(Caja caja) {
this.caja = caja;
}
@Override
public String toString() {
return "Ingreso{" +
"id=" + id +
", valor=" + valor +
", nroZInicial='" + nroZInicial + '\'' +
", nroZFinal='" + nroZFinal + '\'' +
", nroInicial='" + nroInicial + '\'' +
", nroFinal='" + nroFinal + '\'' +
", tipoIngreso=" + tipoIngreso +
", caja=" + caja +
'}';
}
}

View File

@@ -82,6 +82,9 @@ public class TipoEgreso {
@Override
public String toString() {
return this.nombre;
return "TipoEgreso{" +
"id=" + id +
", nombre='" + nombre + '\'' +
'}';
}
}

View File

@@ -82,6 +82,9 @@ public class TipoIngreso {
@Override
public String toString() {
return this.nombre;
return "TipoIngreso{" +
"id=" + id +
", nombre='" + nombre + '\'' +
'}';
}
}

View File

@@ -26,8 +26,8 @@ package danielcortes.xyz.views;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import danielcortes.xyz.views.components.FondoTableModel;
import danielcortes.xyz.views.components.NumberFormatedTextField;
import danielcortes.xyz.views.components.table_model.FondoTableModel;
import javax.swing.*;
import javax.swing.table.TableModel;

View File

@@ -93,7 +93,7 @@
<text value="Tipo"/>
</properties>
</component>
<component id="5602d" class="javax.swing.JComboBox" binding="tipoCombo">
<component id="5602d" class="javax.swing.JComboBox" binding="tipoCombo" custom-create="true">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>

View File

@@ -28,8 +28,9 @@ import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.views.components.EgresosTableModel;
import danielcortes.xyz.views.components.KeySelectionRenderer;
import danielcortes.xyz.views.components.NumberFormatedTextField;
import danielcortes.xyz.views.components.table_model.EgresosTableModel;
import javax.swing.*;
import javax.swing.table.TableRowSorter;
@@ -57,6 +58,7 @@ public class EgresosView {
private void createUIComponents() {
createEgresosTable();
createTipoCombo();
}
private void createEgresosTable() {
@@ -68,6 +70,17 @@ public class EgresosView {
egresosTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private void createTipoCombo() {
this.tipoCombo = new JComboBox<>();
KeySelectionRenderer renderer = new KeySelectionRenderer(this.tipoCombo) {
@Override
public String getDisplayValue(Object value) {
TipoEgreso tipoEgreso = (TipoEgreso) value;
return tipoEgreso.getNombre();
}
};
}
public JPanel getContentPanel() {
return contentPanel;
}
@@ -175,7 +188,6 @@ public class EgresosView {
final JLabel label4 = new JLabel();
label4.setText("Tipo");
panel2.add(label4, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
tipoCombo = new JComboBox();
panel2.add(tipoCombo, new GridConstraints(1, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
errorNumero = new JLabel();
errorNumero.setEnabled(true);
@@ -243,4 +255,5 @@ public class EgresosView {
public JComponent $$$getRootComponent$$$() {
return contentPanel;
}
}

View File

@@ -47,7 +47,7 @@
<text value="Tipo"/>
</properties>
</component>
<component id="b5d8c" class="javax.swing.JComboBox" binding="tipoCombo">
<component id="b5d8c" class="javax.swing.JComboBox" binding="tipoCombo" custom-create="true">
<constraints>
<grid row="1" column="5" 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"/>

View File

@@ -28,8 +28,9 @@ import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.views.components.IngresosTableModel;
import danielcortes.xyz.views.components.KeySelectionRenderer;
import danielcortes.xyz.views.components.NumberFormatedTextField;
import danielcortes.xyz.views.components.table_model.IngresosTableModel;
import javax.swing.*;
import javax.swing.table.TableRowSorter;
@@ -59,6 +60,7 @@ public class IngresosView {
private void createUIComponents() {
this.createIngresosTable();
this.createTipoCombo();
}
private void createIngresosTable() {
@@ -70,6 +72,17 @@ public class IngresosView {
this.ingresosTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private void createTipoCombo() {
this.tipoCombo = new JComboBox<>();
KeySelectionRenderer renderer = new KeySelectionRenderer(this.tipoCombo) {
@Override
public String getDisplayValue(Object value) {
TipoIngreso tipoIngreso = (TipoIngreso) value;
return tipoIngreso.getNombre();
}
};
}
public JPanel getContentPanel() {
return contentPanel;
}
@@ -178,7 +191,6 @@ public class IngresosView {
final JLabel label1 = new JLabel();
label1.setText("Tipo");
panel2.add(label1, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
tipoCombo = new JComboBox();
final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel();
tipoCombo.setModel(defaultComboBoxModel1);
panel2.add(tipoCombo, new GridConstraints(1, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
@@ -268,4 +280,5 @@ public class IngresosView {
public JComponent $$$getRootComponent$$$() {
return contentPanel;
}
}

View File

@@ -1,105 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.views.components;
import danielcortes.xyz.models.egreso.Egreso;
import javax.swing.table.AbstractTableModel;
import java.text.NumberFormat;
import java.util.ArrayList;
public class EgresosTableModel extends AbstractTableModel {
private String[] columns;
private ArrayList<Egreso> rows;
private NumberFormat nf;
public EgresosTableModel() {
super();
this.columns = new String[]{"", "Descripcion", "Valor", "Tipo"};
this.rows = new ArrayList<>();
this.nf = NumberFormat.getIntegerInstance();
}
@Override
public String getColumnName(int col) {
return columns[col];
}
@Override
public int getColumnCount() {
return columns.length;
}
@Override
public int getRowCount() {
return rows.size();
}
public void addRow(Egreso egreso) {
rows.add(egreso);
this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
}
public void removeRow(int row) {
this.rows.remove(row);
this.fireTableRowsDeleted(row, row);
}
public void removeRows() {
int rowCount = getRowCount();
if (rowCount > 0) {
this.rows.clear();
this.fireTableRowsDeleted(0, rowCount - 1);
}
}
public void setEgreso(int editingId, Egreso egreso) {
this.rows.set(editingId, egreso);
this.fireTableRowsUpdated(0, getRowCount() - 1);
}
@Override
public Object getValueAt(int row, int col) {
switch (col) {
case 0:
return rows.get(row).getNro();
case 1:
return rows.get(row).getDescripcion();
case 2:
return nf.format(rows.get(row).getValor());
case 3:
return rows.get(row).getTipoEgreso();
}
return null;
}
public Egreso getEgreso(int row) {
return rows.get(row);
}
}

View File

@@ -1,101 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.views.components;
import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
import javax.swing.table.AbstractTableModel;
import java.text.NumberFormat;
import java.util.ArrayList;
public class FondoTableModel extends AbstractTableModel {
private String[] columns;
private ArrayList<CalculoFondo> rows;
private NumberFormat nf;
public FondoTableModel() {
super();
this.columns = new String[]{"Valor", "Descripcion"};
this.rows = new ArrayList<>();
this.nf = NumberFormat.getIntegerInstance();
}
@Override
public String getColumnName(int col) {
return columns[col];
}
@Override
public int getColumnCount() {
return columns.length;
}
@Override
public int getRowCount() {
return rows.size();
}
public void addRow(CalculoFondo calculoFondo) {
rows.add(calculoFondo);
this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
}
public void removeRow(int row) {
this.rows.remove(row);
this.fireTableRowsDeleted(row, row);
}
public void removeRows() {
int rowCount = getRowCount();
if (rowCount > 0) {
this.rows.clear();
this.fireTableRowsDeleted(0, rowCount - 1);
}
}
public void setCalculoFondo(int editingId, CalculoFondo calculoFondo) {
this.rows.set(editingId, calculoFondo);
this.fireTableRowsUpdated(0, getRowCount() - 1);
}
@Override
public Object getValueAt(int row, int col) {
switch (col) {
case 0:
return nf.format(rows.get(row).getValor());
case 1:
return rows.get(row).getDescripcion();
}
return null;
}
public CalculoFondo getCalculoFondo(int row) {
return rows.get(row);
}
}

View File

@@ -1,106 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.views.components;
import danielcortes.xyz.models.ingreso.Ingreso;
import javax.swing.table.AbstractTableModel;
import java.text.NumberFormat;
import java.util.ArrayList;
public class IngresosTableModel extends AbstractTableModel {
private String[] columns;
private ArrayList<Ingreso> rows;
private NumberFormat nf;
public IngresosTableModel() {
super();
this.columns = new String[]{"Valor", "N° Z Inicial", "N° Z Final", "N° Inicial", "N° Final", "Tipo"};
this.rows = new ArrayList<>();
this.nf = NumberFormat.getIntegerInstance();
}
@Override
public String getColumnName(int col) {
return this.columns[col];
}
@Override
public int getColumnCount() {
return this.columns.length;
}
@Override
public int getRowCount() {
return this.rows.size();
}
public void addRow(Ingreso ingreso) {
this.rows.add(ingreso);
this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
}
public void removeRow(int row) {
this.rows.remove(row);
this.fireTableRowsDeleted(row, row);
}
public void removeRows() {
int rowCount = getRowCount();
if (rowCount > 0) {
this.rows.clear();
this.fireTableRowsDeleted(0, rowCount - 1);
}
}
@Override
public Object getValueAt(int row, int col) {
switch (col) {
case 0:
return nf.format(this.rows.get(row).getValor());
case 1:
return this.rows.get(row).getNroZInicial();
case 2:
return this.rows.get(row).getNroZFinal();
case 3:
return this.rows.get(row).getNroInicial();
case 4:
return this.rows.get(row).getNroFinal();
case 5:
return this.rows.get(row).getTipoIngreso().getNombre();
}
return null;
}
public Ingreso getIngreso(int row) {
return this.rows.get(row);
}
public void setIngreso(int editingId, Ingreso ingreso) {
this.rows.set(editingId, ingreso);
this.fireTableRowsUpdated(getRowCount() - 2, getRowCount() - 1);
}
}