package com.zuxia.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.zuxia.model.CustomerDetailInfo;
import com.zuxia.model.CustomerInfo;
import com.zuxia.model.GoodsInfo;
import com.zuxia.model.GoodsType;
import com.zuxia.model.OrderGoodsInfo;
import com.zuxia.model.OrderInfo;
import com.zuxia.util.DBUtil;
import com.zuxia.util.PageModel;
public class OrderDAO {
//查询所有订单信息
public PageModel<OrderInfo> queryAll(int page){
PageModel<OrderInfo> pm=new PageModel<OrderInfo>();
pm.setCurrentPage(page);
pm.setSize(5);
pm.setSumCount(getCount());
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
ResultSet rs=null;
List<OrderInfo> list=new ArrayList<OrderInfo>();
String sql = "select top "+pm.getSize()+" o.orderId,o.status,o.orderTime,c.email,cd.name,cd.telphone,cd.movePhone,c.id from OrderInfo o inner join CustomerInfo c on o.customerId=c.id left join CustomerDetailInfo cd on cd.customerId=c.id where o.orderId not in(select top (("+pm.getCurrentPage()+"-1)*"+pm.getSize()+") orderId from OrderInfo)";
try {
pstmt = conn.prepareStatement(sql);
// 执行查询
rs=pstmt.executeQuery();
while(rs.next()){
//封装订单数据
OrderInfo oi=new OrderInfo();
oi.setOrderId(rs.getInt("orderId"));
oi.setStatus(rs.getInt("status"));
oi.setOrderTime(rs.getDate("orderTime"));
//封装客户详情数据
CustomerDetailInfo cdi=new CustomerDetailInfo();
cdi.setName(rs.getString("name"));
cdi.setTelphone(rs.getString("telphone"));
cdi.setMovePhone(rs.getString("movePhone"));
//封装客户数据
CustomerInfo ci=new CustomerInfo();
ci.setId(rs.getInt("id"));
ci.setEmail(rs.getString("email"));
ci.setCustomerDetailInfo(cdi);
oi.setCustomerInfo(ci);
//订单添加到集合中
list.add(oi);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.getClose(conn, pstmt, rs);
}
pm.setList(list);
return pm;
}
//得到所有条数
private int getCount(){
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
ResultSet rs=null;
String sql = "select count(1) from OrderInfo o inner join CustomerInfo c on o.customerId=c.id left join CustomerDetailInfo cd on cd.customerId=c.id";
try {
pstmt = conn.prepareStatement(sql);
// 执行查询
rs=pstmt.executeQuery();
if(rs.next()){
return rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.getClose(conn, pstmt, rs);
}
return 0;
}
//模糊查询
public PageModel<OrderInfo> querySome(int page,String key){
PageModel<OrderInfo> pm=new PageModel<OrderInfo>();
pm.setCurrentPage(page);
pm.setSize(5);
pm.setSumCount(getCount(key));
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
ResultSet rs=null;
List<OrderInfo> list=new ArrayList<OrderInfo>();
String sql = "select top "+pm.getSize()+" o.orderId,o.status,o.orderTime,c.email,cd.name,cd.telphone,cd.movePhone from OrderInfo o inner join CustomerInfo c on o.customerId=c.id left join CustomerDetailInfo cd on cd.customerId=c.id where (o.orderId like ? or c.email like ?) and o.orderId not in(select top (("+pm.getCurrentPage()+"-1)*"+pm.getSize()+") orderId from OrderInfo)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "%"+key+"%");
pstmt.setString(2, "%"+key+"%");
// 执行查询
rs=pstmt.executeQuery();
while(rs.next()){
//封装订单数据
OrderInfo oi=new OrderInfo();
oi.setOrderId(rs.getInt("orderId"));
oi.setStatus(rs.getInt("status"));
oi.setOrderTime(rs.getDate("orderTime"));
//封装客户详情数据
CustomerDetailInfo cdi=new CustomerDetailInfo();
cdi.setName(rs.getString("name"));
cdi.setTelphone(rs.getString("telphone"));
cdi.setMovePhone(rs.getString("movePhone"));
//封装客户数据
CustomerInfo ci=new CustomerInfo();
ci.setEmail(rs.getString("email"));
ci.setCustomerDetailInfo(cdi);
oi.setCustomerInfo(ci);
//订单添加到集合中
list.add(oi);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.getClose(conn, pstmt, rs);
}
pm.setList(list);
return pm;
}
//得到所有条数
private int getCount(String key){
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
ResultSet rs=null;
String sql = "select count(1) from OrderInfo o inner join CustomerInfo c on o.customerId=c.id left join CustomerDetailInfo cd on cd.customerId=c.id where o.orderId like ? or c.email like ?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "%"+key+"%");
pstmt.setString(2, "%"+key+"%");
// 执行查询
rs=pstmt.executeQuery();
if(rs.next()){
return rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.getClose(conn, pstmt, rs);
}
return 0;
}
//状态分页查询
public PageModel<OrderInfo> queryByStatus(int page,int status){
PageModel<OrderInfo> pm=new PageModel<OrderInfo>();
pm.setCurrentPage(page);
pm.setSize(5);
pm.setSumCount(getCount(status));
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
ResultSet rs=null;
List<OrderInfo> list=new ArrayList<OrderInfo>();
String sql = "select top "+pm.getSize()+" o.orderId,o.status,o.orderTime,c.email,cd.name,cd.telphone,cd.movePhone from OrderInfo o inner join CustomerInfo c on o.customerId=c.id left join CustomerDetailInfo cd on cd.customerId=c.id where o.status=? and o.orderId not in(select top (("+pm.getCurrentPage()+"-1)*"+pm.getSize()+") orderId from OrderInfo)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, status);
// 执行查询
rs=pstmt.executeQuery();
while(rs.next()){
//封装订单数据
OrderInfo oi=new OrderInfo();
oi.setOrderId(rs.getInt("orderId"));
oi.setStatus(rs.getInt("status"));
oi.setOrderTime(rs.getDate("orderTime"));
//封装客户详情数据
CustomerDetailInfo cdi=new CustomerDetailInfo();
cdi.setName(rs.getString("name"));
cdi.setTelphone(rs.getString("telphone"));
cdi.setMovePhone(rs.getString("movePhone"));
//封装客户数据
CustomerInfo ci=new CustomerInfo();
ci.setEmail(rs.getString("email"));
ci.setCustomerDetailInfo(cdi);
oi.setCustomerInfo(ci);
//订单添加到集合中
list.add(oi);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.getClose(conn, pstmt, rs);
}
pm.setList(list);
return pm;
}
//得到所有条数
private int getCount(int status){
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
ResultSet rs=null;
String sql = "select count(1) from OrderInfo o inner join CustomerInfo c on o.customerId=c.id left join CustomerDetailInfo cd on cd.customerId=c.id where o.status=?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, status);
// 执行查询
rs=pstmt.executeQuery();
if(rs.next()){
return rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.getClose(conn, pstmt, rs);
}
return 0;
}
//删除单个
public boolean delete(int id){
Connection conn = DBUtil.getConn();;
PreparedStatement pstmt = null;
String sql = "delete from OrderGoodsInfo where orderId=? ";
String sql1 = "delete from OrderInfo where orderId=? ";
try {
pstmt = conn.prepareStatement(sql+sql1);
pstmt.setInt(1, id);
pstmt.setInt(2, id);
// 执行查询
int count=pstmt.executeUpdate();
if(count>0){
return true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.g
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
毕业设计javajsp网购旅游商品sqlserver-qlkrp源码工具包 页面是jsp,数据库sqlserver,jdk1.8,开发工具用ecplise、myecplise、sts、idea都可以 公告管理 发布公告 公告管理 商品管理 添加商品 商品信息管理 添加商品类型 商品类型管理 订单管理 订单信息管理 客广管理 客户信息管理 系统管理 修改密码 修改用户名 退出系统 包含:源码、数据库脚本、环境工具包、相同框架项目的安装教程(在说明文档中)
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计javajsp网购旅游商品sqlserver-qlkrp源码工具包 (267个子文件)
org.eclipse.wst.common.project.facet.core.xml.bak 307B
OrderDAO.class 13KB
CustomerInfoDAO.class 10KB
BulletinDAO.class 8KB
GoodsTypeDAO.class 8KB
GoodsInfoDAO.class 6KB
BulletinServlet.class 5KB
OrderServlet.class 5KB
CustomerInfoServlet.class 5KB
GoodsTypeServlet.class 5KB
CustomerForwardServlet.class 4KB
PayServlet.class 4KB
CartServlet.class 4KB
SystemServlet.class 4KB
GoodsInfo.class 3KB
UserInfoDAO.class 2KB
PageModel.class 2KB
OrderInfo.class 2KB
DBUtil.class 2KB
Cart.class 2KB
CustomerInfo.class 2KB
Bulletin.class 2KB
CustomerDetailInfo.class 2KB
AjaxGetIsEmailExists.class 1KB
GoodsType.class 1KB
UserInfo.class 1KB
OrderGoodsInfo.class 1KB
.classpath 548B
org.eclipse.wst.common.component 467B
org.eclipse.wst.jsdt.ui.superType.container 49B
common.css 738B
data_manage.css 615B
add_skin.css 468B
common.css 357B
logo_ico.gif 43KB
kefu.gif 17KB
product.gif 16KB
welcome_2.gif 16KB
login_div_bg.gif 15KB
specilproduct2.gif 9KB
newproduct5.gif 7KB
logo.gif 6KB
login_register.gif 6KB
topten2.gif 6KB
error.gif 6KB
btn_register.gif 5KB
login_logo.gif 5KB
register_logo.gif 4KB
logo.gif 4KB
recommend2.gif 4KB
btn_login.gif 3KB
buycart_logo.gif 3KB
kefu_tel.gif 3KB
login.gif 3KB
jrjs.gif 2KB
sideBoxTop.gif 2KB
best.gif 2KB
jxgm.gif 2KB
addtocart.gif 2KB
sideBoxTitle.gif 1KB
peisong_logo.gif 1KB
gonggao.gif 1KB
site_ico.gif 1KB
open_left.gif 1KB
head_top.gif 1021B
close_left.gif 972B
title_ico.gif 740B
shoucang.gif 592B
loginOut.gif 577B
btn_search.gif 507B
search_ico.gif 366B
order.gif 319B
nav_line.gif 313B
login_border_y.gif 272B
border_bg.gif 260B
register_div_line.gif 246B
dot.gif 245B
help.gif 215B
user_info.gif 183B
border.gif 175B
item.gif 173B
bg.gif 154B
border_bg.gif 152B
cart.gif 141B
doc_red.gif 107B
home.gif 80B
doc.gif 76B
mysql-connector-java-5.1.27-bin.jar 852KB
sqljdbc4.jar 525KB
javax.servlet-5.1.12.jar 129KB
OrderDAO.java 13KB
CustomerInfoDAO.java 11KB
BulletinDAO.java 8KB
GoodsTypeDAO.java 8KB
GoodsInfoDAO.java 5KB
BulletinServlet.java 5KB
CustomerInfoServlet.java 5KB
OrderServlet.java 5KB
GoodsTypeServlet.java 5KB
CustomerForwardServlet.java 4KB
共 267 条
- 1
- 2
- 3
资源评论
言宇程序
- 粉丝: 2413
- 资源: 5237
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 一个相当完整的与 VB6 兼容的 DirectX 11 类型库.zip
- 一个用 DirectX11 编写的 helloworld OpenVR 程序 .zip
- 一个玩具 c++,directX 游戏引擎 .zip
- 基于计算机视觉yolov5算法实现小鼠肿瘤块检测及尺寸大小预测系统python源码+模型+测试数据.zip
- QML系统整机测试模板,包含磁盘阵列RAID管理、系统压力测试、整机拷机测试、日志收集、用户权限管理
- NVIDIA GeForce 7 Series显卡驱动下载
- 一个正在开发的现代 C++20 跨平台游戏引擎,带有 C# 脚本 .zip
- sssssssseffffffffffssdddd
- 使用kettle完成数据集管理.pptx
- 一个挂接 DirectX 并显示简单 AntTweakBar 菜单的示例项目 .zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功