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

📄 consumerecordoperate.java

📁 JAVA实现的酒店管理系统
💻 JAVA
字号:
package file1;

/*
 * Description:调用ConsumeRecord类,根据ConsumeRecord类的属性值存取数据库
 * @Author:黄顺武
 * Create Time:2007-12-22
 */
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import sun.jdbc.rowset.CachedRowSet;

public class ConsumeRecordOperate implements Operate {

	public ConsumeRecordOperate() {
	}

	public void insertToDB(Object object) {// 插入吧台消费记录时调用的方法
		ConsumeRecord consume_record = (ConsumeRecord) object;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer(
					"insert into ConsumeRecord values(");
			if (consume_record.getConsumerID() == -1) {
				JOptionPane.showMessageDialog(null, "消费客户不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getConsumeItemID() == -1) {
				JOptionPane.showMessageDialog(null, "消费项目不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getMoneyConsumed() == -1) {
				JOptionPane.showMessageDialog(null, "消费金额不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getTimeConsumed().equals("")) {
				JOptionPane.showMessageDialog(null, "消费时间不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			sqlSB.append(consume_record.getConsumerID()).append(",");
			sqlSB.append(consume_record.getConsumeItemID()).append(",");
			sqlSB.append(consume_record.getMoneyConsumed()).append(",'");
			sqlSB.append(consume_record.getTimeConsumed()).append("')");
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public void deleteFromDB(Object object) {// 删除吧台消费记录时调用的方法
		ConsumeRecord consume_record = (ConsumeRecord) object;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer(
					"delete from  ConsumeRecord where ");
			if (consume_record.getID() == -1) {
				JOptionPane.showMessageDialog(null, "要删除的吧台消费记录不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			sqlSB.append("id=").append(consume_record.getID());
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public void modifyToDB(Object object) {// 修改吧台消费记录时调用的方法
		ConsumeRecord consume_record = (ConsumeRecord) object;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer("update ConsumeRecord set ");
			if (consume_record.getID() == -1) {
				JOptionPane.showMessageDialog(null, "要更新的吧台消费记录不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getConsumerID() == -1) {
				JOptionPane.showMessageDialog(null, "消费客户不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getConsumeItemID() == -1) {
				JOptionPane.showMessageDialog(null, "消费项目不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getMoneyConsumed() == -1) {
				JOptionPane.showMessageDialog(null, "消费金额不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_record.getTimeConsumed().equals("")) {
				JOptionPane.showMessageDialog(null, "消费时间不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			sqlSB.append("consumerID=").append(consume_record.getConsumerID())
					.append(",");
			sqlSB.append("ConsumeItemID=").append(
					consume_record.getConsumeItemID()).append(",");
			sqlSB.append("MoneyConsumed=").append(
					consume_record.getMoneyConsumed()).append(",");
			sqlSB.append("TimeConsumed=").append(
					consume_record.getTimeConsumed());
			sqlSB.append(" where id=").append(consume_record.getID());
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public ArrayList selectFromDB(Object object) {// 查询吧台消费记录时调用的方法

		ConsumeRecord consume_record = (ConsumeRecord) object;
		if (consume_record.getID() == -1) {
			JOptionPane.showMessageDialog(null, "要查询的吧台消费记录id不能为空!", "",
					JOptionPane.INFORMATION_MESSAGE);
			return null;
		}
		ArrayList valuesList = new ArrayList();
		CachedRowSet crs = null;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer("");
			if (consume_record.getID() == 0) {// 表示查询数据库中的全部吧台消费记录,传参数的时候一定要注意
				sqlSB.append("select* from ConsumeRecord ");
			}
			if (consume_record.getID() != -1 && consume_record.getID() != 0) {// 表示查询数据库中的某一吧台消费记录,传参数的时候一定要注意
				sqlSB.append("select* from ConsumeRecord where ID="
						+ consume_record.getID());
			}
			crs = con.getResultSet(sqlSB.toString());
			while (crs.next()) {
				ConsumeRecord consumeRecord = new ConsumeRecord();
				consumeRecord.setID(crs.getInt(1));
				consumeRecord.setConsumerID(crs.getInt(2));
				consumeRecord.setConsumeItemID(crs.getInt(3));
				consumeRecord.setMoneyConsumed(crs.getFloat(4));
				consumeRecord.setTimeConsumed(crs.getString(5));
				valuesList.add( consumeRecord);
			}
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
		return valuesList;
	}
}

⌨️ 快捷键说明

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