public void AddUpSpLeave_convertToDic(ref Dictionary <string, string> Dic, AnnualLeaveRule data) { data = (data == null? new AnnualLeaveRule() : data); Dic.Add("seniority", data.seniority == 0.5 ? "6個月" : (data.seniority.ToString() + "年")); Dic.Add("spDays", data.specialDays.ToString()); Dic.Add("buffDays", data.buffDays.ToString()); }
public int AddSpLeaveRule(AnnualLeaveRule data) { using (var trans = _DbContext.Database.BeginTransaction()){ var count = 0; try{ _DbContext.annualleaverule.Add(data); count = _DbContext.SaveChanges(); if (count == 1) { var dic = new Dictionary <string, string> { }; var opLog = new OperateLog() { operateID = data.lastOperaAccID, active = "新增", category = "特休天數設定", createTime = definePara.dtNow() }; toNameFn.AddUpSpLeave_convertToDic(ref dic, data); opLog.content = toNameFn.AddUpSpLeave_convertToText(dic); saveOperateLog(opLog); //紀錄操作紀錄 if (data.ID > 0) //data.ID = new add dataID { AnnualLeave.refreshLowAnnualLeaveData(data); } trans.Commit(); } }catch (Exception ex) { count = catchErrorProcess(ex, count); } return(count); } }
public int addUpSpLeaveRule(AnnualLeaveRule data) { data.lastOperaAccID = (int)loginID; if (data.ID == 0) { data.createTime = definePara.dtNow(); return(Repository.AddSpLeaveRule(data)); } else { data.updateTime = definePara.dtNow(); return(Repository.UpdateSpLeaveRule(data)); } }
public AnnualLeaveRule FindLowOneThanThisRule(int newRuleID) { var allRule = GetAnnualLeaveRule(); var lowRule = new AnnualLeaveRule(); for (int i = 0; i < allRule.Count; i++) { if (allRule[i].ID == newRuleID) { lowRule = i > 0 ? allRule[i - 1] : new AnnualLeaveRule(); break; } } return(lowRule); }
public object addUpSpLeaveRule(AnnualLeaveRule data) { data.lastOperaAccID = (int)loginID; var result = 0; if (data.ID == 0) { data.createTime = definePara.dtNow(); result = Repository.AddSpLeaveRule(data); } else { data.updateTime = definePara.dtNow(); result = Repository.UpdateSpLeaveRule(data); } return(cudAjaxResult(result)); }
public int UpdateSpLeaveRule(AnnualLeaveRule data) { using (var trans = _DbContext.Database.BeginTransaction()){ var oDic = new Dictionary <string, string> { }; var nDic = new Dictionary <string, string> { }; var opLog = new OperateLog() { operateID = data.lastOperaAccID, active = "更新", category = "特休天數設定", createTime = definePara.dtNow() }; var count = 0; int diffSpecialDays = 0, diffBuffDays = 0; try{ var context = _DbContext.annualleaverule.FirstOrDefault(b => b.ID == data.ID); if (context != null) { toNameFn.AddUpSpLeave_convertToDic(ref oDic, context); diffSpecialDays = data.specialDays - context.specialDays; diffBuffDays = data.buffDays - context.buffDays; //context.seniority = data.seniority; context.specialDays = data.specialDays; context.buffDays = data.buffDays; context.lastOperaAccID = data.lastOperaAccID; context.updateTime = data.updateTime; count = _DbContext.SaveChanges(); if (count == 1) { toNameFn.AddUpSpLeave_convertToDic(ref nDic, context); opLog.content = toNameFn.AddUpSpLeave_convertToText(nDic, oDic); saveOperateLog(opLog); //紀錄操作紀錄 AnnualLeave.UpEmployeeSpLeave(data.ID, diffSpecialDays, diffBuffDays); trans.Commit(); } } }catch (Exception ex) { count = catchErrorProcess(ex, count); } return(count); } }
public void refreshLowAnnualLeaveData(AnnualLeaveRule newRule) { var dayToHour = definePara.dayToHour(); var normalDeadLineMonth = 12; var newSeniorityMon = newRule.seniority * 12; var dtNow = definePara.dtNow(); var lowRule = FindLowOneThanThisRule(newRule.ID); var lowData = _DbContext.employeeannualleaves .Where(b => b.ruleID == lowRule.ID && b.deadLine > dtNow).ToList(); var emIDs = lowData.Select(b => b.employeeID).Distinct().ToArray(); foreach (var emID in emIDs) { var emDetail = _DbContext.employeedetails.FirstOrDefault(b => b.accountID == emID); var totalMonth = calThisEmployeeSeniority(emDetail); if (totalMonth < newSeniorityMon) { continue; } var upData = lowData.Where(b => b.employeeID == emID) .OrderByDescending(b => b.deadLine).ToList(); //動使用lowRule2筆(最多2筆) if ((totalMonth - newSeniorityMon) < normalDeadLineMonth) //動使用lowRule1筆 { upData = new List <EmployeeAnnualLeave> { upData[0] }; //取期限最晚的那筆 } foreach (var tmp in upData) { var costHours = tmp.specialDays * dayToHour - tmp.remainHours; tmp.ruleID = newRule.ID; tmp.specialDays = newRule.specialDays; tmp.remainHours = newRule.specialDays * dayToHour; tmp.remainHours -= costHours; tmp.remainHours = tmp.remainHours >= 0? tmp.remainHours : 0; tmp.deadLine = tmp.deadLine.AddMonths(-(lowRule.buffDays) / 30); tmp.deadLine = tmp.deadLine.AddMonths(newRule.buffDays / 30); tmp.updateTime = dtNow; _DbContext.SaveChanges(); } } calObj.start(); }
public void refreshAnnualLeaveHours(AnnualLeaveRule context) { var oldRecord = _DbContext.employeeannualleaves.Where( b => b.ruleID == context.ID && b.deadLine > definePara.dtNow()).ToList(); var oldSeniority = context.seniority * 12; var oldBuffDays = context.buffDays; var spDaysRule = GetAnnualLeaveRule(); var dayToHour = definePara.dayToHour(); var useIndex = -1; for (var i = 0; i < spDaysRule.Count; i++) //list<spDaysRule> 有排序 從小到大 { if (oldSeniority >= (spDaysRule[i].seniority) * 12) //年資有到規則設定的年資 { useIndex = i; } } if (useIndex <= -1) { return; } var useRule = spDaysRule[useIndex]; foreach (var tmp in oldRecord) { var costHours = tmp.specialDays * dayToHour - tmp.remainHours; tmp.ruleID = useRule.ID; tmp.specialDays = useRule.specialDays; tmp.remainHours = useRule.specialDays * dayToHour; tmp.remainHours -= costHours; tmp.remainHours = tmp.remainHours >= 0? tmp.remainHours : 0; tmp.deadLine = tmp.deadLine.AddMonths(-oldBuffDays / 30); tmp.deadLine = tmp.deadLine.AddMonths(useRule.buffDays / 30); tmp.updateTime = definePara.dtNow(); _DbContext.SaveChanges(); } }