package 小学期;
import java.sql.*;
import java.util.*;
import javax.swing.*;
public class PersonBean {
String sql;
ResultSet rs=null;
String field1;
String field2;
String field3;
String field4;
String field5;
String field6;
String field7;
String field8;
String field9;
String field10;
String colName ;
String colValue;
String colValue2;
public void add(String f1,String f2,String f3,String f4,
String f5,String f6,String f7,String f8,String f9,String f10){
DataBase DB = new DataBase();
this.field1 = f1;
this.field2 = f2;
this.field3 = f3;
this.field4 = f4;
this.field5 = f5;
this.field6 = f6;
this.field7 = f7;
this.field8 = f8;
this.field9 = f9;
this.field10 = f10;
if(field2 == null||field2.equals("")){
JOptionPane.showMessageDialog(null,"请输入员工姓名" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field3 == null||field3.equals("")){
JOptionPane.showMessageDialog(null,"请输入员工性别" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field4 == null||field4.equals("")){
JOptionPane.showMessageDialog(null,"请输入出生年月" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field5 == null||field5.equals("")){
JOptionPane.showMessageDialog(null,"请输入民族" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field6 == null||field6.equals("")){
JOptionPane.showMessageDialog(null,"请输入地址" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field7 == null||field7.equals("")){
JOptionPane.showMessageDialog(null,"请输入部门" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field8 == null||field8.equals("")){
JOptionPane.showMessageDialog(null,"请输入薪酬" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else{
sql = "insert into Person(PersonID,Name,Sex,Birth,Nat,Address,DeptID,Salary,Assess,Other) values ('"+field1+"','"+field2+"','"+field3+"','"+field4+"','"+field5+"','"+field6+"','"+field7+"','"+field8+"','"+field9+"','"+field10+"')";
try{
DB.OpenConn();
DB.excuteUpdate(sql);
JOptionPane.showMessageDialog(null,"成功添加一条新纪录!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"保存失败" ,"错误",JOptionPane.ERROR_MESSAGE);
}
finally{
DB.closeStmt();
DB.closeStmt();
}
}
}
public void modify(String f1,String f2,String f3,String f4,
String f5,String f6,String f7,String f8,String f9,String f10){
DataBase DB = new DataBase();
this.field1 = f1;
this.field2 = f2;
this.field3 = f3;
this.field4 = f4;
this.field5 = f5;
this.field6 = f6;
this.field7 = f7;
this.field8 = f8;
this.field9 = f9;
this.field10 = f10;
if(field2 == null||field2.equals("")){
JOptionPane.showMessageDialog(null,"请输入员工姓名" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field3 == null||field3.equals("")){
JOptionPane.showMessageDialog(null,"请输入员工性别" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field4 == null||field4.equals("")){
JOptionPane.showMessageDialog(null,"请输入出生年月" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field5 == null||field5.equals("")){
JOptionPane.showMessageDialog(null,"请输入民族" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field6 == null||field6.equals("")){
JOptionPane.showMessageDialog(null,"请输入地址" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field7 == null||field7.equals("")){
JOptionPane.showMessageDialog(null,"请输入部门" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else if(field8 == null||field8.equals("")){
JOptionPane.showMessageDialog(null,"请输入薪酬" ,"错误",JOptionPane.ERROR_MESSAGE);
return ;
}
else{
sql = "Update Person set Name = '"+field2+"',"+ "Sex = '"+field3+"',"+"Birth =+field4+ "
+"Nat = '"+field5+"',"+"Address = '"+field6+"'"+"DeptID ='"+field7+"'"
+"Salary = '"+field8+"'"+"Assess = '"+field9+"'"+"'"+field10+"'";
try{
DB.OpenConn();
DB.excuteUpdate(sql);
JOptionPane.showMessageDialog(null,"成功修改一条新纪录!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"更新失败" ,"错误",JOptionPane.ERROR_MESSAGE);
}
finally{
DB.closeStmt();
DB.closeStmt();
}
}
}
public void delete(String f1){
DataBase DB = new DataBase();
this.field1 = f1;
sql = "delete from Person where PersonID = '"+field1+"',";
try{
DB.OpenConn();
DB.excuteUpdate(sql);
JOptionPane.showMessageDialog(null,"成功删除一条新纪录!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"删除失败" ,"错误",JOptionPane.ERROR_MESSAGE);
}
finally{
DB.closeStmt();
DB.closeStmt();
}
}
public String[] search(String f1){
DataBase DB = new DataBase();
this.field1 = f1;
String[] s = new String[10];
sql = "select * from Person where PersonID = '"+field1+"',";
try{
DB.OpenConn();
rs = DB.excuteQuery(sql);
if(rs.next()){
s[0] = rs.getString("PersonID");
s[1] = rs.getString("Name");
s[2] = rs.getString("Sex");
s[3] = rs.getString("Birth");
s[4] = rs.getString("Nat");
s[5] = rs.getString("Address");
s[6] = rs.getString("DeptID");
s[7] = rs.getString("Salary");
s[8] = rs.getString("Assess");
s[9] = rs.getString("Other");
}
else
s = null;
}
catch(Exception e){
}
finally{
DB.closeStmt();
DB.closeStmt();
}
return s;
}
public String[][] searchAllForNode(){
DataBase DB = new DataBase();
String[][] sn = null;
int row = 0;
int i = 0;
sql = "SELECT PersonID,Name,Sex,Dept.DeptID as DeptID,B_Dept,S_Dept,Salary,Assess FROM Dept,Person where Dept.DeptID = Person.DeptID order by PersonID";
try{
DB.OpenConn();
rs = DB.excuteQuery(sql);
if(rs.last()){
row = rs.getRow();
}
if(row==0){
sn = new String[1][6];
sn[0][0]= " ";
sn[0][1]= " ";
sn[0][2]= " ";
sn[0][3]= " ";
sn[0][4]= " ";
sn[0][5]= " ";
}
else
sn = new String[row][6];
rs.first();
rs.previous();
while(rs.next()){
sn[i][0]= rs.getString("PersonID");
sn[i][1]= rs.getString("Name");
sn[i][2]= rs.getString("Sex");
sn[i][3]= rs.getString("B_Dept")+rs.getString("S_Dept");
sn[i][4]= rs.getString("Salary");
sn[i][5]= rs.getString("Assess");
i++;
}
}
catch(Exception e){
}
finally{
DB.closeStmt();
DB.closeStmt();
}
return sn;
}
public void updataDept(String f1,String f7){
DataBase DB= new DataBase();
this.field1 = f1;
this.field7 = f7;
sql = "Update Person set DeptID ="+field7+" where PersonID =" +field1;
try{
DB.OpenConn();
DB.excuteUpdate(sql);
JOptionPane.showMessageDialog(null,"人员调动成功!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"更新失败" ,"错误",JOptionPane.ERROR_MESSAGE);
}
finally{
DB.closeStmt();
DB.closeStmt();
}
}
public void updataSalary(String f1,String f8){
DataBase DB= new DataBase();
this.field1 = f1;
this.field7 = f8;
sql = "Update Person set Salary ="+field8+" where PersonID =" +field1;
try{
DB.OpenConn();
DB.excuteUpdate(sql);
JOptionPane.showMessageDialog(null,"劳资更改成功!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"更新失败" ,"错误",JOptionPane.ERROR_MESSAGE);
}
finally{
DB.closeStmt();
DB.closeStmt();
}
}
public void updataAssess(String f1,String f9){
DataBase DB= new DataBase();
this.field1 = f1;
this.field7 = f9;
sql = "Update Person set Assess ="+field9+" where PersonID =" +field1;
try{
DB.OpenConn();
DB.excuteUpdate(sql);
JOptionPane.showMessageDialog(null,"人员考核成功!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null,"更新失败" ,"错误",JOptionPane.ERRO