Skip to content

Commit

Permalink
final ver
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryrdyyrd committed Nov 28, 2015
1 parent 55eb074 commit 447cf7f
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 66 deletions.
23 changes: 16 additions & 7 deletions src/java/sos/bean/OrderBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ public class OrderBean implements Serializable {

private String no, type, status;
private double amount;
private Date time;
private Date orderDate, delivDate;
private int clientId;

public OrderBean() {
}

public OrderBean(String no, double amount, Date time, String type, String status, int clientId) {
public OrderBean(String no, double amount, Date orderDate, Date delivDate, String type, String status, int clientId) {
this.no = no;
this.amount = amount;
this.time = time;
this.orderDate = orderDate;
this.delivDate = delivDate;
this.type = type;
this.status = status;
this.clientId = clientId;
Expand Down Expand Up @@ -53,13 +54,21 @@ public double getAmount() {
public void setAmount(double amount) {
this.amount = amount;
}

public Date getOrderDate() {
return orderDate;
}

public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}

public Date getTime() {
return time;
public Date getDelivDate() {
return delivDate;
}

public void setTime(Date time) {
this.time = time;
public void setDelivDate(Date delivDate) {
this.delivDate = delivDate;
}

public int getClientId() {
Expand Down
9 changes: 4 additions & 5 deletions src/java/sos/db/ItemDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public int addItem(String name, String desc, String brand, String catId, float p
id = rs.getInt(1);
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return id;
}
Expand All @@ -47,7 +47,7 @@ public boolean removeItem(String prodNo) {
success = true;
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return success;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public ArrayList<ItemBean> getItemsByAttr(String table, String attr, String op,
products.add(itemFronResult(table, result));
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return products;
}
Expand Down Expand Up @@ -145,7 +145,6 @@ public ArrayList<CategoryBean> getCategoriesByAttr(String attr, String op, Strin
statement.close();
} catch (Exception e) {
e.printStackTrace();
/* Who cares? */
}
return categories;
}
Expand Down Expand Up @@ -188,7 +187,7 @@ public boolean update(ItemBean item) {
statement.close();
return true;
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return false;
}
Expand Down
57 changes: 30 additions & 27 deletions src/java/sos/db/OrderDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,58 @@ public boolean addCreditRequest(int clientId, int bonus, long time) {
success = true;
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return success;
}

public int addOrder(double amount, Date time, String ordType, String status, int clientId) {
public int addOrder(double amount, Date orderDate, Date delivDate, String orderType, String status, int clientId) {
PreparedStatement statement = null;
int id = -1;
try {
statement = getConnection().prepareStatement("INSERT INTO ORDERS (AMOUNT,TIME,ORDTYPE,STATUS,CLIENTID) VALUES (?,?,?,?,?)",
statement = getConnection().prepareStatement("INSERT INTO ORDERS (AMOUNT,ORDERTIME,COLLECTTIME,ORDERTYPE,STATUS,CLIENTID) VALUES (?,?,?,?,?,?)",
Statement.RETURN_GENERATED_KEYS);
statement.setDouble(1, amount);
statement.setLong(2, time.getTime());
statement.setString(3, ordType);
statement.setString(4, status);
statement.setInt(5, clientId);
statement.setLong(2, orderDate.getTime());
statement.setLong(3, delivDate.getTime());
statement.setString(4, orderType);
statement.setString(5, status);
statement.setInt(6, clientId);
ResultSet rs;
if (statement.executeUpdate() >= 1)
if ((rs = statement.getGeneratedKeys()).next())
id = rs.getInt(1);
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return id;
}

public boolean addProductOrder(int quantity, String prodNo, int ordNo) {
public boolean addProductOrder(int quantity, String prodNo, int orderNo) {
PreparedStatement statement = null;
boolean success = false;
try {
statement = getConnection().prepareStatement("INSERT INTO PRODUCTS_ORDERS (QUANTITY,PRODNO,ORDNO) VALUES (?,?,?)");
statement = getConnection().prepareStatement("INSERT INTO PRODUCTS_ORDERS (QUANTITY,PRODNO,ORDERNO) VALUES (?,?,?)");
statement.setInt(1, quantity);
statement.setString(2, prodNo);
statement.setInt(3, ordNo);
statement.setInt(3, orderNo);
if (statement.executeUpdate() >= 1)
success = true;
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return success;
}

private OrderBean orderFronResult (ResultSet result) throws Exception {
OrderBean order = new OrderBean();
order.setNo(result.getString("OrdNo"));
order.setNo(result.getString("OrderNo"));
order.setAmount(result.getDouble("Amount"));
order.setTime(new Date(result.getLong("Time")));
order.setType(result.getString("OrdType"));
order.setOrderDate(new Date(result.getLong("OrderTime")));
order.setDelivDate(new Date(result.getLong("CollectTime")));
order.setType(result.getString("OrderType"));
order.setStatus(result.getString("Status"));
order.setClientId(result.getInt("ClientID"));
return order;
Expand All @@ -97,21 +99,21 @@ public ArrayList<OrderBean> getOrdersByAttr(String attr, String op, String val,
orders.add(orderFronResult(result));
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return orders;
}

public ArrayList<OrderBean> getOrder10LastClient(int clientID) {
return getOrdersByAttr("CLIENTID", "=", clientID + " order by time desc", 10);
return getOrdersByAttr("CLIENTID", "=", clientID + " ORDER BY ORDERTIME DESC", 10);
}

public ArrayList<OrderBean> getAllOrders() {
return getOrdersByAttr("STATUS", "LIKE", "'%'");
}

public OrderBean getOrder(String no) {
ArrayList<OrderBean> result = getOrdersByAttr("ORDNO", "=", no);
ArrayList<OrderBean> result = getOrdersByAttr("ORDERNO", "=", no);
return result.size() == 1 ? result.get(0) : null;
}

Expand All @@ -125,7 +127,7 @@ public boolean removeCreditRequest(String id) {
success = true;
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return success;
}
Expand All @@ -146,7 +148,7 @@ public ArrayList<BonusRequestBean> getCreditRequestsByAttr(String attr, String o
}
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return requests;
}
Expand All @@ -163,19 +165,20 @@ public BonusRequestBean getCreditRequest(String id) {
public boolean update(OrderBean order) {
PreparedStatement statement = null;
try {
String preQueryStatement = "UPDATE ORDERS SET AMOUNT=?,TIME=?,STATUS=?,CLIENTID=?,ORDTYPE=? WHERE ORDNO = ?";
String preQueryStatement = "UPDATE ORDERS SET AMOUNT=?,ORDERTIME=?,COLLECTTIME=?,STATUS=?,CLIENTID=?,ORDERTYPE=? WHERE ORDERNO = ?";
statement = getConnection().prepareStatement(preQueryStatement);
statement.setDouble(1, order.getAmount());
statement.setLong(2, order.getTime().getTime());
statement.setString(3, order.getStatus());
statement.setInt(4, order.getClientId());
statement.setString(5, order.getType());
statement.setString(6, order.getNo());
statement.setLong(2, order.getOrderDate().getTime());
statement.setLong(3, order.getDelivDate().getTime());
statement.setString(4, order.getStatus());
statement.setInt(5, order.getClientId());
statement.setString(6, order.getType());
statement.setString(7, order.getNo());
statement.executeUpdate();
statement.close();
return true;
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions src/java/sos/db/UserDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public boolean addClient(String name, int phone, String address) {
statement.close();
} catch (Exception e) {
e.printStackTrace();
/* Who cares? */
}
return success;
}
Expand Down Expand Up @@ -69,7 +68,7 @@ public IUserBean login(String username, String password) {
}
}
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return null;
}
Expand All @@ -84,7 +83,7 @@ public ArrayList<ClientBean> getClientsByAttr(String attr, String op, String val
clients.add(clientFromResult(result));
statement.close();
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return clients;
}
Expand All @@ -110,7 +109,7 @@ public boolean update(ClientBean client) {
statement.close();
return true;
} catch (Exception e) {
/* Who cares? */
e.printStackTrace();
}
return false;
}
Expand Down
24 changes: 24 additions & 0 deletions src/java/sos/ejb/ViewCountSessionBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sos.ejb;

import java.util.LinkedHashMap;
import javax.ejb.Remote;
import javax.ejb.Stateful;

@Stateful
@Remote(ViewCounter.class)
public class ViewCountSessionBean implements ViewCounter {

private LinkedHashMap<String, Integer> counts = new LinkedHashMap<>();

public void plusOne(String itemNo) {
if (counts.get(itemNo) == null)
counts.put(itemNo, 1);
else
counts.put(itemNo, counts.get(itemNo) + 1);
}

public int getCount(String itemNo) {
return counts.get(itemNo);
}

}
9 changes: 9 additions & 0 deletions src/java/sos/ejb/ViewCounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sos.ejb;

public interface ViewCounter {

void plusOne(String itemNo);

int getCount(String itemNo);

}
Loading

0 comments on commit 447cf7f

Please sign in to comment.