From fe187e4892a84aaf37f2db19ceab9b7ae15eeb2e Mon Sep 17 00:00:00 2001 From: Daniel Cortes Date: Fri, 28 Dec 2018 18:23:15 -0300 Subject: [PATCH] Agregadas clases para compatibilidad con sqlite --- caja.iml | 9 +- conf | 24 ++ database.sqlite | Bin 0 -> 32768 bytes database/{create.sql => mysql.sql} | 0 database/sqlite.sql | 120 ++++++++ pom.xml | 5 + src/main/java/danielcortes/xyz/Main.java | 5 +- .../xyz/data/ConnectionHolder.java | 31 ++ ...ection.java => MysqlConnectionHolder.java} | 6 +- .../xyz/data/SQLiteConnectionHolder.java | 40 +++ .../xyz/models/caja/MysqlCajaDAO.java | 6 +- .../xyz/models/caja/SQLiteCajaDAO.java | 168 +++++++++++ .../models/documentos/MysqlDocumentosDAO.java | 6 +- .../documentos/SQLiteDocumentosDAO.java | 224 +++++++++++++++ .../xyz/models/efectivo/MysqlEfectivoDAO.java | 6 +- .../models/efectivo/SQLiteEfectivoDAO.java | 245 ++++++++++++++++ .../xyz/models/egreso/MysqlEgresoDAO.java | 45 +-- .../xyz/models/egreso/SQLiteEgresoDAO.java | 267 ++++++++++++++++++ .../xyz/models/ingreso/MysqlIngresoDAO.java | 6 +- .../xyz/models/ingreso/SQLiteIngresoDAO.java | 244 ++++++++++++++++ .../tipo_egreso/MysqlTipoEgresoDAO.java | 6 +- .../tipo_egreso/SQLiteTipoEgresoDAO.java | 128 +++++++++ .../tipo_ingreso/MysqlTipoIngresoDAO.java | 6 +- .../tipo_ingreso/SQLiteTipoIngresoDAO.java | 128 +++++++++ .../danielcortes/xyz/views/ArqueoView.java | 12 +- 25 files changed, 1682 insertions(+), 55 deletions(-) create mode 100644 conf create mode 100644 database.sqlite rename database/{create.sql => mysql.sql} (100%) create mode 100644 database/sqlite.sql create mode 100644 src/main/java/danielcortes/xyz/data/ConnectionHolder.java rename src/main/java/danielcortes/xyz/data/{MysqlConnection.java => MysqlConnectionHolder.java} (89%) create mode 100644 src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java create mode 100644 src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java create mode 100644 src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java create mode 100644 src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java create mode 100644 src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java create mode 100644 src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java create mode 100644 src/main/java/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java create mode 100644 src/main/java/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java diff --git a/caja.iml b/caja.iml index 213a563..47ecf4d 100644 --- a/caja.iml +++ b/caja.iml @@ -11,10 +11,6 @@ - - - - @@ -24,5 +20,10 @@ + + + + + \ No newline at end of file diff --git a/conf b/conf new file mode 100644 index 0000000..0622f76 --- /dev/null +++ b/conf @@ -0,0 +1,24 @@ +# configuracion del sistema de Caja + +# configuracion de la base de datos: + +# database_type sirve para elegir el sistema de base de datos que utilizara el sistema. +# los valores soportados son: +# - mysql +# - 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 + + +# 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. + +look_and_feel = javax.swing.plaf.metal.MetalLookAndFeel +#look_and_feel = com.sun.java.swing.plaf.gtk.GTKLookAndFeel +#look_and_feel = com.sun.java.swing.plaf.windows.WindowsLookAndFeel diff --git a/database.sqlite b/database.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..b1644b6d7ce19c1bc0ab37e6170b74be55043b11 GIT binary patch literal 32768 zcmeI)&u-f`90zbIaw6ARrvj)Hva>~( zqO!HOtiXENOYFRd=y@-&N7!Z9b+-ZgQL-G-P=Xu^6b`-u49O(LKc63ETL_iM-#m~; zumh#X+_1ae70>s*uNm_^?;5?@^s2Tl9ki-9wD)VrryXANJ{ic%lpD6&Ui4cuxGX>T zr}OWnEA$o{1Rwwb2tWV=?^)pI`tB zJ=kU^>77A`F`2M(lc^DhLbHjMW3FGaAH>UBlpjA6FLIGl!D)V~3`_IT$YvU@p9{mY z#>|*M=liz$rZeexi;#z@ZG{b{B{!KC2SST9ruJ+a8^~mnsg&iDgwv0mm}fChgiT4r zNKlFvnb9&foz2(rO4z%8-G9?99H^q$$Rm}_4%&{wEZIdk>FgZCk+7rKAInkWa1tqA z6`3a$)SY6P#;VM3!bns$J-M-R+vr@7>XpC9Wh#r1H=Z3+-Wg}xuH|$#Z|=Dr*jZ;+ zF>XHl-ACChhrNE^fAe_}Wtkq*3{Y9M51klSsq-N&##6;%KF)lk^mM>>R~4Hj)#X#I z_Q^h$ybO>LKbcuUdoW-4K&I28bnTo~*vN^kx)`0khN^DlX+~F#NSvBy7uvM#GYdN* znQO+m0Bv4Y_2K+iqWxHK+ISZi_p4UeyLr<;zFS1y>6!Cp#fiU@Ri6YE&|K_OHGZl^ z8JH?^^uh8)5cbyB{a+rHA1vjJ6XkB%X>giYZ>pLOr!}cnRl@G8IZ?H4F%yx+T25j~ zpL(YhIdUg$)mFV0Yq4MUuRfpZMdqeaQ!P$l-6|XAPTAaho;p7+g}sdp|M*UA>XaQT zr$>1lIB~4!)Pq@(oNL~E?}xo^*FWwT4O?9MT5=k)DYXVpsh_^eo^e)u16J|sY}$Ks zy6MLT0SG_<0uX=z1Rwwb2tWV=5P-l17O?mKs~`U7MSn$qM88MBMk@L)+KO&P>(L4& zV}k$$AOHafKmY;|fB*y_009UrzCgGdc-==vtF=zx-QE*MYL&5_V(pmZ(WSuK*yV?c z?Q(78SX^xf-lxOV&`O;NB?_G>T8DErtfvmOriD_8>aGOdot<2A_K=pGY1;4F1##=k zf%oMO&y1pGQlV)X&pld@v88Ak8t=CPZ|G(|mMPm4*@TZ0^>Gk*UzOPpMM}$y+?toD z=KDN0x#p}WWk*spA+nGB!27JqbWW@N{ok(04{I;`erfT8j1fQp0uX=z1Rwwb2tWV= z5P$##AW*yi2L=Qn009U<00Izz00bZa0SG_<0vA-k-v76vw_fyj^d~(5@b-cZ6T^Z4 z1Rwwb2tWV=5P$##AOHafEV4kG9vSG_#|*MndODy#UE-gu(Zc|@%ZCawdQ2eA`AB4I z^bo)-@xG-0flG<_`~M<`AAN@a1Rwwb2tWV=5P$##AOHafoKFDv|L1c;DF{FS0uX=z S1Rwwb2tWV=5P-lU3;Yky4h!4> literal 0 HcmV?d00001 diff --git a/database/create.sql b/database/mysql.sql similarity index 100% rename from database/create.sql rename to database/mysql.sql diff --git a/database/sqlite.sql b/database/sqlite.sql new file mode 100644 index 0000000..2f09574 --- /dev/null +++ b/database/sqlite.sql @@ -0,0 +1,120 @@ +/* +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. +*/ +pragma foreign_keys = ON; + +drop table if exists egresos; +drop table if exists tipos_egreso; +drop table if exists ingresos; +drop table if exists tipos_ingreso; +drop table if exists efectivos; +drop table if exists documentos; +drop table if exists caja; + +create table caja +( + id integer primary key, + fecha date not null +); + +create table tipos_egreso +( + id integer primary key, + nombre text not null +); + +create table egresos +( + id integer primary key, + nro text not null, + descripcion text not null, + valor integer not null, + tipo_egreso_id integer not null, + caja_id integer not null, + foreign key (tipo_egreso_id) references tipos_egreso (id) on update cascade on delete restrict, + foreign key (caja_id) references caja (id) on update cascade on delete restrict +); + +create table tipos_ingreso +( + id integer primary key, + nombre text not null +); + +create table ingresos +( + id integer primary key, + valor integer not null, + nro_inicial text not null, + nro_final text not null, + tipo_ingreso_id integer unsigned not null, + caja_id integer unsigned not null, + foreign key (tipo_ingreso_id) references tipos_ingreso (id) on update cascade on delete restrict, + foreign key (caja_id) references caja (id) on update cascade on delete restrict +); + +create table efectivos +( + id integer primary key, + veinte_mil integer not null, + diez_mil integer not null, + cinco_mil integer not null, + dos_mil integer not null, + mil integer not null, + quinientos integer not null, + cien integer not null, + cincuenta integer not null, + diez integer not null, + caja_id integer not null, + foreign key (caja_id) references caja (id) on update cascade on delete restrict +); + +create table documentos +( + id integer primary key, + cheques integer not null, + tarjetas integer not null, + caja_id integer not null, + foreign key (caja_id) references caja (id) on update cascade on delete restrict +); + + +insert into tipos_egreso (nombre) +values ('Factura Materia Prima'), + ('Factura Gastos Generales'), + ('Gasto Menor Materia Prima'), + ('Gasto General Sin Respaldo'), + ('Gasto General Con Boleta'), + ('Guia Materia Prima'), + ('Anticipo Arriendo'), + ('Anticipo Personal'), + ('Pago Partime'), + ('Retiros Gerencia'), + ('Otro'); + +insert into tipos_ingreso (nombre) +values ('Boletas Fiscales'), + ('Boletas Manuales'), + ('Facturas'), + ('Guias') + diff --git a/pom.xml b/pom.xml index e5a5efc..7ca8850 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,11 @@ mysql-connector-java 8.0.13 + + org.xerial + sqlite-jdbc + 3.25.2 + com.github.lgooddatepicker LGoodDatePicker diff --git a/src/main/java/danielcortes/xyz/Main.java b/src/main/java/danielcortes/xyz/Main.java index 0e8d026..b09226a 100644 --- a/src/main/java/danielcortes/xyz/Main.java +++ b/src/main/java/danielcortes/xyz/Main.java @@ -31,11 +31,11 @@ import danielcortes.xyz.models.caja.MysqlCajaDAO; import danielcortes.xyz.views.ManagerView; import javax.swing.*; +import java.sql.SQLException; import java.util.Locale; public class Main { - public static void main(String[] args) { - + public static void main(String[] args) throws SQLException { System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("swing.aatext", "true"); @@ -47,6 +47,7 @@ public class Main { Locale.setDefault(new Locale("es")); + CajaDAO cajaDAO = new MysqlCajaDAO(); ManagerView view = new ManagerView(); ManagerController managerController = new ManagerController(view, cajaDAO); diff --git a/src/main/java/danielcortes/xyz/data/ConnectionHolder.java b/src/main/java/danielcortes/xyz/data/ConnectionHolder.java new file mode 100644 index 0000000..8cbdec2 --- /dev/null +++ b/src/main/java/danielcortes/xyz/data/ConnectionHolder.java @@ -0,0 +1,31 @@ +/* + * 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.data; + +import java.sql.SQLException; + +public interface ConnectionHolder { + public java.sql.Connection getConnection() throws SQLException; +} diff --git a/src/main/java/danielcortes/xyz/data/MysqlConnection.java b/src/main/java/danielcortes/xyz/data/MysqlConnectionHolder.java similarity index 89% rename from src/main/java/danielcortes/xyz/data/MysqlConnection.java rename to src/main/java/danielcortes/xyz/data/MysqlConnectionHolder.java index a27eb0e..caccf5f 100644 --- a/src/main/java/danielcortes/xyz/data/MysqlConnection.java +++ b/src/main/java/danielcortes/xyz/data/MysqlConnectionHolder.java @@ -26,13 +26,13 @@ package danielcortes.xyz.data; import java.sql.*; -public class MysqlConnection { +public class MysqlConnectionHolder implements ConnectionHolder { private String databaseURI; - public MysqlConnection(){ + public MysqlConnectionHolder(){ this.databaseURI = Properties.getInstance().getProperty("database_uri"); } - public Connection getConnection() throws SQLException{ + public java.sql.Connection getConnection() throws SQLException{ return DriverManager.getConnection(databaseURI); } } diff --git a/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java b/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java new file mode 100644 index 0000000..1c63245 --- /dev/null +++ b/src/main/java/danielcortes/xyz/data/SQLiteConnectionHolder.java @@ -0,0 +1,40 @@ +/* + * 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.data; + +import java.sql.DriverManager; +import java.sql.SQLException; + +public class SQLiteConnectionHolder implements ConnectionHolder { + private String databaseURI; + public SQLiteConnectionHolder(){ + this.databaseURI = Properties.getInstance().getProperty("database_uri"); + } + + @Override + public java.sql.Connection getConnection() throws SQLException{ + return DriverManager.getConnection(databaseURI); + } +} diff --git a/src/main/java/danielcortes/xyz/models/caja/MysqlCajaDAO.java b/src/main/java/danielcortes/xyz/models/caja/MysqlCajaDAO.java index 2012b02..3907c4a 100644 --- a/src/main/java/danielcortes/xyz/models/caja/MysqlCajaDAO.java +++ b/src/main/java/danielcortes/xyz/models/caja/MysqlCajaDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.caja; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import java.sql.*; import java.time.LocalDate; @@ -32,10 +32,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlCajaDAO implements CajaDAO { - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlCajaDAO() { - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override diff --git a/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java b/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java new file mode 100644 index 0000000..a3b6777 --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java @@ -0,0 +1,168 @@ +/* + * 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.caja; + +import danielcortes.xyz.data.SQLiteConnectionHolder; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class SQLiteCajaDAO implements CajaDAO { + private SQLiteConnectionHolder connectionHolder; + + public SQLiteCajaDAO() { + this.connectionHolder = new SQLiteConnectionHolder(); + } + + @Override + public List findAll() { + List cajaList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from caja"); + ResultSet rs = ps.executeQuery(); + + cajaList = this.cajasFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return cajaList; + } + + @Override + public Caja findById(int id) { + Caja caja = null; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?"); + + ps.setInt(1, id); + + ResultSet rs = ps.executeQuery(); + + caja = this.cajasFromResultSet(rs).get(0); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return caja; + } + + @Override + public Caja findByFecha(LocalDate fecha) { + Caja caja = null; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?"); + + ps.setObject(1, fecha); + + ResultSet rs = ps.executeQuery(); + + List cajaList = this.cajasFromResultSet(rs); + + if(cajaList.size() > 0){ + caja = cajaList.get(0); + } + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return caja; + } + + @Override + public boolean insertCaja(Caja caja) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)"); + ps.setObject(1, caja.getFecha()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + caja.setId(rs.getInt(1)); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean updateCaja(Caja caja) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?"); + ps.setObject(1, caja.getFecha()); + ps.setInt(2, caja.getId()); + + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + + private List cajasFromResultSet(ResultSet rs) throws SQLException { + List cajaList = new ArrayList<>(); + while (rs.next()) { + Caja caja = new Caja(); + caja.setId(rs.getInt("id")); + caja.setFecha(rs.getObject("fecha", LocalDate.class)); + cajaList.add(caja); + } + return cajaList; + } +} diff --git a/src/main/java/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java b/src/main/java/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java index db9d85c..b99a36e 100644 --- a/src/main/java/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java +++ b/src/main/java/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.documentos; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO; @@ -37,10 +37,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlDocumentosDAO implements DocumentosDAO { - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlDocumentosDAO() { - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override diff --git a/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java b/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java new file mode 100644 index 0000000..479bf83 --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java @@ -0,0 +1,224 @@ +/* + * 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.documentos; + +import danielcortes.xyz.data.ConnectionHolder; +import danielcortes.xyz.data.MysqlConnectionHolder; +import danielcortes.xyz.models.caja.Caja; +import danielcortes.xyz.models.caja.CajaDAO; +import danielcortes.xyz.models.caja.MysqlCajaDAO; + +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 SQLiteDocumentosDAO implements DocumentosDAO{ + private ConnectionHolder connectionHolder; + + public SQLiteDocumentosDAO() { + this.connectionHolder = new MysqlConnectionHolder(); + } + + @Override + public List findAll() { + List documentosList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from documentos"); + ResultSet rs = ps.executeQuery(); + + documentosList = this.documentosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return documentosList; + } + + @Override + public Documentos findById(int id) { + Documentos documentos = null; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from documentos where id = ?"); + ps.setInt(1, id); + + ResultSet rs = ps.executeQuery(); + + List documentosList = this.documentosFromResultSet(rs); + if(documentosList.size() > 0){ + documentos = documentosList.get(0); + } + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return documentos; + } + + @Override + public Documentos findByCaja(Caja caja) { + Documentos documentos = null; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from documentos where caja_id = ?"); + ps.setInt(1, caja.getId()); + + ResultSet rs = ps.executeQuery(); + + List documentosList = this.documentosFromResultSet(rs); + if(documentosList.size() > 0){ + documentos = documentosList.get(0); + } + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return documentos; + } + + @Override + public boolean insertDocumentos(Documentos documentos) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (?,?,?)"); + ps.setInt(1, documentos.getCheques()); + ps.setInt(2, documentos.getTarjetas()); + ps.setInt(3, documentos.getCaja().getId()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + documentos.setId(rs.getInt(1)); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean insertDefaultDocumentos(Documentos documentos) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (0,0,?)"); + ps.setInt(1, documentos.getCaja().getId()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + documentos.setId(rs.getInt(1)); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean updateDocumentos(Documentos documentos) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("update documentos set tarjetas = ?, cheques = ?, caja_id = ? where id = ?"); + ps.setInt(1, documentos.getTarjetas()); + ps.setInt(2, documentos.getCheques()); + ps.setInt(3, documentos.getCaja().getId()); + ps.setInt(4, documentos.getId()); + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean deleteDocumentos(Documentos documentos) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("delete from documentos where id = ?"); + ps.setInt(1, documentos.getId()); + + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + private List documentosFromResultSet(ResultSet rs) throws SQLException { + List documentosList = new ArrayList<>(); + while (rs.next()) { + CajaDAO cajaDAO = new MysqlCajaDAO(); + Caja caja = cajaDAO.findById(rs.getInt("caja_id")); + + Documentos documentos = new Documentos(); + documentos.setCaja(caja); + documentos.setId(rs.getInt("id")); + documentos.setCheques(rs.getInt("cheques")); + documentos.setTarjetas(rs.getInt("tarjetas")); + + documentosList.add(documentos); + } + return documentosList; + } +} diff --git a/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java b/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java index e85f390..d1ce48d 100644 --- a/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java +++ b/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.efectivo; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO; @@ -37,10 +37,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlEfectivoDAO implements EfectivoDAO { - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlEfectivoDAO() { - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override diff --git a/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java b/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java new file mode 100644 index 0000000..f966876 --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java @@ -0,0 +1,245 @@ +/* + * 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.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 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 SQLiteEfectivoDAO implements EfectivoDAO{ + private ConnectionHolder connectionHolder; + + public SQLiteEfectivoDAO() { + this.connectionHolder = new SQLiteConnectionHolder(); + } + + @Override + public List findAll() { + List efectivoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from efectivos"); + ResultSet rs = ps.executeQuery(); + + efectivoList = this.efectivosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + return efectivoList; + } + + @Override + public Efectivo findById(int id) { + Efectivo efectivo = null; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?"); + ps.setInt(1, id); + ResultSet rs = ps.executeQuery(); + + efectivo = this.efectivosFromResultSet(rs).get(0); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + return efectivo; + } + + @Override + public Efectivo findByCaja(Caja caja) { + Efectivo efectivo = null; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?"); + ps.setInt(1, caja.getId()); + ResultSet rs = ps.executeQuery(); + + List efectivoList = this.efectivosFromResultSet(rs); + if (efectivoList.size() > 0) { + efectivo = efectivoList.get(0); + } + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + return efectivo; + } + + @Override + public boolean insertEfectivo(Efectivo efectivo) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)"); + ps.setInt(1, efectivo.getVeinteMil()); + ps.setInt(2, efectivo.getDiezMil()); + ps.setInt(3, efectivo.getCincoMil()); + ps.setInt(4, efectivo.getDosMil()); + ps.setInt(5, efectivo.getMil()); + ps.setInt(6, efectivo.getQuinientos()); + ps.setInt(7, efectivo.getCien()); + ps.setInt(8, efectivo.getCincuenta()); + ps.setInt(9, efectivo.getDiez()); + ps.setInt(10, efectivo.getCaja().getId()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + efectivo.setId(rs.getInt(1)); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean insertDefaultEfectivo(Efectivo efectivo) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)"); + ps.setInt(1, efectivo.getCaja().getId()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + efectivo.setId(rs.getInt(1)); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean updateEfectivo(Efectivo efectivo) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?"); + ps.setInt(1, efectivo.getVeinteMil()); + ps.setInt(2, efectivo.getDiezMil()); + ps.setInt(3, efectivo.getCincoMil()); + ps.setInt(4, efectivo.getDosMil()); + ps.setInt(5, efectivo.getMil()); + ps.setInt(6, efectivo.getQuinientos()); + ps.setInt(7, efectivo.getCien()); + ps.setInt(8, efectivo.getCincuenta()); + ps.setInt(9, efectivo.getDiez()); + ps.setInt(10, efectivo.getCaja().getId()); + ps.setInt(11, efectivo.getId()); + + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean deleteEfectivo(Efectivo efectivo) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?"); + ps.setInt(1, efectivo.getId()); + + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + private List efectivosFromResultSet(ResultSet rs) throws SQLException { + List efectivoList = new ArrayList<>(); + while (rs.next()) { + CajaDAO cajaDAO = new MysqlCajaDAO(); + Caja caja = cajaDAO.findById(rs.getInt("caja_id")); + + Efectivo efectivo = new Efectivo(); + efectivo.setCaja(caja); + efectivo.setId(rs.getInt("id")); + efectivo.setVeinteMil(rs.getInt("veinte_mil")); + efectivo.setDiezMil(rs.getInt("diez_mil")); + efectivo.setCincoMil(rs.getInt("cinco_mil")); + efectivo.setDosMil(rs.getInt("dos_mil")); + efectivo.setMil(rs.getInt("mil")); + efectivo.setQuinientos(rs.getInt("quinientos")); + efectivo.setCien(rs.getInt("cien")); + efectivo.setCincuenta(rs.getInt("cincuenta")); + efectivo.setDiez(rs.getInt("diez")); + + efectivoList.add(efectivo); + } + return efectivoList; + } +} diff --git a/src/main/java/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java b/src/main/java/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java index e6203c1..07df71a 100644 --- a/src/main/java/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.egreso; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO; @@ -40,10 +40,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlEgresoDAO implements EgresoDAO { - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlEgresoDAO(){ - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override @@ -65,6 +65,26 @@ public class MysqlEgresoDAO implements EgresoDAO { return egresoList; } + @Override + public List findById(int id) { + List egresoList = new ArrayList<>(); + try { + Connection conn = mysqlConnection.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?"); + ps.setInt(1,id); + ResultSet rs = ps.executeQuery(); + + egresoList = this.egresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return egresoList; + } + @Override public List findByCaja(Caja caja) { List egresoList = new ArrayList<>(); @@ -85,25 +105,6 @@ public class MysqlEgresoDAO implements EgresoDAO { return egresoList; } - @Override - public List findById(int id) { - List egresoList = new ArrayList<>(); - try { - Connection conn = mysqlConnection.getConnection(); - PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?"); - ps.setInt(1,id); - ResultSet rs = ps.executeQuery(); - - egresoList = this.egresosFromResultSet(rs); - - rs.close(); - ps.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - return egresoList; - } @Override public List findByNro(String nro) { diff --git a/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java b/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java new file mode 100644 index 0000000..d49948f --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java @@ -0,0 +1,267 @@ +/* + * 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.egreso; + +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.tipo_egreso.TipoEgreso; +import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO; + +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 SQLiteEgresoDAO implements EgresoDAO{ + private ConnectionHolder connectionHolder; + + public SQLiteEgresoDAO(){ + this.connectionHolder = new SQLiteConnectionHolder(); + } + + @Override + public List findAll() { + List egresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from egresos"); + ResultSet rs = ps.executeQuery(); + + egresoList = this.egresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return egresoList; + } + + @Override + public List findById(int id) { + List egresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?"); + ps.setInt(1,id); + ResultSet rs = ps.executeQuery(); + + egresoList = this.egresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return egresoList; + } + + @Override + public List findByCaja(Caja caja) { + List egresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from egresos where caja_id = ?"); + ps.setInt(1, caja.getId()); + ResultSet rs = ps.executeQuery(); + + egresoList = this.egresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return egresoList; + } + + @Override + public List findByNro(String nro) { + List egresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from egresos where nro = ?"); + ps.setString(1, nro); + ResultSet rs = ps.executeQuery(); + + egresoList = this.egresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return egresoList; + } + + @Override + public List findByTipoEgreso(TipoEgreso tipoEgreso) { + List egresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from egresos where tipo_egreso_id = ?"); + ps.setInt(1, tipoEgreso.getId()); + ResultSet rs = ps.executeQuery(); + + egresoList = this.egresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return egresoList; + } + + @Override + public boolean insertEgreso(Egreso egreso) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into egresos (nro, descripcion, valor, tipo_egreso_id, caja_id) values (?,?,?,?,?)"); + ps.setString(1,egreso.getNro()); + ps.setString(2,egreso.getDescripcion()); + ps.setInt(3,egreso.getValor()); + ps.setInt(4,egreso.getTipoEgreso().getId()); + ps.setInt(5, egreso.getCaja().getId()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + egreso.setId(rs.getInt(1)); + + rs.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean updateEgreso(Egreso egreso) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("update egresos set nro = ?, descripcion = ?, valor = ?, tipo_egreso_id = ?, caja_id = ? where id = ? "); + ps.setString(1,egreso.getNro()); + ps.setString(2,egreso.getDescripcion()); + ps.setInt(3,egreso.getValor()); + ps.setInt(4,egreso.getTipoEgreso().getId()); + ps.setInt(5, egreso.getCaja().getId()); + ps.setInt(6, egreso.getId()); + + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean deleteEgreso(Egreso egreso) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("delete from egresos where id = ? "); + ps.setInt(1, egreso.getId()); + + updates = ps.executeUpdate(); + + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public int getTotalEgreso(Caja caja) { + int total = 0; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select sum(valor) from egresos where caja_id = ?"); + ps.setInt(1, caja.getId()); + 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 egresosFromResultSet(ResultSet rs) throws SQLException { + ArrayList egresoList = new ArrayList<>(); + while(rs.next()){ + int tipoEgresoId = rs.getInt("tipo_egreso_id"); + TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO(); + TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0); + + int cajaId = rs.getInt("caja_id"); + CajaDAO cajaDAO = new MysqlCajaDAO(); + Caja caja = cajaDAO.findById(cajaId); + + Egreso egreso = new Egreso(); + + egreso.setId(rs.getInt("id")); + egreso.setNro(rs.getString("nro")); + egreso.setDescripcion(rs.getString("descripcion")); + egreso.setValor(rs.getInt("valor")); + egreso.setTipoEgreso(tipoEgreso); + egreso.setCaja(caja); + + egresoList.add(egreso); + } + return egresoList; + } +} diff --git a/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java b/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java index bdb40e3..193294f 100644 --- a/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.ingreso; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO; @@ -40,10 +40,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlIngresoDAO implements IngresoDAO{ - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlIngresoDAO(){ - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override diff --git a/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java b/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java new file mode 100644 index 0000000..3f076f6 --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java @@ -0,0 +1,244 @@ +/* + * 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.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.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 SQLiteIngresoDAO implements IngresoDAO{ + private ConnectionHolder connectionHolder; + + public SQLiteIngresoDAO(){ + this.connectionHolder = new SQLiteConnectionHolder(); + } + + @Override + public List findAll() { + List ingresosList = new ArrayList<>(); + try { + Connection conn = connectionHolder.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 findByCaja(Caja caja) { + List ingresosList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from ingresos where caja_id = ?"); + ps.setInt(1, caja.getId()); + ResultSet rs = ps.executeQuery(); + + ingresosList = this.ingresosFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return ingresosList; + } + + @Override + public List findById(int id) { + List ingresosList = new ArrayList<>(); + try { + Connection conn = connectionHolder.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 findByTipoIngreso(TipoIngreso tipoIngreso) { + List ingresosList = new ArrayList<>(); + try { + Connection conn = connectionHolder.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 = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?)"); + ps.setInt(1, ingreso.getValor()); + ps.setString(2, ingreso.getNroInicial()); + ps.setString(3, ingreso.getNroFinal()); + ps.setInt(4, ingreso.getTipoIngreso().getId()); + ps.setInt(5, ingreso.getCaja().getId()); + + updates = ps.executeUpdate(); + ps.close(); + + ps = conn.prepareStatement("select last_insert_rowid()"); + ResultSet rs = ps.executeQuery(); + rs.next(); + ingreso.setId(rs.getInt(1)); + + rs.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + return updates > 0; + } + + @Override + public boolean updateIngreso(Ingreso ingreso) { + int updates; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ? , nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?"); + ps.setInt(1,ingreso.getValor()); + ps.setString(2, ingreso.getNroInicial()); + ps.setString(3, ingreso.getNroFinal()); + ps.setInt(4, ingreso.getTipoIngreso().getId()); + ps.setInt(5, ingreso.getCaja().getId()); + ps.setInt(6, 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 = connectionHolder.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(Caja caja) { + int total = 0; + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select sum(valor) from ingresos where caja_id = ?"); + ps.setInt(1, caja.getId()); + 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 ingresosFromResultSet(ResultSet rs) throws SQLException { + ArrayList ingresosList = new ArrayList<>(); + while(rs.next()){ + int tipoIngresoId = rs.getInt("tipo_ingreso_id"); + TipoIngresoDAO tipoEgresoDAO = new MysqlTipoIngresoDAO(); + TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0); + + int cajaId = rs.getInt("caja_id"); + CajaDAO cajaDAO = new MysqlCajaDAO(); + Caja caja = cajaDAO.findById(cajaId); + + Ingreso ingreso = new Ingreso(); + + ingreso.setId(rs.getInt("id")); + ingreso.setValor(rs.getInt("valor")); + ingreso.setNroInicial(rs.getString("nro_inicial")); + ingreso.setNroFinal(rs.getString("nro_final")); + ingreso.setTipoIngreso(tipoIngreso); + ingreso.setCaja(caja); + + ingresosList.add(ingreso); + } + return ingresosList; + } +} diff --git a/src/main/java/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java b/src/main/java/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java index 397c4c4..311281b 100644 --- a/src/main/java/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.tipo_egreso; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import java.sql.Connection; import java.sql.PreparedStatement; @@ -34,10 +34,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlTipoEgresoDAO implements TipoEgresoDAO { - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlTipoEgresoDAO(){ - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override diff --git a/src/main/java/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java b/src/main/java/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java new file mode 100644 index 0000000..6785335 --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java @@ -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_egreso; + +import danielcortes.xyz.data.ConnectionHolder; +import danielcortes.xyz.data.SQLiteConnectionHolder; + +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 SQLiteTipoEgresoDAO implements TipoEgresoDAO{ + private ConnectionHolder connectionHolder; + + public SQLiteTipoEgresoDAO(){ + this.connectionHolder = new SQLiteConnectionHolder(); + } + + @Override + public List findAll() { + List tipoEgresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso"); + ResultSet rs = ps.executeQuery(); + + tipoEgresoList = this.TipoEgresoFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return tipoEgresoList; + } + + @Override + public List findById(int id) { + List tipoEgresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where id = ?"); + ps.setInt(1, id); + ResultSet rs = ps.executeQuery(); + + tipoEgresoList = this.TipoEgresoFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return tipoEgresoList; + } + + @Override + public List findByNombre(String nombre) { + List tipoEgresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.getConnection(); + PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where nombre = ?"); + ps.setString(1, nombre); + ResultSet rs = ps.executeQuery(); + + tipoEgresoList = this.TipoEgresoFromResultSet(rs); + + rs.close(); + ps.close(); + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return tipoEgresoList; + } + + @Override + public boolean insertTipoEgreso(TipoEgreso tipoEgreso) { + return false; + } + + @Override + public boolean updateTipoEgreso(TipoEgreso tipoEgreso) { + return false; + } + + @Override + public boolean deleteTipoEgreso(TipoEgreso tipoEgreso) { + return false; + } + + private List TipoEgresoFromResultSet(ResultSet rs) throws SQLException { + ArrayList tipoEgresoList = new ArrayList<>(); + while(rs.next()){ + TipoEgreso tipoEgreso = new TipoEgreso(); + tipoEgreso.setId(rs.getInt("id")); + tipoEgreso.setNombre(rs.getString("nombre")); + tipoEgresoList.add(tipoEgreso); + } + return tipoEgresoList; + } +} diff --git a/src/main/java/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java b/src/main/java/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java index d169cc3..d62f998 100644 --- a/src/main/java/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java @@ -24,7 +24,7 @@ package danielcortes.xyz.models.tipo_ingreso; -import danielcortes.xyz.data.MysqlConnection; +import danielcortes.xyz.data.MysqlConnectionHolder; import java.sql.Connection; import java.sql.PreparedStatement; @@ -34,10 +34,10 @@ import java.util.ArrayList; import java.util.List; public class MysqlTipoIngresoDAO implements TipoIngresoDAO{ - private MysqlConnection mysqlConnection; + private MysqlConnectionHolder mysqlConnection; public MysqlTipoIngresoDAO(){ - this.mysqlConnection = new MysqlConnection(); + this.mysqlConnection = new MysqlConnectionHolder(); } @Override diff --git a/src/main/java/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java b/src/main/java/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java new file mode 100644 index 0000000..c9cd5c7 --- /dev/null +++ b/src/main/java/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java @@ -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.ConnectionHolder; +import danielcortes.xyz.data.SQLiteConnectionHolder; + +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 SQLiteTipoIngresoDAO implements TipoIngresoDAO{ + private ConnectionHolder connectionHolder; + + public SQLiteTipoIngresoDAO(){ + this.connectionHolder = new SQLiteConnectionHolder(); + } + + @Override + public List findAll() { + List tiposIngresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.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 findById(int id) { + List tiposIngresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.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 findByNombre(String nombre) { + List tiposIngresoList = new ArrayList<>(); + try { + Connection conn = connectionHolder.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 tiposIngresoFromResultSet(ResultSet rs) throws SQLException { + ArrayList 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; + } +} diff --git a/src/main/java/danielcortes/xyz/views/ArqueoView.java b/src/main/java/danielcortes/xyz/views/ArqueoView.java index 0faf5ce..3c2bd81 100644 --- a/src/main/java/danielcortes/xyz/views/ArqueoView.java +++ b/src/main/java/danielcortes/xyz/views/ArqueoView.java @@ -273,14 +273,14 @@ public class ArqueoView { ingresosField.setText("0"); panel2.add(ingresosField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label7 = new JLabel(); - label7.setText("Debe Rendir"); - panel2.add(label7, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + label7.setText("Rendido"); + panel2.add(label7, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); arqueoField = new JTextField(); arqueoField.setEditable(false); Font arqueoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, arqueoField.getFont()); if (arqueoFieldFont != null) arqueoField.setFont(arqueoFieldFont); arqueoField.setText("0"); - panel2.add(arqueoField, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + panel2.add(arqueoField, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); ajusteField = new JTextField(); ajusteField.setEditable(false); Font ajusteFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, ajusteField.getFont()); @@ -293,13 +293,13 @@ public class ArqueoView { final JSeparator separator1 = new JSeparator(); panel2.add(separator1, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); final JLabel label9 = new JLabel(); - label9.setText("Rendido"); - panel2.add(label9, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + label9.setText("Debe Rendir"); + panel2.add(label9, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); rendidoField = new JTextField(); Font rendidoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, rendidoField.getFont()); if (rendidoFieldFont != null) rendidoField.setFont(rendidoFieldFont); rendidoField.setText("0"); - panel2.add(rendidoField, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + panel2.add(rendidoField, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JPanel panel3 = new JPanel(); panel3.setLayout(new GridLayoutManager(19, 2, new Insets(10, 10, 10, 10), -1, -1)); contentPanel.add(panel3, new GridConstraints(0, 0, 3, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));