📄 feedbackdatainjpanel.java
字号:
package file1;
/*
* @Author:黄顺武
* Description:客户申诉记录的反馈情况数据的录入面版
* Create Time:2008-2-2
*/
import javax.swing.*;
import java.awt.*;
import sun.jdbc.rowset.*;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FeedBackDataInJPanel extends JPanel implements ActionListener {
private JLabel operater = new JLabel("操作者:");// 操作者
private JComboBox operaterBox = new JComboBox();// 操作者选择下拉列表框
private JLabel operateTime = new JLabel("操作时间:");// 操作时间
private JTextField operateTimeJTF = new JTextField(10);
private JLabel suggestion = new JLabel("意见:");//
private JTextArea suggestionJTA = new JTextArea(5, 10);
private JButton confirmButton = new JButton("确定");
private JButton cancelButton = new JButton("取消");
private FeedBackRecord feedBackRecord = null;// 存储操作者录入的数据
private int[] eids = null;// 存储所有操作者的id
private DBConnection con = null;// 生命数据库连接对象
private GetDate getD = null;// 日期格式化对象
public FeedBackDataInJPanel() {
getD = new GetDate();
con = new DBConnection();// 实例化
feedBackRecord = new FeedBackRecord();// 实例化
int valueReturned = getAllOperaters();
if (valueReturned == 1) {// 函数体执行出现异常
return;
}
this.setLayout(new GridLayout(4, 2, 5, 10));
this.add(operater);
this.add(operaterBox);
this.add(operateTime);
this.add(operateTimeJTF);
this.add(suggestion);
this.add(suggestionJTA);
this.add(confirmButton);
this.add(cancelButton);
operateTimeJTF.setBorder(null);
operateTimeJTF.setBackground(Color.lightGray);
suggestionJTA.setBackground(Color.lightGray);
suggestionJTA.setBorder(null);
confirmButton.setBorder(null);
cancelButton.setBorder(null);
confirmButton.setFont(new Font(Font.DIALOG,Font.ITALIC,13));
cancelButton.setFont(new Font(Font.DIALOG,Font.ITALIC,13));
confirmButton.setBackground(Color.LIGHT_GRAY);
cancelButton.setBackground(Color.LIGHT_GRAY);
confirmButton.setContentAreaFilled(false);
cancelButton.setContentAreaFilled(false);
confirmButton.addActionListener(this);
cancelButton.addActionListener(this);
cancelButton.setEnabled(false);
}
private int getAllOperaters() {// 从数据库中查得所有操作者的id和名称,执行成功返回0,否则返回1
String sqlStr = "select ID,name from Employee";
try {
CachedRowSet crs = con.getResultSet(sqlStr);
int totalRecord = 0;// 记录总数的记录变量
while (crs.next()) {
totalRecord++;
}
eids = new int[totalRecord];
totalRecord = 0;// 记录变量重新置零,以备新一轮的循环
crs.beforeFirst();
while (crs.next()) {
eids[totalRecord++] = crs.getInt(1);
operaterBox.addItem(crs.getString(2).trim());
}
operaterBox.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;
}
return 0;
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == confirmButton) {// 点击了"确定"按钮,提交解决情况记录数据
int indexTemp = operaterBox.getSelectedIndex();
if (indexTemp == -1) {// 操作者为空
JOptionPane.showMessageDialog(null, "操作者不能为空!", "",
JOptionPane.INFORMATION_MESSAGE);
return;
}
feedBackRecord.setOperater(eids[indexTemp]);
if (!operateTimeJTF.getText().trim().equals("")) {
if (getD.getDate(operateTimeJTF.getText().trim()) != null) {
feedBackRecord.setOperateTime(operateTimeJTF.getText()
.trim());
} else {
JOptionPane.showMessageDialog(null, "操作时间必须为如2008-2-4的格式!",
"", JOptionPane.INFORMATION_MESSAGE);
return;
}
} else {
JOptionPane.showMessageDialog(null, "操作时间不能为空!", "",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!suggestionJTA.getText().trim().equals("")) {
feedBackRecord.setSuggestion(suggestionJTA.getText().trim());
}
}
// if(ae.getSource()==cancelButton){//点击了"取消"按钮,关闭窗口
// }
}
public FeedBackRecord getFeedBackRecord() {
return feedBackRecord;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -