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

📄 takeclothesdaoimpl.java

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

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.ClothesTypeVo;
import vo.OperatorVo;
import vo.OrderItemVo;
import vo.OrderVo;
import vo.RefundmentVo;
import vo.RewashVo;
import vo.VipConsumeVo;
import dao.common.DBConnectionManager;
import dao.common.DbException;
import dao.common.sql.DbTakeClothesSql;
import dao.getClothesDao.GetClothesDao;
import dao.getClothesDao.getClothesDaoImpl.GetClothesDaoImpl;
import dao.takeClothesDao.TakeClothesDao;

public class TakeClothesDaoImpl implements TakeClothesDao {
	private DBConnectionManager manager = DBConnectionManager.getInstance();

	public boolean takeClothes(OrderVo orderVo) throws DbException {
		boolean flag = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con
					.prepareStatement(DbTakeClothesSql.SET_ORDER_PAID_OR_NOT);
			pstmt.setString(1, "是");
			pstmt.setString(2, "是");
			pstmt.setLong(3, orderVo.getOrderId());
			int count = pstmt.executeUpdate();
			if (count == 0) {
				throw new DbException("订单表" + orderVo.getOrderId()
						+ "设置赊欠已付和衣服取走失败");
			} else {
				flag = true;
			}

			if (!orderVo.isPaidOrNot()) {
				GetClothesDao getClothesDao = new GetClothesDaoImpl();
				double totalValue = orderVo.getOrderValue();
				if (!getClothesDao.updateVipCardAfterPaying(orderVo))
					return false;
				else {					
					long orderId = orderVo.getOrderId();
					int vipId = orderVo.getCustomerId();
					String consumeDate = orderVo.getGetClothesDate();
					double neededAmount = orderVo.getOrderValue();
					double receivedAmount = neededAmount;
					double reducedAmount = 0;
					Iterator it = orderVo.getOrderItemVector().iterator();
					while (it.hasNext()) {
						OrderItemVo itemVo = (OrderItemVo) it.next();
						reducedAmount += itemVo.getClothesType()
								.getUnitOriginalPrice()
								* itemVo.getClothesQuatity()
								- itemVo.getItemValue();
					}
					VipConsumeVo cosumeVo = new VipConsumeVo(orderId, vipId,
							consumeDate, neededAmount, receivedAmount,
							reducedAmount);
					getClothesDao.registConsumevo(cosumeVo);
				}
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return true;
	}

	public boolean registRewash(RewashVo rewashVo) throws DbException {
		if (!setNewTakeDateInOrder(rewashVo.getNewTakeDate(), rewashVo
				.getOrderId()))
			return false;
		boolean flag = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbTakeClothesSql.REGIST_REWASH);
			pstmt.setLong(1, rewashVo.getOrderId());
			pstmt.setString(2, rewashVo.getOriginalTakeDate());
			pstmt.setString(3, rewashVo.getNewTakeDate());
			pstmt.setString(4, rewashVo.getRequireRewashDate());
			pstmt.setString(5, rewashVo.getOperatorName());
			int count = pstmt.executeUpdate();
			if (count == 0) {
				throw new DbException("数据库插入洗衣单" + rewashVo.getOrderId()
						+ "重洗失败");
			} else {
				flag = true;
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return flag;
	}

	private boolean setNewTakeDateInOrder(String newTakeDate, long orderId)
			throws DbException {
		boolean flag = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con
					.prepareStatement(DbTakeClothesSql.SET_ORDER_NEW_TAKE_DATE);
			pstmt.setString(1, newTakeDate);
			pstmt.setLong(2, orderId);
			int count = pstmt.executeUpdate();
			if (count == 0) {
				throw new DbException("数据库设置洗衣单" + orderId + "新领取日期失败");
			} else {
				flag = true;
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return flag;
	}

	public boolean registRefundment(RefundmentVo refundmentVo)
			throws DbException {
		boolean flag = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbTakeClothesSql.REGIST_REFUND_ORDER);
			pstmt.setLong(1, refundmentVo.getOrderId());
			pstmt.setString(2, refundmentVo.getRefundDate());
			pstmt.setDouble(3, refundmentVo.getRefundAmount());
			pstmt.setString(4, refundmentVo.getRefundReason());
			pstmt.setString(5, refundmentVo.getOperatorName());
			int count = pstmt.executeUpdate();
			if (count == 0) {
				throw new DbException("数据库中设置洗衣单" + refundmentVo.getOrderId()
						+ "赔偿失败");
			} else {
				flag = true;
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return flag;
	}

	public Vector getNotTakeOrderVo() throws DbException {
		boolean flag = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		Vector v = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con
					.prepareStatement(DbTakeClothesSql.GET_ORDER_BY_TAKE_OR_BOT);
			pstmt.setString(1, "否");
			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");
				
				Vector orderItemVector = this.getOrderItemByOrderId(orderId);
				/*Vector orderItemVector = new Vector();
				Vector v1 = this.getOrderItemByOrderId(orderId);
				Iterator it = v1.iterator();
				while (it.hasNext()) {
					orderItemVector.addElement((OrderItemVo) it.next());
				}*/
				OrderVo orderVo = new OrderVo(orderId, orderItemVector, vipId,
						orderValue, inDate, outDate, paidOrNot, takeOrNot,
						operaterName);
				v.add(orderVo);
			}
			if (v.size() == 0) {
				throw new DbException("数据库中的衣服已全部取走");
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return v;
	}

	public Vector getOrderItemByOrderId(long orderId) throws DbException {
		Vector v = null;
		ClothesTypeVo type = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con
					.prepareStatement(DbTakeClothesSql.GET_ORDER_ITEM_BY_ORDERID);
			pstmt.setLong(1, orderId);
			set = pstmt.executeQuery();
			v = new Vector();
			while (set.next()) {
				int clothesId = set.getInt("clothes_id");// 衣服编号
				type = this.getClothesTypeByClothesID(clothesId);
				String brand = set.getString("clothes_brand");// 衣服品牌
				String accessory = set.getString("clothes_accessory");// 衣服附件
				String color = set.getString("clothes_color");// 衣服颜色
				String flaw = set.getString("clothes_flaw");// 衣服瑕疵
				String additionInfo = set.getString("clothes_addition_info");// 衣服备注
				int quantity = set.getInt("clothes_quantity");// 衣服件数
				double itemValue = set.getDouble("order_item_value");// 打折后,该订单项的应付金额
				v.addElement(new OrderItemVo(type, accessory, brand, color,
						flaw, additionInfo, quantity, itemValue));
			}
			if (v.size() == 0) {
				throw new DbException("数据库中洗衣单"+orderId+"中item没有内容");
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		}finally {
			manager.freeConnection("oracle", con);
		}
		return v;
	}

	public ClothesTypeVo getClothesTypeByClothesID(int clothesId)
			throws DbException {
		ClothesTypeVo vo = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbTakeClothesSql.GET_CLOTHESTYPE_BY_CLOTHESID);
			pstmt.setInt(1, clothesId);
			set = pstmt.executeQuery();
			while (set.next()) {
				String clothesName = set.getString("clothes_name");// 衣服名称
				String service = set.getString("service_type");// 服务类型
				double price = set.getDouble("unit_original_price");// 衣服单件原价
				double lowestDiscount = set.getDouble("lowest_discount");// 衣服最低折扣,当为0时表示按照会员卡打折
				vo = new ClothesTypeVo(clothesId, clothesName, service, price,
						lowestDiscount, null, null);
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		}finally {
			manager.freeConnection("oracle", con);
		}
		return vo;
	}

	public boolean isThisOperatorExists(OperatorVo opearatorVo)throws DbException{
		boolean flag = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbTakeClothesSql.GET_OPERATOR);
			set = pstmt.executeQuery();
			while(set.next()){
				String operatorName = set.getString("operator_name");
				String operatorPsw = set.getString("operator_psw");
				if(operatorName.equals(opearatorVo.getOperatorName())
						&& operatorPsw.equals(opearatorVo.getOperatorPsw())){
					return true;
				}
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return flag;
	}
	
	public Vector getAllOperatorName() throws DbException{
		Vector v = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbTakeClothesSql.GET_OPERATOR_NAME);
			set = pstmt.executeQuery();
			v = new Vector();
			while(set.next()){
				String operatorName = set.getString("operator_name");
				v.add(operatorName);
			}
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return v;
	}
}

⌨️ 快捷键说明

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