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

📄 consumeitemgoodtypeoperate.java

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

/*
 * Description:调用ConsumeItemGoodType类,实现对消费项目和对应货品类型记录的操作的面向对象性
 * @Author:黄顺武
 * Create Time:2007-12-21
 */
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import sun.jdbc.rowset.CachedRowSet;

public class ConsumeItemGoodTypeOperate implements Operate {

	public ConsumeItemGoodTypeOperate() {
	}

	public void insertToDB(Object object) {// 往数据库中插入消费项目和对应货品类型记录时调用的方法
		ConsumeItemGoodType consume_item_good_type = (ConsumeItemGoodType) object;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer(
					"insert into ConsumeItem_GoodType values(");
			if (consume_item_good_type.getConsume_Item_ID() == -1) {
				JOptionPane.showMessageDialog(null, "消费项目不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_item_good_type.getGood_Type_ID() == -1) {
				JOptionPane.showMessageDialog(null, "消费项目所对应的货品类型不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			sqlSB.append(consume_item_good_type.getConsume_Item_ID()).append(
					",");
			sqlSB.append(consume_item_good_type.getGood_Type_ID()).append(")");
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public void deleteFromDB(Object object) {// 从数据库中删除消费项目和对应货品类型记录时调用的方法
		ConsumeItemGoodType consume_item_good_type = (ConsumeItemGoodType) object;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer(
					"delete from ConsumeItem_GoodType where ConsumeItemID=");
			if (consume_item_good_type.getConsume_Item_ID() == -1) {
				JOptionPane.showMessageDialog(null, "要删除的消费项目不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_item_good_type.getGood_Type_ID() == -1) {
				JOptionPane.showMessageDialog(null, "要删除的消费项目所对应的货品类型不能为空!",
						"", JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			sqlSB.append(consume_item_good_type.getConsume_Item_ID()).append(
					" and GoodTypeID=");
			sqlSB.append(consume_item_good_type.getGood_Type_ID());
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public void modifyToDB(Object object) {// 修改消费项目和对应货品类型记录时调用的方法
		ConsumeItemGoodType consume_item_good_type = (ConsumeItemGoodType) object;
		try {
			DBConnection con = new DBConnection();
			StringBuffer sqlSB = new StringBuffer(
					"update ConsumeItem_GoodType set ");
			if (consume_item_good_type.getConsume_Item_ID() == -1) {
				JOptionPane.showMessageDialog(null, "要更新的消费项目不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			if (consume_item_good_type.getGood_Type_ID() == -1) {
				JOptionPane.showMessageDialog(null, "要更新的消费项目所对应的货品类型不能为空!",
						"", JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			sqlSB.append("GoodTypeID=").append(
					consume_item_good_type.getGood_Type_ID());
			sqlSB.append(" where ConsumeItemID=").append(
					consume_item_good_type.getConsume_Item_ID());
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public ArrayList selectFromDB(Object object) {// 查询消费项目和对应货品类型记录时调用的方法
		ConsumeItemGoodType consume_item_good_type = (ConsumeItemGoodType) object;
		if (consume_item_good_type.getConsume_Item_ID() == -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_item_good_type.getConsume_Item_ID() == 0) {// 表示查询数据库中的全部消费项目和对应货品类型记录,传参数的时候一定要注意
				sqlSB.append("select* from ConsumeItem_GoodType ");
			}
			if (consume_item_good_type.getConsume_Item_ID() != -1
					&& consume_item_good_type.getConsume_Item_ID() != 0) {// 表示查询数据库中的某一消费项目,传参数的时候一定要注意
				sqlSB
						.append("select* from ConsumeItem_GoodType where ConsumeItemID="
								+ consume_item_good_type.getConsume_Item_ID());
			}
			crs = con.getResultSet(sqlSB.toString());
			while (crs.next()) {
				ConsumeItemGoodType consumeitem_goodtype = new ConsumeItemGoodType();
				consumeitem_goodtype.setConsume_Item_ID(crs.getInt(1));
				consumeitem_goodtype.setGood_Type_ID(crs.getInt(2));
				valuesList.add(consumeitem_goodtype);
			}
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
		return valuesList;
	}
}

⌨️ 快捷键说明

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