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

📄 kwsituation.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;

public class KWSituation extends JPanel implements ActionListener {

	private JLabel head = new JLabel("员工职称:");
	private JLabel monthArea = new JLabel("时间范围:");
	private JComboBox headBox = new JComboBox();
	private String[] monthValue = { "一个月内", "两个月内", "半年内", "一年内" };
	private JComboBox monthWidthBox = new JComboBox(monthValue);
	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();//实例化对两个日期进行相关性判断的类对象

	public KWSituation() {
		String index = getHead();
		if (index == null) {
			return;
		}
		p1.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 0));
		p1.add(head);
		p1.add(headBox);
		headBox.setSelectedIndex(-1);
		monthWidthBox.setSelectedIndex(-1);
		p1.add(monthArea);
		p1.add(monthWidthBox);
		query.setBackground(Color.LIGHT_GRAY);
		query.setBorder(null);
		p1.add(query);
		this.setLayout(new BorderLayout(0, 0));
		this.add(p1, BorderLayout.NORTH);
		this.validate();
		query.addActionListener(this);
	}

	private String getHead() {
		try {
			DBConnection con = new DBConnection();
			titleNum = title.length;
			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).trim());
			}
			crs = null;
			headBox.setSelectedIndex(-1);
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			return null;
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		}
		return "success";
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == query) {
			String eTitle = (String) headBox.getSelectedItem();
			if (eTitle == null) {
				JOptionPane.showMessageDialog(null, "查询员工职称不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			String timeArea = (String) monthWidthBox.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 "
					+ "nWorkRecord.eID=Employee.ID and nWorkRecord.nTypeID=NNormalWork.ID and head='"
					+ eTitle + "'";
			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();
				return;
			} catch (ClassNotFoundException cnfe) {
				cnfe.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

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