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

📄 vipdaoimpl.java

📁 一个优秀的干洗店管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}

	/**
	 * 判断输入的数据Id是否在数据库中已经存在
	 * 
	 * @param con
	 *            从调用函数那里传递过来的数据库连接对象
	 * @param vipId
	 *            传递过来的会员Id
	 * @return boolean true 存在相同编号的雇员 false 不存在相同编号
	 */
	public boolean VipIdExists(Connection con, int vipId) {
		PreparedStatement pstmt = null;
		ResultSet set = null;
		try {
			pstmt = con.prepareStatement(VipSql.SEARCH_BY_VIP_ID);
			pstmt.setInt(1, vipId);
			set = pstmt.executeQuery();
			if (set.next()) {
				return true;
			}
		} catch (SQLException e) {
			System.out.println("雇员确定查询dao异常:= " + e.getMessage());
		} finally {
			manager.freeConnection("oracle", con);
		}
		return false;
	}

	/**
	 * 通过接收的VipVo的值,获取其Id,修改对应Id的数据库表中的数据,采用了合并事务管理
	 */
	public boolean updateVipInfo(VipVo value) {
		boolean flag = false;
		PreparedStatement pstmt1 = null;
		PreparedStatement pstmt2 = null;
		Connection con = null;
		try {
			con = manager.getConnection("oracle");
			con.setAutoCommit(false);
			pstmt1 = con.prepareStatement(VipSql.UPDATE_VIP_BY_ID);
			pstmt1.setString(1, value.getVipSex());
			pstmt1.setString(2, value.getVipPhone());
			pstmt1.setString(3, value.getVipAddress());
			pstmt1.setInt(4, value.getVipCard().getVipId());
			int count1 = pstmt1.executeUpdate();

			pstmt2 = con.prepareStatement(VipSql.UPDATE_CARD_BY_ID);
			pstmt2.setString(1, value.getVipCard().getVipPsw());
			pstmt2.setInt(2, value.getVipCard().getVipId());
			int count2 = pstmt2.executeUpdate();
			if ((count1 != 0) && (count2 != 0)) {
				flag = true;
				con.commit(); // 当两个更新的结果都不为零时,说明整个事物进行顺利,此时提交结果
			} else {
				con.rollback(); // 如果两个过程没有同时成功,则回滚
			}
			con.setAutoCommit(true); // 将自动提交设置回来
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(
					null,"会员信息修改异常:= " + e.getMessage(),"提示",JOptionPane.YES_OPTION);
		} finally {
			manager.freeConnection("oracle", con);
		}
		return flag;

		/*
		 * pstmt1 = con.prepareStatement(VipSql.UPDATE_VIP_BY_ID);
		 * pstmt1.setInt(1, value.getVipCard().getVipId()); pstmt1.setString(2,
		 * value.getVipName()); pstmt1.setString(3, value.getVipSex());
		 * pstmt1.setString(4, value.getVipBirthday()); pstmt1.setString(5,
		 * value.getVipPhone()); pstmt1.setString(6, value.getVipAddress());
		 * pstmt1.setInt(7, value.getVipCard().getVipId()); int count1 =
		 * pstmt1.executeUpdate();
		 */

		/*
		 * pstmt2 = con.prepareStatement(VipSql.UPDATE_CARD_BY_ID);
		 * pstmt2.setInt(1, value.getVipCard().getVipId()); pstmt2.setInt(2,
		 * getNewCardId()); pstmt2.setString(3, value.getVipCard().getVipPsw());
		 * pstmt2.setString(4, value.getVipCard().getRegistDate());
		 * pstmt2.setString(5, value.getVipCard().getVipLevel());
		 * pstmt2.setDouble(6, value.getVipCard().getRestMoney());
		 * pstmt2.setInt(7, value.getVipCard().getPoints()); pstmt2.setString(8,
		 * value.getVipCard().getCardState()); pstmt2.setInt(9,
		 * value.getVipCard().getVipId()); int count2 = pstmt2.executeUpdate();
		 */

		/**
		 * update vip set vip_id = ?, vip_name = ?, vip_sex = ?, vip_birthday =
		 * to_date(?, 'yyyy-MM-dd'), vip_phone = ?, vip_address = ? where vip_id
		 * = ?;
		 * 
		 * update vip_card set vip_id = ?, vip_pwd = ?, regist_date =
		 * to_date(?,'yyyy-MM-dd'), vip_level = ?, rest_money = ?, vip_point =
		 * ?, card_state = ? where vip_id = ?;
		 */
	}

	/**
	 * 更新充值的记录,包括更新账户余额,插入更新记录到充值记录表
	 */
	public boolean rechargeUpdate(double restMoney, VipChargeVo value, int vipId) {

		Connection con = null;
		PreparedStatement pstmt1 = null;
		PreparedStatement pstmt2 = null;
		boolean flag = false;
		try {
			con = manager.getConnection("oracle");
			con.setAutoCommit(false);

			pstmt1 = con.prepareStatement(VipSql.UPDATE_RESTMONEY_BY_ID);
			pstmt1.setDouble(1, restMoney);
			pstmt1.setInt(2, vipId);
			int count1 = pstmt1.executeUpdate();

			pstmt2 = con.prepareStatement(VipSql.INSERT_RECHARGE_RECORD);
			pstmt2.setInt(1, vipId);

			pstmt2.setString(2, value.getChargeDate());
			pstmt2.setDouble(3, value.getChargeAmount());
			pstmt2.setDouble(4, value.getReceiveAmount());
			pstmt2.setString(5, value.getOperatorName());
			int count2 = pstmt2.executeUpdate();

			if (count1 != 0 && count2 != 0) {
				flag = true;
				con.commit();
				con.setAutoCommit(true);
			}
		} catch (SQLException e) {

			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}

		return flag;
	}

	public int getNewCardId() {
		int currentCardId = 0;
		Connection con = manager.getConnection("oracle");
		Statement stmt = null;
		ResultSet set = null;

		try {
			stmt = con.createStatement();
			set = stmt.executeQuery(VipSql.MAX_CARD_ID);
			while (set.next()) {
				currentCardId = set.getInt("MAX(CARD_ID)") + 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}

		return currentCardId;
	}

	public boolean updateVipCard(String newPassword, int vipId) {
		Connection con = null;
		PreparedStatement pstmt1 = null;
		boolean flag = false;
		try {
			con = manager.getConnection("oracle");
			pstmt1 = con.prepareStatement(VipSql.CHANGE_VIP_CARD_ID);
			pstmt1.setInt(1, getNewCardId());
			pstmt1.setString(2, newPassword);
			pstmt1.setInt(3, vipId);

			int count1 = pstmt1.executeUpdate();

			if (count1 != 0) {
				flag = true;
			}
		} catch (SQLException e) {

			e.printStackTrace();
		}

		return flag;
	}

	public Vector<VipChargeVo> getRechargeRecord(String sql, int vipId) {
		Vector<VipChargeVo> vector = null;
		PreparedStatement pstmt = null;
		Connection con = null;
		ResultSet set = null;

		try {
			con = manager.getConnection("oracle");
			pstmt = con.prepareStatement(sql);
			pstmt.setInt(1, vipId);
			set = pstmt.executeQuery();

			vector = new Vector<VipChargeVo>();
			while (set.next()) {
				String chargeDate = set.getString("CHARGE_DATE");
				int chargeAmount = set.getInt("CHARGE_AMOUNT");
				int receiveAmount = set.getInt("RECEIVE_AMOUNT");
				String operatorName = set.getString("OPERATOR_NAME");
				vector.add(new VipChargeVo(vipId, chargeDate, chargeAmount,
						receiveAmount, operatorName));
			}
		} catch (NumberFormatException e) {

			e.printStackTrace();
		} catch (SQLException e) {

			e.printStackTrace();
		}

		manager.freeConnection("oracle", con);
		return vector;
	}

	public int getNewVipId() {
		int currentVipId = 0;
		Connection con = manager.getConnection("oracle");
		Statement stmt = null;
		ResultSet set = null;
		try {
			stmt = con.createStatement();
			set = stmt.executeQuery(VipSql.MAX_VIP_ID);
			while (set.next()) {
				currentVipId = set.getInt("MAX(VIP_ID)") + 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			manager.freeConnection("oracle", con);
		}

		return currentVipId;
	}

}

⌨️ 快捷键说明

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