?? timecardpanel.java
字號(hào):
package com.mwq.frame.personnel;
import java.awt.BorderLayout;
import java.awt.Color;
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.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
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.TbAccountItem;
import com.mwq.hibernate.mapping.TbDept;
import com.mwq.hibernate.mapping.TbDutyInfo;
import com.mwq.hibernate.mapping.TbRecord;
import com.mwq.hibernate.mapping.TbTimecard;
import com.mwq.tool.Today;
public class TimecardPanel extends JPanel {
private JTextField inDeptTextField;
private JTextField deptTextField;
private JTextArea explainTextArea;
private JTextField endDateTextField;
private JTextField startDateTextField;
private JTextField ratifierDateTextField;
private JComboBox ratifierPersonComboBox;
private JComboBox timecardTypeComboBox;
private JComboBox personnalComboBox;
private Dao dao = Dao.getInstance();
/**
* Create the panel
*/
public TimecardPanel() {
super();
setLayout(new BorderLayout());
final JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.WHITE);
add(buttonPanel, BorderLayout.NORTH);
final JButton createButton = new JButton();
createButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inDeptTextField.setText(null);
personnalComboBox.removeAllItems();
personnalComboBox.addItem("請(qǐng)選擇");
Iterator recordsIt = dao.queryRecord().iterator();
while (recordsIt.hasNext()) {
TbRecord record = (TbRecord) recordsIt.next();
personnalComboBox.addItem(record.getRecordNumber() + " "
+ record.getName());
}
HibernateSessionFactory.closeSession();
timecardTypeComboBox.setSelectedIndex(0);
explainTextArea.setText("");
startDateTextField.setText(Today.TODAY_DATE);
endDateTextField.setText(Today.TODAY_DATE);
deptTextField.setText("");
ratifierPersonComboBox.removeAllItems();
ratifierPersonComboBox.setEnabled(false);
ratifierDateTextField.setText(Today.TODAY_DATE);
}
});
createButton.setText("新建");
buttonPanel.add(createButton);
final JButton saveButton = new JButton();
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
TbTimecard timecard = new TbTimecard();
String personnal = personnalComboBox.getSelectedItem()
.toString();
if (personnal.equals("請(qǐng)選擇")) {
JOptionPane.showMessageDialog(null, "請(qǐng)選擇欲考勤的職員!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
TbRecord record = (TbRecord) dao.queryRecordByNum(personnal
.substring(0, 6));
timecard.setTbRecordByRecordId(record);
String timecardType = timecardTypeComboBox.getSelectedItem()
.toString();
if (timecardType.equals("請(qǐng)選擇")) {
JOptionPane.showMessageDialog(null, "請(qǐng)選擇考勤類(lèi)型!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
TbAccountItem accountItem = (TbAccountItem) dao
.queryAccountItemByName(timecardType);
timecard.setTbAccountItem(accountItem);
if (explainTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(null, "請(qǐng)?zhí)顚?xiě)考勤說(shuō)明!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
timecard.setExplain(explainTextArea.getText());
try {
timecard.setStartDate(Date.valueOf(startDateTextField
.getText()));
timecard.setEndDate(Date
.valueOf(endDateTextField.getText()));
} catch (RuntimeException e) {
JOptionPane.showMessageDialog(null, "開(kāi)始日期或結(jié)束日期填寫(xiě)錯(cuò)誤,請(qǐng)重新填寫(xiě)!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
if (deptTextField.getText().equals("")) {
JOptionPane.showMessageDialog(null, "請(qǐng)選擇批準(zhǔn)部門(mén)!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
TbDept dept = (TbDept) dao.queryDeptByName(deptTextField
.getText());
timecard.setTbDept(dept);
String ratifierPerson = ratifierPersonComboBox
.getSelectedItem().toString();
if (ratifierPerson.equals("請(qǐng)選擇")) {
JOptionPane.showMessageDialog(null, "請(qǐng)選擇批準(zhǔn)人!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
TbRecord ratifierRecord = (TbRecord) dao
.queryRecordByNum(ratifierPerson.substring(0, 6));
timecard.setTbRecordByRatifierRecordId(ratifierRecord);
try {
timecard.setRatifierDate(Date.valueOf(ratifierDateTextField
.getText()));
} catch (RuntimeException e) {
JOptionPane.showMessageDialog(null, "批準(zhǔn)日期填寫(xiě)錯(cuò)誤,請(qǐng)重新填寫(xiě)!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
// 持久化考勤信息
dao.saveObject(timecard);
HibernateSessionFactory.closeSession();
//
JOptionPane.showMessageDialog(null, "已經(jīng)成功保存此次考勤信息!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
}
});
saveButton.setText("保存");
buttonPanel.add(saveButton);
final JPanel contentPanel = new JPanel();
contentPanel.setBackground(Color.WHITE);
contentPanel.setLayout(new GridBagLayout());
add(contentPanel, BorderLayout.CENTER);
final JLabel inDeptLabel = new JLabel();
inDeptLabel.setText("所在部門(mén):");
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 0;
gridBagConstraints.gridx = 0;
contentPanel.add(inDeptLabel, gridBagConstraints);
inDeptTextField = new JTextField();
inDeptTextField.setEditable(false);
inDeptTextField.setColumns(11);
final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints();
gridBagConstraints_9.gridy = 0;
gridBagConstraints_9.gridx = 1;
contentPanel.add(inDeptTextField, gridBagConstraints_9);
final JButton inDeptTreeButton = new JButton();// 創(chuàng)建按鈕對(duì)象
inDeptTreeButton.setMargin(new Insets(0, 6, 0, 3));
inDeptTreeButton.addActionListener(new ActionListener() {// 捕獲按鈕事件
public void actionPerformed(ActionEvent e) {
DeptTreeDialog deptTree = new DeptTreeDialog(
inDeptTextField);// 創(chuàng)建部門(mén)選取對(duì)話框
deptTree.setBounds(375, 317, 101, 175);// 設(shè)置部門(mén)選取對(duì)話框的顯示位置
deptTree.setVisible(true);// 彈出部門(mén)選取對(duì)話框
TbDept dept = (TbDept) dao
.queryDeptByName(inDeptTextField.getText());// 檢索選中的部門(mén)對(duì)象
personnalComboBox.removeAllItems();// 清空“考勤員工”下拉菜單中的所有選項(xiàng)
personnalComboBox.addItem("請(qǐng)選擇"); // 添加提示項(xiàng)
// 通過(guò)Hibernate的一對(duì)多關(guān)聯(lián)獲得與該部門(mén)關(guān)聯(lián)的職務(wù)信息對(duì)象
Iterator dutyInfoIt = dept.getTbDutyInfos().iterator();
while (dutyInfoIt.hasNext()) {// 遍歷職務(wù)信息對(duì)象
TbDutyInfo dutyInfo = (TbDutyInfo) dutyInfoIt
.next();// 獲得職務(wù)信息對(duì)象
TbRecord tbRecord = dutyInfo.getTbRecord();// 通過(guò)Hibernate的一對(duì)一關(guān)聯(lián)獲得與職務(wù)信息對(duì)象關(guān)聯(lián)的檔案信息對(duì)象
personnalComboBox.addItem(tbRecord
.getRecordNumber()
+ " " + tbRecord.getName());// 將該員工添加到“考勤員工”下拉菜單中
}
}
});
inDeptTreeButton.setText("...");
final GridBagConstraints gridBagConstraints_21 = new GridBagConstraints();
gridBagConstraints_21.gridy = 0;
gridBagConstraints_21.gridx = 2;
contentPanel.add(inDeptTreeButton, gridBagConstraints_21);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -