Agregadas clases para compatibilidad con sqlite
This commit is contained in:
9
caja.iml
9
caja.iml
@@ -11,10 +11,6 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.lgooddatepicker:LGoodDatePicker:10.3.1" level="project" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
@@ -24,5 +20,10 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.xerial:sqlite-jdbc:3.25.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.lgooddatepicker:LGoodDatePicker:10.3.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
24
conf
Normal file
24
conf
Normal file
@@ -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
|
||||
BIN
database.sqlite
Normal file
BIN
database.sqlite
Normal file
Binary file not shown.
120
database/sqlite.sql
Normal file
120
database/sqlite.sql
Normal file
@@ -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')
|
||||
|
||||
5
pom.xml
5
pom.xml
@@ -32,6 +32,11 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.25.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.lgooddatepicker</groupId>
|
||||
<artifactId>LGoodDatePicker</artifactId>
|
||||
|
||||
@@ -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);
|
||||
|
||||
31
src/main/java/danielcortes/xyz/data/ConnectionHolder.java
Normal file
31
src/main/java/danielcortes/xyz/data/ConnectionHolder.java
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
168
src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java
Normal file
168
src/main/java/danielcortes/xyz/models/caja/SQLiteCajaDAO.java
Normal file
@@ -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<Caja> findAll() {
|
||||
List<Caja> 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<Caja> 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<Caja> cajasFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Caja> 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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<Documentos> findAll() {
|
||||
List<Documentos> 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<Documentos> 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<Documentos> 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<Documentos> documentosFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Documentos> 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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<Efectivo> findAll() {
|
||||
List<Efectivo> 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<Efectivo> 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<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Efectivo> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<Egreso> findById(int id) {
|
||||
List<Egreso> 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<Egreso> findByCaja(Caja caja) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
@@ -85,25 +105,6 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
return egresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Egreso> findById(int id) {
|
||||
List<Egreso> 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<Egreso> findByNro(String nro) {
|
||||
|
||||
@@ -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<Egreso> findAll() {
|
||||
List<Egreso> 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<Egreso> findById(int id) {
|
||||
List<Egreso> 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<Egreso> findByCaja(Caja caja) {
|
||||
List<Egreso> 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<Egreso> findByNro(String nro) {
|
||||
List<Egreso> 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<Egreso> findByTipoEgreso(TipoEgreso tipoEgreso) {
|
||||
List<Egreso> 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<Egreso> egresosFromResultSet(ResultSet rs) throws SQLException {
|
||||
ArrayList<Egreso> 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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<Ingreso> findAll() {
|
||||
List<Ingreso> 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<Ingreso> findByCaja(Caja caja) {
|
||||
List<Ingreso> 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<Ingreso> findById(int id) {
|
||||
List<Ingreso> 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<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
|
||||
List<Ingreso> 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<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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<TipoEgreso> findAll() {
|
||||
List<TipoEgreso> 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<TipoEgreso> findById(int id) {
|
||||
List<TipoEgreso> 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<TipoEgreso> findByNombre(String nombre) {
|
||||
List<TipoEgreso> 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<TipoEgreso> TipoEgresoFromResultSet(ResultSet rs) throws SQLException {
|
||||
ArrayList<TipoEgreso> 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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<TipoIngreso> findAll() {
|
||||
List<TipoIngreso> 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<TipoIngreso> findById(int id) {
|
||||
List<TipoIngreso> 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<TipoIngreso> findByNombre(String nombre) {
|
||||
List<TipoIngreso> 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<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;
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user