资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

使用java怎么实现一个全年考勤日历

本篇文章为大家展示了使用java怎么实现一个全年考勤日历,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

创新互联是少有的成都网站设计、网站制作、外贸营销网站建设、营销型企业网站、微信小程序、手机APP,开发、制作、设计、外链、推广优化一站式服务网络公司,2013年开创至今,坚持透明化,价格低,无套路经营理念。让网页惊喜每一位访客多年来深受用户好评

JAVA代码:

package com.wp.action;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
 
public class CalendarAction extends MainAction {
 
 private static final long serialVersionUID = 1L;
 
 private int maxCols;
 private String html;
 private String clickDate;
 
 public String getClickDate() {
 return clickDate;
 }
 
 public void setClickDate(String clickDate) {
 this.clickDate = clickDate;
 }
 
 public String init() {
 Calendar cal = Calendar.getInstance();
 int month = cal.get(Calendar.MONTH) + 1;
 initMaxCols();
 html = createTbl();
 
 return SUCCESS;
 }
 
 private void initMaxCols() {
 // 每行开头灰色的格数
 int headDisabledDays;
 // 当月的天数
 int oneMonthDays;
 Calendar cal = Calendar.getInstance();
 cal.set(Calendar.DAY_OF_MONTH, 1);
 
 for (int i = 0; i < 12; i++) {
 
  if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
  // 周日空六格
  headDisabledDays = 6;
  } else {
  headDisabledDays = cal.get(Calendar.DAY_OF_WEEK)
   - Calendar.MONDAY;
  }
 
  oneMonthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
  if (headDisabledDays + oneMonthDays > maxCols) {
  maxCols = headDisabledDays + oneMonthDays;
  }
  cal.add(Calendar.MONTH, 1);
 }
 
 }
 
 private String createTbl() {
 StringBuffer html = new StringBuffer();
 String[] weekdays = { "一", "二", "三", "四", "五", "六", "日" };
 SimpleDateFormat formatTd = new SimpleDateFormat("yyyyMMdd");
 SimpleDateFormat formatHeader = new SimpleDateFormat("yyyy年MM月");
 SimpleDateFormat formatTitle = new SimpleDateFormat("yyyy年MM月dd日");
 HashMap map = getCalendarDetail();
 
 // 每行开头灰色的格数
 int headDisabledDays;
 
 // html.append("\r\n");
 html.append("\r\n");
 html.append("\r\n");
 for (int col = 0; col < maxCols; col++) {
  html.append("");
  html.append(weekdays[col % weekdays.length]);
  html.append("\r\n");
 }
 html.append("\r\n");
 Calendar cal = Calendar.getInstance();
 int month = cal.get(Calendar.MONTH);
 for (int months = 0; months < 12; months++) {
  html.append("\r\n");
  String s;
  s = formatHeader.format(cal.getTime());
  html.append("" + s + "\r\n");
  
  cal.set(Calendar.DAY_OF_MONTH, 1);
  if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
  // 周日空六格
  headDisabledDays = 6;
  } else {
  headDisabledDays = cal.get(Calendar.DAY_OF_WEEK)
   - Calendar.MONDAY;
  }
  cal.add(Calendar.DAY_OF_MONTH, -headDisabledDays);
 
  for (int col = 0; col < maxCols; col++) {
 
  html.append(" 0) {
  // html.append("class='disabledTd'");
  // }else
  if (month != cal.get(Calendar.MONTH)) {
   html.append("class='disabledTd'");
  
  } else if (map.containsKey(formatTd.format(cal.getTime()))) {
   int type = Integer.parseInt(map.get(formatTd.format(cal
    .getTime())));
   if(type == 1){
   //html.append("class='holidayTd'");
   }else if(type == 2){
   html.append("class='holidayTd'");
   }
  } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
   || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
   html.append("class='weekendTd'");
  } else {
   html.append("class='generalTd'");
  }
  html.append(" title='" + formatTitle.format(cal.getTime())
   + "'");
  html.append(">");
 
  html.append(cal.get(Calendar.DAY_OF_MONTH));
  html.append("\r\n");
  cal.add(Calendar.DAY_OF_MONTH, 1);
 
  }
 
  html.append("\r\n");
  if (month == cal.get(Calendar.MONTH)) {
  cal.add(Calendar.MONTH, 1);
  }
  month = cal.get(Calendar.MONTH);
 }
 // html.append("\r\n");
 return html.toString();
 }
 
 public String getHtml() {
 return html;
 }
 
 public void setHtml(String html) {
 this.html = html;
 }
 
 private HashMap getCalendarDetail() {
 HashMap map;
 map = new HashMap();
 map.put("20150404", "2");
 map.put("20150405", "2");
 map.put("20150406", "2");
 map.put("20150501", "2");
 map.put("20150502", "2");
 map.put("20150503", "2");
 map.put("20150622", "2");
 map.put("20151001", "2");
 map.put("20151002", "2");
 map.put("20151003", "2");
 
 return map;
 }
 public String dateCellClick(){
 
 return SUCCESS;
 }
}

action配置:


   

HTML代码:


<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
  + request.getServerName() + ":" + request.getServerPort()
  + path;
%>
<%@taglib prefix="s" uri="/struts-tags"%>

 
  .disabledTd{
  background-color:gray;
  }
  .weekendTd{
  background-color:yellow;
  }
  .holidayTd{
  background-color:green;
  }
  .generalTd{
  background-color:white;
  }
  #calTbl{
  font-family: verdana,arial,sans-serif;
  font-size:13px;
  color:#333333;
  border-width: 1px;
  border-color: #a9c6c9;
  border-collapse: collapse;
  }
  #calTbl th{
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #a9c6c9;
  background-color:olive;
  }
  #calTbl td {
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #a9c6c9;
  }
  .rowHeader{
  background-color:olive;
  }
 
 
 
 
 
 Login page
 
 /html/scripts/common.js"
  type="text/javascript">
 /html/scripts/jquery.js"
  type="text/javascript">
 /html/scripts/jquery.json-2.2.min.js"
  type="text/javascript">
 /html/scripts/jquery.ui.custom.js"
  type="text/javascript">
 /html/scripts/script.js"
  type="text/javascript">
  
  $(document).ready(function(){
  var checkType = 0;
  $.post('calendar',{},function(data,status)
  {
   if(data != null && data.html != null && data.html != ""){
   $("#calTbl").html( data.html);
   $("#calTbl td").click(tdClick);
   $("#checkType input").click(typeCheck);
   }
  }).error(function(){
   
  });
 
  var tdClick = function(){
  
   if(this.className == 'rowHeader' || this.className == 'disabledTd'){
   return;
   }
   if(checkType != null && checkType != "" && checkType != 0){
   if(checkType == 1){   
    this.style.backgroundColor="white";
   }else if(checkType == 2){    
    this.style.backgroundColor="yellow";
   }else if(checkType == 3){    
    this.style.backgroundColor="green";
   }
   }
  };
  var typeCheck = function(){
   checkType = this.value;
  };
  
  
  });
  
 
 
 
 
    
 
 
                            
   

效果如下

使用java怎么实现一个全年考勤日历

上述内容就是使用java怎么实现一个全年考勤日历,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。


网页名称:使用java怎么实现一个全年考勤日历
本文路径:http://cdkjz.cn/article/ighigo.html
返回首页 了解更多建站资讯
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220