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

📄 housebookanduse.java

📁 JAVA实现的酒店管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if (e.getActionCommand().equals("修改记录")) {
				buttonsSet();
				autoResearch.setEnabled(false);
				id = common();
				if (id == null) {
					return;
				}
				modify.setText("确认修改");
				return;
			}
			if (e.getActionCommand().equals("确认修改")) {
				int hGradeIndex = hGradeBox.getSelectedIndex();
				if (hGradeIndex == -1) {
					JOptionPane.showMessageDialog(null, "客房级别不能为空!", "提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				String hGrade = (String) hGradeBox.getSelectedItem();
				String hNum = hNumTF.getText();
				int numOfH;
				try {
					numOfH = Integer.valueOf(hNum);
					if (numOfH <= 0) {
						JOptionPane.showMessageDialog(null, "订房数量必须为正整数!",
								"提示", JOptionPane.INFORMATION_MESSAGE);
						return;
					}
				} catch (NumberFormatException nfe) {
					JOptionPane.showMessageDialog(null, "订房数量必须为正整数!", "提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				String checkIn = dateGet.getDate(checkInTF.getText());
				if (checkIn == null) {
					JOptionPane.showMessageDialog(null,
							"入住日期输入有误,必须为如2007-09-08的格式!", "提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				String checkOut = dateGet.getDate(checkOutTF.getText());
				if (checkOut == null) {
					JOptionPane.showMessageDialog(null,
							"退房日期输入有误,必须为如2007-09-08的格式!", "提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				int index = stateBox.getSelectedIndex();
				if (index == -1) {
					JOptionPane.showMessageDialog(null, "状态不能为空!", "提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				String state = (String) stateBox.getSelectedItem();
				String update = null;
				DBConnection con = new DBConnection();
				if (numOfH == num && hGrade.equals(hG)) {
					update = "update HUseBook set dateIn='" + checkIn
							+ "',dateOut='" + checkOut + "',consume=0,state='"
							+ state + "' where ID=" + Integer.valueOf(id);
					con.addSql(update);
					try {
						con.doDML();
					} catch (SQLException sqle) {
						sqle.printStackTrace();
					} catch (ClassNotFoundException cnfe) {
						cnfe.printStackTrace();
					}
				} else {
					String addStr = null;
					if (hNo.contains(",")) {
						StringTokenizer st = new StringTokenizer(hNo, ",");
						while (st.hasMoreTokens()) {
							String noGet = st.nextToken();
							if (noGet != null) {
								addStr = "update House set state='是' where HouseNo='"
										+ noGet + "'";
								con.addSql(addStr);
							}
						}
					} else {
						addStr = "update House set state='是' where HouseNo='"
								+ hNo + "'";
						con.addSql(addStr);
					}
					String indicate = research();
					if (indicate == null) {
						return;
					}
					String reAutoHNo = autoHNoTF.getText();
					update = "update HUseBook set bookNum=" + numOfH + ",hNo='"
							+ reAutoHNo + "',dateIn='" + checkIn
							+ "',dateOut='" + checkOut + "',consume=0,state='"
							+ state + "' where ID=" + Integer.valueOf(id);
					con.addSql(update);
					if (reAutoHNo.contains(",")) {
						StringTokenizer st = new StringTokenizer(reAutoHNo, ",");
						while (st.hasMoreTokens()) {
							String noGet = st.nextToken();
							if (noGet != null) {
								addStr = "update House set state='否' where HouseNo='"
										+ noGet + "'";
								con.addSql(addStr);
							}
						}
					} else {
						addStr = "update House set state='否' where HouseNo='"
								+ reAutoHNo + "'";
						con.addSql(addStr);
					}
					try {
						con.doDML();
					} catch (SQLException sqle) {
						sqle.printStackTrace();
					} catch (ClassNotFoundException cnfe) {
						cnfe.printStackTrace();
					}
				}
				String returnValue = doIt();
				if (returnValue == null) {
					return;
				}
				buttonsSet();
				if (!autoResearch.isEnabled()) {
					autoResearch.setEnabled(true);
				}
				modify.setText("修改记录");
			}
		}
		if (e.getSource() == delete) {
			if (modify.getText().equals("确认修改")) {
				modify.setText("修改记录");
			}
			buttonsSet();
			if (!autoResearch.isEnabled()) {
				autoResearch.setEnabled(true);
			}
			try {
				id = common();
				if (id == null) {
					return;
				}
				int confirm = JOptionPane.showConfirmDialog(null, "您真的确认删除吗?",
						"", JOptionPane.YES_NO_OPTION);
				if (confirm == -1 || confirm == JOptionPane.NO_OPTION) {
					return;
				}
				DBConnection con = new DBConnection();
				String query = "select hNo from HUseBook where ID=" + id;
				CachedRowSet crs = con.getResultSet(query);
				String houseNo = null;
				if (crs.next()) {
					houseNo = crs.getString(1);
				}
				String delete = "delete from HUseBook where ID=" + id;
				con.addSql(delete);
				String update = null;
				String today = dateGet.getDate(format
						.valueConverted(new Date()));
				if (!houseNo.contains(",")) {
					update = "update House set state='是',beginUseable='"
							+ today + "' where HouseNo='" + houseNo + "'";
					con.addSql(update);
				} else {
					StringTokenizer st = new StringTokenizer(houseNo, ",");
					while (st.hasMoreTokens()) {
						String sHNo = st.nextToken();
						if (sHNo != null && !sHNo.equals("")) {
							update = "update House set state='是',beginUseable='"
									+ today + "' where HouseNo='" + sHNo + "'";
							con.addSql(update);
						}
					}
				}
				con.doDML();
				String returnValue = doIt();
				if (returnValue == null) {
					return;
				}
			} catch (SQLException sqle) {
				sqle.printStackTrace();
			} catch (ClassNotFoundException cnfe) {
				cnfe.printStackTrace();
			}
			buttonsSet();// 重新把按钮置为可用状态
		}
	}

	public void itemStateChanged(ItemEvent e) {
		if (e.getSource() == cGradeBox) {
			if (e.getStateChange() == ItemEvent.SELECTED) {
				int index = cGradeBox.getSelectedIndex();
				if (index != -1) {
					String cGrade = (String) cGradeBox.getSelectedItem();
					String query = "select firstPayPercent from CGrade where grade='"
							+ cGrade + "'";
					CachedRowSet crs = null;
					try {
						DBConnection con = new DBConnection();
						crs = con.getResultSet(query);
						if (crs.next()) {
							typeTF.setText(String.valueOf(crs.getFloat(1)));
							typeTF.setEditable(false);
						}
					} catch (SQLException sqle) {
						sqle.printStackTrace();
					} catch (ClassNotFoundException cnfe) {
						cnfe.printStackTrace();
					}
				}
			}
		}
	}

	private String research() {
		try {
			int houseGradeIndex = hGradeBox.getSelectedIndex();
			if (houseGradeIndex == -1) {
				JOptionPane.showMessageDialog(null, "客房级别不能为空!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			String hGrade = (String) hGradeBox.getSelectedItem();
			int numOfHouse;
			try {
				numOfHouse = Integer.valueOf(hNumTF.getText());
				if (numOfHouse <= 0) {
					JOptionPane.showMessageDialog(null, "订房数量必须为正整数!", "提示",
							JOptionPane.INFORMATION_MESSAGE);
					return null;
				}
			} catch (NumberFormatException nfe) {
				JOptionPane.showMessageDialog(null, "订房数量必须为正整数!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			DBConnection con = new DBConnection();
			String query = "select count(*) from House where hGrade='" + hGrade
					+ "' and state='是'";
			CachedRowSet crs = con.getResultSet(query);
			int count = 0;
			while (crs.next()) {
				count = crs.getInt(1);
			}
			if (count == 0) {
				JOptionPane.showMessageDialog(null, "目前没有该级别的可用房间!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			if (count != 0 && count < numOfHouse) {
				JOptionPane.showMessageDialog(null, "可供客房数量不够,目前该级别的可用房间数为:"
						+ count + "!", "提示", JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			crs = null;
			StringBuffer sb = new StringBuffer();
			query = "select top " + numOfHouse
					+ " HouseNo, beginUseable from House where hGrade='"
					+ hGrade + "' and state='是' order by beginUseable asc";
			crs = con.getResultSet(query);
			count = 0;
			if (numOfHouse == 1) {
				while (crs.next()) {
					sb.append(crs.getString(1));
				}
			} else {
				while (crs.next()) {
					count++;
					if (count == numOfHouse) {
						sb.append(crs.getString(1));
					} else {
						sb.append(crs.getString(1) + ",");
					}
				}
			}
			String sbStr = sb.toString();
			autoHNoTF.setText(sbStr);
			crs = null;
			query = "select Sprice from HGrade where grade='" + hGrade + "'";
			crs = con.getResultSet(query);
			String checkIn = dateGet.getDate(checkInTF.getText());
			if (checkIn == null) {
				JOptionPane.showMessageDialog(null, "入住日期输入有误!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			String checkOut = dateGet.getDate(checkOutTF.getText());
			if (checkOut == null) {
				JOptionPane.showMessageDialog(null, "退房日期输入有误!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			String inAfterAdded = null;
			int dayNum = 1;
			for (;; dayNum++) {
				inAfterAdded = addDay.addDays(checkIn, dayNum);
				if (inAfterAdded.equals(checkOut)) {
					break;
				}
			}
			float money1 = 0;
			while (crs.next()) {
				money1 = crs.getFloat(1) * numOfHouse * dayNum;
			}
			crs = null;
			int cGradeIndex = cGradeBox.getSelectedIndex();
			if (cGradeIndex == -1) {
				JOptionPane.showMessageDialog(null, "客户级别不能为空!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			String type = typeTF.getText().trim();
			if (type.equals("")) {
				JOptionPane.showMessageDialog(null, "预付款比例不能为空!", "提示",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			float typeValue = Float.valueOf(type);
			query = "select standard from CGrade where id="
					+ cGrade_ids[cGradeIndex];
			crs = con.getResultSet(query);
			float money2 = 0;
			while (crs.next()) {
				money2 = money1 * crs.getFloat(1);
			}
			float total = money2 * typeValue;
			firstPayTF.setText(String.valueOf(total));
			firstPayTF.setEditable(false);
			nameTF.setEditable(false);
			typeTF.setEditable(false);
			autoHNoTF.setEditable(false);
			checkInTF.setEditable(false);
			checkOutTF.setEditable(false);
			hNumTF.setEditable(false);
			autoResearch.setEnabled(false);
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		}
		return "success";
	}

	private String common() {
		String id = (String) JOptionPane.showInputDialog(null,
				"请选择要删除或修改的记录ID!", "", JOptionPane.INFORMATION_MESSAGE, null,
				hUseAndBookID, hUseAndBookID[0]);
		if (id == null) {
			return null;
		}
		try {
			DBConnection con = new DBConnection();
			String query = "select cName,bookNum,hNo,hGrade,dateIn,dateOut,state,grade,firstPayPercent "
					+ "from HUseBook,Client,CGrade where HUseBook.ID="
					+ id
					+ " and rendererid=Client.id and Client.cGradeID=CGrade.ID ";
			CachedRowSet crs = con.getResultSet(query);
			if (crs.next()) {
				nameTF.setText(crs.getString(1));
				num = crs.getInt(2);
				hNo = crs.getString(3);
				String hgrade = crs.getString(4);
				String in = crs.getString(5);
				String out = crs.getString(6);
				String state = crs.getString(7);
				String cGrade = crs.getString(8);
				float firstPay = crs.getFloat(9);
				checkInTF.setText(in);
				checkOutTF.setText(out);
				stateBox.setSelectedItem(state);
				cGradeBox.setSelectedItem(cGrade);
				typeTF.setText(String.valueOf(firstPay));
				nameTF.setEditable(false);
				hNumTF.setText(String.valueOf(num));
				autoHNoTF.setText(hNo);
				hGradeBox.setSelectedItem(hgrade);
				typeTF.setEditable(false);
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		}
		return id;
	}

	private void buttonsSet() {
		firstPayTF.setEditable(false);
		nameTF.setEditable(true);
		typeTF.setEditable(true);
		autoHNoTF.setEditable(true);
		checkInTF.setEditable(true);
		checkOutTF.setEditable(true);
		hNumTF.setEditable(true);
	}
}

⌨️ 快捷键说明

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