⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rewardsandpunishmentpanel.java

📁 java swing 开发的一些实例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
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, "请填写奖惩原因!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				//
				if (contentTextArea.getText().equals("")) {
					JOptionPane.showMessageDialog(null, "请填写奖惩内容!", "友情提示",
							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, "请填写奖惩的起止日期!", "友情提示",
							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, "请填写奖惩的起止日期!", "友情提示",
							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, "已经成功保存此次奖惩信息!", "友情提示",
						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 + -