📄 signin.java
字号:
package face;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.util.*;
import rule.Rule;
import displayposition.position;
import queue.Queue;
import queue.Queue2;
import code.QueryData;
import java.io.*;
public class SignIn extends JPanel implements ActionListener
{
QueryData data=new QueryData();
QueryData data2=new QueryData();
JButton btnOn=new JButton("上班签到");
JButton btnOff=new JButton("下班签退");
JButton queryDep=new JButton("出勤统计");
JButton queryEmp=new JButton("员工情况");
ImageIcon icon=new ImageIcon("Image/PRINT.gif");
JButton print=new JButton("打印记录",icon);
DefaultTableModel m=new DefaultTableModel();
JTable table=new JTable(m);
Font font=new Font("宋体",Font.BOLD,12);
JScrollPane jsp=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
boolean bol,bol2;
boolean click;
Queue2 printdata=new Queue2(4);
public SignIn()
{
JPanel p=new JPanel();
p.add(btnOn);
btnOn.addActionListener(this);
p.add(btnOff);
btnOff.addActionListener(this);
p.add(queryEmp);
p.add(queryDep);
p.add(print);
print.addActionListener(this);
queryEmp.addActionListener(this);
queryDep.addActionListener(this);
table.setFont(font);
table.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
if(e.getSource()==table)
{
JTable tab=(JTable)e.getSource();
int i=tab.getSelectedRow();
for(int j=0;j<table.getColumnCount();j++)
{
printdata.put(table.getColumnName(j)+":");
printdata.put(table.getValueAt(i,j).toString());
}
click=true;
}
}
});
this.setLayout(new BorderLayout());
this.add(p,BorderLayout.NORTH);
this.add(jsp,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnOn)
{
new Enter("上班签到");
}
if(e.getSource()==btnOff)
{
new Enter("下班签退");
}
if(e.getSource()==queryEmp)
{
// if(bol==false)
// {
displayTableColumns();
// bol=true;
// }
String i=JOptionPane.showInputDialog(this,"请输入员工编号","");
while(true)
{
if(i==null)
return;
if(i.equals(""))
{
displayAllRecord();
return;
}
if(!data.getEmployee(Integer.parseInt(i)))
{
i=JOptionPane.showInputDialog(this,"员工编号有错,请确认",i);
continue;
}
break;
}
displayTableData(Integer.parseInt(i));
}
if(e.getSource()==queryDep)
{
// if(bol2==false)
// {
displayTotalTableColumns();
// bol2=true;
// }
String i=JOptionPane.showInputDialog(this,"请输入员工编号","");
while(true)
{
if(i==null)
return;
if(i.equals(""))
{
// displayAllTotalRecord();
return;
}
if(!data2.getEmployee(Integer.parseInt(i)))
{
i=JOptionPane.showInputDialog(this,"员工编号有错,请确认",i);
continue;
}
break;
}
displayTotalTableData(Integer.parseInt(i));
}
if(e.getSource()==print)
{
click=true;
new Printer(printRecord());
click=false;
}
}
private void displayTableColumns()
{
ArrayList array=new ArrayList();
array=data.getColumnsFromRecord();
Iterator idata=array.iterator();
while(m.getColumnCount()>0)
{
TableColumnModel columnModel = table.getColumnModel();
TableColumn tableColumn = columnModel.getColumn(m.getColumnCount()-1);
columnModel.removeColumn(tableColumn);
m.setColumnCount(m.getColumnCount()-1);
}
while(idata.hasNext())
{
m.addColumn(idata.next());
}
}
private void displayTotalTableColumns()
{
ArrayList array=new ArrayList();
array=data2.getColumnsFromTotalRecord();
Iterator idata=array.iterator();
while(m.getColumnCount()>0)
{
TableColumnModel columnModel = table.getColumnModel();
TableColumn tableColumn = columnModel.getColumn(m.getColumnCount()-1);
columnModel.removeColumn(tableColumn);
m.setColumnCount(m.getColumnCount()-1);
}
while(idata.hasNext())
{
m.addColumn(idata.next());
}
}
private Queue2 printRecord()
{
if(click==false)
return null;
else
return printdata;
}
private void displayTableData(int empid)
{
ArrayList array=new ArrayList();
while(m.getRowCount()>0)
{
m.removeRow(m.getRowCount()-1);
}
array=data.getDataFromRecord(empid);
Iterator idata=array.iterator();
while(idata.hasNext())
{
m.addRow((Object[])idata.next());
}
}
private void displayTotalTableData(int empid)
{
ArrayList array=new ArrayList();
while(m.getRowCount()>0)
{
m.removeRow(m.getRowCount()-1);
}
array=data2.getDataFromTotalRecord(empid);
Iterator idata=array.iterator();
while(idata.hasNext())
{
m.addRow((Object[])idata.next());
}
}
private void displayAllRecord()
{
ArrayList array=new ArrayList();
while(m.getRowCount()>0)
{
m.removeRow(m.getRowCount()-1);
}
array=data.getEmployeesWorkInformation();
Iterator idata=array.iterator();
while(idata.hasNext())
{
m.addRow((Object[])idata.next());
}
}
private void displayAllTotalRecord()
{
ArrayList array=new ArrayList();
while(m.getRowCount()>0)
{
m.removeRow(m.getRowCount()-1);
}
array=data2.getEmployeesTotalWorkInformation();
Iterator idata=array.iterator();
while(idata.hasNext())
{
m.addRow((Object[])idata.next());
}
}
}
class Enter extends JFrame implements ActionListener,position
{
JLabel lab=new JLabel("请输入员工编号:");
JTextField txt=new JTextField(10);
JButton ok=new JButton("确定");
JButton cancel=new JButton("取消");
String on="上班签到";
String off="下班签退";
Rule rule=new Rule();
QueryData data=new QueryData();
QueryData data2=new QueryData();
String checkstate;
String beLasttime;
Enter(String title)
{
super(title);
JPanel p=new JPanel();
JPanel q=new JPanel();
p.add(lab);
p.add(txt);
q.add(ok);
ok.addActionListener(this);
// q.add(cancel);
this.getContentPane().add(p,"North");
this.getContentPane().add(q,"South");
this.setSize(300,100);
this.setVisible(true);
this.move((int)(this.MOVEWIDTH-300)/2,(int)(this.MOVEHEIGHT-100)/2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok&&this.getTitle()=="上班签到")
{
if(txt.getText().equals("")|txt.getText().equals("请输入员工编号"))
{
txt.setText("请输入员工编号");
return;
}
try{
int i=Integer.parseInt(txt.getText());
}catch(Exception ex)
{
txt.setText("请输入员工编号");
return;
}
Queue str=new Queue(10);
Calendar ca=Calendar.getInstance();
String time=ca.get(Calendar.HOUR_OF_DAY)+":"+ca.get(Calendar.MINUTE)+":"+ca.get(Calendar.SECOND);
if(!data.getEmployee(Integer.parseInt(txt.getText())))
{
JOptionPane.showMessageDialog(this,"没有这个员工","警告",JOptionPane.WARNING_MESSAGE);
return;
}
if(YesNo(time,data.getOntime(Integer.parseInt(txt.getText())),false))
checkstate="正常";
else
checkstate="迟到";
str.put(txt.getText());
str.put(time);
str.put(on);
str.put(checkstate);
str.put(beLasttime);
if(rule.InsertRecord(str)>0)
{
JOptionPane.showMessageDialog(this,"签到成功","签到",JOptionPane.INFORMATION_MESSAGE);
dispose();
}
else
JOptionPane.showMessageDialog(this,"签到失败,请再试一次","签到",JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==ok&&this.getTitle()=="下班签退")
{
if(txt.getText().equals("")|txt.getText().equals("请输入员工编号"))
{
txt.setText("请输入员工编号");
return;
}
try{
int i=Integer.parseInt(txt.getText());
}catch(Exception ex)
{
txt.setText("请输入员工编号");
return;
}
Queue str=new Queue(10);
Calendar ca=Calendar.getInstance();
String time=ca.get(Calendar.HOUR_OF_DAY)+":"+ca.get(Calendar.MINUTE)+":"+ca.get(Calendar.SECOND);
if(!data.getEmployee(Integer.parseInt(txt.getText())))
{
JOptionPane.showMessageDialog(this,"请核对您的员工编号!","警告",JOptionPane.WARNING_MESSAGE);
return;
}
if(YesNo(time,data.getOfftime(Integer.parseInt(txt.getText())),true))
{ checkstate="正常"; }
else
{ checkstate="早退"; }
str.put(txt.getText());
str.put(time);
str.put(off);
str.put(checkstate);
str.put(beLasttime);
if(rule.InsertRecord(str)>0)
{
JOptionPane.showMessageDialog(this,"签退成功,慢走","签退",JOptionPane.INFORMATION_MESSAGE);
dispose();
}
else
JOptionPane.showMessageDialog(this,"签退失败,请再试一次","签退",JOptionPane.INFORMATION_MESSAGE);
}
}
private int getlong(String time)
{
int j=0;
int k[]=new int[3];
short w=0;
while(j<=time.length())
{
int i=time.indexOf(":",j);
if(i==-1)
i=time.length();
k[w]=Integer.parseInt(time.substring(j,i));
j=i+1;
w++;
}
return k[0]*3600+k[1]*60+k[2];
}
private boolean YesNo(String one,String two,boolean t)
{
if(t==false)
{
int hour=0;
int minute=0;
if(getlong(one)<=getlong(two))
{
beLasttime="00:00";
return true;
}
else
{
minute=(getlong(one)-getlong(two))/60;
hour=minute/60;
minute=minute%60;
if(hour==0)
beLasttime="00"+":"+minute;
else
beLasttime=hour+":"+minute;
return false;
}
}
else
{
int hour=0;
int minute=0;
if(getlong(one)>=getlong(two))
{
beLasttime="00:00";
return true;
}
else
{
minute=(getlong(two)-getlong(one))/60;
hour=minute/60;
minute=minute%60;
if(hour==0)
beLasttime="00"+":"+minute;
else
beLasttime=hour+":"+minute;
return false;
}
}
}
}
class Printer extends Frame implements position
{
Queue2 s;
Printer(final Queue2 s)
{
super("显示详细记录") ;
this.s=s;
this.setSize(400,300);
this.setVisible(true);
this.setBackground(Color.WHITE);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
s.clearAll();
dispose();
}
});
this.move((int)(this.MOVEWIDTH-400)/2,(int)(this.MOVEHEIGHT-300)/2);
}
public void paint(Graphics g)
{
Font font=new Font("宋体",Font.BOLD,14);
int x=50;
int y=50;
g.setFont(font);
FontMetrics fm=this.getFontMetrics(font);
for(int i=0;i<s.getlength();)
{
x=50;
g.drawString(s.get(i++),x,y);
x=x+fm.stringWidth(s.get(--i))+20;
i++;
g.drawString(s.get(i++),x,y);
y=y+25;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -