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

📄 goodoperate.java

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

import sun.jdbc.rowset.*;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/*
 * 功能描述:实现对货品记录的封装,供货品操作类的调用
 * @Author:黄顺武
 * Create Time:2007-12-11
 * Version:1.3
 */
public class GoodOperate implements Operate {

	public GoodOperate() {
	}

	public void insertToDB(Object object) {// 增加货品记录时调用的方法
		Good good = (Good) object;
		StringBuffer sqlSB = new StringBuffer("insert into Good values('");
		sqlSB.append(good.getGoodName()).append("',").append(good.getTypeID())
				.append(",").append(good.getStoreIn()).append(",");
		sqlSB.append(good.getSinglePriceIn()).append(",").append(
				good.getSinglePriceOut()).append(",");
		sqlSB.append(good.getStoreInLimit()).append(")");
		try {
			DBConnection con = new DBConnection();
			String sqlStr = "select* from Good where goodName='"
					+ good.getGoodName() + "' and typeID=" + good.getTypeID();
			CachedRowSet crs = con.getResultSet(sqlStr);
			if (crs.next()) {// 相同记录已经存在
				JOptionPane.showMessageDialog(null, "已经存在相同的记录!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public void deleteFromDB(Object object) {// 删除货品记录时调用的方法
		Good good = (Good) object;
		String sqlStr = "delete from Good where ID=" + good.getID();
		try {

			DBConnection con = new DBConnection();
			con.addSql(sqlStr);
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public void modifyToDB(Object object) {// 修改货品记录时调用的方法
		Good good = (Good) object;
		StringBuffer sqlSB = new StringBuffer("update  Good set ");
		sqlSB.append("goodName='").append(good.getGoodName()).append(
				"',typeID=").append(good.getTypeID()).append(",storeIn=")
				.append(good.getStoreIn()).append(",singlePriceIn=");
		sqlSB.append(good.getSinglePriceIn()).append(",singlePriceOut=")
				.append(good.getSinglePriceOut()).append(",storeInLimit=");
		sqlSB.append(good.getStoreInLimit()).append(" where id=").append(
				good.getID());
		try {
			DBConnection con = new DBConnection();
			con.addSql(sqlSB.toString());
			con.doDML();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

	public ArrayList selectFromDB(Object object) {// 查询货品记录时调用的方法
		Good good = (Good) object;
		ArrayList valuesList = new ArrayList();
		StringBuffer sqlSB = new StringBuffer("");
		CachedRowSet crs = null;
		if (good.getID() == 0) {// 表示查询数据库中的全部货品记录,传参数的时候一定要注意
			sqlSB
					.append("select Good.ID,goodName,typeID,storeIn,singlePriceIn,singlePriceOut,storeInLimit,typeName from Good,GoodType where Good.typeID=GoodType.ID order by Good.ID asc");
		}
		if (good.getID() != -1 && good.getID() != 0) {// 表示查询数据库中的某一货品记录,传参数的时候一定要注意
			sqlSB
					.append("select Good.ID,goodName,typeID,storeIn,singlePriceIn,singlePriceOut,storeInLimit,typeName from Good,GoodType where Good.typeID=GoodType.ID and Good.ID="
							+ good.getID());
		}
		if (good.getID() == -1 && good.getTypeID() != -1) {// 表示查询数据库中的某一类型的货品记录,传参数的时候一定要注意
			sqlSB
					.append("select Good.ID,goodName,typeID,storeIn,singlePriceIn,singlePriceOut,storeInLimit,typeName from Good,GoodType where Good.typeID=GoodType.ID and Good.typeID="
							+ good.getTypeID());
		}
		if (good.getProperty("strQuery") != null) {// 表示查询数据库中符合指定条件的货品记录,传参数的时候一定要注意
			sqlSB.append(good.getProperty("strQuery"));
		}
		try {
			DBConnection con = new DBConnection();
			crs = con.getResultSet(sqlSB.toString());
			crs.beforeFirst();
			while (crs.next()) {
				Good newGoodInstance = new Good();
				newGoodInstance.setID(crs.getInt(1));
				newGoodInstance.setGoodName(crs.getString(2).trim());
				newGoodInstance.setTypeID(crs.getInt(3));
				newGoodInstance.setStoreIn(crs.getInt(4));
				newGoodInstance.setSinglePriceIn(crs.getFloat(5));
				newGoodInstance.setSinglePriceOut(crs.getFloat(6));
				newGoodInstance.setStoreInLimit(crs.getInt(7));
				newGoodInstance
						.setProperty("typeName", crs.getString(8).trim());
				valuesList.add(newGoodInstance);
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		}
		return valuesList;
	}
}

⌨️ 快捷键说明

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