diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java index 9a21b21..0cf12b7 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java @@ -108,7 +108,7 @@ public void onClick(View view) { btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null); }else{ - connection.sendRequest(connection.prepareUpdateDevice("updateDevice", ID, txtDevice.getText().toString(), txtDescription.getText().toString(), + connection.sendRequest(connection.prepareUpdateDevice("updateDevice",intent.getStringExtra("Device"), ID, txtDevice.getText().toString(), txtDescription.getText().toString(), Integer.parseInt(txtActions.getText().toString()))); txtDevice.setEnabled(false); diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java index 5651800..f51559f 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java @@ -190,11 +190,12 @@ public JSONObject prepareUpdateInteraction(String request, int updateId, String return jsonRequest; } - public JSONObject prepareUpdateDevice(String request, int updateId, String device, String desc, int actions){ + public JSONObject prepareUpdateDevice(String request, String deleteName, int updateId, String device, String desc, int actions){ try { this.jsonRequest = new JSONObject(); this.jsonRequest.put("header", "gazeboindustries09082004"); this.jsonRequest.put("request", request); + this.jsonRequest.put("deleteName", deleteName); this.jsonRequest.put("updateId", updateId); this.jsonRequest.put("device", device); this.jsonRequest.put("description", desc); diff --git a/Server/DataBase.py b/Server/DataBase.py index 2529788..09c9322 100644 --- a/Server/DataBase.py +++ b/Server/DataBase.py @@ -59,7 +59,7 @@ def updateProject(self, updateId, type, name): self.dataBaseConnector.commit() def updateDevice(self, updateId, name, desc, actions): - self.dataBaseCursor.execute(f"UPDATE Device SET DeviceName = '{name}', DeviceDescription = '{desc}', DeviceJson = '{actions}' WHERE DeviceID = '{updateId}' ") + self.dataBaseCursor.execute(f"UPDATE Device SET DeviceName = '{name}', DeviceDescription = '{desc}', DeviceActions = '{actions}' WHERE DeviceID = '{updateId}' ") self.dataBaseConnector.commit() diff --git a/Server/DevicesStatus.json b/Server/DevicesStatus.json index 9c0ceb3..61855b6 100644 --- a/Server/DevicesStatus.json +++ b/Server/DevicesStatus.json @@ -2,5 +2,9 @@ "Friday": { "action": 0, "url": ".com" + }, + "Interface": { + "action": 0, + "url": ".com" } } \ No newline at end of file diff --git a/Server/Server.py b/Server/Server.py index ab9c90d..19ea1fc 100644 --- a/Server/Server.py +++ b/Server/Server.py @@ -194,6 +194,19 @@ def handle(self): clientRequest['description'], clientRequest['actions']) + readFile = open('E:/Sexta-Feira-Mark_6/Server/DevicesStatus.json', 'r') + + newJson = json.load(readFile) + + print(newJson) + + del newJson[clientRequest['deleteName']] + + newJson[clientRequest['device']] = {'action': 0, 'url': '.com'} + + writeFile = open('E:/Sexta-Feira-Mark_6/Server/DevicesStatus.json', 'w') + json.dump(newJson, writeFile, indent=4) + self.request.send(json.dumps({'requestStatus': True}).encode()) elif clientRequest['request'] == 'updateHomeWork': diff --git a/Server/__pycache__/DataBase.cpython-36.pyc b/Server/__pycache__/DataBase.cpython-36.pyc index 1fadfd5..734ad1f 100644 Binary files a/Server/__pycache__/DataBase.cpython-36.pyc and b/Server/__pycache__/DataBase.cpython-36.pyc differ