public ActionResult CreateLeave(VMCreateLeave vMCLeave) { //請假 tLeave tLeave = new tLeave(); tLeave.fEmployeeId = vMCLeave.employee.id; tLeave.fSort = vMCLeave.leavesort; tLeave.fApplyDate = DateTime.Now; tLeave.fActiveDate = vMCLeave.start; tLeave.fEndDate = vMCLeave.end; tLeave.fTimeCount = vMCLeave.timecount; tLeave.fReason = vMCLeave.reason; db.tLeaves.Add(tLeave); db.SaveChanges(); //簽核表 tSignoff tSignoff = new tSignoff(); tSignoff.fLeaveId = int.Parse(db.tLeaves .OrderByDescending(p => p.fId) .Select(r => r.fId) .First().ToString()); tSignoff.fSupervisorId = Convert.ToInt32(vMCLeave.supervisorId); tSignoff.fApplyClass = vMCLeave.leavesort; tSignoff.fStartdate = DateTime.Now; tSignoff.fEnddate = vMCLeave.start; db.tSignoffs.Add(tSignoff); db.SaveChanges(); return(RedirectToAction("AttendIndex")); }
public VMsignoff convert(tSignoff tSignoff) { VMsignoff vmsignoff = new VMsignoff(); //大項目判斷 string catelogName = ""; if (tSignoff.fLeaveId != null) { catelogName = "請假申請"; } else if (tSignoff.fOvertimeId != null) { catelogName = "加班申請"; } else //(item.fAlpplypunchId == null) { catelogName = "補打卡申請"; } vmsignoff.id = tSignoff.fId; vmsignoff.name = tSignoff.tEmployee.fName; vmsignoff.catelog = catelogName; vmsignoff.applyclass = tSignoff.fApplyClass; vmsignoff.reason = tSignoff.tLeave.fReason; vmsignoff.applydate = tSignoff.tLeave.fApplyDate.ToString("yyyy-MM-dd hh:mm"); vmsignoff.activedate = tSignoff.fStartdate.ToString("yyyy-MM-dd hh:mm"); vmsignoff.enddate = tSignoff.fEnddate.ToString("yyyy-MM-dd hh:mm"); vmsignoff.expireddate = tSignoff.tLeave.fApplyDate.ToString("yyyy-MM-dd hh:mm"); vmsignoff.passdate = (tSignoff.fPassdate != null) ? ((DateTime)tSignoff.fPassdate).ToString("yyyy-MM-dd hh:mm") : ""; vmsignoff.isagreed = tSignoff.fIsAgreed; return(vmsignoff); }
public ActionResult CreateLeave(VMLeave leave) { VMEmployee Emp = getLoginEmpData(); //檢查時數是否超過 var checkLeave = (new CLeaveHelper()).checkLeavehour(Emp.id, leave.leavesort, leave.timecount); if (checkLeave.isPass) { //請假儲存 tLeave tLeave = new tLeave(); tLeave.fEmployeeId = Emp.id; tLeave.fSort = leave.leavesort; tLeave.fApplyDate = DateTime.Now; tLeave.fActiveDate = leave.start; tLeave.fEndDate = leave.end; tLeave.fTimeCount = leave.timecount; tLeave.fReason = leave.reason; db.tLeaves.Add(tLeave); db.SaveChanges(); //簽核表 tSignoff tSignoff = new tSignoff(); tSignoff.fLeaveId = int.Parse(db.tLeaves .OrderByDescending(p => p.fId) .Select(r => r.fId) .First().ToString()); tSignoff.fSupervisorId = leave.supervisorId; tSignoff.fApplyClass = leave.leavesort; tSignoff.fStartdate = DateTime.Now; tSignoff.fEnddate = leave.start; db.tSignoffs.Add(tSignoff); db.SaveChanges(); //通知 //tNotify notify = new tNotify(); //notify.fEmployeeId = Convert.ToInt32(leave.supervisorId); //notify.fTitle = "員工請假申請通知"; //notify.fContent = "員工 " + Emp.name + " 申請" + leave.leavesort; //notify.fType = 0; //notify.fTime = DateTime.Now; //notify.fSort = leave.leavesort; //db.tNotifies.Add(notify); //db.SaveChanges(); TempData["Attend_msg"] = leave.leavesort + " 申請成功"; return(RedirectToAction("AttendIndex", "Attend")); } else { TempData["Attend_err_msg"] = checkLeave.err_msg; return(RedirectToAction("LeaveIndex", "Attend_Leave")); } }
public ActionResult Editpass(int id, int agree) { //資料庫更新 tSignoff signoff = db.tSignoffs.Where(m => m.fId == id).FirstOrDefault(); signoff.fIsAgreed = agree; //通過 不通過 signoff.fPassdate = DateTime.Now; //通過日期 //list更新 var target = list.Where(m => m.id == id).FirstOrDefault(); target.isagreed = agree; target.passdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm"); //通過審核 if (agree == 1) { if (target.catelog == "請假申請") { //儲存假別紀錄 int empId = signoff.tLeave.fEmployeeId; string sortName = signoff.tLeave.fSort; double useTime = signoff.tLeave.fTimeCount; (new CLeaveHelper()).Leavecount(empId, sortName, useTime); createNotifies(empId, "審核通過", "申請" + sortName + "已通過審核"); } if (target.catelog == "補打卡申請") { //儲存假別紀錄 int empId = signoff.tApplypunch.fEmployeeId; //修改打卡紀錄 int punchtimeId = signoff.tApplypunch.fPunchTimeId; string status = "已補打卡"; tPunchtime punchtime = db.tPunchtimes .Where(m => m.fId == punchtimeId) .FirstOrDefault(); punchtime.fstatus = status; createNotifies(empId, "審核通過", "申請補打卡" + punchtime.fDatetime + "已通過審核"); } if (target.catelog == "加班申請") { //儲存假別紀錄 int empId = signoff.tOvertime.fEmployeeId; string sortName = signoff.tOvertime.fSort; createNotifies(empId, "審核通過", "申請" + sortName + "已通過審核"); } } db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); }
public VMsignoff convert(tSignoff tSignoff) { VMsignoff vmsignoff = new VMsignoff(); //大項目判斷 string catelogName = ""; int id = 0; string name = ""; string reason = ""; string applydate = ""; string expireddate = ""; if (tSignoff.fLeaveId != null) { catelogName = "請假申請"; id = tSignoff.tLeave.tEmployee.fEmployeeId; name = tSignoff.tLeave.tEmployee.fName; reason = tSignoff.tLeave.fReason; applydate = tSignoff.tLeave.fApplyDate.AddHours(8).ToString("yyyy-MM-dd HH:mm"); expireddate = tSignoff.tLeave.fActiveDate.ToString("yyyy-MM-dd HH:mm"); } else if (tSignoff.fOvertimeId != null) { catelogName = "加班申請"; id = tSignoff.tOvertime.tEmployee.fEmployeeId; name = tSignoff.tOvertime.tEmployee.fName; reason = tSignoff.tOvertime.fReason; applydate = tSignoff.tOvertime.fSubmitDate.AddHours(8).ToString("yyyy-MM-dd HH:mm"); expireddate = tSignoff.tOvertime.fActiveDate.ToString("yyyy-MM-dd HH:mm"); } else { catelogName = "補打卡申請"; id = tSignoff.tApplypunch.tEmployee.fEmployeeId; name = tSignoff.tApplypunch.tEmployee.fName; reason = tSignoff.tApplypunch.fReason; applydate = tSignoff.tApplypunch.fApplyDate.AddHours(8).ToString("yyyy-MM-dd HH:mm"); expireddate = tSignoff.fEnddate.ToString("yyyy-MM-dd HH:mm"); } vmsignoff.id = tSignoff.fId; vmsignoff.emp_id = id; vmsignoff.emp_name = name; vmsignoff.catelog = catelogName; vmsignoff.applyclass = tSignoff.fApplyClass; vmsignoff.reason = reason; vmsignoff.applydate = applydate; vmsignoff.activedate = tSignoff.fStartdate.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); vmsignoff.enddate = tSignoff.fEnddate.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); vmsignoff.expireddate = expireddate; vmsignoff.passdate = (tSignoff.fPassdate != null) ? ((DateTime)tSignoff.fPassdate).ToLocalTime().ToString("yyyy-MM-dd HH:mm") : "null"; vmsignoff.supervisor = tSignoff.tEmployee.fName; vmsignoff.isagreed = tSignoff.fIsAgreed; return(vmsignoff); }
public ActionResult punchTimeApply(VMPunchtimeApply applyPunchtime) { VMEmployee Emp = getLoginEmpData(); //用完申請紀錄 if (EmpApplyPunchtimeCount(Emp.id) == 0) { return(Json("error", JsonRequestBehavior.AllowGet)); } //重複申請 if (db.tApplypunches.Where(m => m.fPunchTimeId == applyPunchtime.applyId).FirstOrDefault() != null) { return(Json("same", JsonRequestBehavior.AllowGet)); } //申請補打卡 tApplypunch Applypunch = new tApplypunch(); Applypunch.fEmployeeId = Emp.id; Applypunch.fPunchTimeId = applyPunchtime.applyId; Applypunch.fApplyDate = DateTime.Now; Applypunch.fSort = applyPunchtime.sort; Applypunch.fReason = applyPunchtime.reason; db.tApplypunches.Add(Applypunch); db.SaveChanges(); //簽核表 3天內審核完成 tSignoff tSignoff = new tSignoff(); tSignoff.fAlpplypunchId = int.Parse(db.tApplypunches .OrderByDescending(p => p.fId) .Select(r => r.fId) .First().ToString()); tSignoff.fSupervisorId = applyPunchtime.supervisorId; tSignoff.fApplyClass = applyPunchtime.sort; tSignoff.fStartdate = DateTime.Now; tSignoff.fEnddate = DateTime.Now.AddDays(3); db.tSignoffs.Add(tSignoff); db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); }
public ActionResult Editpass(int id, int agree) { //資料庫更新 tSignoff signoff = db.tSignoffs.Where(m => m.fId == id).FirstOrDefault(); signoff.fIsAgreed = agree; //通過 不通過 signoff.fPassdate = DateTime.Now; //通過日期 //更新員工假別紀錄 //list更新 var target = list.Where(m => m.id == id).FirstOrDefault(); target.isagreed = agree; target.passdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm"); db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); }
public ActionResult getOverTimeRecord() { List <VMCOvertime> list = new List <VMCOvertime>(); foreach (tOvertime item in db.tOvertimes.ToList()) { tSignoff temp = db.tSignoffs.Where(m => m.fOvertimeId == item.fId).FirstOrDefault(); VMCOvertime overtime = new VMCOvertime(); overtime.fId = item.fId; overtime.fEmployeeId = item.fEmployeeId; overtime.fSort = item.fSort; overtime.fSubmitDate = item.fSubmitDate; overtime.fActiveDate = item.fActiveDate; overtime.fTimeCount = item.fTimeCount; overtime.fReason = item.fReason; overtime.isAgree = temp.fIsAgreed; list.Add(overtime); } return(Json(new { data = list }, JsonRequestBehavior.AllowGet)); }
public ActionResult submitRevoke(int id) { //移除資料 tSignoff tSignoff = db.tSignoffs.Where(m => m.fId == id).FirstOrDefault(); int attend_id = 0; if (tSignoff.fLeaveId != null) { //請假 attend_id = (int)tSignoff.fLeaveId; db.tLeaves.Remove(db.tLeaves.Where(m => m.fId == attend_id).FirstOrDefault()); } else if (tSignoff.fOvertimeId != null) { //加班 attend_id = (int)tSignoff.fOvertimeId; db.tOvertimes.Remove(db.tOvertimes.Where(m => m.fId == attend_id).FirstOrDefault()); } else { //補打卡 attend_id = (int)tSignoff.fAlpplypunchId; db.tApplypunches.Remove(db.tApplypunches.Where(m => m.fId == attend_id).FirstOrDefault()); } db.tSignoffs.Remove(tSignoff); db.SaveChanges(); //Emp_list 移除資料 var target = Emp_list.Where(m => m.id == id).FirstOrDefault(); Emp_list.Remove(target); return(Json("success", JsonRequestBehavior.AllowGet)); }
public ActionResult CreateOverTime(tOvertime o, tSignoff s, tEmployee t) { HttpCookie cookie = Request.Cookies["id"]; int u = Convert.ToInt32(cookie.Value); int fakeid = u; Emp = (new VMEmployee()) .convert(db.tEmployees .Where(m => m.fEmployeeId == fakeid) .FirstOrDefault()); //ViewBag 傳前端 ViewBag.emp = Newtonsoft.Json.JsonConvert.SerializeObject(Emp); //撈資料庫當月 double TimeCountForMonth = (from a in db.tOvertimes.AsEnumerable() join ts4 in db.tSignoffs.AsEnumerable() on a.fId equals ts4.fOvertimeId where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == DateTime.Now.Month && a.fEmployeeId == fakeid && ts4.fIsAgreed == 1 select a.fTimeCount).DefaultIfEmpty(0).Sum(); ////撈資料庫上個月 //double TimeCountLastMonth = (from a in db.tOvertimes.AsEnumerable() // where a.fActiveDate.Year == DateTime.Now.Year // && a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month // && a.fEmployeeId == fakeid // select a.fTimeCount).Sum(); ////撈資料庫上上個月 //double TimeCountBeforeLastMonth = (from a in db.tOvertimes.AsEnumerable() // where a.fActiveDate.Year == DateTime.Now.Year // && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month // && a.fEmployeeId == fakeid // select a.fTimeCount).Sum(); if (string.IsNullOrEmpty(o.fSort) || string.IsNullOrEmpty(o.fReason)) { TempData["Attend_msg"] = "請輸入加班類別或原因"; return(View()); } //本日加班查詢 int NowDateMonth = o.fActiveDate.Month; int NowDate = o.fActiveDate.Day; double TimeCountToday = (from a in db.tOvertimes.AsEnumerable() join ts5 in db.tSignoffs.AsEnumerable() on a.fId equals ts5.fOvertimeId where a.fActiveDate.Month == NowDateMonth && a.fActiveDate.Day == NowDate && a.fEmployeeId == fakeid && ts5.fIsAgreed == 1 select a.fTimeCount).DefaultIfEmpty().Sum() + o.fTimeCount; //三個月加班合計 //本月 double TimeCountOne = (from b in db.tOvertimes.AsEnumerable() join ts6 in db.tSignoffs.AsEnumerable() on b.fId equals ts6.fOvertimeId where b.fActiveDate.Year == DateTime.Now.Year && b.fActiveDate.Month == DateTime.Now.Month && b.fEmployeeId == fakeid && ts6.fIsAgreed == 1 select b.fTimeCount).Sum(); //上月 double TimeCountTwo = (from c in db.tOvertimes.AsEnumerable() join ts7 in db.tSignoffs.AsEnumerable() on c.fId equals ts7.fOvertimeId where c.fActiveDate.Year == DateTime.Now.Year && c.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month && c.fEmployeeId == fakeid && ts7.fIsAgreed == 1 select c.fTimeCount).Sum(); //上上月 double TimeCountThree = (from d in db.tOvertimes.AsEnumerable() join ts8 in db.tSignoffs.AsEnumerable() on d.fId equals ts8.fOvertimeId where d.fActiveDate.Year == DateTime.Now.Year && d.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month && d.fEmployeeId == fakeid && ts8.fIsAgreed == 1 select d.fTimeCount).Sum(); double TimeCountThreeMonth = TimeCountOne + TimeCountTwo + TimeCountThree; //第一層判斷他目前是不是已經超過加班上限了 //if (TimeCountForMonth > 46) //{ // TempData["message"] = "你太累瞜~~當月加班時數超過上限"; // return View(); //} if (TimeCountThreeMonth > 138) { TempData["Attend_msg"] = "你太累瞜~~三個月內累計加班時數超過上限"; return(View()); } if (o.fTimeCount > 4 || TimeCountToday > 4) { if (o.fSort == "平日加班") { TempData["Attend_msg"] = "你太累瞜~~平日加班時數超過上限"; return(View()); } else if (TimeCountToday > 12) { TempData["Attend_msg"] = "你太累瞜~~當日加班總時數超過上限"; return(View()); } } //假設系統撈出來的資料目前都沒有超過上限 //新增時共有兩個Table,一個是加班申請,一個是簽核表插入 s.fOvertimeId = o.fId; //簽核表編號=加班申請fid s.fApplyClass = o.fSort; //簽核表種類=加班申請 o.fSubmitDate = DateTime.Now /*.ToLocalTime()*/; //申請日期等於Now o.fActiveDate = o.fActiveDate /*.ToLocalTime()*/; s.fStartdate = o.fActiveDate; //簽核表申請日期=現在加班申請日期 //s.tEmployee.fEmployeeId = fakeid;//簽核表寫入員工編號 o.fEmployeeId = fakeid;//加班表寫入員工編號 //查詢部門別及權限用來判斷核決主管是誰 var Check = (from b in db.tEmployees where b.fEmployeeId == fakeid select new { b.fDepartment, b.fAuth }).FirstOrDefault(); //先把物件取出來,登入者的資訊物件 //這個是登入者的部門 string department = Check.fDepartment.ToString(); //這個是登入者的權限 int auth = Check.fAuth; //帶入主管編號 var SupervisorIdCheckJunior = (from a in db.tEmployees where a.fAuth == 2 && a.fDepartment == department select new { a.fEmployeeId }).FirstOrDefault(); var SupervisorIdCheckSenior = (from a in db.tEmployees where a.fAuth == 3 && a.fDepartment == department select new { a.fEmployeeId }).FirstOrDefault(); //這個是一般主管的代號 int SupervisorJunior = SupervisorIdCheckJunior.fEmployeeId; //這個是最高權限的代號 int SupervisorIdSenior = SupervisorIdCheckSenior.fEmployeeId; //寫入相對應的主管編號 if (auth == 1) { s.fSupervisorId = SupervisorJunior;//主管權限 } else { s.fSupervisorId = SupervisorIdSenior;//最高權限編號 } s.fIsAgreed = null; //寫入是否同意,預設為null(待審核) s.fEnddate = o.fActiveDate; o.fTimeCount = Convert.ToDouble(o.fTimeCount); //選單輸入的文字轉成加班的數字並存回加班表 //很遺憾的,可能有超時狀況,進入細項判斷式 if (o.fTimeCount + TimeCountForMonth > 46 || o.fTimeCount + TimeCountThreeMonth > 138) { //這個是申請當月的月份 int NowMonth = s.fStartdate.Month; int LastMonth = s.fStartdate.Month - 1; int BeforeLastMonth = s.fStartdate.Month - 2; //申請加班開始日期的月份已經請的時數 double now = (from to in db.tOvertimes.AsEnumerable() join ts1 in db.tSignoffs.AsEnumerable() on to.fId equals ts1.fOvertimeId where to.fActiveDate.Year == DateTime.Now.Year && to.fActiveDate.Month == NowMonth && to.fEmployeeId == fakeid && ts1.fIsAgreed == 1 select to.fTimeCount).DefaultIfEmpty(0).Sum(); //申請加班開始日期的上個月已經請的時數 double Last = (from a in db.tOvertimes.AsEnumerable() join ts2 in db.tSignoffs.AsEnumerable() on a.fId equals ts2.fOvertimeId where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == LastMonth && a.fEmployeeId == fakeid && ts2.fIsAgreed == 1 select a.fTimeCount).DefaultIfEmpty(0).Sum(); //申請加班開始日期的上上個月已經請的時數 double BeforeLast = (from a in db.tOvertimes.AsEnumerable() join ts3 in db.tSignoffs.AsEnumerable() on a.fId equals ts3.fOvertimeId where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == BeforeLastMonth && a.fEmployeeId == fakeid && ts3.fIsAgreed == 1 select a.fTimeCount).DefaultIfEmpty(0).Sum(); //申請加班當月的時數已經超過上限 if (now + o.fTimeCount > 46) { TempData["Attend_msg"] = "你太累瞜~~當月加班時數超過上限"; return(View()); } //申請加班的前三個月總時數已經超過上限 else if (Last + BeforeLast + o.fTimeCount > 138) { TempData["Attend_msg"] = "你太累瞜~~累計三個月內加班時數超過上限"; return(View()); } //沒事,他有可能是申請上個月的加班,但是因為這個月已經滿了,才會進來這個鬼地方 else { //他可以出去判斷式了 db.tOvertimes.Add(o); //加入t物件(加班表) db.tSignoffs.Add(s); //加入s物件(簽核表) db.SaveChanges(); //存檔 TempData["Attend_msg"] = "送出成功"; //return View(); return(RedirectToAction("AttendIndex", "Attend")); } } //他當月既沒有超過上限,三個月內也沒有超過上限 db.tOvertimes.Add(o); //加入t物件(加班表) db.tSignoffs.Add(s); //加入s物件(簽核表) db.SaveChanges(); //存檔 TempData["Attend_msg"] = "送出成功"; //return View(); return(RedirectToAction("AttendIndex", "Attend")); }
public ActionResult CreateOverTime(tOvertime o, tSignoff s) { //撈資料庫當月 double TimeCountForMonth = (from a in db.tOvertimes where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == DateTime.Now.Month && a.fEmployeeId == fakeid select a.fTimeCount).DefaultIfEmpty(0).Sum(); ////撈資料庫上個月 //double TimeCountLastMonth = (from a in db.tOvertimes.AsEnumerable() // where a.fActiveDate.Year == DateTime.Now.Year // && a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month // && a.fEmployeeId == fakeid // select a.fTimeCount).Sum(); ////撈資料庫上上個月 //double TimeCountBeforeLastMonth = (from a in db.tOvertimes.AsEnumerable() // where a.fActiveDate.Year == DateTime.Now.Year // && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month // && a.fEmployeeId == fakeid // select a.fTimeCount).Sum(); //三個月加班合計 double TimeCountThreeMonth = (from a in db.tOvertimes.AsEnumerable() where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == DateTime.Now.AddMonths(-2).Month || a.fActiveDate.Month == DateTime.Now.AddMonths(-1).Month || a.fActiveDate.Month == DateTime.Now.Month && a.fEmployeeId == fakeid select a.fTimeCount).DefaultIfEmpty(0).Sum(); //第一層判斷他目前是不是已經超過加班上限了 //if (TimeCountForMonth > 54) //{ // TempData["message"] = "你太累瞜~~當月加班時數超過上限"; // return View(); //} if (TimeCountThreeMonth > 138) { TempData["message"] = "你太累瞜~~三個月內累計加班時數超過上限"; return(View()); } if (o.fTimeCount > 4) { TempData["message"] = "你太累瞜~~當日加班時數超過上限"; return(View()); } //假設系統撈出來的資料目前都沒有超過上限 //新增時共有兩個Table,一個是加班申請,一個是簽核表插入 s.fOvertimeId = o.fId; //簽核表編號=加班申請fid s.fApplyClass = "加班申請"; //簽核表種類=加班申請 o.fSubmitDate = DateTime.Now; //申請日期等於Now o.fActiveDate = o.fActiveDate; s.fStartdate = o.fActiveDate; //簽核表申請日期=現在加班申請日期 //s.tEmployee.fEmployeeId = fakeid;//簽核表寫入員工編號 o.fEmployeeId = fakeid; //加班表寫入員工編號 s.fSupervisorId = 106; //主管編號 s.fIsAgreed = null; //寫入是否同意,預設為null(待審核) s.fEnddate = o.fActiveDate; o.fTimeCount = Convert.ToDouble(o.fTimeCount); //選單輸入的文字轉成加班的數字並存回加班表 //很遺憾的,可能有超時狀況,進入細項判斷式 if (o.fTimeCount + TimeCountForMonth > 54 || o.fTimeCount + TimeCountThreeMonth > 138) { //這個是申請當月的月份 int NowMonth = s.fStartdate.Month; int LastMonth = s.fStartdate.Month - 1; int BeforeLastMonth = s.fStartdate.Month - 2; //申請加班開始日期的月份已經請的時數 double now = (from a in db.tOvertimes where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == NowMonth && a.fEmployeeId == fakeid select a.fTimeCount).DefaultIfEmpty(0).Sum(); //申請加班開始日期的上個月已經請的時數 double Last = (from a in db.tOvertimes where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == LastMonth && a.fEmployeeId == fakeid select a.fTimeCount).DefaultIfEmpty(0).Sum(); //申請加班開始日期的上上個月已經請的時數 double BeforeLast = (from a in db.tOvertimes where a.fActiveDate.Year == DateTime.Now.Year && a.fActiveDate.Month == BeforeLastMonth && a.fEmployeeId == fakeid select a.fTimeCount).DefaultIfEmpty(0).Sum(); //申請加班當月的時數已經超過上限 if (now + o.fTimeCount > 54) { TempData["message"] = "你太累瞜~~當月加班時數超過上限"; return(View()); } //申請加班的前三個月總時數已經超過上限 else if (Last + BeforeLast + o.fTimeCount > 138) { TempData["message"] = "你太累瞜~~累計三個月內加班時數超過上限"; return(View()); } //沒事,他有可能是申請上個月的加班,但是因為這個月已經滿了,才會進來這個鬼地方 else { //他可以出去判斷式了 db.tOvertimes.Add(o); //加入t物件(加班表) db.tSignoffs.Add(s); //加入s物件(簽核表) db.SaveChanges(); //存檔 return(RedirectToAction("CreateOverTime")); } } //他當月既沒有超過上限,三個月內也沒有超過上限 db.tOvertimes.Add(o); //加入t物件(加班表) db.tSignoffs.Add(s); //加入s物件(簽核表) db.SaveChanges(); //存檔 return(RedirectToAction("CreateOverTime")); }