public ActionResult Create(ApplyDetailModel model) { if (ModelState.IsValid) { try { var item = new CHK_STAFF_APPLYDETAIL() { APPLY_STATE = (byte)6, APPLY_TIME = DateTime.Now, APPLY_USR_ID = UserState.UserID, AUD_TIME = DateTime.Now, AUD_USR_ID = UserState.UserID, BEGIN_TIME = model.BeginTime.AddHours(model.BeginTimeHours), CHK_STAFF_ID = model.CHK_STAFF_ID, END_TIME = model.EndTime.AddHours(model.EndTimeHours), HOLLI_TYP = (byte)model.HOLLI_TYP, APPLY_REASON = model.APPLY_REASON }; item = AppDao.AddObject(item); var detail = new CHK_STAFF_APPLYITEM() { HOLLI_TYP = item.HOLLI_TYP, APPLY_DATE = item.BEGIN_TIME, APPLYDETAIL_ID = item.APPLYDETAIL_ID, CHK_STAFF_ID = item.CHK_STAFF_ID, A_P_TYP = 1 }; var d = getDiffDays(model.BeginTime, model.EndTime); for (var i = 0; i < d; i++) { detail.APPLY_DATE = model.BeginTime.Date; detail.A_P_TYP = 1; ApplyitemDao.AddObject(detail); detail.A_P_TYP = 2; ApplyitemDao.AddObject(detail); model.BeginTime = model.BeginTime.AddDays(1); } if (model.BeginTimeHours == 8 && model.EndTimeHours >= 12) { detail.A_P_TYP = 1; detail.APPLY_DATE = model.BeginTime.Date; ApplyitemDao.AddObject(detail); } if (model.BeginTimeHours == 8 && model.EndTimeHours == 17) { detail.A_P_TYP = 2; detail.APPLY_DATE = model.BeginTime.Date; ApplyitemDao.AddObject(detail); } if (model.BeginTimeHours == 12) { detail.A_P_TYP = 2; detail.APPLY_DATE = model.BeginTime.Date; ApplyitemDao.AddObject(detail); } Alter("新增成功!", util.Enum.AlterTypeEnum.Success, false, true); return(Redirect("/Home/Blank")); } catch (Exception ex) { LogHelper.ErrorLog("新增出错。", ex); ModelState.AddModelError("", "新增出错。"); return(View(model)); } } return(View(model)); }