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

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-24
  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.emex;
  8. import oa.sys.*;
  9. import oa.sys.Time;
  10. import java.io.IOException;
  11. import java.io.PrintWriter;
  12. import java.sql.*;
  13. import javax.servlet.*;
  14. import javax.servlet.http.*;
  15. /**
  16.  ****************************************************
  17.  *类名称: Add<br>
  18.  *类功能: 增加优秀员工信息<br>
  19.  *创建: 白伟明 2004年10月6日<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 sqlse;
  26. private int deid;
  27. private String sqlsd;
  28. private HttpSession session=null;
  29. private ResultSet rs=null;
  30. private Statement stmt=null;
  31. private String title,content,sqli,sqls;
  32. private int temp=0,id,emid;
  33. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  34. request.setCharacterEncoding("gb2312");
  35. response.setContentType("text/html; charset=gb2312");
  36. Str str=new Str();
  37. Db db=new Db();
  38. Time time=new Time();
  39. PrintWriter out=response.getWriter();
  40. session=request.getSession();
  41. try{
  42. id=Integer.parseInt((String)session.getAttribute("id"));
  43. emid=Integer.parseInt((String)request.getParameter("emid"));
  44. }catch(Exception e){
  45. }
  46. if(emid==id){
  47. emid=-1;
  48. }
  49. sqlsd="SELECT departmentid FROM eminfo WHERE employeeid="+emid;
  50. sqls="SELECT * FROM eminfo WHERE employeeid="+emid;
  51. sqlse="SELECT * FROM emexcellence WHERE time>='"+time.getYMD()+"' AND employeeid="+emid;
  52. try {
  53. stmt=db.getStmtread();
  54. rs=stmt.executeQuery(sqlsd);
  55. //查找被提名人部门id
  56. if(rs.next()){
  57. deid=rs.getInt(1);
  58. sqli="INSERT INTO emexcellence(employeeid,time,departmentid) VALUES('"+emid+"','"+time.getYMD()+"','"+deid+"')";
  59. }
  60. db.close();
  61. stmt=db.getStmtread();
  62. rs=stmt.executeQuery(sqls);
  63. //查找别提名人是否存在
  64. if(rs.next()){
  65. db.close();
  66. stmt=db.getStmtread();
  67. rs=stmt.executeQuery(sqlse);
  68. //判断被提名人本月是否被重复提名
  69. if(!rs.next()){
  70. db.close();
  71. stmt=db.getStmt();
  72. temp=stmt.executeUpdate(sqli);
  73. //判断提名是否成功
  74. if(temp>0){
  75. request.setAttribute("msg","提名成功");
  76. }else{
  77. request.setAttribute("msg","提名失败");
  78. }
  79. db.close();
  80. }else{
  81. request.setAttribute("msg","该员工已被提名");
  82. db.close();
  83. }
  84. }else{
  85. request.setAttribute("msg","员工不存在");
  86. db.close();
  87. }
  88. } catch (SQLException e) {
  89. e.printStackTrace();
  90. }finally{
  91. RequestDispatcher dispatcher=request.getRequestDispatcher("add.jsp");
  92. dispatcher.forward(request,response);
  93. }
  94. }
  95. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  96. doPost(request,response);
  97. }
  98. }