?? 408895cfe946001c1160e657ddb92502
字號:
package hall;
/**
* Project: NWPU online shop
* JDK version used: jdk1.5.0
* Version: 1.01
* class opOrder 用來處理有關于訂單的各種操作
*/
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
public class opOrder {
private Vector orderItemList;//訂單項的向量數組
private Vector orderList;//訂單的向量數組
private Vector products;//貨物的向量數組
private int page = 1; // 顯示的頁碼
private int pageSize = 15; // 每頁顯示的訂單數
private int pageCount = 0; // 頁面總數
private long recordCount = 0; // 查詢的記錄總數
private double account = 0.0;//查詢的貨物總額
private DBWrapper myConnection = null;
private String sqlStr = "";
public opOrder() throws Exception {
myConnection = DBWrapper.Instance();
}
/**
* double getAccount()
* Description :得到所要查詢的訂單的總額
* @return double
*/
public double getAccount() {
return account;
}
/**
* Vector getOrderList()
* Description :得到訂單的向量數組
* @return Vector
*/
public Vector getOrderList() {
return orderList;
}
/**
* Vector getProducts()
* Description :得到貨物的向量數組
* @return Vector
*/
public Vector getProducts() {
return products;
}
/**
* Vector getProducts()
* Description :得到訂單項目的向量數組
* @return Vector
*/
public Vector getOrderItemList() {
return orderItemList;
}
/**
* int getPage()
* Description :得到要顯示的頁數
* @return int
*/
public int getPage() {
return page;
}
/**
* void setPage(int newpage)
* Description :修改要顯示的頁數
* @param int
*/
public void setPage(int newpage) {
page = newpage;
}
/**
* int getPageSize()
* Description :得到每頁要顯示的訂單數
* @return int
*/
public int getPageSize() {
return pageSize;
}
/**
* void setPageSize(int newpsize)
* Description :修改每頁要顯示的訂單數
* @param int
*/
public void setPageSize(int newpsize) {
pageSize = newpsize;
}
/**
* int getPageCount()
* Description :得到頁面總數
* @return int
*/
public int getPageCount() {
return pageCount;
}
/**
* void setPageCount(int newpcount)
* Description :修改頁面總數
* @param int
*/
public void setPageCount(int newpcount) {
pageCount = newpcount;
}
/**
* int getRecordCount()
* Description :得到記錄總數
* @return long
*/
public long getRecordCount() {
return recordCount;
}
/**
* void setRecordCount(long newrcount)
* Description :修改記錄總數
* @param long
*/
public void setRecordCount(long newrcount) {
recordCount = newrcount;
}
// 管理員確認發貨
public boolean modifedOrder(long inItem, String inOrderWay, String inSender) {
boolean flag = false;
try {
sqlStr = "update orders set ";
sqlStr += "orderWay = '" + inOrderWay + "',";
sqlStr += "sender = '" + inSender + "',";
sqlStr += "state = " + 2 + " ";
sqlStr += "where orders = " + inItem;
System.out.println(sqlStr);
myConnection.runUpdate(sqlStr);
flag = true;
} catch (Exception e) {
flag = false;
System.out.println(e);
}
return flag;
}
// 管理員確定已發貨
public boolean check(long inItem) throws Exception {
Date tempDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
String sdate = sdf.format(tempDate);
try {
sqlStr = "update orders set ";
sqlStr += "receiveTime = '" + sdate + "',";
sqlStr += "state = " + 3 + " ";
sqlStr += "where OrderID = " + inItem;
System.out.println(sqlStr);
myConnection.runUpdate(sqlStr);
return true;
} catch (Exception e) {
System.out.println(sqlStr);
return false;
}
}
/**
* boolean query(int inYear, int inMonth, int inDay, String inArea)
* Description :根據時間或地區或結合查詢營業額,結果放入account中
* @param int 所要查詢的年份
* @param int 所要查詢的月份
* @param int 所要查詢的天
* @param String 所要查詢的地區
* @return boolean 返回操作是否成功信息
*/
public boolean query(int inYear, int inMonth, int inDay, String inArea) {
boolean flag = true;
if (inArea == null)
inArea = "";
int year = inYear;
int month = inMonth;
int day = inDay;
String date;
/*
* 若天不填,則認為查詢一個月份的
* 若月份不填,則認為查詢一年的
* 若年份不填,則認為查詢全部的
*/
if (year == 0) {
date = "";
} else {
if (month == 0) {
date = year + "";
} else {
if (day == 0)
date = year + "/" + month;
else
date = year + "/" + month + "/" + day;
}
}
sqlStr = "select sum(amount) from orders where orderTime like '%"
+ date + "%'" + " and address like '%" + inArea + "%'";
try {
System.out.println(sqlStr);
ResultSet rs1 = myConnection.runQuery(sqlStr);
rs1.next();
account = rs1.getInt(1);
flag = true;
} catch (Exception e) {
flag = false;
System.out.println(e);
}
return flag;
}
/**
* boolean getOrder(String userName, int state)
* Description :用戶根據不同訂單狀態查詢訂單
* @param String 用戶名
* @param int 訂單狀態,1代表尚未被處理的訂單
* 2代表已經發送的訂單,3代表已經收到貨的訂單
* 0代表所有訂單
* @return boolean 返回操作是否成功信息
*/
public boolean getOrder(String userName, int state) throws Exception {
String sqlStr1 = "";
if (state == 0) {
sqlStr1 = "select count(*) from orders where customerName = '"
+ userName + "'";
} else if (state == 1 || state == 2 || state == 3) {
sqlStr1 = "select count(*) from orders where state = " + state
+ "and customerName = '" + userName + "'";
;
} else
return false;
try {
ResultSet rs1 = myConnection.runQuery(sqlStr1);
if (rs1.next())
recordCount = rs1.getInt(1);
rs1.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
sqlStr = "select * from orders where customerName = '" + userName
+ "' order by orderTime desc";
try {
ResultSet rs = myConnection.runQuery(sqlStr);
orderList = new Vector();
while (rs.next()) {
order tempOrder = new order();
tempOrder.setOrderItem(Long.parseLong(rs.getString("orderID")));
tempOrder.setCustomerName(rs.getString("customerName"));
tempOrder.setOrderTime(rs.getString("orderTime"));
tempOrder.setAddress(rs.getString("address"));
tempOrder.setCode(rs.getString("code"));
tempOrder.setOrderWay(rs.getString("orderWay"));
tempOrder.setReceiveTime(rs.getString("receiveTime"));
tempOrder.setSender(rs.getString("sender"));
tempOrder.setAccount(rs.getDouble("amount"));
System.out.println("123");
orderList.addElement(tempOrder);
}
rs.close();
return true;
} catch (SQLException e) {
System.out.println(e);
return false;
}
}
/**
* boolean showItemDetail(long inOrderID)
* Description :根據訂單號得到訂單的詳細信息,并將訂單中的貨物信息存入向量數組中
* @param long 訂單號
* @return boolean 返回操作是否成功信息
*/
public boolean showItemDetail(long inOrderID) throws Exception {
sqlStr = "select * from orderItem where orderID = '" + inOrderID + "'";
try {
ResultSet rs = myConnection.runQuery(sqlStr);
orderItemList = new Vector();
products = new Vector();
while (rs.next()) {
orderItem tempOrderItem = new orderItem();
tempOrderItem.setOrderID(Long
.parseLong(rs.getString("orderID")));
tempOrderItem.setProducItem(rs.getInt("producItem"));
tempOrderItem.setQuantity(rs.getInt("quantity"));
orderItemList.addElement(tempOrderItem);
sqlStr = "select * from products where producItem = "
+ tempOrderItem.getProItem();
ResultSet rs1 = myConnection.runQuery(sqlStr);
rs1.next();
products tempPro = new products();
tempPro.setProductorItem(tempOrderItem.getProItem());
tempPro.setProductorName(rs1.getString("producName"));
tempPro.setType(rs1.getString("type"));
tempPro.setQuantity(rs1.getInt("quantity"));
products.addElement(tempPro);
rs1.close();
}
rs.close();
return true;
} catch (Exception e) {
System.out.println(e);
return false;
}
}
/**
* boolean getAllorder(int inState)
* Description :管理員根據不同訂單狀態查看所有訂單
*
* @param int 訂單狀態,1代表尚未被處理的訂單
* 2代表已經發送的訂單,3代表已經收到貨的訂單
* 0代表所有訂單
* @return boolean 返回操作是否成功信息
*/
public boolean getAllorder(int inState) throws Exception {
String sqlStr1 = "", sqlStr2 = "";
if (inState == 0) {
sqlStr1 = "select count(*) from orders";
sqlStr2 = "select * from orders";
} else if (inState == 1 || inState == 2 || inState == 3) {
sqlStr1 = "select count(*) from orders where state = " + inState;
sqlStr2 = "select * from orders where state = " + inState;
} else
return false;
try {
ResultSet rs1 = myConnection.runQuery(sqlStr1);
if (rs1.next())
recordCount = rs1.getInt(1);
rs1.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
if (recordCount < 1)
pageCount = 0;
else
pageCount = (int) (recordCount - 1) / pageSize + 1;
if (page < 1)
page = 1;
else if (page > pageCount)
page = pageCount;
try {
ResultSet rs2 = myConnection.runQuery(sqlStr2);
if (page == 1) {
} else {
for (int i = 0; i < pageSize * (page - 1); i++) {
rs2.next();
}
}
orderList = new Vector();
while (rs2.next()) {
order tempOrder = new order();
tempOrder.setOrderItem(Integer.parseInt(rs2
.getString("orderID")));
tempOrder.setCustomerName(rs2.getString("customerName"));
tempOrder.setOrderTime(rs2.getString("orderItem"));
tempOrder.setAddress(rs2.getString("address"));
tempOrder.setCode(rs2.getString("code"));
tempOrder.setOrderWay(rs2.getString("orderWay"));
tempOrder.setReceiveTime(rs2.getString("receiveTime"));
tempOrder.setSender(rs2.getString("sender"));
tempOrder.setAccount(rs2.getDouble("account"));
orderList.addElement(tempOrder);
}
rs2.close();
return true;
} catch (SQLException e) {
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -