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

📄 inventory.java

📁 一个货物管理系
💻 JAVA
字号:
package good;

import java.sql.ResultSet;

import javax.swing.JOptionPane;

public class Inventory extends SortedList {
	//存货清单构造函数
   private String goodId;
   private String employeeId;
   private int number;
   private String supplyName;
   private double InPrice;
   private String date;
	
	public int getNumber() {
	return number;
   }

public void setNumber(int number) {
	this.number = number;
}

	public Inventory(int maxItem) {
		super(maxItem, new ItemComparer());	
		String quy;
		DataConn storCon = new DataConn();
		String addSql = null;
		ResultSet rs = null;
		storCon.dataConnDerectForMySql();
		String goodId,goodName;
		String imanufname;
		String employeeid;
		double price;
		int number;
		quy = "select * from goods " ;
		     
		try {
			rs = storCon.executeDerectQuery(quy);
			while (rs.next())
			{
				goodId=rs.getString("goodId");
				goodName=rs.getString("goodName");
				price=rs.getDouble("goodPrice");
				number=rs.getInt("goodNumber");				
				add(new InventoryItem(goodId,goodName,price,number));			

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();

		}		
			
	}

	//根据用户输入的id,返回相应的存货条目,不存在的话,返回null
	public InventoryItem getPart(String _id) {
		int index = indexOf(new Item(_id));
		if (index >= 0)
			return (InventoryItem) get(index);
		else
			return null;
	}

	//在存货清单中,根据用户输入的id和用户输入的数量,增加相应货物的数量
	public void addUnits(String _id, int _number) {
		InventoryItem item = getPart(_id);
		if (item != null)
			item.add(_number);
		else
			JOptionPane.showMessageDialog(null, "没有找到和输入ID对应的项!", "警告",
					JOptionPane.ERROR_MESSAGE);
		
	}

	//在存货清单中,根据用户输入的id和用户输入的数量,减少相应货物的数量
	public void removeUnits(String _id, int _number) {
		InventoryItem item = getPart(_id);
		if ((item != null) && (item.units >= _number) && (_number >= 0))
			item.remove(_number);
		else
			JOptionPane.showMessageDialog(null, "没有找到和输入ID对应的项或空间不足!", "警告",
					JOptionPane.ERROR_MESSAGE);
	}
	public boolean InventoryAdd()
	{
		DataConn storCon = new DataConn();
		String addSql = null;
		storCon.dataConnDerectForMySql();
		//System.out.print(date);
		addSql="Insert into Inventory(goodId,employeeId,indate,supplyName,Innumber"+
		",InPrice)values('"+goodId+"','"+employeeId+"','"+date+"','"+supplyName+
		"',"+number+","+InPrice+")";
		System.out.println(addSql);
		storCon.executeDerectUpdate(addSql);
		//同时修改数量
		storCon.dataConnDerectForMySql();		
		addSql="update goods set goodNumber=goodNumber+"+Integer.toString(number)
		+"  where goodId='"+goodId+"'";	
		storCon.executeDerectUpdate(addSql);
		System.out.println(addSql);
		return true;
	}
	public String getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String getGoodId() {
		return goodId;
	}

	public void setGoodId(String goodId) {
		this.goodId = goodId;
	}
	



	

	public String getSupplyName() {
		return supplyName;
	}

	public void setSupplyName(String supplyName) {
		this.supplyName = supplyName;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public void setInPrice(double inPrice) {
		InPrice = inPrice;
	}

	public double getInPrice() {
		return InPrice;
	}
}

⌨️ 快捷键说明

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