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

📄 bringupoperatepanel.java

📁 用Java写的人事管理系统 数据库是sql 2000
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.mwq.frame.personnel;
// Download by http://www.codefans.net
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.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import com.mwq.frame.common.DeptAndPersonnelDialog;
import com.mwq.hibernate.Dao;
import com.mwq.hibernate.HibernateSessionFactory;
import com.mwq.hibernate.mapping.TbBringUpContent;
import com.mwq.hibernate.mapping.TbBringUpOntent;
import com.mwq.hibernate.mapping.TbDutyInfo;
import com.mwq.hibernate.mapping.TbRecord;
import com.mwq.mwing.MTable;
import com.mwq.tool.Today;

public class BringUpOperatePanel extends JPanel {

	private MTable table;

	private JTextField lecuterTextField;

	private JTextField objectTextField;

	private JTextField unitTextField;

	private JTextField endDateTextField;

	private JTextField addressTextField;

	private JTextField startDateTextField;

	private JTextField contentTextField;

	private JTextField nameTextField;

	private final Vector<String> columnNameV = new Vector<String>();

	private final Vector<Vector<String>> cellV = new Vector<Vector<String>>();

	private final DefaultTableModel tableModel = new DefaultTableModel();

	/**
	 * Create the panel
	 */
	public BringUpOperatePanel(final JPanel rightPanel, String bucId) {
		super();
		setLayout(new BorderLayout());

		final JPanel buttonPanel = new JPanel();
		buttonPanel.setBackground(Color.WHITE);
		add(buttonPanel, BorderLayout.NORTH);

		final JButton exitButton = new JButton();
		exitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rightPanel.removeAll();
				rightPanel.add(new BringUpSelectedPanel(rightPanel),
						BorderLayout.CENTER);
				SwingUtilities.updateComponentTreeUI(rightPanel);
			}
		});
		exitButton.setText("退出");
		buttonPanel.add(exitButton);

		final JButton addButton = new JButton();
		addButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DeptAndPersonnelDialog dpDialog = new DeptAndPersonnelDialog();
				Dimension screenSize = Toolkit.getDefaultToolkit()
						.getScreenSize();
				int w = 550;
				int h = 400;
				int x = (screenSize.width - w) / 2;
				int y = (screenSize.height - h) / 2;
				dpDialog.setBounds(x, y, w, h);
				dpDialog.setVisible(true);
				Vector<Vector<String>> selectedRecordV = dpDialog
						.getSelectedRecordV();
				if (cellV.size() == 0) {
					for (int i = 0; i < selectedRecordV.size(); i++) {
						Vector<String> newRecordV = selectedRecordV.get(i);
						newRecordV.set(0, i + 1 + "");
						cellV.add(newRecordV);
					}
				} else {
					int k = cellV.size();
					for (int i = 0; i < selectedRecordV.size(); i++) {
						Vector<String> newRecordV = selectedRecordV.get(i);
						boolean add = true;
						for (int j = 0; j < cellV.size(); j++) {
							Vector<String> oldRecordV = cellV.get(j);
							if (newRecordV.get(1).equals(oldRecordV.get(1))) {
								add = false;
								break;
							}
						}
						if (add) {
							newRecordV.set(0, ++k + "");
							cellV.add(newRecordV);
						}
					}
				}
				tableModel.setDataVector(cellV, columnNameV);
				dpDialog.dispose();
			}
		});
		addButton.setText("添加参训人员");
		buttonPanel.add(addButton);

		final JButton deleteButton = new JButton();
		deleteButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int[] selectedRows = table.getSelectedRows();
				if (selectedRows.length == 0) {
					JOptionPane.showMessageDialog(null, "请选择要取消参加此次培训资格的员工!",
							"友情提示", JOptionPane.INFORMATION_MESSAGE);
					return;
				} else {
					for (int i = selectedRows.length - 1; i >= 0; i--) {
						cellV.remove(selectedRows[i]);
					}
					for (int i = 0; i < cellV.size(); i++) {
						cellV.get(i).set(0, i + 1 + "");
					}
					tableModel.setDataVector(cellV, columnNameV);
				}
			}
		});
		deleteButton.setText("取消参训资格");
		buttonPanel.add(deleteButton);

		final JButton saveButton = new JButton();
		saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// 通过Java反射机制验证培训信息是否为空(所有信息均不允许为空)
				Field[] fields = BringUpOperatePanel.class.getDeclaredFields();// 通过Java反射机制获得类中的所有属性
				for (int i = 0; i < fields.length; i++) {// 遍历属性数组
					Field field = fields[i];// 获得属性
					if (field.getType().equals(JTextField.class)) {// 只验证JTextField类型的属性
						field.setAccessible(true);// 默认情况下不允许访问私有属性,如果设为true则允许访问
						JTextField textField = null;
						try {
							textField = (JTextField) field
									.get(BringUpOperatePanel.this);// 获得本类中的对应属性
						} catch (Exception e) {
							e.printStackTrace();
						}
						if (textField.getText().equals("")) {// 查看该属性是否为空
							String infos[] = { "请将培训信息填写完整!", "所有信息均不允许为空!" };
							JOptionPane.showMessageDialog(null, infos, "友情提示",// 弹出提示信息
									JOptionPane.INFORMATION_MESSAGE);
							textField.requestFocus();// 令为空的文本框获得焦点
							return;
						}
					}
				}
				// 验证日期
				String dateFormat = "20[0-9]{2}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}";
				Pattern pattern = Pattern.compile(dateFormat);
				Matcher startDateMatch = pattern.matcher(startDateTextField
						.getText());
				Matcher endDateMatch = pattern.matcher(endDateTextField
						.getText());
				if (!startDateMatch.matches() || !endDateMatch.matches()) {
					JOptionPane.showMessageDialog(null, "培训日期输入错误,请重新输入!",
							"友情提示", JOptionPane.INFORMATION_MESSAGE);
					return;
				}

				// 验证是否添加了参训人员
				if (cellV.size() == 0) {
					JOptionPane.showMessageDialog(null, "请设置参训人员!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}

				// 培训内容
				TbBringUpContent bringUpContent = new TbBringUpContent();
				bringUpContent.setName(nameTextField.getText());
				bringUpContent.setContent(contentTextField.getText());
				bringUpContent.setObject(objectTextField.getText());
				//
				DateFormat df = DateFormat.getDateInstance();
				try {
					bringUpContent.setStartDate(df.parse(startDateTextField
							.getText()));
					bringUpContent.setEndDate(df.parse(endDateTextField
							.getText()));
				} catch (ParseException e) {
					e.printStackTrace();
				}
				//
				bringUpContent.setUnit(unitTextField.getText());
				bringUpContent.setLecturer(lecuterTextField.getText());
				bringUpContent.setPlace(addressTextField.getText());

				// 培训人员
				int column = 0;
				for (int i = 0; i < table.getColumnCount(); i++) {
					if (table.getColumnName(i).equals("档案编号")) {
						column = i;
						break;
					}
				}
				Dao dao = Dao.getInstance();
				for (int i = 0; i < cellV.size(); i++) {
					TbBringUpOntent bringUpOntent = new TbBringUpOntent();
					bringUpOntent.setTbBringUpContent(bringUpContent);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -