📄 op_buy.java~127~
字号:
catch (NumberFormatException e)
{
// System.out.print(e.getMessage());
return false;
}
}
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");
//float payPrice=(Float.parseFloat(TotalPrice))*opUser.getUserRate(Userid);
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 + "',GETDATE(),GETDATE()+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
{
DataBase db = new DataBase();
db.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);
//}
//close();
for (int i = 0; i < purchaselist.size(); i++)
{
allorder iList = (allorder) purchaselist.elementAt(i);
sqlStr =
"insert into allorder (orderId,BookNo,Amount, SoldPrice) values (";
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + iList.getBookNo() + "','";
sqlStr = sqlStr + iList.getAmount() + "',";
sqlStr = sqlStr + iList.getSoldPrice() + "')";
db.stmt.execute(sqlStr);
sqlStr = "UPDATE book set leav_number=leav_number - " +
iList.getAmount() + " WHERE id = " + iList.getBookNo();
db.stmt.execute(sqlStr);
}
db.finalize();
return true;
}
catch (SQLException e)
{
System.out.print(e.getMessage());
return false;
}
}
/**
* 查询指定用户id的所有订单
* @param userid
* @return
*/
public boolean getOrder(long userid)
{
sqlStr = "SELECT id, orderId, userid, submitTime, ConsignmentTime," ;
sqlStr += " TotalPrice, content, IpAddress, IsPayoff, IsSales ";
sqlStr += " FROM orders WHERE userid = " + userid;
sqlStr += " ORDER BY id DESC";
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
rs = db.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();
db.finalize();
return true;
}
catch (SQLException e)
{
return false;
}
}
/**
* 查询指定订单编号的订单
* @param iid
* @return
*/
public boolean getSinggleOrder(String order_id)
{
sqlStr = "SELECT id, orderId, userid, submitTime, ConsignmentTime, ";
sqlStr += " TotalPrice, content, IpAddress, IsPayoff, IsSales ";
sqlStr += " FROM orders WHERE orderId = '" + order_id + "'";
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
rs = db.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();
db.finalize();
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 = db.stmt.executeQuery(sqlStr);
if (rs1.next())
recordCount = rs1.getInt(1);
rs1.close();
db.finalize();
}
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 TOP " + (recordCount-pageSize * (page-1)) ;
sqlStr = sqlStr + " id, orderid, userid, submitTime, ConsignmentTime, ";
sqlStr += " TotalPrice, content, IpAddress, IsPayoff, IsSales ";
sqlStr += " 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));
//sqlStr = sqlStr + " ORDER BY Id DESC limit "+ pageSize * (page - 1) +","+ pageSize;
sqlStr = sqlStr + " ORDER BY id ASC ";
sqlStr = " SELECT TOP " + pageSize + " * FROM ( " + sqlStr + " ) myTable ORDER BY myTable.id DESC " ;
//}
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
rs = db.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();
db.finalize();
return true;
}
catch (SQLException e)
{
System.out.println(e);
return false;
}
}
/**
* 获得订单列表
* @param nid
* @return
*/
public boolean getAllorder(String order_id)
{
sqlStr = "SELECT id, orderId, BookNo, Amount, SoldPrice ";
sqlStr += " FROM allorder WHERE orderId = '" + order_id + "'";
try
{
DataBase db = new DataBase();
//db.connect();
//stmt = db.conn.createStatement ();
rs = db.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"));
identlist.setSoldPrice(rs.getFloat("SoldPrice"));
order_list.addElement(identlist);
}
rs.close();
db.finalize();
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");
//1) 获取订单原始信息
order ident;
if( !getSinggleOrder(orderId) )
{
return false;
}
ident = (order) getAllorder().elementAt(0);
boolean bIsSold = ident.getIsSales();
//2) 更新orders表
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);
db.stmt.execute(sqlStr);
//3) 更新用户积分
if( !bIsSold && 2 == sales )
{
String priceString = String.valueOf(ident.getTotalPrice());
int point=Integer.parseInt((priceString).substring(0,priceString.indexOf(".")));
System.out.println("dddddd:" + point);
op_user oper=new op_user();
oper.updateUserPoint( String.valueOf(ident.getUserId()), point);
}
db.finalize();
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;
db.stmt.execute(sqlStr);
sqlStr = "DELETE FROM orders WHERE id= " + id;
db.stmt.execute(sqlStr);
db.finalize();
return true;
}
catch (SQLException e)
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -