import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class diaoru extends Frame implements ActionListener,ItemListener{
String sql;
ResultSet rs=null;
lianjie conn=null;
lianjie connT=null;
//生成控件
Label idLab=new Label("员工号");
Label nameLab=new Label("员工姓名");
Label sexLab=new Label("性别");
Label wTypeLab=new Label("工龄");
Label postLab=new Label("职称");
Label dtmtLab=new Label("部门");
Label wageLab=new Label("基本工资");
TextField idTxt=new TextField();
TextField nameTxt=new TextField();
TextField sexTxt=new TextField("");
TextField wTypeTxt=new TextField("");
TextField postTxt=new TextField("");
TextField wageTxt=new TextField("");
Choice dtmtChoice=new Choice();
Choice idChoice=new Choice();
Button addBut=new Button("调入");
Button exitBut=new Button("退出");
public diaoru(){
super("人员调入");
setSize(350,400);
setResizable(false);
setLayout(null);
this.setLocationRelativeTo(this.getParent());
//设置控件大小
idLab.setSize(50,20);
nameLab.setSize(50,20);
sexLab.setSize(50,20);
postLab.setSize(50,20);
dtmtLab.setSize(50,20);
wageLab.setSize(50,20);
wTypeLab.setSize(50,20);
idTxt.setSize(100,20);
nameTxt.setSize(100,20);
sexTxt.setSize(100,20);
postTxt.setSize(100,20);
wageTxt.setSize(100,20);
wTypeTxt.setSize(100,20);
dtmtChoice.setSize(100,20);
idChoice.setSize(100,20);
addBut.setSize(40,20);
exitBut.setSize(40,20);
//设置控件位置
idLab.setLocation(80,50);
nameLab.setLocation(80,80);
sexLab.setLocation(80,110);
postLab.setLocation(80,170);
dtmtLab.setLocation(80,200);
wageLab.setLocation(80,230);
wTypeLab.setLocation(80,260);
idTxt.setLocation(160,50);
nameTxt.setLocation(160,80);
sexTxt.setLocation(160,110);
postTxt.setLocation(160,170);
dtmtChoice.setLocation(160,200);
wageTxt.setLocation(160,230);
wTypeTxt.setLocation(160,260);
idChoice.setLocation(160,290);
addBut.setLocation(50,320);
exitBut.setLocation(250,320);
//把各控件添加到Frame上
add(idLab);
add(nameLab);
add(sexLab);
add(postLab);
add(dtmtLab);
add(wageLab);
add(wTypeLab);
add(idTxt);
add(nameTxt);
add(sexTxt);
add(postTxt);
add(wageTxt);
add(wTypeTxt);
add(dtmtChoice);
add(idChoice);
add(addBut);
add(exitBut);
//在四个按钮上注册监听器
addBut.addActionListener(this);
exitBut.addActionListener(this);
idChoice.addItemListener(this);
//初始化列表
initDtmtChoice();
initIdChoice();
//窗口"关闭"按钮添加窗口适配器
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
}
});
}
public void initDtmtChoice(){
try{
conn=new lianjie();
sql="select department from taizhang";
rs=conn.getRs(sql);
while(rs.next()){
dtmtChoice.addItem(rs.getString("department"));
}
conn.dbClose(rs);
conn=null;
}
catch(Exception e){}
}
public void initIdChoice()
{ try{
conn=new lianjie();
sql="select id from taizhang";
rs=conn.getRs(sql);
while(rs.next()){
idChoice.addItem(rs.getString("id"));
}
conn.dbClose(rs);
conn=null;
}
catch(Exception e){}
}
public void actionPerformed(ActionEvent ae){
if(ae.getActionCommand().equals("退出"))
dispose();
if(ae.getActionCommand().equals("调入")){
sql="select * from taizhang where id='"+idTxt.getText()+"'";
conn=new lianjie();
try{
rs=conn.getRs(sql);
if(rs.next()){
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"该员工已经存在!","警告",1);
conn.dbClose(rs);
conn=null;
rs=null;
}
else{
try{
sql="insert into taizhang values('"+idTxt.getText()+"','"+nameTxt.getText()+"','"+sexTxt.getText()+"','"+dtmtChoice.getSelectedItem()+"','"+postTxt.getText()+"','"+wTypeTxt.getText()+"','"+wageTxt.getText()+"')";
conn=new lianjie();
conn.dbMod(sql);
conn.dbClose(rs);
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"添加成功!","提示信息",1);
sql="insert into butie values('"+idTxt.getText()+"','"+nameTxt.getText()+"','"+sexTxt.getText()+"','100','0','0','0','0','2010-9-1')";
connT=new lianjie();
connT.dbMod(sql);
connT.dbClose(rs);
sql="insert into koukuan values('"+idTxt.getText()+"','"+nameTxt.getText()+"','"+sexTxt.getText()+"','150','60','0','0','0','0','2010-9-1')";
connT=new lianjie();
connT.dbMod(sql);
connT.dbClose(rs);
conn=new lianjie();
sql="update butie set sumb=jtbutie+zfbutie+ysbutie+qtbutie";
conn.dbMod(sql);
conn.dbClose(rs);
sql="update koukuan set sumk=fang+shuidian+tuoer+jiezhi+qita";
conn=new lianjie();
conn.dbMod(sql);
conn.dbClose(rs);
sql="insert into huizong values('"+idTxt.getText()+"','"+nameTxt.getText()+"','"+wageTxt.getText()+"','150','60','0','0','2010-9-1')";
connT=new lianjie();
connT.dbMod(sql);
connT.dbClose(rs);
conn=new lianjie();
sql="update huizong,butie set huizong.补贴=butie.sumb where huizong.员工号=butie.id";
conn.dbMod(sql);
conn.dbClose(rs);
conn=new lianjie();
sql="update huizong,koukuan set huizong.扣款=koukuan.sumk where huizong.员工号=koukuan.id";
conn.dbMod(sql);
conn.dbClose(rs);
conn=new lianjie();
conn=new lianjie();
sql="update huizong,taizhang set huizong.工龄工资=taizhang.wagetype*0.5 where huizong.员工号=taizhang.id";
conn.dbMod(sql);
conn.dbClose(rs);
conn=new lianjie();
sql="update huizong set 实发工资=补贴+工龄工资-扣款+基本工资";
conn.dbMod(sql);
conn.dbClose(rs);
}
catch(Exception se){}
idChoice.addItem(idTxt.getText());
idTxt.setText("");
nameTxt.setText("");
sexTxt.setText("");
postTxt.setText("");
wageTxt.setText("");
conn=null;
connT=null;
}
}catch(Exception a){}
}
}
public void itemStateChanged(ItemEvent ie){
String sqlTemp;
ResultSet rsTemp=null;
idTxt.setText(idChoice.getSelectedItem());
sqlTemp="select * from taizhang where id='"+idTxt.getText()+"'";
try{
lianjie sConn=new lianjie();
rsTemp=sConn.getRs(sqlTemp);
if(rsTemp.next()){
idTxt.setText(rsTemp.getString("id"));
nameTxt.setText(rsTemp.getString("name"));
sexTxt.setText(rsTemp.getString("sex"));
wTypeTxt.setText(rsTemp.getString("wagetype"));
postTxt.setText(rsTemp.getString("post"));
dtmtChoice.select(rsTemp.getString("department"));
wageTxt.setText(rsTemp.getString("wage"));
sConn.dbClose(rsTemp);
sConn=null;
rsTemp=null;
sConn=null;
}
}
catch(Exception e){
System.out.println("列表连接数据库出错!");
}
}
}