📄 employeeface.java
字号:
this.getContentPane().add(p5);
this.getContentPane().add(p6);
this.getContentPane().add(p7);
this.getContentPane().add(p8);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
dispose();
}
});
ButtonGroup bg=new ButtonGroup();
bg.add(radep);
bg.add(raother);
ArrayList array=new ArrayList();
array=querydate.getDepartmentData();
System.out.println (array.size());
Iterator idata=array.iterator();
while(idata.hasNext())
{
comdep.addItem(((Object[])idata.next())[0]);
}
this.setSize(500,400);
this.move((int)(this.MOVEWIDTH-500)/2,(int)(this.MOVEHEIGHT-400)/2);
this.setVisible(true);
}
Employee(EmployeeFace emp,String title, String updatedata[])
{
super(title);
this.emp=emp;
tu=true;
if(updatedata.length!=0)
ID=updatedata[0];
JPanel p2=new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.LEFT));
p2.add(new JLabel(" "));
p2.add(labname);
p2.add(txtname);
txtname.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e) {
if(txtname.getText().equals("")|txtname.getText().equals("请输入姓名"))
{
txtname.setForeground(Color.RED);
txtname.setText("请输入姓名");
txtname.requestFocus(true);
}else
{
txtname.setForeground(Color.BLACK);
}
}
});
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(p1);
this.getContentPane().add(p2);
this.getContentPane().add(p3);
this.getContentPane().add(p4);
this.getContentPane().add(p5);
this.getContentPane().add(p6);
this.getContentPane().add(p7);
this.getContentPane().add(p8);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
dispose();
}
});
ButtonGroup bg=new ButtonGroup();
bg.add(radep);
bg.add(raother);
ArrayList array=new ArrayList();
array=querydate.getDepartmentData();
System.out.println (array.size());
Iterator idata=array.iterator();
while(idata.hasNext())
{
comdep.addItem(((Object[])idata.next())[0]);
}
if(this.getTitle()=="员工信息更改")
{
//if(updatedata==null)
//return;
txtname.setText(updatedata[1]);
for(int i=0;i<comdep.getItemCount();i++)
{
if(comdep.getItemAt(i).toString().equals(updatedata[2]))
comdep.setSelectedIndex(i);
}
}
this.setSize(500,400);
this.move((int)(this.MOVEWIDTH-500)/2,(int)(this.MOVEHEIGHT-400)/2);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==radep)
{
ArrayList array=new ArrayList();
array=querydate.getOnTimeAndOffTime((String)comdep.getSelectedItem());
Iterator idata=array.iterator();
Object[] ob=(Object[])idata.next();
txtontime.setText((String)ob[0]);
txtofftime.setText((String)ob[1]);
txtontime.setEditable(false);
txtontime.setForeground(Color.RED);
txtofftime.setEditable(false);
txtofftime.setForeground(Color.RED);
select=1;
}
if(e.getSource()==raother)
{
tu=true;
txtontime.setEditable(false);
txtofftime.setEditable(false);
select=2;
new Timeselect(this,"请设置上班时间");
}
if(e.getSource()==btnadd&&this.getTitle()=="员工信息增加")
{
if(txtontime.getText().equals("")|txtofftime.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"请检查上下班时间","警告",JOptionPane.WARNING_MESSAGE);
return;
}
if(YesNo(txtontime.getText(),txtofftime.getText()))
{
if(insertEmployee())
{
//System.out.println (JOptionPane.showConfirmDialog(this,"是否继续添加?","提示",JOptionPane.QUESTION_MESSAGE));
if(JOptionPane.showConfirmDialog(this,"是否继续添加?","提示",JOptionPane.WARNING_MESSAGE)==JOptionPane.YES_OPTION)
{
txtname.setText("");
txtname.requestFocus(true);
txtontime.setText("");
txtofftime.setText("");
//emp.displayEmployee();
}
else
dispose();
emp.displayEmployee();
}
}
else
{
JOptionPane.showMessageDialog(this,"请检查上下班时间","警告",JOptionPane.WARNING_MESSAGE);
}
}
if(e.getSource()==btnadd&&this.getTitle()=="员工信息更改")
{
if(txtontime.getText().equals("")|txtofftime.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"请检查上下班时间","警告",JOptionPane.WARNING_MESSAGE);
return;
}
if(YesNo(txtontime.getText(),txtofftime.getText()))
{
String empdep=null;
if(tu==false)
empdep="部门";
else
empdep="其他";
String[]s={ID,txtname.getText(), (String)comdep.getSelectedItem(),empdep,txtontime.getText(),txtofftime.getText(),(String)comjob.getSelectedItem()};
int i=rule.UpdateEmployee(s);
if(i>0)
{
JOptionPane.showMessageDialog(this,"修改记录成功","提示",JOptionPane.INFORMATION_MESSAGE);
emp.displayEmployee();
dispose();
}
}else
{
JOptionPane.showMessageDialog(this,"请检查上下班时间","警告",JOptionPane.WARNING_MESSAGE);
}
}
if(e.getSource()==btncancel)
{
dispose();
}
}
public void focusLost(FocusEvent e)
{
}
public void focusGained(FocusEvent e){
if((txtname.getText().equals("")|txtname.getText().equals("请输入姓名")))
{
txtname.setFont(new Font("隶书",Font.ITALIC,15));
txtname.setForeground(Color.RED);
txtname.requestFocus(true);
txtname.setText("请输入姓名");
}
}
public boolean insertEmployee()
{
String s[]=new String[6];
s[0]=txtname.getText();
s[1]=(String)comdep.getSelectedItem();
if(select==1)
{
s[2]=radep.getText();
select=0;
}
if(select==2)
{
s[2]=raother.getText();
select=0;
}
s[3]=txtontime.getText();
s[4]=txtofftime.getText();
s[5]=(String)comjob.getSelectedItem();
int i=rule.ExcuteInsertEmployee(s);
if(i>0)
{
JOptionPane.showMessageDialog(this,"添加了'"+i+"'条记录","增加记录",JOptionPane.INFORMATION_MESSAGE);
return true;
}
return false;
}
public void setontime(String s)
{
txtontime.setText(s);
if(!txtontime.getText().equals(""))
new Timeselect(this,"请设置下班时间");
}
public void setofftime(String s)
{
txtofftime.setText(s);
}
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)
{
if(getlong(one)<getlong(two))
return true;
else
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -