📄 ewsituation.java
字号:
package file1;
/*
* 功能描述:酒店员工的非正常出勤情况的总体查询
* @Author:黄顺武
* Version:1.2
*/
import java.awt.*;
import java.sql.*;
import java.util.Date;
import javax.swing.*;
import sun.jdbc.rowset.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class EWSituation extends JPanel implements ActionListener {
private JLabel monthArea = new JLabel("时间范围:");
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=null;//引入对两个日期进行相关判断的类
public EWSituation() {
titleNum = title.length;
p1.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 0));
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);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == query) {
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 order by head";
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 dateStr=crs.getString(5);
identityDate=new IdentityDate();
identityDate.setFirstDate(dateStr.trim());
identityDate.setSecondDate(new Date());
Date dateFirst=identityDate.getFirstDate();
if (dateFirst != null) {
if (identityDate.daysNotEqual() <= tArea) {//该条记录发生在统计时间内
data[count][0] = crs.getString(1);
data[count][1] = crs.getString(2);
data[count][2] = crs.getString(3);
data[count][3] = crs.getString(4);
data[count][4] = crs.getString(5);
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();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -