📄 clothesitemdlglistener.java
字号:
package control.getClothes;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.Iterator;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import view.dialog.getClothes.ClothesItemDlg;
import view.panel.getClothes.AddClothesPanel;
import vo.ClothesTypeVo;
import vo.OrderItemVo;
public class ClothesItemDlgListener implements ActionListener {
private ClothesItemDlg clothesItemDlg;
/**
* @param clothesItemDlg
*/
public ClothesItemDlgListener(ClothesItemDlg clothesItemDlg) {
super();
this.clothesItemDlg = clothesItemDlg;
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("确定")) {
try {
if (!addItemToTable())
return;
if (!addItemtoOrder())
return;
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(null, "添加洗衣数目必须为整数");
return;
}
clothesItemDlg.dispose();
} else if (command.equals("取消")) {
clothesItemDlg.dispose();
}
}
public boolean addItemToTable() throws NumberFormatException {
Object[] rowContent = getItemValue();
if (rowContent == null) {
return false;
}
DefaultTableModel tableModel = (DefaultTableModel) clothesItemDlg
.getGetClothesPanel().buildBuyingClothesTable().getModel();
tableModel.addRow(rowContent);
return true;
}
public boolean addItemtoOrder() throws NumberFormatException {
Object[] content = getItemValue();
if (content == null) {
return false;
}
ClothesTypeVo clothesType = clothesItemDlg.getClothesTypeVo();
String clothesBrand = content[2].toString();
String accessory = content[3].toString();
String color = content[4].toString();
String flaw = content[5].toString();
int clothesQuatity = Integer.parseInt(content[7].toString());
double itemValue = Double.parseDouble(content[8].toString());
String clothesAdditionInfo = content[9].toString();
OrderItemVo itemVo = new OrderItemVo(clothesType, accessory,
clothesBrand, color, flaw, clothesAdditionInfo, clothesQuatity,
itemValue);
clothesItemDlg.getGetClothesPanel().itemVector.add(itemVo);
double totalValue = 0;
Iterator it = clothesItemDlg.getGetClothesPanel().itemVector.iterator();
while (it.hasNext()) {
OrderItemVo item = (OrderItemVo) it.next();
totalValue += item.getItemValue();
}
clothesItemDlg.getGetClothesPanel().buildMoneyLabel().setText(
new Double(totalValue).toString());
return true;
}
private Object[] getItemValue() throws NumberFormatException {
AddClothesPanel addClothesPanel = clothesItemDlg.getAddClothesPanel();
String quantity = addClothesPanel.buildQuantityTxFld().getText();
if (quantity.equals("")) {
JOptionPane.showMessageDialog(null, "请先确定添加的衣服数量");
return null;
}
if (quantity.equals("0")) {
JOptionPane.showMessageDialog(null, "添加的衣服数量必须大于0");
return null;
}
if (Double.parseDouble(quantity) >= 100) {
JOptionPane.showMessageDialog(null, "添加的衣服数量必须小于100");
return null;
}
double uinitPrice = Double.parseDouble(addClothesPanel.buildPriceLb().getText());
double discount = Double.parseDouble(addClothesPanel.buildDiscountLb().getText());
double priAftDis = uinitPrice*discount/10;
String priceAftDis = new Double(priAftDis).toString();
if((priAftDis+"").indexOf(".") > 0){
priceAftDis = (priAftDis+"").substring(0,(priAftDis+"").indexOf(".")+2);
}
Object[] content = {
addClothesPanel.buildClothesNameLb().getText(),
addClothesPanel.buildServiceTypeLb().getText(),
addClothesPanel.buildBrandCmbBox().getSelectedItem(),
addClothesPanel.buildAccesoriesCmbBox().getSelectedItem(),
addClothesPanel.buildColorCmbBox().getSelectedItem(),
addClothesPanel.buildFlawCmbBox().getSelectedItem(),
priceAftDis,
addClothesPanel.buildQuantityTxFld().getText(),
addClothesPanel.buildTotalPriceTxFld().getText(),
addClothesPanel.buildAdditionTxArea().getText() };
return content;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -