-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsult.java
More file actions
283 lines (256 loc) · 10.5 KB
/
Copy pathConsult.java
File metadata and controls
283 lines (256 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Connection;
import Models.*;
import java.sql.SQLException;
import java.util.List;
import javax.swing.JOptionPane;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
/**
*
* @author AlexJPZ
*/
public class Consult extends Conexion {
private QueryRunner QR = new QueryRunner();
public List<Clientes> clientes() {
try {
numCliente = (List<Clientes>) QR.query(getConn(), "SELECT * FROM Clientes",
new BeanListHandler(Clientes.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return numCliente;
}
public void insert(String sql, Object[] data) {
try {
final QueryRunner qr = new QueryRunner(true);
qr.insert(getConn(), sql, new ColumnListHandler(), data);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
public List<Reportes_clientes> reportesClientes(int idCliente, int funcion) {
String where = "";
String condicion = " clientes.IdCliente = reportes_clientes.IdCliente ";
String campos = " clientes.IdCliente,clientes.ID,clientes.Nombre,clientes.Apellido,"
+ "reportes_clientes.IdRegistro,reportes_clientes.SaldoActual,"
+ "reportes_clientes.FechaActual,reportes_clientes.UltimoPago,reportes_clientes.FechaPago ";
if (funcion == 1) {
where = " WHERE reportes_clientes.IdCliente =" + idCliente;
}
try {
reportes_clientes = (List<Reportes_clientes>) QR.query(getConn(),
"SELECT " + campos + " FROM reportes_clientes Inner Join clientes ON "
+ condicion + where, new BeanListHandler(Reportes_clientes.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return reportes_clientes;
}
public void update(String sql, Object[] data) {
try {
final QueryRunner qr = new QueryRunner(true);
qr.update(getConn(), sql, data);
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
}
public void delete(String sql, int id) {
try {
final QueryRunner qr = new QueryRunner(true);
if (0 < id) {
qr.update(getConn(), sql, "%" + id + "%");
} else {
qr.update(getConn(), sql);
}
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
}
public List<Proveedores> proveedores() {
try {
numProveedore = (List<Proveedores>) QR.query(getConn(), "SELECT * FROM proveedores",
new BeanListHandler(Proveedores.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return numProveedore;
}
public List<Reportes_proveedores> reportesProveedor(int idProveedor) {
String condicion = " proveedores.IdProveedor = reportes_proveedores.IdProveedor ";
String campos = " proveedores.IdProveedor,proveedores.Proveedor,"
+ "reportes_proveedores.IdRegistro,reportes_proveedores.SaldoActual,"
+ "reportes_proveedores.FechaActual,reportes_proveedores.UltimoPago,"
+ "reportes_proveedores.FechaPago ";
try {
reportes_proveedores = (List<Reportes_proveedores>) QR.query(getConn(),
"SELECT " + campos + " FROM reportes_proveedores Inner Join proveedores ON "
+ condicion + " WHERE reportes_proveedores.IdProveedor ="
+ idProveedor, new BeanListHandler(Reportes_proveedores.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return reportes_proveedores;
}
public List<Usuarios> usuarios() {
try {
listUsuario = (List<Usuarios>) QR.query(getConn(), "SELECT * FROM usuarios",
new BeanListHandler(Usuarios.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return listUsuario;
}
public List<Cajas> cajas() {
try {
listCaja = (List<Cajas>) QR.query(getConn(), "SELECT * FROM cajas",
new BeanListHandler(Cajas.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return listCaja;
}
public List<Departamentos> departamentos() {
try {
departamento = (List<Departamentos>) QR.query(getConn(), "SELECT * FROM departamentos",
new BeanListHandler(Departamentos.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return departamento;
}
public List<Categorias> categorias() {
try {
categorias = (List<Categorias>) QR.query(getConn(), "SELECT * FROM categorias",
new BeanListHandler(Categorias.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return categorias;
}
public List<Tempo_compras> tempoCompras() {
try {
numTempoCompras = (List<Tempo_compras>) QR.query(getConn(), "SELECT * FROM tempo_compras",
new BeanListHandler(Tempo_compras.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return numTempoCompras;
}
public List<Reportes_proveedores> reportesProveedores() {
String condicion = " proveedores.IdProveedor = reportes_proveedores.IdProveedor ";
String campos = " proveedores.IdProveedor,proveedores.Proveedor,proveedores.Telefono,"
+ "proveedores.Email,reportes_proveedores.IdRegistro,reportes_proveedores.SaldoActual ";
try {
reportes_proveedores = (List<Reportes_proveedores>) QR.query(getConn(),
"SELECT " + campos + " FROM reportes_proveedores Inner Join proveedores ON "
+ condicion, new BeanListHandler(Reportes_proveedores.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return reportes_proveedores;
}
public List<Cajas_ingresos> cajasIngresos() {
try {
cajasIngresos = (List<Cajas_ingresos>) QR.query(getConn(), "SELECT * FROM cajas_ingresos",
new BeanListHandler(Cajas_ingresos.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return cajasIngresos;
}
public List<Compras> compras() {
try {
compras = (List<Compras>) QR.query(getConn(), "SELECT * FROM compras",
new BeanListHandler(Compras.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return compras;
}
public List<Tempo_productos> tempoProductos() {
String condicion = " tempo_productos.IdCompra = compras.IdCompra ";
String campos = " tempo_productos.IdCompra,compras.Producto,compras.Cantidad,compras.Precio,"
+ "compras.Importe,compras.Proveedor,compras.Fecha,compras.Codigo ";
try {
tempo_productos = (List<Tempo_productos>) QR.query(getConn(),
"SELECT " + campos + " FROM tempo_productos Inner Join compras ON "
+ condicion, new BeanListHandler(Tempo_productos.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return tempo_productos;
}
public List<Productos> productos() {
try {
productos = (List<Productos>) QR.query(getConn(), "SELECT * FROM productos",
new BeanListHandler(Productos.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return productos;
}
public List<Bodega> bodega() {
try {
bodega = (List<Bodega>) QR.query(getConn(), "SELECT * FROM bodega",
new BeanListHandler(Bodega.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return bodega;
}
public List<Tempo_ventas> TempoVentas() {
try {
tempoVentas = (List<Tempo_ventas>) QR.query(getConn(), "SELECT * FROM tempo_ventas",
new BeanListHandler(Tempo_ventas.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return tempoVentas;
}
public List<Roles> roles() {
try {
roles = (List<Roles>) QR.query(getConn(), "SELECT * FROM roles",
new BeanListHandler(Roles.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return roles;
}
public List<Cajas_registros> cajas_registros() {
try {
cajas_registros = (List<Cajas_registros>) QR.query(getConn(), "SELECT * FROM cajas_registros",
new BeanListHandler(Cajas_registros.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return cajas_registros;
}
public List<Productos> getBodega() {
String condicion = " bodega.Codigo = productos.Codigo ";
String campos = " bodega.Id,productos.Codigo,productos.Producto,bodega.Existencia,"
+ "bodega.Fecha ";
try {
productos = (List<Productos>) QR.query(getConn(),
"SELECT " + campos + " FROM bodega Inner Join productos ON "
+ condicion, new BeanListHandler(Productos.class));
} catch (SQLException ex) {
System.out.println("Error : " + ex);
}
return productos;
}
public List<Ventas> ventas() {
try {
ventas = (List<Ventas>) QR.query(getConn(), "SELECT * FROM ventas",
new BeanListHandler(Ventas.class));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error : " + ex);
}
return ventas;
}
}