package com.zzz.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import com.zzz.bean.Customer;
import com.zzz.bean.OrderForm;
import com.zzz.bean.OrderLine;
import com.zzz.bean.Product;
import com.zzz.dao.IOrderFormDao;
import com.zzz.exception.DataAccessException;
import com.zzz.exception.ServiceException;
import com.zzz.service.impl.OrderFormService;
import com.zzz.service.impl.ProductService;
import com.zzz.util.ConnectionFactory;
public class OrderFormDao implements IOrderFormDao {
@Override
public void saveOrderForm(OrderForm order) throws DataAccessException {
// TODO Auto-generated method stub
Connection con = ConnectionFactory.getConn();
PreparedStatement pst = null;
String sql = "insert into orderform values(null,?,?,?)";
try {
pst = con.prepareStatement(sql);
pst.setFloat(1, order.getCost());
pst.setString(2, order.getOrderdate());
pst.setInt(3, order.getCustomer().getId());
pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnectionFactory.close(pst, con);
}
}
@Override
public void deleteOrder(Integer orderid) throws DataAccessException {
// TODO Auto-generated method stub
Connection con = ConnectionFactory.getConn();
Statement stm = null;
String sql = "delete from orderform where id = " + orderid;
try {
stm = con.createStatement();
stm.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnectionFactory.close(stm, con);
}
}
@Override
public OrderForm findOrderByOrderid(Integer orderid)
throws DataAccessException {
// TODO Auto-generated method stub
Connection con = ConnectionFactory.getConn();
ResultSet rst = null;
Statement stm = null;
OrderForm order = new OrderForm();
String sql = "select * from orderform where id = " + orderid;
try {
stm = con.createStatement();
rst = stm.executeQuery(sql);
while(rst.next()){
order.setCost(rst.getFloat("cost"));
Customer customer = new CustomerDao().findUserByUserid(rst.getInt("customerid"));
order.setCustomer(customer);
order.setId(rst.getInt("id"));
order.setOrderdate(rst.getString("orderdate"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnectionFactory.close(rst, stm, con);
}
return order;
}
@Override
public List<OrderForm> findOrderByUserid(Integer userid) throws DataAccessException {
// TODO Auto-generated method stub
List<OrderForm> list = new ArrayList<OrderForm>();
Connection con = ConnectionFactory.getConn();
Statement stm = null;
ResultSet rst = null;
String sql = "select * from orderform where customerid = " + userid;
try {
stm = con.createStatement();
rst = stm.executeQuery(sql);
while(rst.next()){
OrderForm order = new OrderForm();
order.setCost(rst.getFloat("cost"));
Customer customer = new CustomerDao().findUserByUserid(userid);
order.setCustomer(customer);
order.setId(rst.getInt("id"));
order.setOrderdate(rst.getString("orderdate"));
list.add(order);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
@Override
public Map<?, ?> findAllPayway() throws DataAccessException {
// TODO Auto-generated method stub
return null;
}
@Override
public List<?> findOrderByPageNumber(Integer page, Integer userid)
throws DataAccessException {
// TODO Auto-generated method stub
return null;
}
//保存所有订单明细
public void saveAllOrderLine(List<OrderLine> orderlines) throws DataAccessException{
for (OrderLine orderLine : orderlines) {
saveOrderLine(orderLine);
}
}
//保存订单明细
public void saveOrderLine(OrderLine orderline) throws DataAccessException{
Connection con = ConnectionFactory.getConn();
PreparedStatement pst = null;
String sql = "insert into orderline values(null,?,?,?)";
try {
pst = con.prepareStatement(sql);
pst.setInt(1, orderline.getNum());
pst.setInt(2, orderline.getOrderform().getId());
pst.setInt(3,orderline.getProduct().getId());
pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//删除所有订单明细通过订单号
public void delOrderLinesByOrderid(Integer orderid) throws DataAccessException{
Connection con = ConnectionFactory.getConn();
Statement stm = null;
String sql = "delete from orderline where orderformid = " + orderid;
try {
stm = con.prepareStatement(sql);
stm.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//根据订单生成时间获取订单
public OrderForm getOrderFormByTime(String time) throws DataAccessException{
OrderForm orderform = new OrderForm();
Connection con = ConnectionFactory.getConn();
Statement stm = null;
ResultSet rst = null;
String sql = "select * from orderform where orderdate = \'" + time +"\'";
try {
stm = con.createStatement();
rst = stm.executeQuery(sql);
while(rst.next()){
orderform.setCost(rst.getFloat("cost"));
Customer customer = new CustomerDao().findUserByUserid(rst.getInt("customerid"));
orderform.setCustomer(customer);
orderform.setId(rst.getInt("id"));
orderform.setOrderdate(rst.getString("orderdate"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return orderform;
}
//通过订单id获取或有订单项
public List<OrderLine> getOrderLinesByOrderid(Integer orderid) throws ServiceException{
List<OrderLine> orderlines = new ArrayList<OrderLine>();
Connection con = ConnectionFactory.getConn();
ResultSet rst = null;
Statement stm = null;
String sql = "select * from orderline where orderformid = " + orderid;
try {
stm = con.createStatement();
rst = stm.executeQuery(sql);
while(rst.next()){
OrderLine orderline = new OrderLine();
orderline.setId(rst.getInt("id"));
orderline.setNum(rst.getInt("num"));
OrderForm orderform = new OrderFormService().listOrderByOrderid(rst.getInt("orderformid"));
orderline.setOrderform(orderform);
Product product = new ProductService().getProductByProductid(rst.getInt("productid"));
orderline.setProduct(product);
orderlines.add(orderline);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnectionFactory.close(rst, stm, con);
}
return orderlines;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
jsp + servlet + mysql 电子商城 (143个子文件)
DV_getcode.asp 1KB
OrderFormDao.class 8KB
CustomerDao.class 5KB
saveOrder.class 4KB
ProductDao.class 3KB
OrderFormService.class 3KB
updateUserInfo.class 3KB
register.class 3KB
addProduct2Cart.class 3KB
ShoppingCart.class 3KB
orderinfo.class 3KB
Product.class 3KB
ConnectionFactory.class 3KB
removeOrder.class 3KB
Customer.class 2KB
productDetail.class 2KB
login.class 2KB
updateShopCart.class 2KB
removeProduct.class 2KB
removeAllProducts.class 2KB
ApplicationListener.class 2KB
EncodingFilter.class 2KB
CustomerService.class 2KB
OrderForm.class 1KB
OrderLine.class 1KB
SessionListener.class 1KB
ProductService.class 1KB
IOrderFormDao.class 616B
IOrderFormService.class 614B
DataAccessException.class 529B
ServiceException.class 456B
IProductService.class 407B
IProductDao.class 392B
ICustomerService.class 369B
ICustomerDao.class 345B
.classpath 797B
org.eclipse.wst.common.component 484B
org.eclipse.wst.jsdt.ui.superType.container 49B
main.css 3KB
zcover.gif 18KB
zcover8.gif 11KB
zcover2.gif 11KB
zcover6.gif 10KB
zcover7.gif 9KB
zcover3.gif 8KB
cover.gif 8KB
top_r.gif 7KB
dvmenubg3.gif 5KB
zcover4.gif 5KB
zcover5.gif 4KB
bot_bg.gif 4KB
briup3.gif 3KB
submit.gif 3KB
next.gif 3KB
logo.gif 2KB
courselist_on.gif 2KB
courselist.gif 2KB
reg_on.gif 2KB
reg.gif 2KB
cart_on.gif 2KB
carts_on.gif 2KB
cart.gif 2KB
exit_on.gif 2KB
order.gif 2KB
exit.gif 2KB
order_on.gif 2KB
index_on.gif 2KB
index.gif 2KB
dog.gif 2KB
Female.gif 2KB
Male.gif 1KB
car_new.gif 1KB
buycar.gif 720B
cancelone.gif 388B
Forum_nav.gif 280B
dh_bg.gif 261B
bg2.gif 153B
top_bg.gif 138B
tabs_m_tile.gif 99B
navspacer.gif 56B
bottombg.gif 53B
mysql-connector-java-3.1.13-bin.jar 446KB
jstl-1.2.jar 405KB
OrderFormDao.java 7KB
CustomerDao.java 5KB
OrderFormService.java 3KB
saveOrder.java 3KB
updateUserInfo.java 3KB
register.java 3KB
ProductDao.java 2KB
ConnectionFactory.java 2KB
removeOrder.java 2KB
addProduct2Cart.java 2KB
orderinfo.java 2KB
Product.java 2KB
login.java 2KB
productDetail.java 2KB
Customer.java 2KB
ShoppingCart.java 2KB
ApplicationListener.java 2KB
共 143 条
- 1
- 2
资源评论
ZZZ123147
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功