Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

My97DatePicker请假日期后端判断已选日期不可再选

TripMaster无名 2019-08-23 10:14:00 阅读数:23 评论数:0 点赞数:0 收藏数:0

对于后台进行请假日期验证,如果有重复可以判断,如法提交

 public String doAddLeaves(){
 try {
 TbUser tbUser=(TbUser) getFromSession("loginUser");
 leaveList=leaveService.getLeavesByUsername(tbUser.getId());//获取当前用户所有请假条
int row = 0;
 //System.err.println("======="+tbLeave.getBeginLeave()+","+tbLeave.getEndLeave());
for (TbLeave leaves : leaveList) {
 if (tbLeave.getEndLeave().compareTo(leaves.getBeginLeave())<=0
|| tbLeave.getBeginLeave().compareTo(leaves.getEndLeave())>=0 ) {

//System.err.println("1..."+tbLeave.getBeginLeave()+","+tbLeave.getEndLeave());
 //System.err.println("2..."+leaves.getBeginLeave()+","+leaves.getEndLeave());
row=0;

}else{
 row=1;
 break;
  }
  }
 if (tbLeave.getEndLeave().compareTo(tbLeave.getBeginLeave())<0) {
 log.info("fail!!!");
 resultMap.put("retcode", RetCode.FAIL);
 resultMap.put("retmsg", "请假时间需要大于开始时间");
 }else {

if (row==0) {

 leaveService.addLeaves(tbLeave);
 //putToSession("leave", leave)
log.info("success!!!");
 resultMap.put("retcode", RetCode.SUCCESS);
 resultMap.put("retmsg", "保存成功");
 }else{
 log.info("fail!!!");
 resultMap.put("retcode", RetCode.FAIL);
 resultMap.put("retmsg", "请假时间存在冲突");
  }
  }
 } catch (Exception e) {
  e.printStackTrace();
 log.error("method addEmails bug:{}",e);
 resultMap.put("retcode", RetCode.UNKOWN_WRONG);
 resultMap.put("retmsg", "未知错误,请重试或联系管理员");
  }
 return SUCCESS;
 }
action
 <tr>
<td align="right" width="30%">开始时间:</td>
<td align="left"><input type="text" name="tbLeave.beginLeave" readOnly="readonly"
id="beginLeave"
onClick="WdatePicker({minDate:'%y-%M-{%d+1}',maxDate:'#F{$dp.$D(\'endLeave\')}',onpicked:function(){endLeave.click();},disabledDays:[0,6]})" class="Wdate" /><br/>
</td>
</tr><br/>
<tr>
<td align="right" width="30%">结束时间:</td>
<td align="left"><input type="text" name="tbLeave.endLeave" readOnly="readonly"
id="endLeave" onClick="WdatePicker({errDealMode:3,minDate:'#F{$dp.$D(\'beginLeave\')}',disabledDays:[0,6]})" class="Wdate"/><br/></td>
</tr>
jsp
 <script type="text/javascript">
 $(function() {

$("#loginForm").validate({
  rules : {
 "tbLeave.beginLeave" : {
 required : true,
  },
 "tbLeave.endLeave" : {
 required : true,
 /* remote: {
  url: "${ctx}/leave/beginTOEnd.action",
  type: "post",
  dataType: "json",
  data: {
  "tbLeave.beginLeave": function(){
  return $("#beginLeave").val()
  },
  "tbLeave.endLeave": function(){
  return $("#endLeave").val();
  }
  }
  } */
 },
 /* "tbLeave.reason" : {
  required : true,
  } */
 },
  messages : {
 "tbLeave.beginLeave" : {
 required : "输入开始请假日期",
  },
 "tbLeave.endLeave" : {
 required : "输入结束请假日期",
 //remote:"*请假日期不能重复"
 },
 /* "tbLeave.reason" : {
  required : "输入请假原因",
  } */
 }
  });

$("#sendLeave").click(function() {
 if ($("#loginForm").valid()) {
 if(confirm("是否要提交吗?")){
 var url = "${ctx}/leave/doAddLeaves.action";
  $.post(
  url,
  {
 "tbLeave.isdelete" : $("#isdelete").val(),
 "tbLeave.read" : $("#read").val(),
 "tbLeave.tbUserByUserId.id" : $("#isid").val(),
 "tbLeave.beginLeave" : $("#beginLeave").val(),
 "tbLeave.endLeave" : $("#endLeave").val(),
 "tbLeave.reason" : $("#reason").val()
  },
  function(data) {
 if (data.retcode == "0") {
 alert("提交成功");
 window.location.href = "${ctx}/leave/findAllLeaves.action";
 } else {
  alert(data.retmsg);
  }
  });
  }
  }
  });
  });
 </script>
script

 

版权声明
本文为[TripMaster无名]所创,转载请带上原文链接,感谢
https://www.cnblogs.com/TripMaster/p/11398399.html