?? inventory.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 + -