diff --git a/src/techdomotica/java/forms/devices/DeviceHistory.java b/src/techdomotica/java/forms/devices/DeviceHistory.java index 4f02351..fdceb88 100644 --- a/src/techdomotica/java/forms/devices/DeviceHistory.java +++ b/src/techdomotica/java/forms/devices/DeviceHistory.java @@ -101,17 +101,19 @@ private void checkTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI public void loadTable() { DefaultTableModel model = new DefaultTableModel(); + model.addColumn("#"); model.addColumn("Modelo"); model.addColumn("Marca"); model.addColumn("Gasto energético"); + model.addColumn("Tiempo de vida (%)"); String query = ""; if(checkTable.isSelected()) { model.addColumn("Estado"); - query = "SELECT id_componente, nom_componente, marca, uso, gasto_energetico, habilitado FROM componente WHERE habilitado = 1;"; - } - else { query = "SELECT id_componente, nom_componente, marca, uso, gasto_energetico, habilitado FROM componente WHERE 1;"; } + else { + query = "SELECT id_componente, nom_componente, marca, uso, gasto_energetico, habilitado FROM componente WHERE habilitado = 1;"; + } if(conx.executeRS(query)) { tableDevices.getTableHeader().setReorderingAllowed(false); devices.clear(); @@ -122,11 +124,12 @@ public void loadTable() { devices.add(user); Object[] fila; if(checkTable.isSelected()) { - Object[] filaCopy = {conx.getResultSetRow("id_componente"), conx.getResultSetRow("nom_componente"), conx.getResultSetRow("marca"), conx.getResultSetRow("gasto_energetico") + " Watts", (Integer.parseInt(String.valueOf(conx.getResultSetRow("habilitado"))) == 1 ? "Habilitado" : "Deshabilitado") }; + String desh = (Integer.parseInt(String.valueOf(conx.getResultSetRow("habilitado"))) == 1 ? "Habilitado" : "Deshabilitado"); + Object[] filaCopy = {conx.getResultSetRow("id_componente"), conx.getResultSetRow("nom_componente"), conx.getResultSetRow("marca"), conx.getResultSetRow("gasto_energetico") + " Watts", conx.getResultSetRow("uso") + "%", desh}; fila = Arrays.copyOf(filaCopy, filaCopy.length); } else { - Object[] filaCopy = {conx.getResultSetRow("id_componente"), conx.getResultSetRow("nom_componente"), conx.getResultSetRow("marca"), conx.getResultSetRow("gasto_energetico") + " Watts"}; + Object[] filaCopy = {conx.getResultSetRow("id_componente"), conx.getResultSetRow("nom_componente"), conx.getResultSetRow("marca"), conx.getResultSetRow("gasto_energetico") + " Watts", conx.getResultSetRow("uso") + "%"}; fila = Arrays.copyOf(filaCopy, filaCopy.length); } model.addRow(fila); diff --git a/src/techdomotica/objs/Ambiente.java b/src/techdomotica/objs/Ambiente.java index 4f4c2a1..0d7552b 100644 --- a/src/techdomotica/objs/Ambiente.java +++ b/src/techdomotica/objs/Ambiente.java @@ -73,7 +73,7 @@ public void createACondicionado(int index, String model, String mark, double val } public void loadACondicionados() { - connection.executeRS("SELECT * FROM acondicionado INNER JOIN componente ON acondicionado.id_componente = componente.id_componente WHERE 1 LIMIT 2;"); + connection.executeRS("SELECT * FROM acondicionado INNER JOIN componente ON acondicionado.id_componente = componente.id_componente WHERE habilitado = 1 LIMIT 2;"); int i = 0; while(connection.nextRow()) { createACondicionado(i, String.valueOf(connection.getResultSetRow("nom_componente")), String.valueOf(connection.getResultSetRow("marca")), Double.parseDouble(String.valueOf(connection.getResultSetRow("uso")))); @@ -110,7 +110,7 @@ public void createSensor(int index, String model, String mark, double value) { } public void loadSensores() { - connection.executeRS("SELECT * FROM sensor INNER JOIN componente ON sensor.id_componente = componente.id_componente WHERE 1 LIMIT 2;"); + connection.executeRS("SELECT * FROM sensor INNER JOIN componente ON sensor.id_componente = componente.id_componente WHERE habilitado = 1 LIMIT 2;"); int i = 0; while(connection.nextRow()) { if(String.valueOf(connection.getResultSetRow("tiposensor")).equalsIgnoreCase("puerta")) i = 0; @@ -126,7 +126,7 @@ public void loadSensores() { } public void loadProyector() { - if(connection.executeRSOne("SELECT * FROM tv INNER JOIN componente ON tv.id_componente = componente.id_componente WHERE 1 LIMIT 1;")) { + if(connection.executeRSOne("SELECT * FROM tv INNER JOIN componente ON tv.id_componente = componente.id_componente WHERE habilitado = 1 LIMIT 1;")) { proyector = new Televisor(String.valueOf(connection.getResultSetRow("nom_componente")), String.valueOf(connection.getResultSetRow("marca")), Double.parseDouble(String.valueOf(connection.getResultSetRow("uso")))); proyector.setDeviceID(Integer.parseInt(String.valueOf(connection.getResultSetRow("id_componente")))); proyector.setCalidadTV(String.valueOf(connection.getResultSetRow("calidadtv"))); @@ -146,7 +146,7 @@ public void createCamara(int index, String model, String mark, double value) { } public void insertACIntoDB(String model, String mark) { - connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 25, 0);", model, mark)); + connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 25, 0, 1);", model, mark)); if(connection.executeRSOne(String.format("SELECT id_componente FROM componente ORDER BY id_componente DESC LIMIT 1;"))) { int id_componente = Integer.parseInt(String.valueOf(connection.getResultSetRow("id_componente"))); connection.execute(String.format("INSERT INTO acondicionado VALUES (null, %d, 23);", id_componente)); @@ -156,7 +156,7 @@ public void insertACIntoDB(String model, String mark) { } public void insertCamaraIntoDB(int index, String model, String mark) { - connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 5, 1);", model, mark)); + connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 5, 1, 1);", model, mark)); if(connection.executeRSOne(String.format("SELECT id_componente FROM componente ORDER BY id_componente DESC LIMIT 1;"))) { int id_componente = Integer.parseInt(String.valueOf(connection.getResultSetRow("id_componente"))); connection.execute(String.format("INSERT INTO camara VALUES (null, %d, '1080p', %d);", id_componente, (index + 1))); @@ -166,7 +166,7 @@ public void insertCamaraIntoDB(int index, String model, String mark) { } public void insertSensorIntoDB(String tipo, String model, String mark) { - connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 5, 1);", model, mark)); + connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 5, 1, 1);", model, mark)); if(connection.executeRSOne(String.format("SELECT id_componente FROM componente ORDER BY id_componente DESC LIMIT 1;"))) { int id_componente = Integer.parseInt(String.valueOf(connection.getResultSetRow("id_componente"))); if(tipo.equalsIgnoreCase("puerta")) connection.execute(String.format("INSERT INTO sensor VALUES (null, %d, 'puerta', 'puerta');", id_componente)); @@ -177,7 +177,7 @@ public void insertSensorIntoDB(String tipo, String model, String mark) { } public void insertTVIntoDB(String model, String mark) { - connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 5, 1);", model, mark)); + connection.execute(String.format("INSERT INTO componente VALUES(null, 1, '%s', '%s', 100, 5, 1, 1);", model, mark)); if(connection.executeRSOne(String.format("SELECT id_componente FROM componente ORDER BY id_componente DESC LIMIT 1;"))) { int id_componente = Integer.parseInt(String.valueOf(connection.getResultSetRow("id_componente"))); connection.execute(String.format("INSERT INTO tv VALUES (null, %d, 'Full HD', '1080p');", id_componente)); @@ -195,7 +195,7 @@ public void createTelevisor(String model, String mark, double value) { } public void loadCamaras() { - connection.executeRS("SELECT * FROM camara INNER JOIN componente ON camara.id_componente = componente.id_componente WHERE 1 LIMIT 4;"); + connection.executeRS("SELECT * FROM camara INNER JOIN componente ON camara.id_componente = componente.id_componente WHERE habilitado = 1 LIMIT 4;"); int i = 0; while(connection.nextRow()) { i = Integer.parseInt(String.valueOf(connection.getResultSetRow("ubicacion"))) - 1; @@ -224,8 +224,8 @@ public ACondicionado[] getACondicionadoAsArray() { } public void destroyACondicionado(int index) { - connection.execute(String.format("DELETE FROM componente WHERE id_componente = %d;", proyector.getDeviceID())); - connection.execute(String.format("DELETE FROM acondicionado WHERE id_componente = %d;", proyector.getDeviceID())); + connection.execute(String.format("UPDATE componente SET habilitado = 0 WHERE id_componente = %d;", acondicionado[index].getDeviceID())); + //connection.execute(String.format("DELETE FROM acondicionado WHERE id_componente = %d;", proyector.getDeviceID())); acondicionado[index] = null; } @@ -238,8 +238,8 @@ public Camara[] getCamaraAsArray() { } public void destroyCamara(int index) { - connection.execute(String.format("DELETE FROM componente WHERE id_componente = %d;", proyector.getDeviceID())); - connection.execute(String.format("DELETE FROM camara WHERE id_componente = %d;", proyector.getDeviceID())); + connection.execute(String.format("UPDATE componente SET habilitado = 0 WHERE id_componente = %d;", camaras[index].getDeviceID())); + //connection.execute(String.format("DELETE FROM camara WHERE id_componente = %d;", proyector.getDeviceID())); camaras[index] = null; } @@ -256,8 +256,8 @@ public Sensor[] getSensorAsArray() { } public void destroySensor(int index) { - connection.execute(String.format("DELETE FROM componente WHERE id_componente = %d;", proyector.getDeviceID())); - connection.execute(String.format("DELETE FROM sensor WHERE id_componente = %d;", proyector.getDeviceID())); + connection.execute(String.format("UPDATE componente SET habilitado = 0 WHERE id_componente = %d;", sensores[index].getDeviceID())); + //connection.execute(String.format("DELETE FROM sensor WHERE id_componente = %d;", proyector.getDeviceID())); sensores[index] = null; } @@ -266,8 +266,8 @@ public Televisor getTelevisor() { } public void destroyTelevisor() { - connection.execute(String.format("DELETE FROM componente WHERE id_componente = %d;", proyector.getDeviceID())); - connection.execute(String.format("DELETE FROM tv WHERE id_componente = %d;", proyector.getDeviceID())); + connection.execute(String.format("UPDATE componente SET habilitado = 0 WHERE id_componente = %d;", proyector.getDeviceID())); + //connection.execute(String.format("DELETE FROM tv WHERE id_componente = %d;", proyector.getDeviceID())); proyector = null; } diff --git a/src/techdomotica/objs/Util.java b/src/techdomotica/objs/Util.java index b758c4a..b92abd1 100644 --- a/src/techdomotica/objs/Util.java +++ b/src/techdomotica/objs/Util.java @@ -1,16 +1,11 @@ package techdomotica.objs; - -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; - /** * Clase de funciones o métodos útiles. No es necesario instanciar esta clase, es una clase estática. * @author Andres */ public class Util { - public static final String VERSION = "0.6-alpha"; + public static final String VERSION = "0.6.1-beta"; /** * Chequea si el String está vacío.