Add.java
上传用户:sxwtmm
上传日期:2022-08-11
资源大小:2183k
文件大小:5k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-25
  3.  *
  4.  * To change the template for this generated file go to
  5.  * Window>Preferences>Java>Code Generation>Code and Comments
  6.  */
  7. package com.em;
  8. import oa.sys.*;
  9. import oa.data.*;
  10. import java.io.*;
  11. import java.sql.*;
  12. import java.util.*;
  13. import javax.servlet.*;
  14. import javax.servlet.http.*;
  15. /**
  16.  ****************************************************
  17.  *类名称: Add<br>
  18.  *类功能: 获取部门、职位、员工状态信息<br>
  19.  *创建: 白伟明 2004年9月25日<br>
  20.  ****************************************************
  21.  * To change the template for this generated type comment go to
  22.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  23.  */
  24. public class Add extends HttpServlet{
  25. private String state;
  26. private String job;
  27. private String dep;
  28. private int stateid;
  29. private String addr;
  30. private String tel;
  31. private int jobid;
  32. private int deid;
  33. private String post;
  34. private String learn;
  35. private String birthday;
  36. private int sex;
  37. private String name;
  38. private Statement stmt=null;
  39. private ResultSet rs=null;
  40. private RequestDispatcher dispatcher=null;
  41. private HttpSession session=null;
  42. private int id=0;
  43. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  44. request.setCharacterEncoding("gb2312");
  45. response.setContentType("text/html; charset=gb2312");
  46. session=request.getSession();
  47. Db db=new Db();
  48. Str str=new Str();
  49. PrintWriter out=response.getWriter();
  50. //获取id取出员工基本信息
  51. try{
  52. id=Integer.parseInt((String)request.getParameter("id"));
  53. Collection coll=new ArrayList();
  54. stmt=db.getStmtread();
  55. rs=stmt.executeQuery("SELECT * FROM eminfo WHERE employeeid="+id);
  56. if(rs.next()){
  57. rs.beforeFirst();
  58. while(rs.next()){
  59. id=rs.getInt(1);
  60. name=rs.getString(2);
  61. sex=rs.getInt(3);
  62. birthday=rs.getString(4);
  63. learn=rs.getString(5);
  64. post=rs.getString(6);
  65. deid=rs.getInt(7);
  66. jobid=rs.getInt(8);
  67. tel=rs.getString(9);
  68. addr=rs.getString(10);
  69. stateid=rs.getInt(11);
  70. dep=db.IdtoDo("Name","department WHERE departmentid="+deid);
  71. job=db.IdtoDo("Name","job WHERE jobid="+jobid);
  72. state=db.IdtoDo("Name","emstate WHERE stateid="+stateid);
  73. //字符转换
  74. name=str.outStr(name);
  75. birthday=birthday.substring(0,10);
  76. dep=str.outStr(dep);
  77. job=str.outStr(job);
  78. state=str.outStr(state);
  79. learn=str.outStr(learn);
  80. post=str.outStr(post);
  81. tel=str.outStr(tel);
  82. addr=str.outStr(addr);
  83. Eminfo eminfo=new Eminfo();
  84. eminfo.setId(id);
  85. eminfo.setName(name);
  86. eminfo.setSex(sex);
  87. eminfo.setBirthday(birthday);
  88. eminfo.setLearn(learn);
  89. eminfo.setPost(post);
  90. eminfo.setDepartment(dep);
  91. eminfo.setJob(job);
  92. eminfo.setTel(tel);
  93. eminfo.setAddr(addr);
  94. eminfo.setState(state);
  95. coll.add(eminfo);
  96. }//while
  97. session.setAttribute("msgem",coll);
  98. }
  99. }catch(Exception e){
  100. e.printStackTrace();
  101. id=0;
  102. }finally{
  103. db.close();
  104. }
  105. //三个条件分别保存
  106. Collection retd=new ArrayList();
  107. Collection retj=new ArrayList();
  108. Collection rete=new ArrayList();
  109. try{
  110. stmt=db.getStmtread();
  111. rs=stmt.executeQuery("SELECT * from department");
  112. if(rs.next()){
  113. rs.beforeFirst();
  114. while(rs.next()){
  115. int id=rs.getInt(1);
  116. String name=rs.getString(2);
  117. String explain=rs.getString(3);
  118. name=str.outStr(name);
  119. explain=str.outStr(explain);
  120. Department dep=new Department();
  121. dep.setId(id);
  122. dep.setName(name);
  123. dep.setExplain(explain);
  124. retd.add(dep);
  125. }
  126. }
  127. db.close();
  128. stmt=db.getStmtread();
  129. rs=stmt.executeQuery("SELECT * from job");
  130. if(rs.next()){
  131. rs.beforeFirst();
  132. while(rs.next()){
  133. int id=rs.getInt(1);
  134. String name=rs.getString(2);
  135. String explain=rs.getString(3);
  136. name=str.outStr(name);
  137. explain=str.outStr(explain);
  138. Job dep=new Job();
  139. dep.setId(id);
  140. dep.setName(name);
  141. dep.setExplain(explain);
  142. retj.add(dep);
  143. }
  144. }
  145. db.close();
  146. stmt=db.getStmtread();
  147. rs=stmt.executeQuery("SELECT * from emstate");
  148. if(rs.next()){
  149. rs.beforeFirst();
  150. while(rs.next()){
  151. int id=rs.getInt(1);
  152. String name=rs.getString(2);
  153. String explain=rs.getString(3);
  154. name=str.outStr(name);
  155. explain=str.outStr(explain);
  156. Emstate dep=new Emstate();
  157. dep.setId(id);
  158. dep.setName(name);
  159. dep.setExplain(explain);
  160. rete.add(dep);
  161. }
  162. }
  163. db.close();
  164. session.removeAttribute("msgd");
  165. session.setAttribute("msgd",retd);
  166. session.removeAttribute("msgj");
  167. session.setAttribute("msgj",retj);
  168. session.removeAttribute("msge");
  169. session.setAttribute("msge",rete);
  170. }catch(Exception e){
  171. e.printStackTrace();
  172. }finally{
  173. db.close();
  174. if(id==0){
  175. dispatcher=request.getRequestDispatcher("add.jsp");
  176. }else{
  177. dispatcher=request.getRequestDispatcher("change.jsp");
  178. }
  179. dispatcher.forward(request,response);
  180. }
  181. }
  182. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  183. doPost(request,response);
  184. }
  185. }