?? rewardsandpunishmentpanel.java
字號:
package com.mwq.frame.personnel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.Date;
import java.util.Iterator;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import com.mwq.frame.common.DeptTreeDialog;
import com.mwq.hibernate.Dao;
import com.mwq.hibernate.HibernateSessionFactory;
import com.mwq.hibernate.mapping.TbDept;
import com.mwq.hibernate.mapping.TbDutyInfo;
import com.mwq.hibernate.mapping.TbRecord;
import com.mwq.hibernate.mapping.TbRewardsAndPunishment;
import com.mwq.tool.Today;
public class RewardsAndPunishmentPanel extends JPanel {
private JTextField ratifierDeptTextField;
private JTextField inDeptTextField;
private JTextField ratifierDateTextField;
private JTextArea reasonTextArea;
private ButtonGroup buttonGroup = new ButtonGroup();
private JTextField endDateTextField;
private JComboBox ratifierPersonComboBox;
private JTextField startDateTextField;
private JTextField moneyTextField;
private JTextArea contentTextArea;
private Dao dao = Dao.getInstance();
final JRadioButton rewardsRadioButton;
final JRadioButton punishmentRadioButton;
private JComboBox personnalComboBox;
/**
* Create the panel
*/
public RewardsAndPunishmentPanel() {
super();
setLayout(new BorderLayout());
final JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
add(panel, BorderLayout.NORTH);
final JButton createButton = new JButton();
createButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inDeptTextField.setText(null);
personnalComboBox.removeAllItems();
personnalComboBox.addItem("請選擇");
Iterator recordIt = dao.queryRecord().iterator();
while (recordIt.hasNext()) {
TbRecord record = (TbRecord) recordIt.next();
personnalComboBox.addItem(record.getRecordNumber() + " "
+ record.getName());
}
HibernateSessionFactory.closeSession();
rewardsRadioButton.setSelected(false);
punishmentRadioButton.setSelected(false);
reasonTextArea.setText(null);
contentTextArea.setText(null);
moneyTextField.setText("00.00");
startDateTextField.setText(Today.TODAY_DATE);
endDateTextField.setText(Today.TODAY_DATE);
ratifierDeptTextField.setText("");
ratifierPersonComboBox.removeAllItems();
ratifierPersonComboBox.setEnabled(false);
ratifierDateTextField.setText(Today.TODAY_DATE);
}
});
createButton.setText("新建");
panel.add(createButton);
final JButton saveButton = new JButton();
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//
String personnal = personnalComboBox.getSelectedItem()
.toString();
if (personnal.equals("請選擇")) {
JOptionPane.showMessageDialog(null, "請選擇欲獎懲的職員!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
//
String type = null;
if (rewardsRadioButton.isSelected())
type = rewardsRadioButton.getText();
if (punishmentRadioButton.isSelected())
type = punishmentRadioButton.getText();
if (type == null) {
JOptionPane.showMessageDialog(null, "請選擇獎懲類型!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
//
if (reasonTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(null, "請?zhí)顚應剳驮颍?quot;, "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
//
if (contentTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(null, "請?zhí)顚應剳蛢?nèi)容!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
//
String money = moneyTextField.getText();
if (money.equals("0.00")) {
money = "0";
} else {
try {
money = Float.valueOf(money).intValue() + "";
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "獎懲金額填寫錯誤,請重新填寫!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
//
String startDate = startDateTextField.getText();
String endDate = endDateTextField.getText();
if (startDate.equals("") || endDate.equals("")) {
JOptionPane.showMessageDialog(null, "請?zhí)顚應剳偷钠鹬谷掌冢?quot;, "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else {
try {
Date.valueOf(startDate);
Date.valueOf(endDate);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "起止日期填寫錯誤,請重新填寫!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
//
if (!ratifierPersonComboBox.isEnabled()) {
JOptionPane.showMessageDialog(null, "請先選擇批準的部門,然后再選擇批準人!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
String ratifierPerson = ratifierPersonComboBox
.getSelectedItem().toString();
if (ratifierPerson.equals("請選擇")) {
JOptionPane.showMessageDialog(null, "請選擇批準部門及批準人!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
//
String ratifierDate = ratifierDateTextField.getText();
if (ratifierDate.equals("")) {
JOptionPane.showMessageDialog(null, "請?zhí)顚應剳偷钠鹬谷掌冢?quot;, "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
} else {
try {
Date.valueOf(ratifierDate);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "批準日期填寫錯誤,請重新填寫!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
//
TbRewardsAndPunishment rap = new TbRewardsAndPunishment();
TbRecord record = (TbRecord) dao.queryRecordByNum(personnal
.substring(0, 6));
rap.setTbRecordByRecordId(record);
rap.setType(type);
rap.setReason(reasonTextArea.getText());
rap.setContent(contentTextArea.getText());
rap.setMoney(new Integer(money));
rap.setStartDate(Date.valueOf(startDate));
rap.setEndDate(Date.valueOf(endDate));
TbDept ratifierDept = (TbDept) dao
.queryDeptByName(ratifierDeptTextField.getText());
rap.setTbDept(ratifierDept);
TbRecord ratifierRecord = (TbRecord) dao
.queryRecordByNum(ratifierPerson.substring(0, 6));
rap.setTbRecordByRatifierRecordId(ratifierRecord);
rap.setRatifierDate(Date.valueOf(ratifierDate));
// 持久化獎懲信息
dao.saveObject(rap);
HibernateSessionFactory.closeSession();
//
JOptionPane.showMessageDialog(null, "已經(jīng)成功保存此次獎懲信息!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
}
});
saveButton.setText("保存");
panel.add(saveButton);
final JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setLayout(new GridBagLayout());
add(panel_1, BorderLayout.CENTER);
final JLabel inDeptLabel = new JLabel();
inDeptLabel.setText("所在部門:");
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.insets = new Insets(0, 0, 10, 0);
gridBagConstraints.gridy = 0;
gridBagConstraints.gridx = 0;
panel_1.add(inDeptLabel, gridBagConstraints);
inDeptTextField = new JTextField();
inDeptTextField.setEditable(false);
inDeptTextField.setColumns(11);
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.insets = new Insets(0, 0, 10, 0);
gridBagConstraints_1.gridy = 0;
gridBagConstraints_1.gridx = 1;
panel_1.add(inDeptTextField, gridBagConstraints_1);
final JButton inDeptTreeButton = new JButton();
inDeptTreeButton.setMargin(new Insets(0, 6, 0, 3));
inDeptTreeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DeptTreeDialog deptTree = new DeptTreeDialog(inDeptTextField);
deptTree.setBounds(465, 259, 102, 175);
deptTree.setVisible(true);
TbDept dept = (TbDept) dao.queryDeptByName(inDeptTextField
.getText());
personnalComboBox.removeAllItems();
personnalComboBox.addItem("請選擇");
Iterator dutyInfoIt = dept.getTbDutyInfos().iterator();
while (dutyInfoIt.hasNext()) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -