From e555ab9106a035d62a22ced2f67bf42891d4dd8b Mon Sep 17 00:00:00 2001 From: Daniel Cortes Date: Fri, 28 Dec 2018 21:12:10 -0300 Subject: [PATCH] Corregido problemas .w. --- caja.iml | 2 +- conf | 8 +-- database.sqlite | Bin 32768 -> 32768 bytes pom.xml | 4 +- src/main/java/danielcortes/xyz/Main.java | 48 +++++++++++++++++- .../xyz/controllers/ManagerController.java | 35 +++++++------ .../xyz/data/SQLiteConnectionHolder.java | 5 ++ .../xyz/models/caja/SQLiteCajaDAO.java | 12 +++-- .../documentos/SQLiteDocumentosDAO.java | 8 +-- .../models/efectivo/SQLiteEfectivoDAO.java | 5 +- .../xyz/models/egreso/SQLiteEgresoDAO.java | 8 +-- .../xyz/models/ingreso/SQLiteIngresoDAO.java | 8 +-- src/main/resources/META-INF/MANIFEST.MF | 6 +-- 13 files changed, 102 insertions(+), 47 deletions(-) diff --git a/caja.iml b/caja.iml index 47ecf4d..1343501 100644 --- a/caja.iml +++ b/caja.iml @@ -1,6 +1,6 @@ - + diff --git a/conf b/conf index 0622f76..1bcc5b0 100644 --- a/conf +++ b/conf @@ -7,14 +7,14 @@ # - mysql # - sqlite -database_type = mysql -#database_type = sqlite +#database_type = mysql +database_type = sqlite # database_uri es la uri de la base de datos con la que se conectara el sistema. # debe corresponder con el sistema de base de datos seleccionado en database_type -database_uri = jdbc:mysql://localhost/caja?user=root&password=lagging&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC -#database_uri = jdbc:sqlite:/opt/caja/database.db +#database_uri = jdbc:mysql://localhost/caja?user=root&password=lagging&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC +database_uri = jdbc:sqlite:/home/ryuuji/src/caja/database.sqlite # look_and_feel elige el look and feel que intentara utilizar la aplicacion, si el seleccionado no funciona en el sistema operativo se hara fallback a metal. diff --git a/database.sqlite b/database.sqlite index b1644b6d7ce19c1bc0ab37e6170b74be55043b11..5219c72dcc307115f8aa9ea127bff17a9fe72dfa 100644 GIT binary patch delta 569 zcmZWmK}#D!6rP#4o1KlWZ)4bo)CMCxL?MyPMvXac(xnCxH*D5WJ?G@bUm(fN9@~rb zZ`4rmBq-P(1-%u?!9qxn?X8DGpEfChK4zHtzVE&HhWGk?(eI0QONlCDOwyjl%lG+` zUS;d6habCN46YCI@<8X>;KVu>alku$Y*?Rg3csxc5wt|$;-2{$ t3nrZ9pEyBxlLCu?41)kz7f3rh5(e>^pbCZActL6q`T|%4kc>f-1pvhR9OD20 diff --git a/pom.xml b/pom.xml index 7ca8850..636e79e 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,8 @@ 3.8.0 8 - 9 - 9 + 8 + 8 diff --git a/src/main/java/danielcortes/xyz/Main.java b/src/main/java/danielcortes/xyz/Main.java index b09226a..e73d710 100644 --- a/src/main/java/danielcortes/xyz/Main.java +++ b/src/main/java/danielcortes/xyz/Main.java @@ -28,6 +28,25 @@ import danielcortes.xyz.controllers.ManagerController; import danielcortes.xyz.data.Properties; import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO; +import danielcortes.xyz.models.caja.SQLiteCajaDAO; +import danielcortes.xyz.models.documentos.DocumentosDAO; +import danielcortes.xyz.models.documentos.MysqlDocumentosDAO; +import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO; +import danielcortes.xyz.models.efectivo.EfectivoDAO; +import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO; +import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO; +import danielcortes.xyz.models.egreso.EgresoDAO; +import danielcortes.xyz.models.egreso.MysqlEgresoDAO; +import danielcortes.xyz.models.egreso.SQLiteEgresoDAO; +import danielcortes.xyz.models.ingreso.IngresoDAO; +import danielcortes.xyz.models.ingreso.MysqlIngresoDAO; +import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO; +import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO; +import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO; +import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO; +import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO; +import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO; +import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO; import danielcortes.xyz.views.ManagerView; import javax.swing.*; @@ -48,9 +67,34 @@ public class Main { Locale.setDefault(new Locale("es")); - CajaDAO cajaDAO = new MysqlCajaDAO(); + CajaDAO cajaDAO = null; + DocumentosDAO documentosDAO = null; + EfectivoDAO efectivoDAO = null; + EgresoDAO egresoDAO = null; + IngresoDAO ingresoDAO = null; + TipoEgresoDAO tipoEgresoDAO = null; + TipoIngresoDAO tipoIngresoDAO = null; + + if(Properties.getInstance().getProperty("database_type").equals("mysql")){ + cajaDAO = new MysqlCajaDAO(); + documentosDAO = new MysqlDocumentosDAO(); + efectivoDAO = new MysqlEfectivoDAO(); + egresoDAO = new MysqlEgresoDAO(); + ingresoDAO = new MysqlIngresoDAO(); + tipoEgresoDAO = new MysqlTipoEgresoDAO(); + tipoIngresoDAO = new MysqlTipoIngresoDAO(); + }else if(Properties.getInstance().getProperty("database_type").equals("sqlite")){ + cajaDAO = new SQLiteCajaDAO(); + documentosDAO = new SQLiteDocumentosDAO(); + efectivoDAO = new SQLiteEfectivoDAO(); + egresoDAO = new SQLiteEgresoDAO(); + ingresoDAO = new SQLiteIngresoDAO(); + tipoEgresoDAO = new SQLiteTipoEgresoDAO(); + tipoIngresoDAO = new SQLiteTipoIngresoDAO(); + } + ManagerView view = new ManagerView(); - ManagerController managerController = new ManagerController(view, cajaDAO); + ManagerController managerController = new ManagerController(view, cajaDAO, documentosDAO, efectivoDAO, egresoDAO, ingresoDAO, tipoEgresoDAO, tipoIngresoDAO); JFrame frame = new JFrame("Caja"); frame.setContentPane(view.getContentPanel()); diff --git a/src/main/java/danielcortes/xyz/controllers/ManagerController.java b/src/main/java/danielcortes/xyz/controllers/ManagerController.java index d323d97..e00feff 100644 --- a/src/main/java/danielcortes/xyz/controllers/ManagerController.java +++ b/src/main/java/danielcortes/xyz/controllers/ManagerController.java @@ -39,6 +39,7 @@ 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.ArqueoView; import danielcortes.xyz.views.EgresosView; @@ -53,13 +54,25 @@ import java.time.LocalDate; public class ManagerController { private ManagerView view; private CajaDAO cajaDAO; + private DocumentosDAO documentosDAO; + private EfectivoDAO efectivoDAO; + private EgresoDAO egresoDAO; + private IngresoDAO ingresoDAO; + private TipoEgresoDAO tipoEgresoDAO; + private TipoIngresoDAO tipoIngresoDAO; private IngresosController ingresosController; private EgresosController egresosController; private ArqueoController arqueoController; - public ManagerController(ManagerView view, CajaDAO cajaDAO) { + public ManagerController(ManagerView view, CajaDAO cajaDAO, DocumentosDAO documentosDAO, EfectivoDAO efectivoDAO, EgresoDAO egresoDAO, IngresoDAO ingresoDAO, TipoEgresoDAO tipoEgresoDAO, TipoIngresoDAO tipoIngresoDAO) { this.view = view; this.cajaDAO = cajaDAO; + this.documentosDAO = documentosDAO; + this.efectivoDAO = efectivoDAO; + this.egresoDAO = egresoDAO; + this.ingresoDAO = ingresoDAO; + this.tipoEgresoDAO = tipoEgresoDAO; + this.tipoIngresoDAO = tipoIngresoDAO; this.loadCardContents(); this.setUpDate(); this.setUpViewEvents(); @@ -100,15 +113,13 @@ public class ManagerController { caja.setFecha(selectedDate); this.cajaDAO.insertCaja(caja); - EfectivoDAO efectivoDAO = new MysqlEfectivoDAO(); Efectivo efectivo = new Efectivo(); efectivo.setCaja(caja); - efectivoDAO.insertDefaultEfectivo(efectivo); + this.efectivoDAO.insertDefaultEfectivo(efectivo); - DocumentosDAO documentosDAO = new MysqlDocumentosDAO(); Documentos documentos = new Documentos(); documentos.setCaja(caja); - documentosDAO.insertDefaultDocumentos(documentos); + this.documentosDAO.insertDefaultDocumentos(documentos); } this.ingresosController.updateCaja(caja); @@ -124,34 +135,26 @@ public class ManagerController { private void loadIngresosView() { IngresosView ingresosView = new IngresosView(); - IngresoDAO ingresoDAO = new MysqlIngresoDAO(); - TipoIngresoDAO tipoIngresoDAO = new MysqlTipoIngresoDAO(); this.view.getCardPanel().add(ingresosView.getContentPanel(), "INGRESOS"); - this.ingresosController = new IngresosController(ingresosView, ingresoDAO, tipoIngresoDAO); + this.ingresosController = new IngresosController(ingresosView, this.ingresoDAO, this.tipoIngresoDAO); } private void loadEgresosView() { EgresosView egresosView = new EgresosView(); - EgresoDAO egresoDAO = new MysqlEgresoDAO(); - TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO(); this.view.getCardPanel().add(egresosView.getContentPanel(), "EGRESOS"); - this.egresosController = new EgresosController(egresosView, egresoDAO, tipoEgresoDAO); + this.egresosController = new EgresosController(egresosView, this.egresoDAO, this.tipoEgresoDAO); } private void loadArqueoView() { ArqueoView arqueoView = new ArqueoView(); - EfectivoDAO efectivoDAO = new MysqlEfectivoDAO(); - DocumentosDAO documentosDAO = new MysqlDocumentosDAO(); - EgresoDAO egresoDAO = new MysqlEgresoDAO(); - IngresoDAO ingresoDAO = new MysqlIngresoDAO(); this.view.getCardPanel().add(arqueoView.getContentPanel(), "ARQUEO"); - this.arqueoController = new ArqueoController(arqueoView, efectivoDAO, documentosDAO, ingresoDAO, egresoDAO); + this.arqueoController = new ArqueoController(arqueoView, this.efectivoDAO, this.documentosDAO, this.ingresoDAO, this.egresoDAO); } private void pressInitialButton() { diff --git a/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java b/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java index 1c63245..d502961 100644 --- a/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java +++ b/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java @@ -35,6 +35,11 @@ public class SQLiteConnectionHolder implements ConnectionHolder { @Override public java.sql.Connection getConnection() throws SQLException{ + try { + Class.forName("org.sqlite.JDBC"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } return DriverManager.getConnection(databaseURI); } } diff --git a/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java b/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java index a3b6777..cfb231e 100644 --- a/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java +++ b/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java @@ -30,7 +30,10 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -89,7 +92,7 @@ public class SQLiteCajaDAO implements CajaDAO { Connection conn = connectionHolder.getConnection(); PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?"); - ps.setObject(1, fecha); + ps.setString(1, fecha.toString()); ResultSet rs = ps.executeQuery(); @@ -114,7 +117,8 @@ public class SQLiteCajaDAO implements CajaDAO { try { Connection conn = connectionHolder.getConnection(); PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)"); - ps.setObject(1, caja.getFecha()); + + ps.setString(1, caja.getFecha().toString()); updates = ps.executeUpdate(); ps.close(); @@ -140,7 +144,7 @@ public class SQLiteCajaDAO implements CajaDAO { try { Connection conn = connectionHolder.getConnection(); PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?"); - ps.setObject(1, caja.getFecha()); + ps.setString(1, caja.getFecha().toString()); ps.setInt(2, caja.getId()); updates = ps.executeUpdate(); @@ -160,7 +164,7 @@ public class SQLiteCajaDAO implements CajaDAO { while (rs.next()) { Caja caja = new Caja(); caja.setId(rs.getInt("id")); - caja.setFecha(rs.getObject("fecha", LocalDate.class)); + caja.setFecha(LocalDate.parse(rs.getString("fecha"))); cajaList.add(caja); } return cajaList; diff --git a/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java b/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java index 479bf83..b2ad6be 100644 --- a/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java +++ b/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java @@ -25,10 +25,10 @@ package danielcortes.xyz.models.documentos; import danielcortes.xyz.data.ConnectionHolder; -import danielcortes.xyz.data.MysqlConnectionHolder; +import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.MysqlCajaDAO; +import danielcortes.xyz.models.caja.SQLiteCajaDAO; import java.sql.Connection; import java.sql.PreparedStatement; @@ -41,7 +41,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO{ private ConnectionHolder connectionHolder; public SQLiteDocumentosDAO() { - this.connectionHolder = new MysqlConnectionHolder(); + this.connectionHolder = new SQLiteConnectionHolder(); } @Override @@ -208,7 +208,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO{ private List documentosFromResultSet(ResultSet rs) throws SQLException { List documentosList = new ArrayList<>(); while (rs.next()) { - CajaDAO cajaDAO = new MysqlCajaDAO(); + CajaDAO cajaDAO = new SQLiteCajaDAO(); Caja caja = cajaDAO.findById(rs.getInt("caja_id")); Documentos documentos = new Documentos(); diff --git a/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java b/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java index f966876..2ab6b5d 100644 --- a/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java +++ b/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java @@ -25,11 +25,10 @@ package danielcortes.xyz.models.efectivo; import danielcortes.xyz.data.ConnectionHolder; -import danielcortes.xyz.data.MysqlConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.MysqlCajaDAO; +import danielcortes.xyz.models.caja.SQLiteCajaDAO; import java.sql.Connection; import java.sql.PreparedStatement; @@ -222,7 +221,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO{ private List efectivosFromResultSet(ResultSet rs) throws SQLException { List efectivoList = new ArrayList<>(); while (rs.next()) { - CajaDAO cajaDAO = new MysqlCajaDAO(); + CajaDAO cajaDAO = new SQLiteCajaDAO(); Caja caja = cajaDAO.findById(rs.getInt("caja_id")); Efectivo efectivo = new Efectivo(); diff --git a/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java b/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java index d49948f..5c3c516 100644 --- a/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java @@ -28,8 +28,8 @@ import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.MysqlCajaDAO; -import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO; +import danielcortes.xyz.models.caja.SQLiteCajaDAO; +import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO; @@ -244,11 +244,11 @@ public class SQLiteEgresoDAO implements EgresoDAO{ ArrayList egresoList = new ArrayList<>(); while(rs.next()){ int tipoEgresoId = rs.getInt("tipo_egreso_id"); - TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO(); + TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO(); TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0); int cajaId = rs.getInt("caja_id"); - CajaDAO cajaDAO = new MysqlCajaDAO(); + CajaDAO cajaDAO = new SQLiteCajaDAO(); Caja caja = cajaDAO.findById(cajaId); Egreso egreso = new Egreso(); diff --git a/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java b/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java index 3f076f6..8b353c7 100644 --- a/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java @@ -28,8 +28,8 @@ import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.MysqlCajaDAO; -import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO; +import danielcortes.xyz.models.caja.SQLiteCajaDAO; +import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO; import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO; @@ -221,11 +221,11 @@ public class SQLiteIngresoDAO implements IngresoDAO{ ArrayList ingresosList = new ArrayList<>(); while(rs.next()){ int tipoIngresoId = rs.getInt("tipo_ingreso_id"); - TipoIngresoDAO tipoEgresoDAO = new MysqlTipoIngresoDAO(); + TipoIngresoDAO tipoEgresoDAO = new SQLiteTipoIngresoDAO(); TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0); int cajaId = rs.getInt("caja_id"); - CajaDAO cajaDAO = new MysqlCajaDAO(); + CajaDAO cajaDAO = new SQLiteCajaDAO(); Caja caja = cajaDAO.findById(cajaId); Ingreso ingreso = new Ingreso(); diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF index e463e67..847ee37 100644 --- a/src/main/resources/META-INF/MANIFEST.MF +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0 -Main-Class: danielcortes.xyz.Main - +Manifest-Version: 1.0 +Main-Class: danielcortes.xyz.Main +