📄 appealdatainjpanel.java
字号:
package file1;
/*
* @Author:黄顺武
* Description:投诉客户的投诉数据的录入模块
* Create Time:2008-1-31
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import sun.jdbc.rowset.*;
import java.sql.*;
public class AppealDataInJPanel extends JPanel implements ItemListener {
private JLabel appealer = new JLabel("投诉客户 :");// 和数据库通信的则是客户的id,保证数据的唯一性
private JComboBox appealerBox = new JComboBox();// 查询数据库中的客户记录并显示到列表框中供操作员选择
private JLabel appealToKind = new JLabel("被投诉对象性质 :");
private JComboBox appealToKindBox = new JComboBox(
new String[] { "部门", "员工" });// 被投诉对象的性质
private JLabel appealTo = new JLabel("被投诉对象 :");// 和数据库通信的则是被投诉对象的id,保证数据的唯一性
private JComboBox appealToBox = new JComboBox();// 根据被投诉对象的性质从数据库中查询相应的数据记录并显示到列表框中
private JLabel appealContent = new JLabel("投诉内容 :");// 投诉内容
private JTextArea appealContentJTA = new JTextArea(5, 20);// 投诉内容输入框,为5行20列
private JLabel appealTime = new JLabel("投诉时间 :");// 投诉时间
private JTextField appealTimeJTF = new JTextField(10);// 投诉时间输入框,实际上这种时间录入方式是不合理的,给用户带来了一定的数据录入上的麻烦,等以后有时间的时候再寻求其它的实现方案
private JLabel processTime = new JLabel("投诉被处理时间 :");// 投诉被处理时间
private JTextField processTimeJTF = new JTextField(10);// 投诉被处理时间输入框,同上,这种时间录入方式也是不合理的
private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
private String[] cids = null;// 存储所有客户的id
private String[] ids = null;// 存储所有可投诉的员工或部门的ID
private DBConnection con = null;
public AppealDataInJPanel() {
con = new DBConnection();
int valueReturned = getAllClients();
if (valueReturned == 1) {
return;
}
appealContentJTA.setLineWrap(true);
appealContentJTA.setAutoscrolls(true);
appealContentJTA.setWrapStyleWord(true);
this.setLayout(new BorderLayout(0, 10));
panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 35, 0));
panel2.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 0));
panel1.add(appealer);
panel1.add(appealerBox);
panel1.add(appealToKind);
panel1.add(appealToKindBox);
panel1.add(appealTo);
panel1.add(appealToBox);
panel2.add(appealContent);
panel2.add(appealContentJTA);
panel2.add(appealTime);
panel2.add(appealTimeJTF);
panel2.add(processTime);
panel2.add(processTimeJTF);
this.add(panel1, BorderLayout.NORTH);
this.add(panel2, BorderLayout.CENTER);
appealToKindBox.addItemListener(this);
appealToKindBox.setSelectedIndex(-1);
}
private int getAllClients() {
String sqlStr = "select id,cName from Client";
try {
CachedRowSet crs = con.getResultSet(sqlStr);
int totalRecord = 0;
while (crs.next()) {
totalRecord++;
}
cids = new String[totalRecord];
crs.beforeFirst();
totalRecord = 0;
while (crs.next()) {
cids[totalRecord++] = String.valueOf(crs.getInt(1));
appealerBox.addItem(crs.getString(2).trim());
}
appealerBox.setSelectedIndex(-1);
} catch (ClassNotFoundException cnfe) {
JOptionPane.showMessageDialog(null, "发生ClassNotFound错误!", "",
JOptionPane.INFORMATION_MESSAGE);
return 1;
} catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "发生Sql错误!", "",
JOptionPane.INFORMATION_MESSAGE);
return 1;// 函数体执行不正常返回1
}
return 0;// 函数体执行正常返回0
}
public void itemStateChanged(ItemEvent ie) {
if (ie.getSource() == appealToKindBox) {
String kind = (String) appealToKindBox.getSelectedItem();
if (kind == null) {
return;
}
String sqlStr = "";
if (kind.trim().equals("员工")) {
sqlStr = "select* from Employee";
}
if (kind.trim().equals("部门")) {
sqlStr = "select* from Department";
}
try {
CachedRowSet crs = con.getResultSet(sqlStr);
int totalRecord = 0;// 查得的所有记录数
while (crs.next()) {
totalRecord++;
}
ids = new String[totalRecord];
totalRecord = 0;
crs.beforeFirst();
if (appealToBox.getItemCount() != 0) {
appealToBox.removeAllItems();
}
while (crs.next()) {
ids[totalRecord++] = String.valueOf(crs.getInt(1));
appealToBox.addItem(crs.getString(2).trim());
}
} catch (ClassNotFoundException cnfe) {
JOptionPane.showMessageDialog(null, "发生ClassNotFound错误!", "",
JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "发生Sql错误!", "",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
public JComboBox getAppealerBox(){//取得申诉客户id的下拉框
return appealerBox;
}
public JComboBox getAppealToKindBox(){//取得被投诉对象性质的下拉框
return appealToKindBox;
}
public JComboBox getAppealToBox(){//取得被投诉对象的ID的下拉框
return appealToBox;
}
public JTextArea getAppealContentJTA(){//取得申诉内容的文本区
return appealContentJTA;
}
public JTextField getAppealTimeJTF(){//取得申诉时间的文本框
return appealTimeJTF;
}
public JTextField getProcessTimeTF(){//取得申诉被处理时间的文本框
return processTimeJTF;
}
public String[] getCIDS(){//取得存储存储所有客户的id的数组
return cids;
}
public String[] getIDS(){//取得存储所有可投诉的员工或部门的ID的数组
return ids;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -