Commit bc4556ff authored by melvinfonda's avatar melvinfonda
Browse files

Benerin field

parent 8e6aae4e
......@@ -3,18 +3,9 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
=======
<<<<<<< HEAD
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
=======
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/MainPage.java</file>
>>>>>>> 6ee3636e215ce68e8e6c04438b47fa355e8396b2
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/LoginPage.java</file>
</group>
</open-files>
</project-private>
......@@ -3,12 +3,9 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/TCPServer.java</file>
=======
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/TCPServer.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/MySQLAccess.java</file>
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/server/map.txt</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/MySQLAccess.java</file>
<file>file:/D:/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/TCPServer.java</file>
</group>
</open-files>
</project-private>
......@@ -24,7 +24,8 @@ public class MySQLAccess {
private Statement statement;
private PreparedStatement preparedStatement;
private ResultSet resultSet;
private boolean ada = true;
public MySQLAccess() {}
private void open() {
......@@ -246,6 +247,8 @@ public class MySQLAccess {
preparedStatement.executeUpdate();
response.put("status", "ok");
response.put("time", System.currentTimeMillis()/1000 + 5);
//barang menjadi ada lagi karena berpindah tempat
ada = true;
}
} else {
response.put("status", "error");
......@@ -275,28 +278,32 @@ public class MySQLAccess {
//System.out.println("nih map :"+TCPServer.map[curr_x][curr_y]);
String id_other = TCPServer.map[curr_x][curr_y];
if(id_other.equalsIgnoreCase(""))
{
response.put("status", "fail");
response.put("description", "Item has been taken");
}
else //item belom diambil
{
preparedStatement = connect.prepareStatement("SELECT * FROM items WHERE "+ "id_other=\"" + id_other + "\";");
resultSet = preparedStatement.executeQuery();
if(resultSet.first()) {
int item_taken = resultSet.getInt("id_item");
//masukkan ke inventory
preparedStatement = connect.prepareStatement("UPDATE inventory SET "
+ resultSet.getString("item_name").toLowerCase() + "="
+ resultSet.getString("item_name").toLowerCase() + "+1"
+ " WHERE id_user=" + userID + ";");
preparedStatement.executeUpdate();
//kembalikan response
response.put("status", "ok");
response.put("item", item_taken);
if(ada)
{
preparedStatement = connect.prepareStatement("UPDATE inventory SET "
+ resultSet.getString("item_name").toLowerCase() + "="
+ resultSet.getString("item_name").toLowerCase() + "+1"
+ " WHERE id_user=" + userID + ";");
preparedStatement.executeUpdate();
//kembalikan response
response.put("status", "ok");
response.put("item", item_taken);
ada = false;
}
else
{
response.put("status", "fail");
response.put("description", "Item has been taken");
}
}
}
}
} catch (SQLException e) {
response.put("status", "error");
......
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