📄 employeeface.java
字号:
package face;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import displayposition.position;
import rule.Rule;
import java.util.*;
import java.util.Date;
import java.sql.Time;
import code.QueryData;
class Timeselect extends JFrame implements position,ActionListener
{
static boolean t;
Employee empface;
JLabel labtitle=new JLabel("请选择时间:");
JLabel labhour=new JLabel("小时:");
JLabel labminute=new JLabel("分钟:");
JLabel labsecond=new JLabel("秒钟:");
JComboBox comhour=new JComboBox();
JComboBox comminute=new JComboBox();
JComboBox comsecond=new JComboBox();
JButton btn=new JButton("确定");
Timeselect(Employee empface,String title)
{
super(title);
this.empface=empface;
for(int i=0;i<=23;i++)
{
if(i<10)
comhour.addItem("0"+String.valueOf(i));
else
comhour.addItem(String.valueOf(i));
}
for(int i=0;i<=59;i++)
{
if(i<10)
comminute.addItem("0"+String.valueOf(i));
else
comminute.addItem(String.valueOf(i));
}
for(int i=0;i<=59;i++)
{
if(i<10)
comsecond.addItem("0"+String.valueOf(i));
else
comsecond.addItem(String.valueOf(i));
}
this.getContentPane().add(labtitle);
JPanel p1=new JPanel();
p1.add(labhour);
p1.add(comhour);
p1.add(labminute);
p1.add(comminute);
p1.add(labsecond);
p1.add(comsecond);
p1.add(btn);
btn.addActionListener(this);
btn.setBackground(Color.pink);
this.getContentPane().add(labtitle,"North");
this.getContentPane().add(p1,"South");
this.setSize(400,80);
this.setVisible(true);
this.move((int)(this.MOVEWIDTH-400)/2,(int)(this.MOVEHEIGHT-80)/2);
}
public void actionPerformed(ActionEvent e)
{
if(t==false)
empface.setontime((String)comhour.getSelectedItem()+":"+(String)comminute.getSelectedItem()+":"+(String)comsecond.getSelectedItem());
else
empface.setofftime((String)comhour.getSelectedItem()+":"+(String)comminute.getSelectedItem()+":"+(String)comsecond.getSelectedItem());
dispose();
t=!t;
}
}
public class EmployeeFace extends JPanel implements position ,ActionListener
{
QueryData EmpCode=new QueryData();
Rule rule=new Rule();
Queue selectednum=new Queue(10);
Queue selectedname=new Queue(10);
String update[];
ImageIcon icon=new ImageIcon("Image/Query.gif");
JLabel query=new JLabel("请输入查询的员工编号");
JTextField txtID=new JTextField(10);
JButton btnquery=new JButton("查询",icon);
DefaultTableModel m=new DefaultTableModel();
JTable table=new JTable(m);
Font font=new Font("隶书",Font.BOLD,15);
JScrollPane jsp=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JButton btnAdd=new JButton("添加");
JButton btnDel=new JButton("删除");
JButton btnEdit=new JButton("修改");
public EmployeeFace()
{
JPanel p1=new JPanel();
p1.add(query);
p1.add(txtID);
p1.add(btnquery);
btnquery.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();
if(i>=0)
{
selectednum.put(m.getValueAt(i,0).toString());
selectedname.put(m.getValueAt(i,1).toString());
}
update=new String[table.getColumnCount()];
for(int j=0;j<update.length;j++)
{
update[j]=table.getValueAt(table.getSelectedRow(),j).toString();
}
}
}
});
JPanel p2=new JPanel();
p2.add(btnAdd);
p2.add(btnDel);
btnDel.addActionListener(this);
p2.add(btnEdit);
btnAdd.addActionListener(this);
btnEdit.addActionListener(this);
this.setLayout(new BorderLayout());
this.add(p1,BorderLayout.NORTH);
this.add(jsp,BorderLayout.CENTER);
this.add(p2,BorderLayout.SOUTH);
this.setBackground(Color.WHITE);
this.setVisible(true);
this.move((int)(this.MOVEWIDTH-700)/2,(int)(this.MOVEHEIGHT-400)/2);
displayColumnsName();
}
public void displayColumnsName()
{
ArrayList array=new ArrayList();
array=EmpCode.getColumnsName("Employee");
Iterator idata=array.iterator();
while(idata.hasNext())
{
m.addColumn(idata.next());
}
}
public void displayEmployee()
{
while(m.getRowCount()>0)
{
m.removeRow(m.getRowCount()-1);
}
ArrayList array=EmpCode.getEmployeeData(txtID.getText());
Iterator idata=array.iterator();
while(idata.hasNext())
{
m.addRow((Object[])idata.next());
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnquery) displayEmployee();
if(e.getSource()==btnAdd)
{
new Employee(this,"员工信息增加");
}
if(e.getSource()==btnDel)
{
if(selectedname.getlength()==0)
{
JOptionPane.showMessageDialog(this,"请选择一个或多个员工(点击所在行)","信息不足",JOptionPane.INFORMATION_MESSAGE);
return;
}
String sname="";
for(int j=0;j<selectedname.getlength();j++)
{
sname=sname+" "+selectedname.get(j);
}
if(JOptionPane.showConfirmDialog(this,"您要删除以下员工:"+sname,"删除记录",JOptionPane.WARNING_MESSAGE)==JOptionPane.YES_OPTION)
{
int sum=0;
for(int k=0;k<selectednum.getlength();k++)
{
int i=rule.ExcuteDeleteEmployee(selectednum.get(k));
sum=sum+i;
}
selectednum.clearAll();
selectedname.clearAll();
if(sum>0)
{
JOptionPane.showMessageDialog(this,"删除了'"+sum+"'条记录","删除记录",JOptionPane.INFORMATION_MESSAGE);
displayEmployee();
}
update=null;
}else
{
selectednum.clearAll();
selectedname.clearAll();
}
}
if(e.getSource()==btnEdit)
{
if(update!=null)
new Employee(this,"员工信息更改",update);
}
}
}
class Employee extends JFrame implements position ,ActionListener,FocusListener
{
QueryData querydate=new QueryData();
short select;
String s[]={"在职","出差","离职"};
Rule rule=new Rule();
EmployeeFace emp;
JLabel labname=new JLabel("员工姓名");
JTextField txtname=new JTextField(15);
JLabel labdep=new JLabel("所在部门");
JComboBox comdep=new JComboBox();
JLabel lab=new JLabel("时间标准");
JRadioButton radep=new JRadioButton("部门");
JRadioButton raother=new JRadioButton("其他");
JLabel labontime=new JLabel("上班时间");
JTextField txtontime=new JTextField(10);
JLabel labofftime=new JLabel("下班时间");
JTextField txtofftime=new JTextField(10);
JLabel labjob=new JLabel("在职情况");
JComboBox comjob=new JComboBox(s);
JButton btnadd=new JButton("确定");
JButton btncancel=new JButton("取消");
String ID;
boolean tu;
Employee(EmployeeFace emp,String title)
{
super(title);
this.emp=emp;
JPanel p2=new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.LEFT));
p2.add(new JLabel(" "));
p2.add(labname);
p2.add(txtname);
JPanel p3=new JPanel();
p3.setLayout(new FlowLayout(FlowLayout.LEFT));
p3.add(new JLabel(" "));
p3.add(labdep);
p3.add(comdep);
comdep.addFocusListener(this);
JPanel p4=new JPanel();
p4.setLayout(new FlowLayout(FlowLayout.LEFT));
p4.add(new JLabel(" "));
p4.add(lab);
p4.add(radep);
radep.addActionListener(this);
p4.add(raother);
raother.addActionListener(this);
JPanel p5=new JPanel();
p5.setLayout(new FlowLayout(FlowLayout.LEFT));
p5.add(new JLabel(" "));
p5.add(labontime);
p5.add(txtontime);
txtontime.setEditable(false);
txtontime.setFont(new Font("隶书",Font.BOLD,15));
JPanel p6=new JPanel();
p6.setLayout(new FlowLayout(FlowLayout.LEFT));
p6.add(new JLabel(" "));
p6.add(labofftime);
p6.add(txtofftime);
txtofftime.setEditable(false);
txtofftime.setFont(new Font("隶书",Font.BOLD,15));
JPanel p7=new JPanel();
p7.setLayout(new FlowLayout(FlowLayout.LEFT));
p7.add(new JLabel(" "));
p7.add(labjob);
p7.add(comjob);
JPanel p8=new JPanel();
p8.add(btnadd);
btnadd.addActionListener(this);
p8.add(btncancel);
btncancel.addActionListener(this);
this.getContentPane().setLayout(new GridLayout(8,1));
this.getContentPane().add(p2);
this.getContentPane().add(p3);
this.getContentPane().add(p4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -