package com.idealab.struts.action;
import java.sql.Date;
import java.io.PrintWriter;
import java.sql.ResultSet;
/*import javax.resource.cci.ResultSet;*///与之前导入的ResultSet重名了
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.idealab.dao.Sysuser;
import com.idealab.dao.SysuserDAO;
import com.idealab.dao.Emp;
import com.idealab.dao.EmpDAO;
import com.idealab.dao.Empdoc;
import com.idealab.dao.EmpdocDAO;
import com.idealab.struts.form.NewUserForm;
import com.idealab.util.JdbcUtil;
public class NewAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter writer = response.getWriter();
String newType = request.getParameter("type");
JdbcUtil jdbc = new JdbcUtil();
jdbc.openConn();
String sql = null;
boolean success = false;
if (newType.equals("corp")) {// 新建公司
ResultSet rs1 = jdbc.executeQuery("select max(pk_corp) from corp");
int id;
if(!rs1.first()){
id=1;
}else id = rs1.getInt("max(pk_corp)")+1;
rs1.close();
sql = "insert into corp(pk_corp,name,addr,postcode,legalperson,regicode,regicapital"
+ ",regiorg,corptype,industry,website,email,tel,tel2,fax,content,goal,devcourse,honor) "
+ "values("+id+",'"
+ request.getParameter("name")
+ "','"
+ request.getParameter("addr")
+ "','"
+ request.getParameter("postcode")
+ "','"
+ request.getParameter("legalperson")
+ "','"
+ request.getParameter("regicode")
+ "','"
+ request.getParameter("regicapital")
+ "','"
+ request.getParameter("regiorg")
+ "','"
+ request.getParameter("corptype")
+ "','"
+ request.getParameter("industry")
+ "','"
+ request.getParameter("website")
+ "','"
+ request.getParameter("email")
+ "','"
+ request.getParameter("tel")
+ "','"
+ request.getParameter("tel2")
+ "','"
+ request.getParameter("fax")
+ "','"
+ request.getParameter("content")
+ "','"
+ request.getParameter("goal")
+ "','"
+ request.getParameter("devcourse")
+ "','"
+ request.getParameter("honor") + "')";
success = jdbc.executeUpdate(sql);
jdbc.closeConn();
} else if (newType.equals("dept")) {// 新建部门
ResultSet rs1 = jdbc.executeQuery("select max(pk_dept) from dept");
int id;
if(!rs1.first()){
id=1;
}else id = rs1.getInt("max(pk_dept)")+1;
rs1.close();
sql = "insert into dept(pk_dept,pk_corp,deptname,depttype,deptduty,addr,tel) values("
+ id+",1,'"
+ request.getParameter("deptname")
+ "','"
+ request.getParameter("depttype")
+ "','"
+ request.getParameter("deptduty")
+ "','"
+ request.getParameter("addr")
+ "','"
+ request.getParameter("tel")
+ "')";
System.out.println("valus of sql is:" + sql);
success = jdbc.executeUpdate(sql);
jdbc.closeConn();
} else if (newType.equals("post")) {// 新建职务
ResultSet rs1 = jdbc.executeQuery("select max(pk_post) from post");
int id=0;
if(!rs1.first()){
id=1;
}else if(rs1.first()){
id = rs1.getInt("max(pk_post)")+1;
};
rs1.close();
sql = "insert into post(pk_post,pk_outer_corp,postname,posttype,postdesc,postgoal,postduty) values("
+ id+",1,'"
+ request.getParameter("postname")
+ "','"
+ request.getParameter("posttype")
+ "','"
+ request.getParameter("postdesc")
+ "','"
+ request.getParameter("postgoal")
+ "','"
+ request.getParameter("postduty") + "')";
System.out.println("valus of sql is:" + sql);
success = jdbc.executeUpdate(sql);
jdbc.closeConn();
} else if (newType.equals("job")) {// 新建岗位
ResultSet rs1 = jdbc.executeQuery("select max(pk_job) from job");
int id;
if(!rs1.first()){
id=1;
}else id = rs1.getInt("max(pk_job)")+1;
rs1.close();
sql = "insert into job(pk_job,pk_dept,pk_outer_post,jobcode,jobname,jobtype,jobdesc) values("
+id+"," +request.getParameter("pk_dept")
+ ","
+ request.getParameter("pk_outer_post")
+ ",'"
+ request.getParameter("jobcode")
+ "','"
+ request.getParameter("jobname")
+ "','"
+ request.getParameter("jobtype")
+ "','"
+ request.getParameter("jobdesc")
+ "')";
System.out.println("valus of sql is:" + sql);
success = jdbc.executeUpdate(sql);
jdbc.closeConn();
} else if (newType.equals("emptype")) {// 新建人员类别
ResultSet rs1 = jdbc.executeQuery("select max(pk_emptype) from emptype");
int id;
if(!rs1.first()){
id=1;
}else id = rs1.getInt("max(pk_emptype)")+1;
rs1.close();
sql = "insert into emptype(pk_emptype,pk_outer_corp,typecode,typename,typedesc) values("
+ id+",1,'"
+ request.getParameter("typecode")
+ "','"
+ request.getParameter("typename")
+ "','"
+ request.getParameter("typedesc") + "')";
success = jdbc.executeUpdate(sql);
jdbc.closeConn();
} else if (newType.equals("emp")) {
/*
* Emp emp = new Emp();
* emp.setBirthdate(Date.valueOf(request.getParameter("birthdate")));
* emp.setBloodtype(request.getParameter("bloodtype"));
* emp.setComputerlevel(request.getParameter("computerlevel"));
* emp.setEducation(request.getParameter("education"));
* emp.setEmail(request.getParameter("email"));
* emp.setFirstforlang(request.getParameter("firstforlang"));
* emp.setFirstforlanglevel(request.getParameter("firstforlanglevel"));
* emp.setHealth(request.getParameter("health"));
* emp.setHometel(request.getParameter("hometel"));
* emp.setIdcard(request.getParameter("idcard"));
* emp.setInterest(request.getParameter("interest"));
* emp.setJobdate(Date.valueOf(request.getParameter("jobdate")));
* emp.setJobtype(request.getParameter("jobtype"));
* emp.setMarriagestat(request.getParameter("marriagestat"));
* emp.setMobile(request.getParameter("mobile"));
* emp.setName(request.getParameter("name"));
* emp.setNativeplace(request.getParameter("nativeplace"));
* emp.setOfficetel(request.getParameter("officetel"));
* emp.setPartydate(Date.valueOf(request.getParameter("partydate")));
* emp.setPartyname(request.getParameter("partyname"));
* emp.setPkOuterCorp(6); emp.setPkOuterDept(Integer.valueOf(request
* .getParameter("pk_outer_dept")));
* emp.setPkOuterEmptype(Integer.valueOf(request
* .getParameter("pk_outer_emptype")));
* emp.setPkOuterJob(Integer.valueOf(request
* .getParameter("pk_outer_job")));
* emp.setPostcode(request.getParameter("postcode"));
* emp.setResidentplace(request.getParameter("residentplace"));
* emp.setSex(request.getParameter("sex"));
* emp.setSin(request.getParameter("sin"));
* emp.setUsedname(request.getParameter("usedname")); EmpDAO dao =
* new EmpDAO(); success = dao.save(emp);
* System.out.println("插入人员信息成功"); //人员档案插入
*
* Empdoc doc = new Empdoc(); doc.setPkEmp(emp.getPkEmp());
* doc.setEmpname(emp.getName()); doc.setPkOuterCorp(6);
* doc.setPkOuterDept(emp.getPkOuterDept());
* doc.setPkOuterEmptype(emp.getPkOuterEmptype());
* doc.setPkOuterJob(emp.getPkOuterJob());
*
* EmpdocDAO docDao = new EmpdocDAO(); boolean
* success1=docDao.save(doc);
*/
/*
* System.out