Commit e4457f5f authored by Stephen's avatar Stephen
Browse files

Fixed offer item

parent 949adbb1
......@@ -2121,19 +2121,27 @@ public class MainPage extends javax.swing.JFrame {
// TODO add your handling code here:
try {
System.out.println((Integer) OfferedAmount.getValue());
JSONObject response = client.offer(client.token, OfferedItemId,(Integer) OfferedAmount.getValue(), DemandedItemId,(Integer) DemandedAmount.getValue());
if(response.get("status").equals("ok")) {
showMessage("Offer was made");
loadInventory();
prepareItemToOffer();
}
else if(response.get("status").equals("fail")) {
showMessage(response.getString("description"));
}
else {
showMessage(response.getString("status"));
if(OfferedItemId!=-1 && DemandedItemId!=-1) {
if(((Integer) OfferedAmount.getValue() >= 0) && ((Integer) DemandedAmount.getValue() >=0)) {
JSONObject response = client.offer(client.token, OfferedItemId,(Integer) OfferedAmount.getValue(), DemandedItemId,(Integer) DemandedAmount.getValue());
if(response.get("status").equals("ok")) {
showMessage("Offer was made");
loadInventory();
prepareItemToOffer();
}
else if(response.get("status").equals("fail")) {
showMessage(response.getString("description"));
}
else {
showMessage(response.getString("status"));
}
resetOffer();
} else {
showMessage("Item quantity must be above zero");
}
} else {
showMessage("Offered Item & Demanded Item must be filled");
}
resetOffer();
}
catch (Exception e) {
e.printStackTrace();
......
......@@ -325,7 +325,7 @@ public class TCPServer implements Runnable {
// do nothing
} else if(server.ipAddress.equalsIgnoreCase(thisIP) && server.port==serverPort) {
// do nothing
} else if(server.ipAddress.equalsIgnoreCase("167.205.32.46")){ // Masih cuma pake kakaknya punya
} else{ // Masih cuma pake kakaknya punya
System.out.println("Searching offer from : " + server.ipAddress + ":" + server.port);
JSONObject tempRequest = new JSONObject();
tempRequest.put("method", "findoffer");
......@@ -363,6 +363,7 @@ public class TCPServer implements Runnable {
tempsocket.close();
} catch(Exception e) {
e.printStackTrace();
System.out.println("Cannot connect to " + server.ipAddress + ":" + server.port);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment