kaoqin.jsp
上传用户:jhtang88
上传日期:2014-01-27
资源大小:28528k
文件大小:14k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html;charset=utf-8"%>
  2. <%@ page import = "java.util.Calendar"%>
  3. <%@ page import = "java.util.Date"%>
  4. <%@ page import = "com.redmoon.oa.kaoqin.*"%>
  5. <%@ page import = "cn.js.fan.util.StrUtil"%>
  6. <%@ page import = "cn.js.fan.util.ParamUtil"%>
  7. <%@ page import = "cn.js.fan.util.ErrMsgException"%>
  8. <%@ page import = "cn.js.fan.util.DateUtil"%>
  9. <%@ page import = "cn.js.fan.web.*"%>
  10. <%@ include file="inc/inc.jsp"%>
  11. <%@ page import="java.text.*"%>
  12. <jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/>
  13. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  14. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  18. <title>考勤</title>
  19. <link href="common.css" rel="stylesheet" type="text/css">
  20. <%@ include file="inc/nocache.jsp"%>
  21. <script language="JavaScript" type="text/JavaScript">
  22. <!--
  23. function MM_preloadImages() { //v3.0
  24.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  25.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  26.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  27. }
  28. //-->
  29. </script>
  30. <script language=javascript>
  31. <!--
  32. function openWin(url,width,height)
  33. {
  34.   var newwin=window.open(url,"_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=120,width="+width+",height="+height);
  35. }
  36. //-->
  37. </script>
  38. </head>
  39. <body background="" leftmargin="0" topmargin="5" marginwidth="0" marginheight="0">
  40. <jsp:useBean id="cfgparser" scope="page" class="cn.js.fan.util.CFGParser"/>
  41. <%
  42. if (!privilege.isUserLogin(request))
  43. {
  44. out.println(cn.js.fan.web.SkinUtil.makeErrMsg(request, cn.js.fan.web.SkinUtil.LoadString(request, "pvg_invalid")));
  45. return;
  46. }
  47. %>
  48. <%!
  49.   int daysInMonth[] = {
  50.       31, 28, 31, 30, 31, 30, 31, 31,
  51.       30, 31, 30, 31};
  52.   public int getDays(int month, int year) {
  53.     //测试选择的年份是否是润年?
  54.     if (1 == month)
  55.       return ( (0 == year % 4) && (0 != (year % 100))) ||
  56.           (0 == year % 400) ? 29 : 28;
  57.         else
  58.       return daysInMonth[month];
  59.   }
  60. %>
  61. <%
  62. // 翻月
  63. int showyear,showmonth;
  64. Calendar cal = Calendar.getInstance();
  65. int curday = cal.get(cal.DAY_OF_MONTH);
  66. int curhour = cal.get(cal.HOUR_OF_DAY);
  67. int curminute = cal.get(cal.MINUTE);
  68. int curmonth = cal.get(cal.MONTH);
  69. int curyear = cal.get(cal.YEAR);
  70. String strshowyear = request.getParameter("showyear");
  71. String strshowmonth = request.getParameter("showmonth");
  72. if (strshowyear!=null)
  73. showyear = Integer.parseInt(strshowyear);
  74. else
  75. showyear = cal.get(cal.YEAR);
  76. if (strshowmonth!=null)
  77. showmonth = Integer.parseInt(strshowmonth);
  78. else
  79. showmonth = cal.get(cal.MONTH)+1;
  80. cfgparser.parse("config_oa.xml");
  81. Properties props = cfgparser.getProps();
  82. String mbeginp = props.getProperty("morningbegin");
  83. String mendp = props.getProperty("morningend");
  84. String abeginp = props.getProperty("afternoonbegin");
  85. String aendp = props.getProperty("afternoonend");
  86. String[] strmbegin = mbeginp.split(":");
  87. String[] strmend = mendp.split(":");
  88. String[] strabegin = abeginp.split(":");
  89. String[] straend = aendp.split(":");
  90. int latevalue = Integer.parseInt(props.getProperty("latevalue"));
  91. int[] mbegin = new int[2]; // 上午上班开始时间,0为小时,1为分钟
  92. int[] mend = new int[2];
  93. int[] abegin = new int[2];
  94. int[] aend = new int[2];
  95. for (int k=0; k<2; k++) {
  96. mbegin[k] = Integer.parseInt(strmbegin[k]);
  97. mend[k] = Integer.parseInt(strmend[k]);
  98. abegin[k] = Integer.parseInt(strabegin[k]);
  99. aend[k] = Integer.parseInt(straend[k]);
  100. }
  101. %>
  102. <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableframe">
  103.   <tr>
  104.     <td width="100%" height="23" class="right-title"><span>&nbsp;<%=showmonth%>月 考 勤 表 &nbsp;&nbsp;上午<%=mbeginp%>-<%=mendp%> 下午<%=abeginp%>-<%=aendp%> 迟到或早退为相差 <%=latevalue%>分钟</span></td>
  105.   </tr>
  106.   <tr>
  107.     <td valign="top">
  108. <%
  109. String op = ParamUtil.get(request, "op");
  110. if (op.equals("add"))
  111. {
  112. boolean re = false;
  113. try {
  114. KaoqinMgr km = new KaoqinMgr();
  115. re = km.create(request);
  116. }
  117. catch (ErrMsgException e) {
  118. out.print(StrUtil.Alert(e.getMessage()));
  119. }
  120. if (re)
  121. out.print(StrUtil.Alert("操作成功!"));
  122. }
  123. %>
  124. <table width="98%" border="0" align="center">
  125.         <tr>
  126.           <td align="center">&nbsp;</td>
  127.         </tr>
  128.         <tr> 
  129.           <td align="center">
  130. <select name="showyear" onChange="var y = this.options[this.selectedIndex].value; window.location.href='?showyear=' + y;">
  131.   <%for (int y=curyear-60; y<=curyear; y++) {%>
  132.   <option value="<%=y%>"><%=y%></option>
  133.   <%}%>
  134.   </select>
  135.   <script>
  136.   showyear.value = "<%=showyear%>";
  137.   </script>   
  138. <%
  139. for (int i=1; i<=12; i++) {
  140. if (showmonth==i)
  141. out.print("<a href='kaoqin.jsp?showyear="+showyear+"&showmonth="+i+"'><font color=red>"+i+"月</font></a>&nbsp;");
  142. else
  143. out.print("<a href='kaoqin.jsp?showyear="+showyear+"&showmonth="+i+"'>"+i+"月</a>&nbsp;");
  144. }
  145. %> </td>
  146.         </tr>
  147.         <tr> 
  148.           <td align="center"> <a href="kaoqin.jsp?showyear=<%=showyear%>&showmonth=<%=showmonth%>">全部</a> 
  149.             <a href="kaoqin.jsp?showtype=<%=StrUtil.UrlEncode("考勤")%>&showyear=<%=showyear%>&showmonth=<%=showmonth%>">考勤</a> 
  150.             <a href="kaoqin.jsp?showtype=<%=StrUtil.UrlEncode("外出办事")%>&showyear=<%=showyear%>&showmonth=<%=showmonth%>">外出办事</a> 
  151.             <a href="kaoqin.jsp?showtype=<%=StrUtil.UrlEncode("加班")%>&showyear=<%=showyear%>&showmonth=<%=showmonth%>">加班</a> 
  152.             <a href="kaoqin.jsp?showtype=<%=StrUtil.UrlEncode("其他原因")%>&showyear=<%=showyear%>&showmonth=<%=showmonth%>">其他原因</a> 
  153.           </td>
  154.         </tr>
  155.       </table>
  156. <%
  157. String sql;
  158. // 获取本月考勤
  159. String showtype = ParamUtil.get(request, "showtype");
  160. if (showtype.equals(""))
  161. sql = "select id from kaoqin where name="+fchar.sqlstr(privilege.getUser(request))+" and MONTH(myDate)="+showmonth+" and YEAR(myDate)="+showyear+" order by mydate asc";
  162. else
  163. sql = "select id from kaoqin where name="+fchar.sqlstr(privilege.getUser(request))+" and MONTH(myDate)="+showmonth+" and YEAR(myDate)="+showyear+" and type="+fchar.sqlstr(showtype)+" order by mydate asc";
  164. int i = 1;
  165. String direction="",type="",reason="",mydate="",strweekday="";
  166. int id;
  167. int weekday=0;
  168. Date dt = null;
  169. int monthday = 0;
  170. int monthdaycount = getDays(showmonth-1,showyear);//当前显示月份的天数
  171. String[] wday = {"","日","一","二","三","四","五","六"};
  172. boolean coloralt = true;//背景颜色交替
  173. String backcolor = "#ffffff";
  174. int myhour = 0; //用于计算迟到时间
  175. int myminute = 0;
  176. int latecount = 0;//迟到次数
  177. int beforecount = 0; //早退次数
  178. int latehour = 0;
  179. int lateminute = 0;
  180. Calendar cld = Calendar.getInstance();
  181. KaoqinDb kd = new KaoqinDb();
  182. Vector v = kd.list(sql);
  183. Iterator ir = v.iterator();
  184. %>
  185.       <br>
  186.       <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="stable">
  187.         <tr align="center" bgcolor="#C4DAFF"> 
  188.           <td width="8%" class="stable"> <div align="center">星期</div></td>
  189.           <td width="13%" class="stable">日期</td>
  190.           <td width="13%" class="stable">时间</td>
  191.           <td width="19%" bgcolor="#C4DAFF" class="stable">去向</td>
  192.           <td width="18%" class="stable">类型</td>
  193.           <td width="29%" class="stable">事由</td>
  194.         </tr>
  195.       </table>
  196.       <%
  197. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  198.   if (ir.hasNext()) {
  199. kd = (KaoqinDb)ir.next();
  200. mydate = DateUtil.format(kd.getMyDate(), "yyyy-MM-dd HH:mm:ss");
  201. //dt = rs.getDate("mydate");//这样取的话会丢失小时和分钟信息
  202. dt = kd.getMyDate();
  203. cld.setTime(dt);
  204. monthday = cld.get(cld.DAY_OF_MONTH);
  205. }
  206. while (i<=monthdaycount)
  207. {
  208. if (monthday==i)
  209. {
  210. coloralt = !coloralt;
  211. if (coloralt)
  212. backcolor = "#eeeeee";
  213. else
  214. backcolor = "#ECFFDF";
  215. String oldbackcolor = backcolor;
  216. while (monthday==i) {
  217. backcolor = oldbackcolor;
  218. id = kd.getId();
  219. direction = kd.getDirection();
  220. type = kd.getType();
  221. reason = kd.getReason();
  222. mydate = DateUtil.format(kd.getMyDate(), "yyyy-MM-dd HH:mm:ss");
  223. dt = formatter.parse(mydate);
  224. cld.setTime(dt);
  225. mydate = mydate.substring(11,19);
  226. weekday = cld.get(cld.DAY_OF_WEEK);
  227. strweekday = wday[weekday];
  228. // 计算是否迟到
  229. myhour = cld.get(cld.HOUR_OF_DAY);
  230. myminute = cld.get(cld.MINUTE);
  231. if (type.equals("考勤"))
  232. {
  233. int hbeginf,mbeginf,hendf,mendf;
  234. if (myhour<13) //上午
  235. {
  236. hbeginf = mbegin[0];
  237. mbeginf = mbegin[1];
  238. hendf = mend[0];
  239. mendf = mend[1];
  240. }
  241. else
  242. {
  243. hbeginf = abegin[0];
  244. mbeginf = abegin[1];
  245. hendf = aend[0];
  246. mendf = aend[1];
  247. }
  248. if (direction.equals("c"))
  249. {
  250. latehour = myhour-hbeginf;
  251. lateminute = myminute-mbeginf;
  252. if (lateminute>0) //计算本次迟到的分钟数
  253. lateminute = latehour*60+lateminute;
  254. else
  255. lateminute = latehour*60+lateminute;
  256. //System.out.println("hbeginf="+hbeginf);
  257. //System.out.println("myhour="+myhour);
  258. //System.out.println("myminute="+myminute);
  259. //System.out.println("mbeginf="+mbeginf);
  260. //System.out.println("lateminute="+lateminute);
  261. if (lateminute>latevalue)//如果大于阀值则认为是迟到
  262. {
  263. backcolor = "#FFCECA";
  264. latecount++;
  265. }
  266. }
  267. else
  268. {
  269. latehour = hendf-myhour;
  270. lateminute = mendf-myminute;
  271. if (lateminute>0) //计算本次迟到的分钟数
  272. lateminute = latehour*60+lateminute;
  273. else
  274. lateminute = latehour*60+lateminute;
  275. if (lateminute>latevalue)//如果大于阀值则认为是早退
  276. {
  277. backcolor = "#ffff00";
  278. beforecount++;
  279. }
  280. }
  281. }
  282. if (direction.equals("c"))
  283. direction = "到达单位";
  284. else
  285. direction = "离开单位";
  286. %>
  287.   <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="stable">
  288.         <tr align="center" bgcolor="<%=backcolor%>"> 
  289.           <td width="8%" bgcolor="<%=backcolor%>" class="stable"><%=strweekday%> </td>
  290.           <td width="13%" bgcolor="<%=backcolor%>" class="stable"><%=i%></td>
  291.           <td width="13%" bgcolor="<%=backcolor%>" class="stable"><%=mydate%></td>
  292.           <td width="19%" bgcolor="<%=backcolor%>" class="stable"><%=direction%></td>
  293.           <td width="18%" bgcolor="<%=backcolor%>" class="stable"><%=type%></td>
  294.           <td width="29%" bgcolor="<%=backcolor%>" class="stable"><%=reason%></td>
  295.         </tr>
  296.       </table>
  297. <%
  298. if (ir.hasNext()) {
  299. kd = (KaoqinDb)ir.next();
  300. dt = kd.getMyDate();
  301. cld.setTime(dt);
  302. monthday = cld.get(cld.DAY_OF_MONTH);
  303. }
  304. else {
  305. break;
  306. }
  307.  }
  308. }
  309. else
  310. {
  311. cld.set(showyear,showmonth-1,i);
  312. weekday = cld.get(cld.DAY_OF_WEEK);
  313. strweekday = wday[weekday];
  314. if (weekday==1 || weekday==7)
  315. strweekday = "<font color=red>"+strweekday+"</font>";
  316. %>
  317.   <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="stable">
  318.         <tr align="center"> 
  319.           <td width="8%" class="stable"><%=strweekday%></td>
  320.           <td width="13%" class="stable"><%=i%></td>
  321.           <td width="13%" class="stable">&nbsp;</td>
  322.           <td width="19%" class="stable">&nbsp;</td>
  323.           <td width="18%" class="stable">&nbsp;</td>
  324.           <td width="29%" class="stable">&nbsp;</td>
  325.         </tr>
  326.       </table>
  327. <%
  328. }
  329. i++;
  330. }%>
  331. <br>
  332.       <table width="98%" border="0" align="center">
  333.         <tr>
  334.           <td align="center">迟到次数:<%=latecount%>&nbsp;&nbsp;&nbsp;早退次数:<%=beforecount%></td>
  335.   </tr>
  336. </table>
  337. <%
  338. if (curyear==showyear && (curmonth+1)==showmonth)
  339. {
  340. %>
  341.       <table width="448" border="0" align="center" cellpadding="0" cellspacing="0" class="stable">
  342.         <tr bgcolor="#C4DAFF">
  343.           <td height="21" colspan="4" align="center" bgcolor="#C4DAFF" class="stable">考&nbsp;勤</td>
  344.         </tr>
  345.         <form name="form1" action="?op=add" method="post" onSubmit="">
  346.           <tr bgcolor="#EEEEEE">
  347.             <td width="54" height="19" align="center" class="stable">类型</td>
  348.             <td width="152" height="19" class="stable"> 
  349. <select name="type">
  350. <%
  351. // 如果已过了考勤时间段(该时间段为上午前后1小时和下午前后1小时),则不显示考勤
  352. int curm = curhour*60+curminute;//当前时间在本日中的分钟数
  353. int fz = 60;//阀值为60分钟
  354. if ((curm>mbegin[0]*60+mbegin[1]-fz && curm<mend[0]*60+mend[1]+fz) ||
  355. (curm>abegin[0]*60+abegin[1]-fz && curm<aend[0]*60+aend[1]+fz))
  356. {
  357. %>
  358.                 <option value="考勤" checked>考勤</option>
  359. <% } %>
  360.                 <option value="外出办事">外出办事</option>
  361. <option value="加班">加班</option>
  362.                 <option value="其他原因">其他原因</option>
  363.             </select> </td>
  364.             <td width="95" align="center" class="stable">去向</td>
  365.             <td width="145" class="stable"> <select name="direction">
  366.                 <option value="c" checked>来到单位</option>
  367.                 <option value="l">离开单位</option>
  368.             </select></td>
  369.           </tr>
  370.           <tr bgcolor="#EEEEEE">
  371.             <td height="17" align="center" class="stable">事由</td>
  372.             <td height="17" colspan="3" class="stable"> <textarea name=reason cols="50" class="singleboarder" rows="8"></textarea>            </td>
  373.           </tr>
  374.           <tr bgcolor="#EEEEEE">
  375.             <td colspan="4" align="center" class="stable"> <input name="submit" type=submit class="singleboarder" value="发送">
  376.               &nbsp;&nbsp;&nbsp; <input name="reset" type=reset class="singleboarder" value="取消">            </td>
  377.           </tr>
  378.         </form>
  379.       </table> 
  380.   <%
  381. }
  382. %>
  383.     </td>
  384.   </tr>
  385.   <tr>
  386.     <td height="9">&nbsp;</td>
  387.   </tr>
  388. </table>
  389. </body>
  390. </html>