📄 stockpanelaction.java
字号:
package action.implementclass.panelaction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import view.com.factory.DialogFactory;
import view.panel.subpanel.GetStockPanel;
import view.panel.subpaneloper.StockPanelOper;
import vo.StockProductVo;
import common.jdbc.DbException;
import dao.StockDao;
import dao.StoreDao;
/**
* 进货模块的事件处理
* @author wenjie
*
*/
public class StockPanelAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
if (name.equals("进货查询")) {
DialogFactory.getInstance(name).getContainer();
} else if (name.equals("打印进货单")) {
JOptionPane.showMessageDialog(null, "由于时间仓促,暂时未能实现打印!", "抱歉",
JOptionPane.PLAIN_MESSAGE);
} else if (name.equals("进货")) {
if (StockPanelOper.checkInputValue()) {
StockProductVo value = StockPanelOper.getInputTextValue();
StockDao dao = new StockDao();
StoreDao sdao = new StoreDao();
try {
if (dao.insertStock(value)) {
JOptionPane.showMessageDialog(null, "数据添加成功", "Info",
JOptionPane.YES_OPTION);
// 获得JTable的数据模型
DefaultTableModel tableModel = (DefaultTableModel) GetStockPanel.table
.getModel();
// 将要加入的JTable中的数据构造为一个一维数组
Object[] data = { new Integer(value.getProduct_id()),
value.getProduct_name(), value.getProduct_type(),
new Double(value.getProduct_price()),
new Integer(value.getStock_num()), value.getStock_date() };
// 通过DefaultTableModel模型将数据增加到JTable对象中
tableModel.addRow(data);
sdao.insertStore(value);
}
} catch (DbException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error",
JOptionPane.YES_OPTION);
}
}
} else if (name.equals("重置")) {
StockPanelOper.initiaTextValue();
} else if (name.equals("刷新")) {
Vector v = new StockDao().getStockInfo();
Iterator iter = v.iterator();
DefaultTableModel tableModel = (DefaultTableModel) GetStockPanel.table
.getModel();
int counts = tableModel.getRowCount();
// 循环删除jtable中的所有数据
for (int i = counts - 1; i >= 0; i--) {
tableModel.removeRow(i);
}
while (iter.hasNext()) {
StockProductVo value = (StockProductVo) iter.next();
Object[] data = { new Integer(value.getProduct_id()),
value.getProduct_name(), value.getProduct_type(),
new Double(value.getProduct_price()),
new Integer(value.getStock_num()), value.getStock_date() };
tableModel.addRow(data);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -