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

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-22
  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.sign;
  8. import oa.sys.*;
  9. import java.sql.*;
  10. import java.io.*;
  11. import javax.servlet.http.*;
  12. import javax.servlet.RequestDispatcher;
  13. import javax.servlet.ServletException;
  14. /**
  15.  ****************************************************
  16.  *类名称: Signstate<br>
  17.  *类功能: 设置员工签到时间<br>
  18.  *创建: 白伟明 2004年9月24日<br>
  19.  ****************************************************
  20.  * To change the template for this generated type comment go to
  21.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  22.  */
  23. public class Signstate extends HttpServlet{
  24. private Db db=null;
  25. private Str str=null;
  26. private int temp=0;
  27. private String up=null;
  28. private String down=null;
  29. private HttpSession session=null;
  30. private PrintWriter out=null;
  31. private ResultSet rs=null;
  32. private Statement stmt=null;
  33. private Statement stmtread=null;
  34. private PreparedStatement pstmt=null;
  35. private String sqlu="UPDATE signstate SET time=";
  36. private String sqli="INSERT INTO signstate values(?,?,?)";
  37. private String sqls="SELECT * FROM signstate WHERE signstateid=1 or signstateid=2";
  38. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  39. request.setCharacterEncoding("gb2312");
  40. response.setContentType("text/html; charset=gb2312");
  41. out = response.getWriter();
  42. session=request.getSession();
  43. str=new Str();
  44. db=new Db();
  45. //取得时间
  46. up=request.getParameter("up");
  47. down=request.getParameter("down");
  48. up=str.inStr(up);
  49. down=str.inStr(down);
  50. stmtread=db.getStmtread();
  51. try {
  52. rs=stmtread.executeQuery(sqls);
  53. //不是第一次设置时间更形数据库
  54. if(rs.next()){
  55. rs.beforeFirst();
  56. while(rs.next()){
  57. if(rs.getInt(1)==1){
  58. sqlu="UPDATE signstate SET time='"+up+"' WHERE signstateid=1";
  59. }else if(rs.getInt(1)==2){
  60. sqlu="UPDATE signstate SET time='"+down+"' WHERE signstateid=2";
  61. }
  62. stmt=db.getStmt();
  63. stmt.executeUpdate(sqlu);
  64. }
  65. stmt.close();
  66. rs.close();
  67. stmtread.close();
  68. }else{
  69. //第一次设置时间添加数据库
  70. pstmt=db.getPstmt(sqli);
  71. pstmt.setInt(1,1);
  72. pstmt.setString(2,"上班");
  73. pstmt.setString(3,up);
  74. pstmt.execute();
  75. pstmt.setInt(1,2);
  76. pstmt.setString(2,"下班");
  77. pstmt.setString(3,down);
  78. pstmt.execute();
  79. pstmt.close();
  80. }
  81. db.close();
  82. session.setAttribute("daymsg","设置成功");
  83. } catch (SQLException e) {
  84. session.setAttribute("daymsg","设置失败请输入正确格式");
  85. }finally{
  86. RequestDispatcher dispatcher=request.getRequestDispatcher("signstate.jsp");
  87. dispatcher.forward(request,response);
  88. }
  89. }
  90. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  91. doPost(request,response);
  92. }
  93. }