⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clothesinandoutdaoimpl.java

📁 一个优秀的干洗店管理系统
💻 JAVA
字号:
package dao.inandoutdao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JOptionPane;

import vo.OrderItemVo;
import vo.OrderVo;
import vo.RefundmentVo;
import vo.RewashVo;

import common.LogWriter;

import dao.commomdao.CommonDao;
import dao.commomdao.impl.CommonDaoImpl;
import dao.common.DBConnectionManager;
import dao.common.DbException;
import dao.common.sql.DbSql;
import dao.inandoutdao.ClothesInAndOutDao;

public class ClothesInAndOutDaoImpl implements ClothesInAndOutDao {
	private DBConnectionManager manager = DBConnectionManager.getInstance();

	private LogWriter log;

	/**
	 * @param log
	 */
	public ClothesInAndOutDaoImpl(LogWriter log) {
		this.log = log;
	}

	CommonDao dao = new CommonDaoImpl(log);

	public Vector findClothesInGether(String fromDate, String toDate)
			throws DbException {
		Vector v = null;
		Vector<OrderItemVo> orderItemVector = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_CLOTHESIN_GETHER);
			pstmt.setString(1, fromDate);
			pstmt.setString(2, toDate);
			set = pstmt.executeQuery();
			v = new Vector();
			while (set.next()) {
				long orderId = set.getLong("order_id");
				int vipId = set.getInt("vip_id");
				double orderValue = set.getDouble("order_value");
				String inDate = set.getString("in_date").substring(0, 10);
				String outDate = set.getString("out_date_prodicted").substring(
						0, 10);
				String paid = set.getString("paid_or_not");
				boolean paidOrNot = false;
				if (paid.equals("是")) {
					paidOrNot = true;
				}
				String taked = set.getString("take_or_not");
				boolean takeOrNot = false;
				if (taked.equals("是")) {
					takeOrNot = true;
				}
				String operaterName = set.getString("operator_name");
				orderItemVector = new Vector();
				Vector v1 = dao.getOrderItemByOrderId(orderId);
				Iterator iter = v1.iterator();
				while (iter.hasNext()) {
					orderItemVector.addElement((OrderItemVo) iter.next());
				}
				v.addElement(new OrderVo(orderId, orderItemVector, vipId,
						orderValue, inDate, outDate, paidOrNot, takeOrNot,
						operaterName));
			}
			if (v.size() == 0) {
				JOptionPane.showMessageDialog(null, "数据库中没有从"+fromDate+"到"+toDate+"的收衣记录");
			}
			log.log("查找衣物汇总成功", LogWriter.INFO);

		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null,"收取衣物汇总查找dao异常:"+ e.getMessage());
			log.log("查找衣物汇总失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return v;
	}

	public Vector findRefundment(String fromDate, String toDate)
			throws DbException {
		Vector v = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_REFUNDMENT_INFO);
			pstmt.setString(1, fromDate);
			pstmt.setString(2, toDate);
			set = pstmt.executeQuery();
			v = new Vector();
			while (set.next()) {
				long orderId = set.getLong("order_id");// 订单ID
				String refundDate = set.getString("refund_date").substring(0,
						10);// 退款日期
				double refundAmount = set.getDouble("refund_amount");// 退款金额
				String refundReason = set.getString("refund_reason");// 退款原因
				String operator = set.getString("operator_name"); // 操作员姓名
				v.addElement(new RefundmentVo(orderId, refundDate,
						refundAmount, refundReason, operator));

			}
			if (v.size() == 0) {
				JOptionPane.showMessageDialog(null, "数据库中没有从"+fromDate+"到"+toDate+"的索赔衣物记录");
				// throw new DbException("数据库中不存在符合条件的记录");
			}
			log.log("查找赔偿记录成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "赔偿记录查找异常:"+e.getMessage());
			log.log("查找赔偿记录失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return v;
	}

	public Vector findReWashed(String fromDate, String toDate)
			throws DbException {
		Vector v = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_REWASHED_INFO);
			pstmt.setString(1, fromDate);
			pstmt.setString(2, toDate);
			set = pstmt.executeQuery();
			v = new Vector();
			while (set.next()) {
				long orderId = set.getLong("order_id");// 订单ID
				String oldTakeDate = set.getString("old_take_date").substring(
						0, 10);// 原定取衣日期
				String newTakeDate = set.getString("new_take_date").substring(
						0, 10);// 新定取衣日期
				String rewashdate = set.getString("require_rewash_date")
						.substring(0, 10);// 即在哪个时间确定要重洗衣服
				String operator = set.getString("operator_name");// 操作员姓名
				v.addElement(new RewashVo(orderId, oldTakeDate, newTakeDate,
						rewashdate, operator));
			}
			if (v.size() == 0) {
				 JOptionPane.showMessageDialog(null, "数据库中没有从"+fromDate+"到"+toDate+"的重诜衣物记录");
			}
			log.log("查找重洗记录成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "重洗记录查找异常:"+e.getMessage());
			log.log("查找重洗记录失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return v;
	}

	public long[] findOutOfDateOrderId(String fromDate,String toDate) throws DbException {
		long[] orderIds = null;
		Vector v = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_OUTOFDATE_ORDERID);
			pstmt.setString(1, fromDate);
			pstmt.setString(2, toDate);
			set = pstmt.executeQuery();
			v = new Vector();
			while (set.next()) {
				long orderId = set.getLong("order_id");
				v.addElement(new Long(orderId));
			}
			int count = v.size();
			if (v.size()== 0) {
				JOptionPane.showMessageDialog(null, "数据库中没有从"+fromDate+"到"+toDate+"的过期未领衣物记录");
			}
			orderIds = new long[count];
			Iterator iter = v.iterator();
			int i = 0;
			while (iter.hasNext()) {
				orderIds[i] = Long.valueOf(iter.next().toString());
//				System.out.println("orderIds[" + i + "] = " + orderIds[i]);
				i++;
			}
			log.log("查找过期的定单的编号成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "过期未领定单编号查找异常:"+e.getMessage());
			log.log("查找过期的定单的编号失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return orderIds;
	}

	public int[] findClothesIds(String fromDate,String toDate) throws DbException {
		int[] clothesIds = null;
		Vector v = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_CLOTHESIDS);
			pstmt.setString(1, fromDate);
			pstmt.setString(2, toDate);
			set = pstmt.executeQuery();
			v = new Vector();
			while (set.next()) {
				int clothesId = set.getInt("clothes_id");
				v.addElement(new Integer(clothesId));
			}
			int count = v.size();
			if (count == 0) {
				JOptionPane.showMessageDialog(null, "数据库中没有从"+fromDate+"到"+toDate+"的收衣记录");
			}
			clothesIds = new int[count];
			Iterator iter = v.iterator();
			int i = 0;
			while (iter.hasNext()) {
				clothesIds[i] = Integer.valueOf(iter.next().toString());
				i++;
			}
			log.log("查找衣服编号成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "查找衣物dao异常:"+e.getMessage());
			log.log("查找衣服编号失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return clothesIds;
	}

	public int findClothesCountById(int clothesId) throws DbException {
		int count = 0;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_CLOTHESINCOUNT_BY_CLOTHESID);
			pstmt.setInt(1, clothesId);
			set = pstmt.executeQuery();
			while (set.next()) {
				count = set.getInt(1);
//				System.out.println("count = " + count);
			}
			log.log("通过衣服编号查找衣服数量成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "通过衣服编号查找衣服数量dao异常:"+e.getMessage());
			log.log("通过衣服编号查找衣服数量失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return count;
	}

	public double getClothesIncomeByClothesId(int clothesId) throws DbException {
		double income = 0;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_INCOMECOUNT_BY_CLOTHESID);
			pstmt.setInt(1, clothesId);
			set = pstmt.executeQuery();
			while (set.next()) {
				income = set.getDouble(1);
//				System.out.println("income = " + income);
			}
			log.log("通过衣服编号获取该类衣服的总收入成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "通过衣服编号获取该类衣服的总收入dao异常:"+e.getMessage());
			log.log("通过衣服编号获取该类衣服的总收入失败", LogWriter.ERROR);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return income;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -