Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
0.6.1-beta. Añadido soporte para la habilitación y deshabilitación de…
Browse files Browse the repository at this point in the history
… los dispositivos de forma sencilla.
  • Loading branch information
xman40100 committed May 7, 2019
1 parent db7b7fe commit 5284626
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
13 changes: 8 additions & 5 deletions src/techdomotica/java/forms/devices/DeviceHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
32 changes: 16 additions & 16 deletions src/techdomotica/objs/Ambiente.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))));
Expand Down Expand Up @@ -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;
Expand All @@ -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")));
Expand All @@ -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));
Expand All @@ -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)));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
7 changes: 1 addition & 6 deletions src/techdomotica/objs/Util.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 5284626

Please sign in to comment.