Creada seccion de ingresos completa.
This commit is contained in:
@@ -40,12 +40,13 @@ public class Main {
|
||||
|
||||
|
||||
ManagerView view = new ManagerView();
|
||||
ManagerController managerController = new ManagerController(view);
|
||||
|
||||
JFrame frame = new JFrame("Caja");
|
||||
frame.setContentPane(view.getContentPanel());
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(1300,700);
|
||||
frame.setLocationRelativeTo(null);
|
||||
ManagerController managerController = new ManagerController(view);
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
|
||||
@@ -24,19 +24,18 @@
|
||||
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.models.Egreso;
|
||||
import danielcortes.xyz.models.EgresoDAO;
|
||||
import danielcortes.xyz.models.TipoEgreso;
|
||||
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.Egreso;
|
||||
import danielcortes.xyz.models.egreso.EgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.views.EgresosView;
|
||||
import danielcortes.xyz.views.components.EgresosTableModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class EgresosController {
|
||||
private EgresosView view;
|
||||
@@ -49,11 +48,12 @@ public class EgresosController {
|
||||
this.tipoEgresoDAO = tipoEgresoDAO;
|
||||
this.setUpViewEvents();
|
||||
this.fillEgresosTable();
|
||||
this.fillEgresosTipo();
|
||||
this.fillTipoEgresoCombo();
|
||||
this.updateTotalEgresos();
|
||||
this.updateEliminarButton();
|
||||
}
|
||||
|
||||
private void fillEgresosTipo() {
|
||||
private void fillTipoEgresoCombo() {
|
||||
JComboBox<TipoEgreso> tipoCombo = view.getTipoCombo();
|
||||
for(TipoEgreso tipoEgreso : this.tipoEgresoDAO.findAll()){
|
||||
tipoCombo.addItem(tipoEgreso);
|
||||
@@ -61,31 +61,30 @@ public class EgresosController {
|
||||
}
|
||||
|
||||
private void fillEgresosTable() {
|
||||
EgresosTableModel egresosTableModel = view.getEgresosTableModel();
|
||||
for(Egreso egreso: this.egresoDAO.findAll()){
|
||||
view.getEgresosTableModel().addRow(egreso);
|
||||
egresosTableModel.addRow(egreso);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpViewEvents(){
|
||||
this.view.getEgresosTable().getSelectionModel().addListSelectionListener(this::onSelectTableRowListener);
|
||||
this.view.getGuardarButton().addActionListener(this::guardarActionListener);
|
||||
this.view.getEliminarButton().addActionListener(this::eliminarActionListener);
|
||||
this.view.getDescripcionField().addActionListener(this::guardarActionListener);
|
||||
this.view.getNroField().addActionListener(this::guardarActionListener);
|
||||
this.view.getValorField().addActionListener(this::guardarActionListener);
|
||||
this.view.getEgresosTable().getSelectionModel().addListSelectionListener(e -> onSelectTableRowListener());
|
||||
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
|
||||
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
|
||||
this.view.getDescripcionField().addActionListener(e -> guardarActionListener());
|
||||
this.view.getNroField().addActionListener(e -> guardarActionListener());
|
||||
this.view.getValorField().addActionListener(e -> guardarActionListener());
|
||||
this.view.getTipoCombo().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyCode() == KeyEvent.VK_ENTER){
|
||||
guardarActionListener();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void eliminarActionListener(ActionEvent e){
|
||||
int selectedID = this.view.getEgresosTable().getSelectedRow();
|
||||
if(selectedID >= 0) {
|
||||
Egreso egreso = this.view.getEgresosTableModel().getEgreso(selectedID);
|
||||
this.view.getEgresosTableModel().removeRow(selectedID);
|
||||
this.egresoDAO.deleteEgreso(egreso);
|
||||
this.updateTotalEgresos();
|
||||
}
|
||||
}
|
||||
|
||||
private void guardarActionListener(ActionEvent e){
|
||||
private void guardarActionListener(){
|
||||
String nro = this.view.getNroField().getText();
|
||||
String descripcion = this.view.getDescripcionField().getText();
|
||||
String valor = this.view.getValorField().getText();
|
||||
@@ -98,7 +97,18 @@ public class EgresosController {
|
||||
}
|
||||
}
|
||||
|
||||
private void onSelectTableRowListener(ListSelectionEvent e){
|
||||
private void eliminarActionListener(){
|
||||
int selectedID = this.view.getEgresosTable().getSelectedRow();
|
||||
if(selectedID >= 0) {
|
||||
Egreso egreso = this.view.getEgresosTableModel().getEgreso(selectedID);
|
||||
this.view.getEgresosTableModel().removeRow(selectedID);
|
||||
this.egresoDAO.deleteEgreso(egreso);
|
||||
this.updateTotalEgresos();
|
||||
this.updateEliminarButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void onSelectTableRowListener(){
|
||||
this.view.getEliminarButton().setEnabled(true);
|
||||
}
|
||||
|
||||
@@ -107,6 +117,14 @@ public class EgresosController {
|
||||
this.view.getTotalEgresosField().setText(String.valueOf(total));
|
||||
}
|
||||
|
||||
private void updateEliminarButton() {
|
||||
if(this.view.getEgresosTable().getSelectedRow()>=0){
|
||||
this.view.getEliminarButton().setEnabled(true);
|
||||
}else{
|
||||
this.view.getEliminarButton().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Egreso createEgreso(String nro, String descripcion, String valor, TipoEgreso tipo){
|
||||
Egreso egreso = new Egreso();
|
||||
egreso.setValor(Integer.valueOf(valor));
|
||||
@@ -182,6 +200,12 @@ public class EgresosController {
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.controllers;
|
||||
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class IngresosController {
|
||||
private IngresosView view;
|
||||
private IngresoDAO ingresoDAO;
|
||||
private TipoIngresoDAO tipoIngresoDAO;
|
||||
|
||||
public IngresosController(IngresosView view, IngresoDAO ingresoDAO, TipoIngresoDAO tipoIngresoDAO) {
|
||||
this.view = view;
|
||||
this.ingresoDAO = ingresoDAO;
|
||||
this.tipoIngresoDAO = tipoIngresoDAO;
|
||||
this.fillTipoIngresoCombo();
|
||||
this.fillIngresosTable();
|
||||
this.setupViewEvents();
|
||||
this.updateTotalIngresos();
|
||||
this.updateEliminarButton();
|
||||
}
|
||||
|
||||
private void fillTipoIngresoCombo() {
|
||||
JComboBox<TipoIngreso> tipoCombo = this.view.getTipoCombo();
|
||||
for (TipoIngreso tipo : this.tipoIngresoDAO.findAll()) {
|
||||
tipoCombo.addItem(tipo);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillIngresosTable() {
|
||||
IngresosTableModel ingresosTableModel = this.view.getIngresosTableModel();
|
||||
for (Ingreso ingreso : this.ingresoDAO.findAll()) {
|
||||
ingresosTableModel.addRow(ingreso);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupViewEvents() {
|
||||
this.view.getIngresosTable().getSelectionModel().addListSelectionListener(e -> onSelectTableRowListener());
|
||||
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
|
||||
this.view.getValorField().addActionListener(e -> guardarActionListener());
|
||||
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
|
||||
|
||||
this.view.getTipoCombo().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyCode() == KeyEvent.VK_ENTER){
|
||||
guardarActionListener();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void guardarActionListener() {
|
||||
String valor = this.view.getValorField().getText();
|
||||
TipoIngreso tipoIngreso = (TipoIngreso) this.view.getTipoCombo().getSelectedItem();
|
||||
|
||||
if(this.validateInput(valor, tipoIngreso)){
|
||||
Ingreso ingreso = this.createIngreso(valor,tipoIngreso);
|
||||
this.view.getIngresosTableModel().addRow(ingreso);
|
||||
this.clearInputs();
|
||||
this.updateTotalIngresos();
|
||||
}
|
||||
}
|
||||
|
||||
private void eliminarActionListener() {
|
||||
int selectedId = this.view.getIngresosTable().getSelectedRow();
|
||||
if(selectedId >= 0){
|
||||
Ingreso ingreso = this.view.getIngresosTableModel().getIngreso(selectedId);
|
||||
this.view.getIngresosTableModel().removeRow(selectedId);
|
||||
this.ingresoDAO.deleteIngreso(ingreso);
|
||||
this.updateTotalIngresos();
|
||||
this.updateEliminarButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void onSelectTableRowListener(){
|
||||
this.view.getEliminarButton().setEnabled(true);
|
||||
}
|
||||
|
||||
private void updateTotalIngresos(){
|
||||
int total = this.ingresoDAO.getTotalIngreso();
|
||||
this.view.getTotalIngresoField().setText(String.valueOf(total));
|
||||
}
|
||||
|
||||
private void updateEliminarButton() {
|
||||
if(this.view.getIngresosTable().getSelectedRow()>=0){
|
||||
this.view.getEliminarButton().setEnabled(true);
|
||||
}else{
|
||||
this.view.getEliminarButton().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Ingreso createIngreso(String valor, TipoIngreso tipoIngreso) {
|
||||
Ingreso ingreso = new Ingreso();
|
||||
ingreso.setTipoIngreso(tipoIngreso);
|
||||
ingreso.setValor(Integer.valueOf(valor));
|
||||
|
||||
this.ingresoDAO.insertIngreso(ingreso);
|
||||
|
||||
return ingreso;
|
||||
}
|
||||
|
||||
private boolean validateInput(String valor, TipoIngreso tipoIngreso) {
|
||||
this.hideErrorMessages();
|
||||
|
||||
boolean valorValidation = this.validateValor(valor);
|
||||
boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso);
|
||||
|
||||
return valorValidation && tipoIngresoValidation;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
valor = valor.trim();
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
private boolean validateTipoIngreso(TipoIngreso tipoIngreso) {
|
||||
if (tipoIngreso == null) {
|
||||
this.view.getErrorTipoIngreso().setText("Hubo un problema con los datos");
|
||||
this.view.getErrorTipoIngreso().setVisible(true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void hideErrorMessages() {
|
||||
this.view.getErrorTipoIngreso().setVisible(false);
|
||||
this.view.getErrorValor().setVisible(false);
|
||||
}
|
||||
|
||||
private void clearInputs() {
|
||||
this.view.getTipoCombo().setSelectedIndex(0);
|
||||
this.view.getValorField().setText("");
|
||||
}
|
||||
}
|
||||
@@ -24,14 +24,19 @@
|
||||
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.models.EgresoDAO;
|
||||
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.mysql.MysqlEgresoDAO;
|
||||
import danielcortes.xyz.models.mysql.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.EgresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.IngresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||
import danielcortes.xyz.views.EgresosView;
|
||||
import danielcortes.xyz.views.IngresosView;
|
||||
import danielcortes.xyz.views.ManagerView;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
@@ -51,13 +56,24 @@ public class ManagerController {
|
||||
});
|
||||
this.view.getIngresosButton().addActionListener(e -> {
|
||||
CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout();
|
||||
layout.show(this.view.getCardPanel(),"NONE");
|
||||
layout.show(this.view.getCardPanel(),"INGRESOS");
|
||||
});
|
||||
}
|
||||
|
||||
private void loadCardContents(){
|
||||
this.view.getCardPanel().add(new JPanel(), "NONE");
|
||||
//this.view.getCardPanel().add(new JPanel(), "NONE");
|
||||
this.loadEgresosView();
|
||||
this.loadIngresosView();
|
||||
}
|
||||
|
||||
private void loadIngresosView() {
|
||||
IngresosView ingresosView = new IngresosView();
|
||||
IngresoDAO ingresoDAO = new MysqlIngresoDAO();
|
||||
TipoIngresoDAO tipoIngresoDAO = new MysqlTipoIngresoDAO();
|
||||
|
||||
this.view.getCardPanel().add(ingresosView.getContentPanel(), "INGRESOS");
|
||||
|
||||
IngresosController ingresosController = new IngresosController(ingresosView,ingresoDAO,tipoIngresoDAO);
|
||||
}
|
||||
|
||||
private void loadEgresosView(){
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.models;
|
||||
package danielcortes.xyz.models.egreso;
|
||||
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
|
||||
public class Egreso {
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.models;
|
||||
package danielcortes.xyz.models.egreso;
|
||||
|
||||
import danielcortes.xyz.models.egreso.Egreso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,13 +22,12 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.models.mysql;
|
||||
package danielcortes.xyz.models.egreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnection;
|
||||
import danielcortes.xyz.models.Egreso;
|
||||
import danielcortes.xyz.models.EgresoDAO;
|
||||
import danielcortes.xyz.models.TipoEgreso;
|
||||
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -52,7 +51,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.EgresosFromResultSet(rs);
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -72,7 +71,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
ps.setInt(1,id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.EgresosFromResultSet(rs);
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -92,7 +91,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
ps.setString(1, nro);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.EgresosFromResultSet(rs);
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -108,13 +107,19 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into egresos (nro, descripcion, valor, tipo_id) values (?,?,?,?)");
|
||||
PreparedStatement ps = conn.prepareStatement("insert into egresos (nro, descripcion, valor, tipo_egreso_id) values (?,?,?,?)");
|
||||
ps.setString(1,egreso.getNro());
|
||||
ps.setString(2,egreso.getDescripcion());
|
||||
ps.setInt(3,egreso.getValor());
|
||||
ps.setInt(4,egreso.getTipo().getId());
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
egreso.setId(rs.getInt(1));
|
||||
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -128,7 +133,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update egresos set nro = ?, descripcion = ?, valor = ?, tipo_id = ? where id = ? ");
|
||||
PreparedStatement ps = conn.prepareStatement("update egresos set nro = ?, descripcion = ?, valor = ?, tipo_egreso_id = ? where id = ? ");
|
||||
ps.setString(1,egreso.getNro());
|
||||
ps.setString(2,egreso.getDescripcion());
|
||||
ps.setInt(3,egreso.getValor());
|
||||
@@ -181,10 +186,10 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
return total;
|
||||
}
|
||||
|
||||
private List<Egreso> EgresosFromResultSet(ResultSet rs) throws SQLException {
|
||||
private List<Egreso> egresosFromResultSet(ResultSet rs) throws SQLException {
|
||||
ArrayList<Egreso> egresoList = new ArrayList<>();
|
||||
while(rs.next()){
|
||||
int tipoEgresoId = rs.getInt("tipo_id");
|
||||
int tipoEgresoId = rs.getInt("tipo_egreso_id");
|
||||
TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
|
||||
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0);
|
||||
|
||||
70
src/main/java/danielcortes/xyz/models/ingreso/Ingreso.java
Normal file
70
src/main/java/danielcortes/xyz/models/ingreso/Ingreso.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.models.ingreso;
|
||||
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
|
||||
public class Ingreso {
|
||||
private int id;
|
||||
private int valor;
|
||||
private TipoIngreso tipoIngreso;
|
||||
|
||||
public Ingreso(int id, int valor, TipoIngreso tipoIngreso ) {
|
||||
this.id = id;
|
||||
this.valor = valor;
|
||||
this.tipoIngreso = tipoIngreso;
|
||||
}
|
||||
|
||||
public Ingreso( int valor, TipoIngreso tipoIngreso) {
|
||||
this.valor = valor;
|
||||
this.tipoIngreso = tipoIngreso;
|
||||
}
|
||||
|
||||
public Ingreso(){}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public TipoIngreso getTipoIngreso() {
|
||||
return tipoIngreso;
|
||||
}
|
||||
|
||||
public void setTipoIngreso(TipoIngreso tipoIngreso) {
|
||||
this.tipoIngreso = tipoIngreso;
|
||||
}
|
||||
|
||||
public int getValor() {
|
||||
return valor;
|
||||
}
|
||||
|
||||
public void setValor(int valor) {
|
||||
this.valor = valor;
|
||||
}
|
||||
}
|
||||
@@ -22,36 +22,19 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.models;
|
||||
|
||||
public class TipoEgreso {
|
||||
private int id;
|
||||
private String nombre;
|
||||
package danielcortes.xyz.models.ingreso;
|
||||
|
||||
public TipoEgreso(int id, String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
|
||||
public TipoEgreso(){}
|
||||
import java.util.List;
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.nombre;
|
||||
}
|
||||
public interface IngresoDAO {
|
||||
List<Ingreso> findAll();
|
||||
List<Ingreso> findById(int id);
|
||||
List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso);
|
||||
boolean insertIngreso(Ingreso ingreso);
|
||||
boolean updateIngreso(Ingreso ingreso);
|
||||
boolean deleteIngreso(Ingreso ingreso);
|
||||
int getTotalIngreso();
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.models.ingreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnection;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlIngresoDAO implements IngresoDAO{
|
||||
private MysqlConnection mysqlConnection;
|
||||
|
||||
public MysqlIngresoDAO(){
|
||||
this.mysqlConnection = new MysqlConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findAll() {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findById(int id) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select ingresos.* from ingresos inner join tipos_ingreso on (ingresos.tipo_ingreso_id = tipos_ingreso.id) where ingresos.tipo_ingreso_id = ?");
|
||||
ps.setInt(1, tipoIngreso.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, tipo_ingreso_id) values (?,?)");
|
||||
ps.setInt(1, ingreso.getValor());
|
||||
ps.setInt(2, ingreso.getTipoIngreso().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
ingreso.setId(rs.getInt(1));
|
||||
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ? , tipo_ingreso_id = ? where id = ?");
|
||||
ps.setInt(1,ingreso.getValor());
|
||||
ps.setInt(2, ingreso.getTipoIngreso().getId());
|
||||
ps.setInt(3, ingreso.getId());
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from ingresos where id = ?");
|
||||
ps.setInt(1,ingreso.getId());
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalIngreso() {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select sum(valor) from ingresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
rs.next();
|
||||
total = rs.getInt(1);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private List<Ingreso> ingresosFromResultSet(ResultSet rs) throws SQLException {
|
||||
ArrayList<Ingreso> ingresosList = new ArrayList<>();
|
||||
while(rs.next()){
|
||||
int tipoIngresoId = rs.getInt("tipo_ingreso_id");
|
||||
TipoIngresoDAO tipoEgresoDAO = new MysqlTipoIngresoDAO();
|
||||
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
|
||||
|
||||
Ingreso ingreso = new Ingreso();
|
||||
|
||||
ingreso.setId(rs.getInt("id"));
|
||||
ingreso.setValor(rs.getInt("valor"));
|
||||
ingreso.setTipoIngreso(tipoIngreso);
|
||||
|
||||
ingresosList.add(ingreso);
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.models.mysql;
|
||||
package danielcortes.xyz.models.tipo_egreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnection;
|
||||
import danielcortes.xyz.models.Egreso;
|
||||
import danielcortes.xyz.models.TipoEgreso;
|
||||
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.models.tipo_egreso;
|
||||
|
||||
public class TipoEgreso {
|
||||
private int id;
|
||||
private String nombre;
|
||||
|
||||
public TipoEgreso(int id, String nombre) {
|
||||
this.id = id;
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public TipoEgreso(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public TipoEgreso(){}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.nombre;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.models.tipo_egreso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TipoEgresoDAO {
|
||||
List<TipoEgreso> findAll();
|
||||
List<TipoEgreso> findById(int id);
|
||||
List<TipoEgreso> findByNombre(String nombre);
|
||||
boolean insertTipoEgreso(TipoEgreso tipoEgreso);
|
||||
boolean updateTipoEgreso(TipoEgreso tipoEgreso);
|
||||
boolean deleteTipoEgreso(TipoEgreso tipoEgreso);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.models.tipo_ingreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlTipoIngresoDAO implements TipoIngresoDAO{
|
||||
private MysqlConnection mysqlConnection;
|
||||
|
||||
public MysqlTipoIngresoDAO(){
|
||||
this.mysqlConnection = new MysqlConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findAll() {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findById(int id) {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where id = ?");
|
||||
ps.setInt(1,id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findByNombre(String nombre) {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where nombre = ?");
|
||||
ps.setString(1,nombre);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertTipoIngreso(TipoIngreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTipoIngreso(TipoIngreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTipoIngreso(TipoIngreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private List<TipoIngreso> tiposIngresoFromResultSet(ResultSet rs) throws SQLException {
|
||||
ArrayList<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
while(rs.next()){
|
||||
TipoIngreso tipoIngreso = new TipoIngreso();
|
||||
tipoIngreso.setId(rs.getInt("id"));
|
||||
tipoIngreso.setNombre(rs.getString("nombre"));
|
||||
tiposIngresoList.add(tipoIngreso);
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.models.tipo_ingreso;
|
||||
|
||||
public class TipoIngreso {
|
||||
private int id;
|
||||
private String nombre;
|
||||
|
||||
public TipoIngreso(int id, String nombre) {
|
||||
this.id = id;
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public TipoIngreso(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public TipoIngreso() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.nombre;
|
||||
}
|
||||
}
|
||||
@@ -22,15 +22,15 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package danielcortes.xyz.models;
|
||||
package danielcortes.xyz.models.tipo_ingreso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TipoEgresoDAO {
|
||||
List<TipoEgreso> findAll();
|
||||
List<TipoEgreso> findById(int id);
|
||||
List<TipoEgreso> findByNombre(String nombre);
|
||||
boolean insertTipoEgreso(TipoEgreso tipoEgreso);
|
||||
boolean updateTipoEgreso(TipoEgreso tipoEgreso);
|
||||
boolean deleteTipoEgreso(TipoEgreso tipoEgreso);
|
||||
public interface TipoIngresoDAO {
|
||||
List<TipoIngreso> findAll();
|
||||
List<TipoIngreso> findById(int id);
|
||||
List<TipoIngreso> findByNombre(String nombre);
|
||||
boolean insertTipoIngreso(TipoIngreso tipoEgreso);
|
||||
boolean updateTipoIngreso(TipoIngreso tipoEgreso);
|
||||
boolean deleteTipoIngreso(TipoIngreso tipoEgreso);
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="9047a" binding="egresosPanel" layout-manager="GridLayoutManager" row-count="5" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="9047a" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<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"/>
|
||||
@@ -16,73 +16,9 @@
|
||||
<properties/>
|
||||
<border type="etched" title="Egresos"/>
|
||||
<children>
|
||||
<component id="d8e90" class="javax.swing.JTextField" binding="descripcionField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="696ee" class="javax.swing.JTextField" binding="valorField">
|
||||
<constraints>
|
||||
<grid row="1" column="2" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="da489" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Descripcion"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f50cf" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Valor"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1af5c" class="javax.swing.JTextField" binding="nroField">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c5b18" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="N°"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5602d" class="javax.swing.JComboBox" binding="tipoCombo">
|
||||
<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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="daec8" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Tipo"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="65bec">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="4" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -93,85 +29,198 @@
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="c5738" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
|
||||
<grid id="98ec" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" 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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Añadir"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3442d" class="javax.swing.JLabel">
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="c5b18" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="N°"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="da489" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Descripcion"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d8e90" class="javax.swing.JTextField" binding="descripcionField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="1af5c" class="javax.swing.JTextField" binding="nroField">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="696ee" class="javax.swing.JTextField" binding="valorField">
|
||||
<constraints>
|
||||
<grid row="1" column="2" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="f50cf" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Valor"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="daec8" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Tipo"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5602d" class="javax.swing.JComboBox" binding="tipoCombo">
|
||||
<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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="33b8a" class="javax.swing.JLabel" binding="errorNumero">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="116af" class="javax.swing.JLabel" binding="errorDescripcion">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42cb" class="javax.swing.JLabel" binding="errorValor">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e586b" class="javax.swing.JLabel" binding="errorTipoEgreso">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="2cb6e" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Total Egresos:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2b8d0" class="javax.swing.JTextField" binding="totalEgresosField">
|
||||
<constraints>
|
||||
<grid row="4" 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"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="68df1" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="c5738" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Añadir"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ee598" class="javax.swing.JButton" binding="eliminarButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
<text value="&Eliminar"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ee598" class="javax.swing.JButton" binding="eliminarButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="4" 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>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
<text value="&Eliminar"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="33b8a" class="javax.swing.JLabel" binding="errorNumero">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="116af" class="javax.swing.JLabel" binding="errorDescripcion">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42cb" class="javax.swing.JLabel" binding="errorValor">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e586b" class="javax.swing.JLabel" binding="errorTipoEgreso">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Error"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="99a08">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="3715e" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="3442d" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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>
|
||||
</component>
|
||||
<component id="2b8d0" class="javax.swing.JTextField" binding="totalEgresosField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
|
||||
@@ -24,16 +24,13 @@
|
||||
|
||||
package danielcortes.xyz.views;
|
||||
|
||||
import danielcortes.xyz.models.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.views.components.EgresosTableModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicComboBoxRenderer;
|
||||
import java.awt.*;
|
||||
|
||||
public class EgresosView {
|
||||
public JPanel contentPanel;
|
||||
private JPanel egresosPanel;
|
||||
private JTable egresosTable;
|
||||
private JButton guardarButton;
|
||||
private JTextField valorField;
|
||||
@@ -98,10 +95,6 @@ public class EgresosView {
|
||||
return egresosTable;
|
||||
}
|
||||
|
||||
public void setEgresosTable(JTable egresosTable) {
|
||||
this.egresosTable = egresosTable;
|
||||
}
|
||||
|
||||
public EgresosTableModel getEgresosTableModel() {
|
||||
return egresosTableModel;
|
||||
}
|
||||
|
||||
175
src/main/java/danielcortes/xyz/views/IngresosView.form
Normal file
175
src/main/java/danielcortes/xyz/views/IngresosView.form
Normal file
@@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.IngresosView">
|
||||
<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"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="766" height="411"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="e14bc" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="etched" title="Ingresos"/>
|
||||
<children>
|
||||
<scrollpane id="bb19b">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="1ba21" class="javax.swing.JTable" binding="ingresosTable" custom-create="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="7fa26" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="50b32" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Tipo"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d0439" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Valor"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="375b0" class="javax.swing.JTextField" binding="valorField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="b5d8c" class="javax.swing.JComboBox" binding="tipoCombo">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d11b0" class="javax.swing.JLabel" binding="errorTipoIngreso">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Label"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4b7ff" class="javax.swing.JLabel" binding="errorValor">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<foreground color="-65536"/>
|
||||
<text value="Label"/>
|
||||
<visible value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="ea865" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="bec48" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="ed411" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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 Ingresos"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d9f4a" class="javax.swing.JTextField" binding="totalIngresoField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="6385a" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="98602" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Añadir"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c9542" class="javax.swing.JButton" binding="eliminarButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Eliminar"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="7b168">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<inspectionSuppressions>
|
||||
<suppress inspection="I18nForm"/>
|
||||
<suppress inspection="FormSpellChecking"/>
|
||||
</inspectionSuppressions>
|
||||
</form>
|
||||
95
src/main/java/danielcortes/xyz/views/IngresosView.java
Normal file
95
src/main/java/danielcortes/xyz/views/IngresosView.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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;
|
||||
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
import danielcortes.xyz.views.components.IngresosTableModel;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class IngresosView {
|
||||
private JPanel contentPanel;
|
||||
private JTable ingresosTable;
|
||||
private JButton guardarButton;
|
||||
private JButton eliminarButton;
|
||||
private JTextField totalIngresoField;
|
||||
private JTextField valorField;
|
||||
private JComboBox<TipoIngreso> tipoCombo;
|
||||
private JLabel errorTipoIngreso;
|
||||
private JLabel errorValor;
|
||||
|
||||
private IngresosTableModel ingresosTableModel;
|
||||
|
||||
private void createUIComponents() {
|
||||
this.createIngresosTable();
|
||||
}
|
||||
|
||||
private void createIngresosTable(){
|
||||
this.ingresosTableModel = new IngresosTableModel();
|
||||
this.ingresosTable = new JTable(ingresosTableModel);
|
||||
this.ingresosTable.setAutoCreateRowSorter(true);
|
||||
this.ingresosTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
|
||||
public JPanel getContentPanel() {
|
||||
return contentPanel;
|
||||
}
|
||||
|
||||
public JTable getIngresosTable() {
|
||||
return ingresosTable;
|
||||
}
|
||||
|
||||
public JButton getGuardarButton() {
|
||||
return guardarButton;
|
||||
}
|
||||
|
||||
public JButton getEliminarButton() {
|
||||
return eliminarButton;
|
||||
}
|
||||
|
||||
public JTextField getTotalIngresoField() {
|
||||
return totalIngresoField;
|
||||
}
|
||||
|
||||
public JTextField getValorField() {
|
||||
return valorField;
|
||||
}
|
||||
|
||||
public JComboBox<TipoIngreso> getTipoCombo() {
|
||||
return tipoCombo;
|
||||
}
|
||||
|
||||
public IngresosTableModel getIngresosTableModel() {
|
||||
return ingresosTableModel;
|
||||
}
|
||||
|
||||
public JLabel getErrorTipoIngreso() {
|
||||
return errorTipoIngreso;
|
||||
}
|
||||
|
||||
public JLabel getErrorValor() {
|
||||
return errorValor;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
package danielcortes.xyz.views.components;
|
||||
|
||||
import danielcortes.xyz.models.Egreso;
|
||||
import danielcortes.xyz.models.egreso.Egreso;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.util.ArrayList;
|
||||
|
||||
public class IngresosTableModel extends AbstractTableModel {
|
||||
private String[] columns;
|
||||
private ArrayList<Ingreso> rows;
|
||||
|
||||
public IngresosTableModel(){
|
||||
super();
|
||||
this.columns = new String[]{"Valor", "Tipo"};
|
||||
this.rows = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getColumnName(int col) {
|
||||
return this.columns[col];
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return this.columns.length;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return this.rows.size();
|
||||
}
|
||||
|
||||
public void addRow(Ingreso ingreso) {
|
||||
this.rows.add(ingreso);
|
||||
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) {
|
||||
switch (col) {
|
||||
case 0:
|
||||
return this.rows.get(row).getValor();
|
||||
case 1:
|
||||
return this.rows.get(row).getTipoIngreso().getNombre();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Ingreso getIngreso(int row){
|
||||
return this.rows.get(row);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user