📄 appealfatherjpanel.java
字号:
package file1;
/*
* @Author:黄顺武
* Description:客户申诉记录的所有操作的主面版
* Create Time:2008-2-2
*/
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AppealFatherJPanel extends JPanel implements ActionListener {
private AppealDataInJPanel appealDataInJPanel = null;
private AppealRecordJPanel appealRecordJPanel = null;
private SolutionAndReplyDetailQueryJPanel solutionAndReplyDetailQueryJPanel = null;
private AMDJPanel AMDJPanel = null;
private String idModified = "";// 储存被修改的申诉记录的id
private GetDate getD = null;// 格式化用户输入的日期值
public AppealFatherJPanel() {
getD = new GetDate();
appealDataInJPanel = new AppealDataInJPanel();// 添加申诉记录录入面版
appealRecordJPanel = new AppealRecordJPanel();// 添加申诉记录显示面版
solutionAndReplyDetailQueryJPanel = new SolutionAndReplyDetailQueryJPanel();// 添加客户申诉记录解决情况可反馈情况条件选择面版
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("修改记录");
}
Appeal appeal = getAppealData();
if (appeal != null) {
AppealOperate appealOperate = new AppealOperate();
appealOperate.insertToDB(appeal);
appealRecordJPanel.getRecords();//刷新界面
changeButtonState();//调用自定义函数调整"修改记录"和"删除记录"按钮的状态
}
}
if (ae.getSource() == AMDJPanel.getModifyButton()) {// 点击了"修改"按钮
if (AMDJPanel.getModifyButton().getActionCommand().equals("修改记录")) {// 用户开始执行修改
String[] ids = appealRecordJPanel.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;
}
Appeal appeal=new Appeal();
appeal.setID(Integer.valueOf(idModified));
AppealOperate appealOperate=new AppealOperate();
ArrayList valuesGet=appealOperate.selectFromDB(appeal);
Iterator iter=valuesGet.iterator();
int j=0;
while(iter.hasNext()){
appeal=(Appeal)valuesGet.get(j++);//获得查询结果
}
appealDataInJPanel.getAppealContentJTA().setText(appeal.getAppealContent());
appealDataInJPanel.getAppealTimeJTF().setText(appeal.getAppealTime());
appealDataInJPanel.getProcessTimeTF().setText(appeal.getProcessTime());
appealDataInJPanel.getAppealToKindBox().setSelectedItem(appeal.getAppealToState());
String[] cids=appealDataInJPanel.getCIDS();//所有投诉客户的id的数组
for(int i=0;i<appealDataInJPanel.getAppealerBox().getItemCount();i++){//遍历申诉客户下拉框
if(Integer.valueOf(cids[i])==appeal.getApplerID()){//找着目标申诉客户
appealDataInJPanel.getAppealerBox().setSelectedIndex(i);
}
}
String[] eids=appealDataInJPanel.getIDS();//所有可被投诉的部门或员工的id的数组
for(int i=0;i<appealDataInJPanel.getAppealToBox().getItemCount();i++){//遍历被申诉对象下拉框
if(Integer.valueOf(eids[i])==appeal.getAppealToID()){
appealDataInJPanel.getAppealToBox().setSelectedIndex(i);//选定找着的目标被申诉对象
}
}
AMDJPanel.getModifyButton().setText("确认修改");
return;
}
if (AMDJPanel.getModifyButton().getActionCommand().equals("确认修改")) {// 用户确认修改结果
Appeal appeal = getAppealData();
appeal.setID(Integer.valueOf(idModified));
AppealOperate appealOperate = new AppealOperate();
appealOperate.modifyToDB(appeal);// 把目标appeal对象传到AppealOperate数据库操作类的对象完成修改
appealRecordJPanel.getRecords();//刷新界面
AMDJPanel.getModifyButton().setText("修改记录");
}
}
if (ae.getSource() == AMDJPanel.getDeleteButton()) {// 点击了"删除"按钮
if (AMDJPanel.getModifyButton().getActionCommand().equals("确认修改")) {// 在点击了"修改记录"按钮后没有在修改完记录后按下确认修改,则把该按钮的文本重新置为"修改记录"
AMDJPanel.getModifyButton().setText("修改记录");
}
String[] ids = appealRecordJPanel.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;
}
Appeal appeal = new Appeal();
appeal.setID(Integer.valueOf(id));
AppealOperate appealOperate = new AppealOperate();
appealOperate.deleteFromDB(appeal);// 把设定id的appeal对象传到数据库操作类
appealRecordJPanel.getRecords();//刷新界面
changeButtonState();//调用自定义函数调整"修改记录"和"删除记录"按钮的状态
}
}
private Appeal getAppealData() {// 把客户申诉记录数据录入到Appeal类的对象中,以备调用,实现对申诉记录操作的面向对象性
Appeal appeal = new Appeal();
int appealerIndex = appealDataInJPanel.getAppealerBox()
.getSelectedIndex();
String appealToKindItem = (String) appealDataInJPanel
.getAppealToKindBox().getSelectedItem();
int appealToIndex = appealDataInJPanel.getAppealToBox()
.getSelectedIndex();
String appealContent = appealDataInJPanel.getAppealContentJTA()
.getText().trim();
String appealTime = getD.getDate(appealDataInJPanel.getAppealTimeJTF()
.getText().trim());
String processTime = getD.getDate(appealDataInJPanel.getProcessTimeTF()
.getText().trim());
if (appealerIndex == -1
|| appealToKindItem == null
|| (appealToKindItem != null && appealToKindItem.trim().equals(
"")) || appealToIndex == -1 || appealContent == null
|| (appealContent != null && appealContent.trim().equals(""))
|| appealTime == null
|| (appealTime != null && appealTime.trim().equals(""))
|| processTime == null
|| (processTime != null && processTime.trim().equals(""))) {
JOptionPane.showMessageDialog(null,
"所有条件均不能为空且日期值必须为如2008-2-4的格式!", "",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
appeal.setApplerID(Integer
.valueOf(appealDataInJPanel.getCIDS()[appealerIndex]));// 设置申诉者ID
appeal.setAppealToState(appealToKindItem.trim());
appeal.setAppealToID(Integer
.valueOf(appealDataInJPanel.getIDS()[appealToIndex]));// 设置被投诉id
appeal.setAppealContent(appealContent.trim());// 设置申诉内容
appeal.setAppealTime(appealTime.trim());// 设置申诉时间
appeal.setProcessTime(processTime.trim());// 设置申诉被处理时间
return appeal;
}
private void setLayout(){
this.add(appealDataInJPanel, BorderLayout.NORTH);
this.add(appealRecordJPanel, BorderLayout.WEST);
this.add(solutionAndReplyDetailQueryJPanel, BorderLayout.EAST);
this.add(AMDJPanel, BorderLayout.SOUTH);
}
private void changeButtonState(){
if(appealRecordJPanel.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 + -