首页>代码>java开发贵美商城系统项目源码下载>/新建文件夹/1/GuiMeiShopping/src/com/dao/IndentDao.java
package com.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.entity.Indent;
import com.util.DBUtil;

public class IndentDao {
	/**
	 * 用户购买商品成功添加订单信息
	 * @param g_id 商品编号
	 * @param g_count 购买数量
	 * @param user 购买用户账号
	 * @param date 购买日期
	 * @return int
	 */
	public static int add(String g_id,String g_count,String user,String date){
		String sql="insert into indent(u_id,ig_id,i_name,i_price,i_count,i_money,i_date,i_dis) values((select id from user where account=?),?" +
				",(select g_name from goods where g_id=?),(select g_price from goods where g_id=?),?,((select g_price from goods where g_id=?)*?),?,(select g_dis from goods where g_id=?))";
		Object obj[]={user,g_id,g_id,g_id,g_count,g_id,g_count,date,g_id};
		int k=DBUtil.Update(sql, obj);
		return k;
	}
	/**
	 * 异步修改订单状态
	 * @param i_status
	 * @param i_id
	 * @return
	 */
	public static int updateStatus(String i_status,String i_id){
		String sql="update indent set i_status=? where i_id=?";
		Object obj[]={i_status,i_id};
		int k=DBUtil.Update(sql, obj);
		return k;
	}
	/**
	 * 异步修改订单商品数量
	 * @param i_count
	 * @param i_id
	 * @return
	 */
	public static int updateCount(String i_id,String i_count){
		String sql="update indent set i_count=? where i_id=?";
		Object obj[]={i_count,i_id};
		int k=DBUtil.Update(sql, obj);
		return k;
	}
	/**
	 * 删除订单
	 * @param i_status
	 * @param i_id
	 * @return
	 */
	public static int delete(String i_id){
		String sql="delete from indent where i_id=?";
		Object obj[]={i_id};
		int k=DBUtil.Update(sql, obj);
		return k;
	}
	/**
	 * 查询订单总数
	 * @return count
	 */
	public static int queryCount(){
		int count=0;
		String sql="select count(*) from indent";
		Object obj[]={};
		ResultSet res=DBUtil.query(sql, obj);
		try {
			if (res.next()) {
				count=res.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return count;
	}
	/**
	 * 模糊查询订单总数
	 * @param serch 订单号
	 * @return count 
	 */
	public static int queryCount(String serch){
		int count=0;
		String sql="select count(*) from indent where i_id=?";
		Object obj[]={serch};
		ResultSet res=DBUtil.query(sql, obj);
		try {
			if (res.next()) {
				count=res.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return count;
	}
	/**
	 * 模糊查询订单总数
	 * @param user  订单用户
	 * @return count 
	 */
	public static int queryUserCount(String user){
		int count=0;
		String sql="select count(*) from indent where u_id=(select id from user where account=?)";
		Object obj[]={user};
		ResultSet res=DBUtil.query(sql, obj);
		try {
			if (res.next()) {
				count=res.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return count;
	}
	/**
	 * 查询订单的编号、商品名称、订单用户、价格、数量、总价、折扣、订单状态、订单日期
	 * @param pageStart
	 * @param pageSize
	 * @return list
	 */
	public static List<Indent> queryAll(Integer pageStart,Integer pageSize){
		String sql="select i_id,i_name,userName,i_price,i_count,i_money,i_dis,i_status,i_date from indent,user where u_id=id limit ?,?";
		Object obj[]={pageStart,pageSize};
		List<Indent> list=new ArrayList<Indent>();
		ResultSet res=DBUtil.query(sql, obj);
		try {
			while(res.next()){
				Indent indent=new Indent(res.getInt(1), res.getString(2), res.getString(3),
						res.getDouble(4), res.getInt(5), res.getDouble(6),res.getDouble(7), res.getString(8), res.getString(9));
				list.add(indent);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return list;
	}
	/**
	 * 分页按订单的编号查询商品名称、订单用户、价格、数量、总价、订单状态、订单日期
	 * @param pageStart
	 * @param pageSize
	 * @return list
	 */
	public static List<Indent> query(Integer pageStart,Integer pageSize,String i_id){
		String sql="select i_id,i_name,userName,i_price,i_count,i_money,i_dis,i_status,i_date from indent,user where u_id=id and i_id=? limit ?,?";
		Object obj[]={i_id,pageStart,pageSize};
		List<Indent> list=new ArrayList<Indent>();
		ResultSet res=DBUtil.query(sql, obj);
		try {
			while(res.next()){
				Indent indent=new Indent(res.getInt(1), res.getString(2), res.getString(3),
						res.getDouble(4), res.getInt(5), res.getDouble(6),res.getDouble(7), res.getString(8), res.getString(9));
				list.add(indent);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return list;
	}
	/**
	 * 分页查询当前用户的订单商品编号、商品名称、商品价格、数量、总价、折扣
	 * @param pageStart
	 * @param pageSize
	 * @return list
	 */
	public static List<Indent> queryUser(String user,Integer pageStart,Integer pageSize){
		String sql="select distinct i_id,ig_id,i_name,i_price,i_count,i_money,i_dis from indent,user where u_id=(select id from user where account=?) limit ?,?";
		Object obj[]={user,pageStart,pageSize};
		List<Indent> list=new ArrayList<Indent>();
		ResultSet res=DBUtil.query(sql, obj);
		try {
			while(res.next()){
				Indent indent=new Indent(res.getInt(1),res.getInt(2), res.getString(3), res.getDouble(4),
						res.getInt(5), res.getDouble(6), res.getDouble(7));
				list.add(indent);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return list;
	}
	/**
	 * 查询是否有此id的用户订单信息
	 * @param bname
	 * @return boolean
	 */
	public static boolean getU_id(String u_id){
		String sql="select * from indent where u_id=?";
		Object obj[]={u_id};
		ResultSet res=DBUtil.query(sql, obj);
		try {
			if (res.next()) {
				return true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close();
		}
		return false;
	}
}
最近下载更多
小逸夜  LV4 2022年12月29日
testuser1234567  LV24 2022年6月15日
微信网友_5934504231161856  LV1 2022年4月27日
lzlzyw  LV14 2022年3月25日
linxi1134  LV4 2022年1月5日
314997zf  LV4 2021年12月23日
lwp011  LV27 2021年11月5日
南风入弦  LV5 2021年6月26日
wanglinddad  LV54 2021年4月22日
那个米龙  LV8 2020年12月8日
最近浏览更多
15103432984  LV2 3月17日
try8023  LV18 1月16日
ncyhhh  LV1 2023年11月26日
蹇金金  LV7 2023年11月6日
abandan  LV4 2023年11月6日
heqian  LV16 2023年10月31日
nimi777 2023年9月12日
暂无贡献等级
SDLFJL  LV6 2023年7月23日
dw45dw  LV1 2023年6月24日
xyzzuidaima  LV3 2023年6月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友