⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clothesadditionsetlistener.java

📁 一个优秀的干洗店管理系统
💻 JAVA
字号:
package control.clothesAddition;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import view.panel.clothesAddition.ClothesAdditionSetPanel;
import dao.clothesAdditionDao.ClothesAdditionDao;
import dao.clothesAdditionDao.additionDaoImpl.AdditionDaoImpl;
import dao.common.DbException;

public class ClothesAdditionSetListener implements ActionListener {
	private ClothesAdditionSetPanel additionPanel;

	public ClothesAdditionSetListener(ClothesAdditionSetPanel panel) {
		additionPanel = panel;
	}

	public void actionPerformed(ActionEvent e) {
		String comand = e.getActionCommand();
		int index = additionPanel.buildTabbedPane().getSelectedIndex();
		if (comand.equals("添加")) {
			if (index == 0) {
				addBrand();
			} else if (index == 1) {
				addAccessory();
			} else if (index == 2) {
				addColor();
			} else if (index == 3) {
				addFlaw();
			}
		} else if (comand.equals("删除")) {
			if (index == 0) {
				deleteBrand();
			} else if (index == 1) {
				deleteAccessory();
			} else if (index == 2) {
				deleteColor();
			} else if (index == 3) {
				deleteFlaw();
			}
		} else if (comand.equals("修改")) {
			if (index == 0) {
				modifyBrand();
			} else if (index == 1) {
				modifyAccessory();
			} else if (index == 2) {
				modifyColor();
			} else if (index == 3) {
				modifyFlaw();
			}
		} else if (comand.equals("退出")) {
		}
	}

	public void addBrand() {
		String brand = JOptionPane.showInputDialog(null, "请输入要添加的衣服品牌名称:");
		if (brand == null)
			return;
		if (!brand.equals("")) {
			DefaultTableModel tableModel = (DefaultTableModel) additionPanel
					.buildBrandSetTable().getModel();
			Object[] content = { brand };
			tableModel.addRow(content);

			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				dao.registAdditionInfo(brand, AdditionDaoImpl.CLOTHES_BARND);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void addAccessory() {
		String accessory = JOptionPane.showInputDialog(null, "请输入要添加的衣服附件名称:");
		if (accessory == null)
			return;
		if (!accessory.equals("")) {
			DefaultTableModel tableModel = (DefaultTableModel) additionPanel
					.buildAccessoriesSetTable().getModel();
			Object[] content = { accessory };
			tableModel.addRow(content);

			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				dao.registAdditionInfo(accessory,
						AdditionDaoImpl.CLOTHES_ACCESSORY);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void addColor() {
		String color = JOptionPane.showInputDialog(null, "请输入要添加的衣服颜色:");
		if (color == null)
			return;
		if (!color.equals("")) {
			DefaultTableModel tableModel = (DefaultTableModel) additionPanel
					.buildColorSetTable().getModel();
			Object[] content = { color };
			tableModel.addRow(content);

			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				dao.registAdditionInfo(color, AdditionDaoImpl.CLOTHES_COLOR);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void addFlaw() {
		String flaw = JOptionPane.showInputDialog(null, "请输入要添加的衣服瑕疵:");
		if (flaw == null)
			return;
		if (!flaw.equals("")) {
			DefaultTableModel tableModel = (DefaultTableModel) additionPanel
					.buildFlawSetTable().getModel();
			Object[] content = { flaw };
			tableModel.addRow(content);
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				dao.registAdditionInfo(flaw, AdditionDaoImpl.CLOTHES_FLAW);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void deleteBrand() {
		JTable brandTable = additionPanel.buildBrandSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) brandTable
				.getModel();
		int row = brandTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要删除的一行");
			return;
		}
		String brand = (String) brandTable.getValueAt(row, 0);
		int answer = JOptionPane.showConfirmDialog(null, "确定要删除" + brand + "?",
				"删除", JOptionPane.YES_NO_OPTION);
		if (answer == JOptionPane.YES_OPTION) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao
						.deleteAdditionInfo(brand,
								AdditionDaoImpl.CLOTHES_BARND))
					tableModel.removeRow(row);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void deleteColor() {
		JTable colorTable = additionPanel.buildColorSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) colorTable
				.getModel();
		int row = colorTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要删除的一行");
			return;
		}
		String color = (String) colorTable.getValueAt(row, 0);
		int answer = JOptionPane.showConfirmDialog(null, "确定要删除" + color + "?",
				"删除", JOptionPane.YES_NO_OPTION);
		if (answer == JOptionPane.YES_OPTION) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao
						.deleteAdditionInfo(color,
								AdditionDaoImpl.CLOTHES_COLOR))
					tableModel.removeRow(row);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void deleteAccessory() {
		JTable accessoryTable = additionPanel.buildAccessoriesSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) accessoryTable
				.getModel();
		int row = accessoryTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要删除的一行");
			return;
		}
		String accessory = (String) accessoryTable.getValueAt(row, 0);
		int answer = JOptionPane.showConfirmDialog(null, "确定要删除" + accessory
				+ "?", "删除", JOptionPane.YES_NO_OPTION);
		if (answer == JOptionPane.YES_OPTION) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao.deleteAdditionInfo(accessory,
						AdditionDaoImpl.CLOTHES_ACCESSORY))
					tableModel.removeRow(row);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void deleteFlaw() {
		JTable flawTable = additionPanel.buildFlawSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) flawTable.getModel();
		int row = flawTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要删除的一行");
			return;
		}
		String flaw = (String) flawTable.getValueAt(row, 0);
		int answer = JOptionPane.showConfirmDialog(null, "确定要删除" + flaw + "?",
				"删除", JOptionPane.YES_NO_OPTION);
		if (answer == JOptionPane.YES_OPTION) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao.deleteAdditionInfo(flaw, AdditionDaoImpl.CLOTHES_FLAW))
					tableModel.removeRow(row);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void modifyBrand() {
		JTable brandTable = additionPanel.buildBrandSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) brandTable
				.getModel();
		int row = brandTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要修改的一行");
			return;
		}
		String oldBrand = (String) brandTable.getValueAt(row, 0);
		String newBrand = JOptionPane.showInputDialog(null, "请输入新的衣服品牌名称:",
				oldBrand);
		if (newBrand != null) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao.updateAdditionInfo(newBrand, oldBrand,
						AdditionDaoImpl.CLOTHES_BARND))
					tableModel.setValueAt(newBrand, row, 0);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void modifyAccessory() {
		JTable accessoryTable = additionPanel.buildAccessoriesSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) accessoryTable
				.getModel();
		int row = accessoryTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要修改的一行");
			return;
		}
		String oldAccessory = (String) accessoryTable.getValueAt(row, 0);
		String newAccessory = JOptionPane.showInputDialog(null, "请输入新的附件名称:",
				oldAccessory);
		if (newAccessory != null) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao.updateAdditionInfo(newAccessory, oldAccessory,
						AdditionDaoImpl.CLOTHES_ACCESSORY))
					tableModel.setValueAt(newAccessory, row, 0);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void modifyColor() {
		JTable colorTable = additionPanel.buildColorSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) colorTable
				.getModel();
		int row = colorTable.getSelectedRow();
		if (row == -1) {
			System.out.println();
			JOptionPane.showMessageDialog(null, "请选择要修改的一行");
			return;
		}
		String oldColor = (String) colorTable.getValueAt(row, 0);
		String newColor = JOptionPane.showInputDialog(null, "请输入新的附件名称:",
				oldColor);
		if (newColor != null) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao.updateAdditionInfo(newColor, oldColor,
						AdditionDaoImpl.CLOTHES_COLOR))
					tableModel.setValueAt(newColor, row, 0);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}

	public void modifyFlaw() {
		JTable flawTable = additionPanel.buildFlawSetTable();
		DefaultTableModel tableModel = (DefaultTableModel) flawTable.getModel();
		int row = flawTable.getSelectedRow();
		if (row == -1) {
			JOptionPane.showMessageDialog(null, "请选择要修改的一行");
			return;
		}
		String oldFlaw = (String) flawTable.getValueAt(row, 0);
		String newFlaw = JOptionPane.showInputDialog(null, "请输入新的附件名称:",
				oldFlaw);
		if (newFlaw != null) {
			ClothesAdditionDao dao = new AdditionDaoImpl();
			try {
				if (dao.updateAdditionInfo(newFlaw, oldFlaw,
						AdditionDaoImpl.CLOTHES_FLAW))
					tableModel.setValueAt(newFlaw, row, 0);
			} catch (DbException e) {
				JOptionPane.showMessageDialog(null, e.getMessage());
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -