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

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 oa.sys.Time;
  10. import java.io.*;
  11. import java.sql.*;
  12. import javax.servlet.*;
  13. import javax.servlet.http.*;
  14. /**
  15.  ****************************************************
  16.  *类名称: State<br>
  17.  *类功能: 员工签到<br>
  18.  *创建: 白伟明 2004年10月4日<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 Sign extends HttpServlet{
  24. private String sqli;
  25. private int temp;
  26. private String id;
  27. private int signstateid;
  28. private int h,m,s;
  29. private int late,quit;
  30. private String up;
  31. private String down;
  32. private ResultSet rs=null;
  33. private Statement stmt=null;
  34. private String sqls=null;
  35. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  36. request.setCharacterEncoding("gb2312");
  37. response.setContentType("text/html; charset=gb2312");
  38. PrintWriter out = response.getWriter();
  39. HttpSession session=request.getSession();
  40. Db db=new Db();
  41. Time time=new Time();
  42. //获取签到人
  43. id=(String)session.getAttribute("id");
  44. //获取签到时间
  45. up=(String)request.getParameter("up");
  46. down=(String)request.getParameter("down");
  47. if(up!=null&&up!=""){
  48. quit=0;
  49. try {
  50. sqls="SELECT signstateid FROM signstate WHERE time = '"+up+"' ";
  51. stmt=db.getStmtread();
  52. rs=stmt.executeQuery(sqls);
  53. if(rs.next()){
  54. signstateid=rs.getInt(1);
  55. }
  56. } catch (SQLException e1) {
  57. e1.printStackTrace();
  58. }finally{
  59. db.close();
  60. }
  61. h=time.getMinH(up);
  62. m=time.getMinM(up);
  63. s=time.getMinS(up);
  64. if(h>0){
  65. //没有迟到
  66. late=0;
  67. }else if(h==0){
  68. if(m>0){
  69. late=0;
  70. }else if(m==0){
  71. if(s>0){
  72. late=0;
  73. }else{
  74. late=1;
  75. }
  76. }else{
  77. late=1;
  78. }
  79. }else{
  80. late=1;
  81. }
  82. }
  83. if(down!=null&&down!=""){
  84. late=0;
  85. try {
  86. sqls="SELECT signstateid FROM signstate WHERE time = '"+down+"'";
  87. stmt=db.getStmtread();
  88. rs=stmt.executeQuery(sqls);
  89. if(rs.next()){
  90. signstateid=rs.getInt(1);
  91. }
  92. } catch (SQLException e1) {
  93. e1.printStackTrace();
  94. }finally{
  95. db.close();
  96. }
  97. h=time.getMinH(down);
  98. m=time.getMinM(down);
  99. s=time.getMinS(down);
  100. if(h<0){
  101. //没有早退
  102. quit=0;
  103. }else if(h==0){
  104. if(m<0){
  105. quit=0;
  106. }else if(m==0){
  107. if(s<=0){
  108. quit=0;
  109. }else{
  110. quit=1;
  111. }
  112. }else{
  113. quit=1;
  114. }
  115. }else{
  116. quit=1;
  117. }
  118. }
  119. sqli="INSERT sign(time,employeeid,late,quit,leave,work,signstateid) VALUES('"+new Time().getYMDHMS()+"',"
  120. +id+","+late+","+quit+","+0+","+0+","+signstateid+")";
  121. out.print(sqli);
  122.    try {
  123.    sqls="SELECT * FROM sign WHERE employeeid="+id+" AND signstateid="+
  124.    signstateid+" AND time >='"+new Time().getYMD()+"'";
  125. stmt=db.getStmtread();
  126. rs=stmt.executeQuery(sqls);
  127. if(!rs.next()){
  128. db.close();
  129. stmt=db.getStmt();
  130. temp=stmt.executeUpdate(sqli);
  131. if(temp>0){
  132. request.setAttribute("msg","以签到");
  133. }
  134. }
  135. } catch (SQLException e) {
  136. e.printStackTrace();
  137. }finally{
  138. db.close();
  139. RequestDispatcher dispatcher=request.getRequestDispatcher("state");
  140. dispatcher.forward(request,response);
  141. }
  142. }
  143. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  144. doPost(request,response);
  145. }
  146. }