📄 clothesinmanagementaction.java
字号:
package control.clothesinmanagementaction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import view.common.CheckInputUtil;
import view.dialog.countmanage.ClothesInManagementDialog;
import vo.ClothesTypeVo;
import vo.OrderItemVo;
import vo.OrderVo;
import vo.VipConsumeVo;
import vo.VipVo;
import common.LogWriter;
import control.common.CheckTimeUtil;
import dao.clothesindao.ClothesInManagementDao;
import dao.clothesindao.impl.ClothesInManagementDaoImpl;
import dao.commomdao.CommonDao;
import dao.commomdao.impl.CommonDaoImpl;
import dao.common.DbException;
import dao.export.ExportDao;
import dao.export.head.TableHead;
public class ClothesInManagementAction implements ActionListener {
private ClothesInManagementDialog dialog;
private LogWriter log;
private ExportDao edao;
public ClothesInManagementAction(ClothesInManagementDialog dialog,
LogWriter log) {
this.dialog = dialog;
this.log = log;
}
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
if (name.equals("查询")) {
String fromDate = dialog.buildFromDateBox().getSelectedItem()
.toString();
String toDate = dialog.buildToDateBox().getSelectedItem()
.toString();
String operator = dialog.buildOperatorCombox().getSelectedItem()
.toString();
String orderId = dialog.buildItemTxt().getText().trim();
if (!CheckInputUtil.checkIsContainNumber(orderId)) {
JOptionPane.showMessageDialog(null, "交易单号只能为数字", "提示信息",
JOptionPane.YES_OPTION);
dialog.buildItemTxt().requestFocus();
dialog.buildItemTxt().setText("");
return;
}
if (CheckTimeUtil.CheckTime(fromDate, toDate)) {
buildTableData(fromDate, toDate, operator, orderId);
} else {
JOptionPane.showMessageDialog(null, "查找的开始日期不能大于结束日期!");
}
} else if (name.equals("打印")) {
int index = dialog.buildTabbedPane().getSelectedIndex();
if(index == 0){
JTable table = dialog.buildClothesInCollectionTable();
String headTitle = "收取衣物汇总";
String[] head = TableHead.CLOTHESIN_COLLECTION;
edao = new ExportDao(dialog);
edao.export(table, headTitle, head);
}else if(index == 1){
JTable table = dialog.buildClothesInListTable();
String headTitle = "收取衣物明细";
String[] head = TableHead.CLOTHESIN_LIST;
edao = new ExportDao(dialog);
edao.export(table, headTitle, head);
}
} else if (name.equals("退出")) {
dialog.dispose();
}
}
private void buildTableData(String fromDate, String toDate,
String operator, String orderId) {
ClothesInManagementDao dao = new ClothesInManagementDaoImpl(log);
CommonDao cdao = new CommonDaoImpl(log);
try {
OrderVo value = null;
Iterator iter = null;
Vector v = null;
Iterator itemIter = null;
OrderItemVo itemVo = null;
Vector<OrderItemVo> orderItemVector = null;
int index = dialog.buildTabbedPane().getSelectedIndex();
if (index == 0) {
v = dao.findClothesInGether(fromDate, toDate, operator,orderId);
iter = v.iterator();
JTable table = dialog.buildClothesInCollectionTable();
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rows = table.getRowCount();
for (int i = rows - 1; i >= 0; i--) {
model.removeRow(i);
}
while (iter.hasNext()) {
value = (OrderVo) iter.next();
VipConsumeVo vo = null;
if (value.getCustomerId() != 0 && value.isPaidOrNot() == true) {
vo = cdao.getVipConsumeInfoByOrderId(value.getOrderId());
}
boolean paidState = value.isPaidOrNot();
int vipId = value.getCustomerId();
String vipName = "无卡用户";
String vipPhone = "无";
if (vipId != 0) {
VipVo vipVo = cdao.getVipInfoByVipId(vipId);
vipName = vipVo.getVipName();
vipPhone = vipVo.getVipPhone();
}
double redRdc = 0;
double recAmt = 0;
double cash = value.getOrderValue();
if(vipId != 0 && paidState == true){
recAmt = vo.getReceivedAmount();
redRdc = vo.getReducedAmount();
cash = 0;
}else if(vipId != 0 && paidState == false){
cash = 0;
}else if(vipId == 0 && paidState == true ){
recAmt = value.getOrderValue();
}
Object[] data = { value.getOrderId(),
value.getGetClothesDate(),
value.getTakeClothesDate(), value.getOrderValue(),
recAmt,redRdc,
paidState?0:value.getOrderValue(), vipId, vipName, vipPhone, value.isTakeOrNot()?"是":"否", value.isPaidOrNot()?"是":"否",
value.getOperatorName(), cash,
recAmt};
model.addRow(data);
}
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
JTable table = dialog.buildClothesInCollectionTable();
int row = table.getSelectedRow();
long orderId = Long.parseLong(table.getValueAt(row, 0)
.toString());
int vipId = Integer.parseInt(table.getValueAt(row, 7)
.toString());
double neededAmount = Double.parseDouble(table
.getValueAt(row, 3).toString());
double receivedAmount = Double.parseDouble(table
.getValueAt(row, 4).toString());
buildItemTableData(orderId, vipId);
buildLabelPanel(orderId, neededAmount, receivedAmount,
vipId);
}
});
} else if (index == 1) {
v = dao
.findClothesInGether(fromDate, toDate, operator,
orderId);
iter = v.iterator();
JTable table = dialog.buildClothesInListTable();
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rows = table.getRowCount();
for (int i = rows - 1; i >= 0; i--) {
model.removeRow(i);
}
while (iter.hasNext()) {
value = (OrderVo) iter.next();
VipConsumeVo vo = null;
if (value.getCustomerId() != 0 && value.isPaidOrNot() == true) {
vo = cdao.getVipConsumeInfoByOrderId(value.getOrderId());
}
String vipName = "无卡用户";
int vipId = value.getCustomerId();
if (value.getCustomerId() != 0) {
VipVo vipVo = cdao.getVipInfoByVipId(vipId);
vipId = vipVo.getVipCard().getVipId();
vipName = vipVo.getVipName();
}
orderItemVector = value.getOrderItemVector();
itemIter = orderItemVector.iterator();
while (itemIter.hasNext()) {
itemVo = (OrderItemVo) itemIter.next();
ClothesTypeVo type = itemVo.getClothesType();
double discount = 10;
if(vipId != 0){
discount = cdao.getDiscountByVipId(vipId);
}
String addition = itemVo.getClothesAdditionInfo();
if(addition == null)
addition = "";
Object[] data = {
value.getOrderId(),
value.getGetClothesDate(),
value.getTakeClothesDate(),
vipId,
vipName,
type.getClothesName(),
itemVo.getClothesQuatity(),
type.getServiceType(),
type.getUnitOriginalPrice() * discount*0.1,
type.getUnitOriginalPrice() * discount
* itemVo.getClothesQuatity()*0.1, discount,
value.isTakeOrNot()?"是":"否", itemVo.getClothesBrand(),
itemVo.getAccessory(), itemVo.getFlaw(),
itemVo.getColor(),
addition,
value.getOperatorName() };
model.addRow(data);
}
}
}
} catch (DbException e) {
JOptionPane.showMessageDialog(null, "收取衣物统计异常:"+e.getMessage());
}
}
public void buildItemTableData(long orderId, int vipId) {
CommonDao cdao = new CommonDaoImpl(log);
try {
OrderItemVo vo = null;
Iterator iter = null;
Vector v = null;
v = cdao.getOrderItemByOrderId(orderId);
iter = v.iterator();
JTable table = dialog.buildItemTable();
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rows = table.getRowCount();
for (int i = rows - 1; i >= 0; i--) {
model.removeRow(i);
}
double discount = 10;
if(vipId != 0){
discount = cdao.getDiscountByVipId(vipId);
}
while (iter.hasNext()) {
vo = (OrderItemVo) iter.next();
ClothesTypeVo type = (ClothesTypeVo) vo.getClothesType();
Object[] data = {
type.getClothesName(),
vo.getClothesQuatity(),
type.getServiceType(),
type.getUnitOriginalPrice() * discount*0.1,
(type.getUnitOriginalPrice()) * discount
* (vo.getClothesQuatity())*0.1, discount,
vo.getClothesBrand(), vo.getAccessory(), vo.getFlaw(),
vo.getColor(), vo.getClothesAdditionInfo() };
model.addRow(data);
}
} catch (DbException e) {
JOptionPane.showMessageDialog(null, "衣服详细信息异常:"+e.getMessage());
}
}
public void buildLabelPanel(long orderId, double neededAmount,
double receivedAmount, int vipId) {
JLabel label = dialog.buildLabel();
CommonDao cdao = new CommonDaoImpl(log);
try {
double discount = cdao.getDiscountByVipId(vipId);
label.setText("交易单:" + orderId + ",应收金额:" + neededAmount
+ "元,实收金额:" + receivedAmount + ",折扣:" + discount);
} catch (DbException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -