📄 clothestypelistener.java
字号:
package control.clothesTpye;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import view.dialog.clothesType.AddClothesTypeDlg;
import view.dialog.clothesType.ClothesTypeDlg;
import view.dialog.clothesType.ModifyClothesTypeDlg;
import view.panel.clothesType.ClothesPriceSetPanel;
import vo.ClothesTypeVo;
import dao.clothesTypeDao.ClothesTypeDao;
import dao.clothesTypeDao.clothesTypeDaoImpl.ClothesTypeDaoImpl;
import dao.common.DbException;
import dao.getClothesDao.GetClothesDao;
import dao.getClothesDao.getClothesDaoImpl.GetClothesDaoImpl;
public class ClothesTypeListener implements ActionListener {
private ClothesPriceSetPanel clothesTypePanel;
private ClothesTypeDlg clothesTypeDlg;
/**
* @param clothesTypePanel
*/
public ClothesTypeListener(ClothesTypeDlg clothesTypeDlg) {
super();
this.clothesTypeDlg = clothesTypeDlg;
this.clothesTypePanel = clothesTypeDlg.getClothesTypePanel();
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("添加")) {
new AddClothesTypeDlg(clothesTypeDlg).setVisible(true);
} else if (command.equals("修改")) {
JTable table = clothesTypePanel.buildClothesTable();
int row = table.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请选择要修改的行!");
return;
}
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
String[] content = new String[5];
for (int i = 0; i < 5; i++)
content[i] = tableModel.getValueAt(row, i).toString();
new ModifyClothesTypeDlg(clothesTypeDlg, content).setVisible(true);
} else if (command.equals("退出")) {
clothesTypeDlg.dispose();
} else if (command.equals("删除")) {
JTable table = clothesTypePanel.buildClothesTable();
int row = table.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请选择要删除的行!");
return;
}
int answer = JOptionPane.showConfirmDialog(null, "确定要删除此衣服信息!");
if (answer == JOptionPane.YES_OPTION) {
DefaultTableModel tableModel = (DefaultTableModel) table
.getModel();
int clothesTypeId = Integer.parseInt(tableModel.getValueAt(row,
0).toString());
ClothesTypeVo clothesTypeVo = new ClothesTypeVo(clothesTypeId,
null, null, 0, 0, null, null);
ClothesTypeDao clothesTypeDao = new ClothesTypeDaoImpl();
try {
if (clothesTypeDao.deleteClothesType(clothesTypeVo))
tableModel.removeRow(row);
} catch (DbException de) {
JOptionPane.showMessageDialog(null, de.getMessage());
}
}
} else if (command.equals("搜素")) {
GetClothesDao getClothesDao = new GetClothesDaoImpl();
String keyword = clothesTypePanel.buildKeywordTxFld().getText();
Vector v = null;
try {
if (keyword != null
&& clothesTypePanel.buildClothesNameRdBtn()
.isSelected()) {
v = getClothesDao.searchClothesTypeByNameAndService(
keyword,
GetClothesDaoImpl.SEARCH_CLOTHESTYPE_BY_NAME);
} else if (keyword != null
&& clothesTypePanel.buildServiceTypeRdBtn()
.isSelected()) {
v = getClothesDao.searchClothesTypeByNameAndService(
keyword,
GetClothesDaoImpl.SEARCH_CLOTHESTYPE_BY_SERVICE);
} else {
v = getClothesDao.searchClothesTypeByNameAndService(
keyword, GetClothesDaoImpl.SEARCH_ALL_CLOTHESTYPE);
}
} catch (DbException de) {
JOptionPane.showMessageDialog(null, de.getMessage());
}
clothesTypePanel.setClothesTypeTable(v);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -