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

Jsp/Servlet

开发平台:

Java

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