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

📄 goodnotequalfatherjpanel.java

📁 JAVA实现的酒店管理系统
💻 JAVA
字号:
package file1;

/*
 * @Author:
 * Create Time:2008-2-22
 * Description:货品损益记录的数据录入及显示等相关操作的主界面
 */
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GoodNotEqualFatherJPanel extends JPanel implements ActionListener {

	private GoodNotEqualDataInJPanel goodNotEqualDataInJPanel = null;
	private GoodNotEqualRecordJPanel goodNotEqualRecordJPanel = null;
	private ProcessionRecordDetailQueryJPanel processionRecordDetailQueryJPanel = null;
	private AMDJPanel AMDJPanel = null;
	private String idModified = "";// 储存被修改的货品损益记录的id

	public GoodNotEqualFatherJPanel() {
		goodNotEqualDataInJPanel = new GoodNotEqualDataInJPanel();// 添加货品损益记录数据录入面版
		goodNotEqualRecordJPanel = new GoodNotEqualRecordJPanel();// 添加货品损益记录显示面版
		processionRecordDetailQueryJPanel = new ProcessionRecordDetailQueryJPanel();// 添加货品损益记录处理情况可反馈情况条件选择面版
		AMDJPanel = new AMDJPanel();// 添加增,删,改,查面版
		this.setLayout(new BorderLayout(0, 20));
		setLayout();// 调用自定义的页面布局函数
		AMDJPanel.getAddButton().addActionListener(this);// 给"添加记录"按钮添加动作事件
		AMDJPanel.getModifyButton().addActionListener(this);// 给"修改记录"按钮添加动作事件
		AMDJPanel.getDeleteButton().addActionListener(this);// 给"删除记录"按钮添加动作事件
		changeButtonState();// 调用自定义函数调整"修改记录"和"删除记录"按钮的状态
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == AMDJPanel.getAddButton()) {// 点击了"添加"按钮
			if (AMDJPanel.getModifyButton().getActionCommand().equals("确认修改")) {// 在点击了"修改记录"按钮后没有在修改完记录后按下确认修改,则把该按钮的文本重新置为"修改记录"
				AMDJPanel.getModifyButton().setText("修改记录");
			}
			GoodNotEqual goodNotEqual = goodNotEqualDataInJPanel
					.getGoodNotEqualRecordDataIn();
			if (goodNotEqual != null) {
				GoodNotEqualOperate goodNotEqualOperate = new GoodNotEqualOperate();
				goodNotEqualOperate.insertToDB(goodNotEqual);
				goodNotEqualRecordJPanel.getRecords();// 刷新界面
				changeButtonState();// 调用自定义函数调整"修改记录"和"删除记录"按钮的状态
			}
		}
		if (ae.getSource() == AMDJPanel.getModifyButton()) {// 点击了"修改"按钮
			if (AMDJPanel.getModifyButton().getActionCommand().equals("修改记录")) {// 用户开始执行修改
				String[] ids = goodNotEqualRecordJPanel.getIDS();
				idModified = (String) JOptionPane.showInputDialog(null,
						"请选择要修改的记录ID!", "", JOptionPane.INFORMATION_MESSAGE,
						null, ids, ids[0]);
				if (idModified == null) {
					return;
				} else if (idModified != null && idModified.trim().equals("")) {
					JOptionPane.showMessageDialog(null, "要修改的货品损益记录ID不能为空!",
							"", JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				GoodNotEqual goodNotEqual = new GoodNotEqual();
				goodNotEqual.setID(Integer.valueOf(idModified));
				GoodNotEqualOperate goodNotEqualOperate = new GoodNotEqualOperate();
				ArrayList value = goodNotEqualOperate.selectFromDB(goodNotEqual);
				Iterator iter = value.iterator();
				goodNotEqual = (GoodNotEqual) value.get(0);// 获得查询结果
				goodNotEqualDataInJPanel
						.GoodNotEqualRecordDataOut(goodNotEqual);// 把已知记录数据初始化到数据录入界面中
				AMDJPanel.getModifyButton().setText("确认修改");
				return;
			}
			if (AMDJPanel.getModifyButton().getActionCommand().equals("确认修改")) {// 用户确认修改结果
				GoodNotEqual goodNotEqual = goodNotEqualDataInJPanel
						.getGoodNotEqualRecordDataIn();
				goodNotEqual.setID(Integer.valueOf(idModified));
				GoodNotEqualOperate goodNotEqualOperate = new GoodNotEqualOperate();
				goodNotEqualOperate.modifyToDB(goodNotEqual);// 把目标appeal对象传到AppealOperate数据库操作类的对象完成修改
				goodNotEqualRecordJPanel.getRecords();// 刷新界面
				AMDJPanel.getModifyButton().setText("修改记录");
			}
		}
		if (ae.getSource() == AMDJPanel.getDeleteButton()) {// 点击了"删除"按钮
			if (AMDJPanel.getModifyButton().getActionCommand().equals("确认修改")) {// 在点击了"修改记录"按钮后没有在修改完记录后按下确认修改,则把该按钮的文本重新置为"修改记录"
				AMDJPanel.getModifyButton().setText("修改记录");
			}
			String[] ids = goodNotEqualRecordJPanel.getIDS();
			String id = (String) JOptionPane.showInputDialog(null,
					"请选择要删除的记录ID!", "", JOptionPane.INFORMATION_MESSAGE, null,
					ids, ids[0]);
			if (id == null) {// 点击了"取消"按钮
				return;
			}
			if (id != null && id.trim().equals("")) {
				JOptionPane.showMessageDialog(null, "要删除的记录ID不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			int confirm = JOptionPane.showConfirmDialog(null, "您真的确认要删除该记录吗?",
					"", JOptionPane.INFORMATION_MESSAGE);
			if (confirm == -1 || confirm == JOptionPane.NO_OPTION) {// 点击了"取消"或"否"按钮
				return;
			}
			GoodNotEqual goodNotEqual = new GoodNotEqual();
			goodNotEqual.setID(Integer.valueOf(id));
			GoodNotEqualOperate goodNotEqualOperate = new GoodNotEqualOperate();
			goodNotEqualOperate.deleteFromDB(goodNotEqual);// 把设定id的appeal对象传到数据库操作类
			goodNotEqualRecordJPanel.getRecords();// 刷新界面
			changeButtonState();// 调用自定义函数调整"修改记录"和"删除记录"按钮的状态
		}
	}

	private void setLayout() {
		this.add(goodNotEqualDataInJPanel, BorderLayout.NORTH);
		this.add(goodNotEqualRecordJPanel, BorderLayout.WEST);
		this.add(processionRecordDetailQueryJPanel, BorderLayout.EAST);
		this.add(AMDJPanel, BorderLayout.SOUTH);
	}

	private void changeButtonState() {
		if (goodNotEqualRecordJPanel.getRecords() == 0) {// 没有货品损益记录
			AMDJPanel.getModifyButton().setEnabled(false);
			AMDJPanel.getDeleteButton().setEnabled(false);
		} else {
			AMDJPanel.getModifyButton().setEnabled(true);
			AMDJPanel.getDeleteButton().setEnabled(true);
		}
	}
}

⌨️ 快捷键说明

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