?? op_buy.java
字號:
}
}
System.out.println("f2");
purchaselist = (Vector) session.getAttribute("shopcar");
if (purchaselist == null || purchaselist.size() < 0) {
return false;
}
String Content = request.getParameter("content");
if (Content == null) {
Content = "";
}
// System.out.print("f3");
Content = getGbk(Content);
String IP = request.getRemoteAddr();
String TotalPrice = request.getParameter("totalprice");
long timeInMillis = System.currentTimeMillis();
//System.out.println("f4");
sqlStr = "insert into orders (orderId,UserId,SubmitTime,ConsignmentTime,TotalPrice,content,IPAddress,IsPayoff,IsSales) values (";
orderId=""+timeInMillis;//以系統時間產生位移的訂單編號
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + userid + "',now(),now()+7,'";
sqlStr = sqlStr + TotalPrice + "','";
sqlStr = sqlStr + dataFormat.toSql(Content) + "','";
sqlStr = sqlStr + IP + "',1,1)";
// System.out.print(sqlStr);
//String setIdSql="udate orders set orderid=orderid+id where UserId = " + userid;
try {
stmt.execute(sqlStr);
//stmt.execute(setIdSql);
// sqlStr = "select max(id) from orders where UserId = " + userid;
// rs = stmt.executeQuery(sqlStr);
//long indentid = 0;
// while (rs.next()) {
// indentid = rs.getLong(1);
//}
//rs.close();
for (int i = 0; i < purchaselist.size(); i++) {
allorder iList = (allorder) purchaselist.elementAt(i);
sqlStr =
"insert into allorder (orderId,BookNo,Amount) values (";
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + iList.getBookNo() + "','";
sqlStr = sqlStr + iList.getAmount() + "')";
stmt.execute(sqlStr);
sqlStr = "update book set leav_number=leav_number - " +
iList.getAmount() + " where id = " + iList.getBookNo();
stmt.execute(sqlStr);
}
return true;
}
catch (SQLException e) {
System.out.print(e.getMessage());
return false;
}
}
/**
* 查詢指定用戶id的所有訂單
* @param userid
* @return
*/
public boolean getOrder(long userid) {
sqlStr = "select * from orders where userid = '" + userid +
"' order by id desc";
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
allorder = new Vector();
while (rs.next()) {
order ind = new order();
ind.setId(rs.getLong("id"));
ind.setOrderId(rs.getString("orderId"));
ind.setUserId(rs.getLong("userid"));
ind.setSubmitTime(rs.getString("submitTime"));
ind.setConsignmentTime(rs.getString("ConsignmentTime"));
ind.setTotalPrice(rs.getFloat("TotalPrice"));
ind.setContent(rs.getString("content"));
ind.setIPAddress(rs.getString("IpAddress"));
if (rs.getInt("IsPayoff") == 1)
ind.setIsPayoff(false);
else
ind.setIsPayoff(true);
if (rs.getInt("IsSales") == 1)
ind.setIsSales(false);
else
ind.setIsSales(true);
allorder.addElement(ind);
}
rs.close();
return true;
}
catch (SQLException e) {
return false;
}
}
/**
* 查詢指定訂單編號的訂單
* @param iid
* @return
*/
public boolean getSinggleOrder(String order_id) {
sqlStr = "select * from orders where orderId = '" + order_id +
"' ";
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
allorder = new Vector();
while (rs.next()) {
order ind = new order();
ind.setId(rs.getLong("id"));
ind.setOrderId(rs.getString("orderId"));
ind.setUserId(rs.getLong("userid"));
ind.setSubmitTime(rs.getString("submitTime"));
ind.setConsignmentTime(rs.getString("ConsignmentTime"));
ind.setTotalPrice(rs.getFloat("TotalPrice"));
ind.setContent(rs.getString("content"));
ind.setIPAddress(rs.getString("IpAddress"));
if (rs.getInt("IsPayoff") == 1)
ind.setIsPayoff(false);
else
ind.setIsPayoff(true);
if (rs.getInt("IsSales") == 1)
ind.setIsSales(false);
else
ind.setIsSales(true);
allorder.addElement(ind);
System.out.print("allorder:"+allorder.size());
}
rs.close();
return true;
}
catch (SQLException e) {
System.out.print(e.getMessage());
return false;
}
}
/**
* 查詢書店的所有訂單數據
* @return
*/
public boolean getOrder() {
sqlStr = "select count(*) from orders"; //取出記錄數
int rscount = pageSize;
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
ResultSet rs1 = stmt.executeQuery(sqlStr);
if (rs1.next())
recordCount = rs1.getInt(1);
rs1.close();
}
catch (SQLException e) {
return false;
}
//設定有多少pageCount
if (recordCount < 1)
pageCount = 0;
else
pageCount = (int) (recordCount - 1) / pageSize + 1;
//檢查查看的頁面數是否在范圍內
if (page < 1)
page = 1;
else if (page > pageCount)
page = pageCount;
rscount = (int) recordCount % pageSize; // 最后一頁記錄數
//sql為倒序取值
sqlStr = "select * from orders ";
if (page == 1) {
sqlStr = sqlStr + " order by Id desc";
}
else {
sqlStr = sqlStr + " order by Id desc limit "+(recordCount - pageSize * page) +","+ (recordCount - pageSize * (page - 1));
}
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
allorder = new Vector();
while (rs.next()) {
order ind = new order();
ind.setId(rs.getLong("id"));
ind.setOrderId(rs.getString("orderid"));
ind.setUserId(rs.getLong("userid"));
ind.setSubmitTime(rs.getString("submitTime"));
ind.setConsignmentTime(rs.getString("ConsignmentTime"));
ind.setTotalPrice(rs.getFloat("TotalPrice"));
ind.setContent(rs.getString("content"));
ind.setIPAddress(rs.getString("IpAddress"));
if (rs.getInt("IsPayoff") == 1)
ind.setIsPayoff(false);
else
ind.setIsPayoff(true);
if (rs.getInt("IsSales") == 1)
ind.setIsSales(false);
else
ind.setIsSales(true);
allorder.addElement(ind);
}
rs.close();
return true;
}
catch (SQLException e) {
System.out.println(e);
return false;
}
}
/**
* 獲得訂單列表
* @param nid
* @return
*/
public boolean getAllorder(String order_id) {
sqlStr = "select * from allorder where orderId = '" + order_id + "'";
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
order_list = new Vector();
while (rs.next()) {
allorder identlist = new allorder();
identlist.setId(rs.getLong("id"));
identlist.setOrderId(rs.getLong("orderId"));
identlist.setBookNo(rs.getLong("BookNo"));
identlist.setAmount(rs.getInt("Amount"));
order_list.addElement(identlist);
}
rs.close();
return true;
}
catch (SQLException e) {
System.out.print(e.getMessage());
return false;
}
}
/**
* 修改訂單,修改付款標志
* @param res
* @return
*/
public boolean update(HttpServletRequest res) {
request = res;
int payoff = 1;
int sales = 1;
//long orderId = 0;
try {
System.out.println("payoff:"+request.getParameter("payoff"));
payoff = Integer.parseInt(request.getParameter("payoff"));
sales = Integer.parseInt(request.getParameter("sales"));
orderId =request.getParameter("indentid");
sqlStr = "update orders set IsPayoff = '" + payoff + "',IsSales='" +
sales + "' where orderId =" + orderId;
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
System.out.print(sqlStr);
stmt.execute(sqlStr);
return true;
}
catch (Exception e) {
System.out.print(e.getMessage());
return false;
}
}
/**
* 刪除訂單
* @param id
* @return
*/
public boolean delete(long id) {
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
sqlStr = "delete from allorder where id =" + id;
stmt.execute(sqlStr);
sqlStr = "delete from orders where id= " + id;
stmt.execute(sqlStr);
return true;
}
catch (SQLException e) {
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -