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

📄 commondaoimpl.java

📁 一个优秀的干洗店管理系统
💻 JAVA
字号:
package dao.commomdao.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.ClothesTypeVo;
import vo.OrderItemVo;
import vo.OrderVo;
import vo.VipCardVo;
import vo.VipConsumeVo;
import vo.VipVo;

import common.LogWriter;

import dao.commomdao.CommonDao;
import dao.common.DBConnectionManager;
import dao.common.DbException;
import dao.common.sql.DbSql;

public class CommonDaoImpl implements CommonDao {

	private DBConnectionManager manager = DBConnectionManager.getInstance();

	private LogWriter log;

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

	/**
	 * 通过定单号获取定单信息
	 */
	public OrderVo getOrderInfoByOrderId(long orderId) throws DbException {
		OrderVo vo = null;
		Vector<OrderItemVo> orderItemVector = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_ORDERINFO_BY_ORDERID);
			pstmt.setLong(1, orderId);
			set = pstmt.executeQuery();
			while (set.next()) {
				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;
				}
				orderItemVector = new Vector();
				Vector v = (Vector) getOrderItemByOrderId(orderId);
				Iterator iter = v.iterator();
				while (iter.hasNext()) {
					orderItemVector.addElement((OrderItemVo) iter.next());
				}
				// System.out.println("v.size() = " + v.size());
				String operaterName = set.getString("operator_name");
				vo = new OrderVo(orderId, orderItemVector, vipId, orderValue,
						inDate, outDate, paidOrNot, takeOrNot, operaterName);
			}
			if (vo == null) {
				JOptionPane.showMessageDialog(null, "数据库中不存在与" + orderId
						+ "有关的定单信息");
				// throw new DbException("数据库中不存在与"+orderId+"有关的定单信息");
			}
			log.log("按定单号查找定单信息查找成功", LogWriter.INFO);
		} catch (SQLException e) {
			log.log("按定单号查找定单信息查找失败", LogWriter.ERROR);
			JOptionPane.showMessageDialog(null, "按定单号查找定单信息查找异常:"
					+ e.getMessage());
			// e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}
		return vo;
	}

	public VipVo getVipInfoByVipId(int vipId) throws DbException {
		VipVo vo = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_VIOINFO_BY_VIPID);
			pstmt.setInt(1, vipId);
			set = pstmt.executeQuery();
			while (set.next()) {
				VipCardVo vipCard = this.getVipCardBycard(vipId);
				String vipName = set.getString("vip_name");
				String vipSex = set.getString("vip_sex");
				String vipBirthday = set.getString("vip_birthday").substring(0,
						10);
				String vipPhone = set.getString("vip_phone");
				String vipAddress = set.getString("vip_address");
				vo = new VipVo(vipCard, vipName, vipSex, vipBirthday, vipPhone,
						vipAddress);
			}
			if (vo == null) {
				JOptionPane.showMessageDialog(null, "数据库中不存在与" + vipId
						+ "有关的会员信息!");
				// throw new DbException("数据库中不存在与"+vipId+"有关的会员信息!");
			}
			log.log("按定会员编号查找会员信息查找成功", LogWriter.INFO);
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "通过会员编号查找会员信息异常:"+e.getMessage());
			log.log("按定会员编号查找会员信息查找失败", LogWriter.ERROR);
			// e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}
		return vo;
	}

	public VipConsumeVo getVipConsumeInfoByOrderId(long orderId)
			throws DbException {
		VipConsumeVo vo = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_VIPCONSUMEINFO_BY_ORDERID);
			pstmt.setLong(1, orderId);
			set = pstmt.executeQuery();
			while (set.next()) {
				int vipId = set.getInt("vip_id");
				String consumeDate = set.getString("consume_date").substring(0,
						10);
				double neededAmount = set.getDouble("needed_amount");
				double receiveAmount = set.getDouble("received_amount");
				double reducedAmount = set.getDouble("reduced_amount");
				vo = new VipConsumeVo(orderId, vipId, consumeDate,
						neededAmount, receiveAmount, reducedAmount);
			}
			if (vo == null) {
				// throw new DbException("数据库中不存在要找的项");
				JOptionPane.showMessageDialog(null, "数据库中不存在与" + orderId
						+ "相关的记录");
			}
			log.log("按定单号查找会员消费信息查找成功", LogWriter.INFO);
		} catch (SQLException e) {
			log.log("按定单号查找会员消费信息查找失败", LogWriter.ERROR);
			JOptionPane.showMessageDialog(null, e.getMessage());
//			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}
		return vo;
	}

	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(DbSql.GET_ORDERITEMINFO_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("数据库中没有要找的内容");
				JOptionPane.showMessageDialog(null, "数据库中不存在与"+orderId+"相关的记录");
			}
			// log.log("按定单号查找定单项的信息成功", LogWriter.ERROR);
		} catch (SQLException e) {
			log.log("按定单号查找定单项的信息失败", LogWriter.ERROR);
			JOptionPane.showMessageDialog(null, "OrderItem查找dao异常"+e.getMessage());			
		} 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(DbSql.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时表示按照会员卡打折
				String operator = set.getString("operator_name");
				String addDate = set.getString("add_date");
				vo = new ClothesTypeVo(clothesId, clothesName, service, price,
						lowestDiscount, operator, addDate);
			}
			// log.log("按衣服编号查找衣服的类型成功", LogWriter.INFO);
			if (vo == null) {
				JOptionPane.showMessageDialog(null, "数据库中没有与"+clothesId+"相关的衣服类型!");
//				throw new DbException("数据库中不存在要找的项");
			}

		} catch (SQLException e) {
			log.log("按衣服编号查找衣服的类型失败", LogWriter.INFO);
			JOptionPane.showMessageDialog(null, "按衣服编号查找衣服的类型异常:"+ e.getMessage());
//			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}
		return vo;
	}

	public double getDiscountByVipId(int vipId) throws DbException {
		double discount = 1;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_DISCOUNT_BY_VIPID);
			pstmt.setInt(1, vipId);
			set = pstmt.executeQuery();
			while (set.next()) {
				discount = set.getDouble("vip_discount");
			}
			log.log("按会员编号查找折扣成功", LogWriter.INFO);
		} catch (SQLException e) {
			log.log("按会员编号查找折扣失败", LogWriter.INFO);
			JOptionPane.showMessageDialog(null, "按会员编号查找折扣异常:"+ e.getMessage());
//			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}
		return discount;
	}

	public int getVipIdByOrderId(long orderId) throws DbException {
		int vipId = 0;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_VIPID_BY_ORDERID);
			pstmt.setLong(1, orderId);
			set = pstmt.executeQuery();
			while (set.next()) {
				vipId = set.getInt("vip_id");
			}
			log.log("按定单号查找会员编号成功", LogWriter.INFO);
		} catch (SQLException e) {
			log.log("按定单号查找会员编号失败", LogWriter.INFO);
			JOptionPane.showMessageDialog(null, "按定单号查找会员编号异常"+e.getMessage());
//			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}

		return vipId;
	}

	public VipCardVo getVipCardBycard(int vipId) throws DbException {
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet set = null;
		VipCardVo vipCardVo = null;
		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(DbSql.GET_VIPCARDVO_BY_ID);
			pstmt.setInt(1, vipId);
			set = pstmt.executeQuery();
			while (set.next()) {
				int cardId = set.getInt("card_id");
				String vipPsw = set.getString("vip_pwd");
				String registDate = set.getString("regist_date").substring(0,
						10);
				String vipLevel = set.getString("vip_level");
				double restMoney = set.getDouble("rest_money");
				int points = set.getInt("vip_point");
				String cardState = set.getString("card_state");
				vipCardVo = new VipCardVo(cardId, vipId, vipPsw, registDate,
						vipLevel, restMoney, points, cardState);
			}
			if (vipCardVo == null) {
				// throw new DbException("数据库中没有卡号为" + vipId + "的账号");
				JOptionPane.showMessageDialog(null, "数据库中不存在与"+vipId+"有关的会员卡信息!");
			}
			log.log("按定员编号查找会员卡信息成功", LogWriter.INFO);
		} catch (SQLException e) {
			log.log("按定员编号查找会员卡信息失败", LogWriter.INFO);
			JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
					JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return vipCardVo;
	}

}

⌨️ 快捷键说明

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