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

📄 swsituation.java

📁 JAVA实现的酒店管理系统
💻 JAVA
字号:
package file1;
/*
 * 功能描述:员工的非正常出勤情况查询入口
 * Author:黄顺武
 * Version:1.3
 */
import java.awt.*;
import sun.jdbc.rowset.*;
import java.sql.*;
import java.util.Date;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class SWSituation extends JPanel implements ActionListener, ItemListener {

	private JLabel head = new JLabel("员工职称:");
	private JLabel name = new JLabel("名字:");
	private JLabel identity = new JLabel("身份证号:");
	private JLabel timeWidth = new JLabel("时间范围:");
	private JComboBox headBox = new JComboBox();
	private JComboBox nameBox = new JComboBox();
	private JTextField identityTF = new JTextField(15);
	private String[] timeValue = { "一个月内", "两个月内", "半年内", "一年内" };
	private JComboBox timeWidthBox = new JComboBox(timeValue);
	private JButton query = new JButton("查询");
	private JPanel p1 = new JPanel();
	private JTable recTable = new JTable();
	private JScrollPane recPane = new JScrollPane();
	private String[] title = { "员工职称", "名字", "身份证号", "非正常出勤类型", "发生时间" };
	private int titleNum = 0;
	private String[][] data = null;
	private IdentityDate identityDate=new IdentityDate();//实例化对两个日期进行相关性判断的类对象
	private String[] identityNoS = null;

	public SWSituation() {
		String index = getHead();
		if (index == null) {
			return;
		}
		titleNum = title.length;
		p1.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 0));
		p1.add(head);
		p1.add(headBox);
		p1.add(name);
		p1.add(nameBox);
		p1.add(identity);
		p1.add(identityTF);
		p1.add(timeWidth);
		p1.add(timeWidthBox);
		timeWidthBox.setSelectedIndex(-1);
		query.setBackground(Color.LIGHT_GRAY);
		query.setBorder(null);
		p1.add(query);
		query.addActionListener(this);
		headBox.addItemListener(this);
		nameBox.addItemListener(this);
		identityTF.setEditable(false);
		this.setLayout(new BorderLayout(0, 0));
		this.add(p1, BorderLayout.NORTH);
		this.validate();
	}

	private String getHead() {
		try {
			DBConnection con = new DBConnection();
			String query = "select count(*) from Head";
			CachedRowSet crs = con.getResultSet(query);
			int count = 0;
			if (crs.next()) {
				count = crs.getInt(1);
			}
			if (count == 0) {
				JOptionPane.showMessageDialog(null, "请您先添加职称!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return null;
			}
			crs = null;
			query = "select hName from Head";
			crs = con.getResultSet(query);
			count = 0;
			while (crs.next()) {
				headBox.addItem(crs.getString(1));
			}
			headBox.setSelectedIndex(-1);
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			return null;
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
			return null;
		}
		return "success";
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == query) {
			String identityNo = identityTF.getText();
			if (identityNo.equals("")) {
				JOptionPane.showMessageDialog(null, "查询的身份证号不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			String timeArea = (String) timeWidthBox.getSelectedItem();
			if (timeArea == null) {
				JOptionPane.showMessageDialog(null, "查询的时间范围不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			int tArea = 0;
			if (timeArea.equals("一个月内")) {
				tArea = 30;
			} else if (timeArea.equals("两个月内")) {
				tArea = 60;
			} else if (timeArea.equals("半年内")) {
				tArea = 183;
			} else {
				tArea = 365;
			}
			String queryStr = "select head,name,IdentityNo,tName,occureTime "
					+ " from nWorkRecord,NNormalWork,Employee where IdentityNo='"
					+ identityNo
					+ "' and nWorkRecord.eID=Employee.ID and nWorkRecord.nTypeID=NNormalWork.ID";
			CachedRowSet crs = null;
			try {
				DBConnection con = new DBConnection();
				crs = con.getResultSet(queryStr);
				int count = 0;
				while (crs.next()) {
					count++;
				}
				data = new String[count][titleNum];
				count = 0;
				crs.beforeFirst();
				while (crs.next()) {
					String head = crs.getString(1);
					String name = crs.getString(2);
					String identity = crs.getString(3);
					String tName = crs.getString(4);
					String occureTime = crs.getString(5);
					identityDate.setFirstDate(occureTime.trim());
					identityDate.setSecondDate(new Date());
					if (identityDate.daysNotEqual() <= tArea) {//两个日期的间隔在查询的日期参数的范围内
						data[count][0] = head;
						data[count][1] = name;
						data[count][2] = identity;
						data[count][3] = tName;
						data[count][4] = occureTime;
						count++;
					}
				}
				recTable = new JTable(data, title);
				recPane = new JScrollPane(recTable);
				this.setLayout(new BorderLayout(0, 30));
				this.add(p1, BorderLayout.NORTH);
				this.add(recPane, BorderLayout.CENTER);
				this.validate();
			} catch (SQLException sqle) {
				sqle.printStackTrace();
			} catch (ClassNotFoundException cnfe) {
				cnfe.printStackTrace();
			}

		}
	}

	public void itemStateChanged(ItemEvent ie) {
		if (ie.getSource() == headBox) {
			if (ie.getStateChange() == ItemEvent.SELECTED) {
				int index = headBox.getSelectedIndex();
				if (index == -1) {
					return;
				}
				String head = (String) headBox.getSelectedItem();
				if (nameBox.getItemCount() != 0) {
					nameBox.removeAllItems();
				}
				StringBuffer querySB = new StringBuffer(
						"select name,IdentityNo from Employee where head='");
				querySB.append(head).append("'");
				CachedRowSet crs = null;
				try {
					DBConnection con = new DBConnection();
					crs = con.getResultSet(querySB.toString());
					int count = 0;
					while (crs.next()) {
						count++;
					}
					identityNoS = new String[count];
					crs.beforeFirst();
					count = 0;
					while (crs.next()) {
						nameBox.addItem(crs.getString(1));
						identityNoS[count] = crs.getString(2);
						count++;
					}
					nameBox.setSelectedIndex(-1);
				} catch (SQLException sqle) {
					sqle.printStackTrace();
				} catch (ClassNotFoundException cnfe) {
					cnfe.printStackTrace();
				}
			}
		}
		if (ie.getSource() == nameBox) {
			if (ie.getStateChange() == ItemEvent.SELECTED) {
				int index = nameBox.getSelectedIndex();
				if (index == -1) {
					return;
				}
				identityTF.setText(identityNoS[index]);
			}
		}
	}
}

⌨️ 快捷键说明

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