📄 405971b8ea46001c1160e657ddb92502
字号:
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(Long.parseLong(rs2
.getString("orderID")));
tempOrder.setCustomerName(rs2.getString("customerName"));
tempOrder.setOrderTime(rs2.getString("orderTime"));
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) {
System.out.println(e);
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -