📄 invoice.java
字号:
package good;
import javax.swing.JOptionPane;
import java.sql.ResultSet;
public class Invoice extends SortedList {
//定义与提货清单关联的存货清单
private Inventory inventory;
private String goodId;
private String employeeId;
private int outnumber;
private String clientname;
private double outPrice;
private String outdate;
//提货清单构造函数
public Invoice(Inventory _inventory) {
//调用父类SortedList的构造函数
super(new ItemComparer());
inventory = _inventory;
}
//在提货清单中增加提货条目,同时在存货清单中对应的存货条目上减少用户输入的货物数量
public boolean addItem(String _id, int _number,double _outPrice) {
InventoryItem item = inventory.getPart(_id);
if ((item != null) && (item.units >= _number) && (_number >= 0)
&& !isFull()) {
item.remove(_number);
add(new InvoiceItem(item, _number,_outPrice));
return true;
} else
{
JOptionPane.showMessageDialog(null, "列表满、项没有找到或者货物已经定购完!", "警告",
JOptionPane.ERROR_MESSAGE);
return false;
}
//System.out.println("List full, item not found or invalid units");
}
//根据用户输入的id,在提货清单上删除提货条目
public void delItem(String _id) {
int index = indexOf(new Item(_id));
if (index >= 0)
delete(index);
}
public boolean Invoicedele()
{
DataConn storCon = new DataConn();
String addSql = null;
storCon.dataConnDerectForMySql();
//System.out.print(date);
addSql="Insert into Invoice(goodId,employeeId,clientName,OutDate,Outnumber"+
",OutPrice)values('"+goodId+"','"+employeeId+"','"+clientname+"','"+outdate+
"',"+outnumber+","+outPrice+")";
storCon.executeDerectUpdate(addSql);
//同时修改数量
storCon.dataConnDerectForMySql();
addSql="update goods set goodNumber=goodNumber-"+Integer.toString(outnumber)
+" where goodId='"+goodId+"'";
storCon.executeDerectUpdate(addSql);
return true;
}
//返回提货清单上货物的价格总和
public double getTotal() {
double total = 0.0;
for (int i = 0; i < getSize(); i++)
total += ((InvoiceItem) get(i)).total;
return total;
}
//以字符串的形式返回提货清单
public String toString() {
return super.toString()+"提货清单:" + Util.dollar(getTotal()) ;
}
public String getClientname() {
return clientname;
}
public void setClientname(String clientname) {
this.clientname = clientname;
}
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 Inventory getInventory() {
return inventory;
}
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
public String getOutdate() {
return outdate;
}
public void setOutdate(String outdate) {
this.outdate = outdate;
}
public int getOutnumber() {
return outnumber;
}
public void setOutnumber(int outnumber) {
this.outnumber = outnumber;
}
public double getOutPrice() {
return outPrice;
}
public void setOutPrice(double outPrice) {
this.outPrice = outPrice;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -