public decimal GetMaxDays(List <T_HR_EMPLOYEE> listEmployees, List <T_HR_EMPLOYEEENTRY> entrys, List <T_HR_EMPLOYEEPOST> employeePosts, T_HR_EMPLOYEELEVELDAYCOUNT employeeFreeCount, bool isBreak, List <T_HR_ATTENDFREELEAVE> freeLeaves) { decimal deDays = 0; try { //获取某个员工的入职信息 var qw = from ent in entrys where ent.T_HR_EMPLOYEE.EMPLOYEEID == employeeFreeCount.EMPLOYEEID select ent; //获取员工的岗位信息 var qp = from ent in employeePosts where ent.T_HR_EMPLOYEE.EMPLOYEEID == employeeFreeCount.EMPLOYEEID && ent.T_HR_EMPLOYEE.OWNERCOMPANYID == employeeFreeCount.OWNERCOMPANYID select ent; var entEmployees = from ent in listEmployees where ent.EMPLOYEEID == employeeFreeCount.EMPLOYEEID select ent; //isBreak 为true 调用处则跳出循环 if (qw == null) { isBreak = true; } if (qp == null) { isBreak = true; } if (entEmployees == null) { isBreak = true; } T_HR_EMPLOYEE entEmployee = entEmployees.FirstOrDefault(); T_HR_EMPLOYEEPOST entPost = qp.FirstOrDefault(); if (entPost == null) { isBreak = true; } T_HR_EMPLOYEEENTRY entEntry = qw.FirstOrDefault(); if (entEntry == null) { isBreak = true; } DateTime dtEntryDate = entEntry.ENTRYDATE.Value; TimeSpan tsWorkTime = DateTime.Now.Subtract(dtEntryDate); decimal dCurWorkAge = 0, dEmployeePostLevel = 0; dCurWorkAge = decimal.Round(tsWorkTime.Days / 30, 0); decimal.TryParse(entPost.POSTLEVEL.ToString(), out dEmployeePostLevel); foreach (T_HR_ATTENDFREELEAVE entAttendFreeLeave in freeLeaves) { T_HR_LEAVETYPESET entLeaveTypeSet = entAttendFreeLeave.T_HR_LEAVETYPESET; if (entLeaveTypeSet == null) { continue; } string strVacType = entLeaveTypeSet.LEAVETYPEVALUE; string strFineType = entLeaveTypeSet.FINETYPE; //如果是调休假,就不需要自动生成 if (strVacType == (Convert.ToInt32(Common.LeaveTypeValue.AdjustLeave) + 1).ToString()) { continue; } //获取假期标准的带薪假设置记录 FreeLeaveDaySetBLL bllFreeLeave = new FreeLeaveDaySetBLL(); IQueryable <T_HR_FREELEAVEDAYSET> entFreeLeaves = bllFreeLeave.GetFreeLeaveDaySetByLeaveTypeID(entLeaveTypeSet.LEAVETYPESETID); if (strFineType != (Convert.ToInt32(Common.LeaveFineType.Free) + 1).ToString()) { continue; } decimal dPostLevelStrict = 0; decimal.TryParse(entLeaveTypeSet.POSTLEVELRESTRICT, out dPostLevelStrict); if (dPostLevelStrict > dEmployeePostLevel) { continue; } if (entLeaveTypeSet.ENTRYRESTRICT == (Convert.ToInt32(Common.IsChecked.Yes) + 1).ToString()) { if (entEmployee.EMPLOYEESTATE != "1") { continue; } } if (entLeaveTypeSet.SEXRESTRICT != "2") { if (entLeaveTypeSet.SEXRESTRICT != entEmployee.SEX) { continue; } } if (!string.IsNullOrEmpty(entLeaveTypeSet.POSTLEVELRESTRICT)) { decimal dPostLeavlStrict = decimal.Parse(entLeaveTypeSet.POSTLEVELRESTRICT); } int j = -1; decimal dLeaveDay = 0; string LeaveDayName = string.Empty; if (entFreeLeaves.Count() > 0) { for (int i = 0; i < entFreeLeaves.Count(); i++) { if (entFreeLeaves.ToList()[i].MINIMONTH > dCurWorkAge) { continue; } if (entFreeLeaves.ToList()[i].MAXMONTH < dCurWorkAge) { continue; } dLeaveDay = entFreeLeaves.ToList()[i].LEAVEDAYS.Value; LeaveDayName = entLeaveTypeSet.LEAVETYPENAME; j = i; break; } } else { dLeaveDay = entLeaveTypeSet.MAXDAYS.Value; j = 1; } decimal dAddDays = 0; if (j > -1) { if (entFreeLeaves.Count() > 0) { if (j == 0) { dAddDays = dLeaveDay; } else { dAddDays = dLeaveDay - entFreeLeaves.ToList()[j - 1].LEAVEDAYS.Value; } } else { dAddDays = dLeaveDay; } } string strNumOfDecDefault = "0.5"; dAddDays = RoundOff(dAddDays, strNumOfDecDefault, 1); dLeaveDay = RoundOff(dLeaveDay, strNumOfDecDefault, 1); deDays = dAddDays; } } catch (Exception ex) { } return(deDays); }
/// <summary> /// 初始化五四三八数据 /// </summary> public void InitYouth() { try { var ents = from ent in dal.GetObjects <T_HR_ATTENDANCESOLUTION>() where ent.CHECKSTATE == "2" orderby ent.CREATEDATE ascending select ent; SMT.Foundation.Log.Tracer.Debug("总数量为:" + ents.Count().ToString()); int intCount = 0; foreach (var ent in ents) { //if (ent.ATTENDANCESOLUTIONID == "1214E853-3536-456F-BBC9-66A059A903A6") //{ // continue; //} #region 八 T_HR_LEAVETYPESET typeset = new T_HR_LEAVETYPESET(); typeset.LEAVETYPESETID = Guid.NewGuid().ToString(); typeset.LEAVETYPENAME = ent.ATTENDANCESOLUTIONNAME + "三八妇女节"; typeset.LEAVETYPEVALUE = "13"; typeset.ISFREELEAVEDAY = "2"; typeset.MAXDAYS = (decimal)0.53; typeset.FINETYPE = "1"; typeset.SEXRESTRICT = "0"; typeset.ENTRYRESTRICT = "1"; typeset.OWNERCOMPANYID = ent.OWNERCOMPANYID; typeset.OWNERDEPARTMENTID = ent.OWNERDEPARTMENTID; typeset.OWNERPOSTID = ent.OWNERPOSTID; typeset.OWNERID = ent.OWNERID; typeset.CREATEDATE = DateTime.Now; typeset.UPDATEDATE = DateTime.Now; typeset.UPDATEUSERID = ent.OWNERID; typeset.CREATECOMPANYID = ent.OWNERCOMPANYID; typeset.CREATEDEPARTMENTID = ent.OWNERDEPARTMENTID; typeset.CREATEPOSTID = ent.OWNERPOSTID; typeset.CREATEUSERID = ent.OWNERID; typeset.REMARK = "系统产生三八妇女节"; var entExist = from ent1 in dal.GetObjects <T_HR_LEAVETYPESET>() where ent1.LEAVETYPEVALUE == "13" && ent1.OWNERCOMPANYID == ent.OWNERCOMPANYID select ent1; LeaveTypeSetBLL bllLeaveTypeSet = new LeaveTypeSetBLL(); if (entExist.Count() == 0) { string aaa = bllLeaveTypeSet.AddLeaveTypeSet(typeset); if (aaa == "{SAVESUCCESSED}") { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "产生了三八节"); } else { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "没有产生三八节"); continue; } } else { typeset = entExist.FirstOrDefault(); } //int iii = dal.Add(typeset); //if (iii > 0) //{ // SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME +"产生了三八节"); //} //dal.SaveContextChanges(); //dal.AddToContext(typeset); T_HR_FREELEAVEDAYSET freeTypeSet = new T_HR_FREELEAVEDAYSET(); freeTypeSet.FREELEAVEDAYSETID = Guid.NewGuid().ToString(); freeTypeSet.T_HR_LEAVETYPESET = typeset; //freeTypeSet.T_HR_LEAVETYPESETReference.EntityKey = //new System.Data.EntityKey("TM_SaaS_OA_EFModelContext.T_HR_LEAVETYPESET", "LEAVETYPESETID", typeset.LEAVETYPESETID); freeTypeSet.MINIMONTH = 0; freeTypeSet.MAXMONTH = 9999; freeTypeSet.LEAVEDAYS = (decimal)0.53; freeTypeSet.ISPERFECTATTENDANCEFACTOR = "1"; freeTypeSet.OFFESTTYPE = "1"; freeTypeSet.OWNERCOMPANYID = ent.OWNERCOMPANYID; freeTypeSet.OWNERDEPARTMENTID = ent.OWNERDEPARTMENTID; freeTypeSet.OWNERPOSTID = ent.OWNERPOSTID; freeTypeSet.OWNERID = ent.OWNERID; freeTypeSet.CREATEDATE = DateTime.Now; freeTypeSet.UPDATEDATE = DateTime.Now; freeTypeSet.UPDATEUSERID = ent.OWNERID; freeTypeSet.CREATECOMPANYID = ent.OWNERCOMPANYID; freeTypeSet.CREATEDEPARTMENTID = ent.OWNERDEPARTMENTID; freeTypeSet.CREATEPOSTID = ent.OWNERPOSTID; freeTypeSet.CREATEUSERID = ent.OWNERID; freeTypeSet.REMARK = "系统产生三八妇女节带薪假"; //dal.AddToContext(freeTypeSet); FreeLeaveDaySetBLL bllFreeLeaveDaySet = new FreeLeaveDaySetBLL(); string aa2 = bllFreeLeaveDaySet.AddFreeLeaveDaySet(freeTypeSet); if (aa2 == "{SAVESUCCESSED}") { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "产生了带薪假三八节"); } else { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "没有产生带薪假三八节"); continue; } T_HR_ATTENDFREELEAVE attendFree = new T_HR_ATTENDFREELEAVE(); attendFree.ATTENDFREELEAVEID = Guid.NewGuid().ToString(); var entSol = from ent11 in dal.GetObjects <T_HR_ATTENDANCESOLUTION>() where ent11.ATTENDANCESOLUTIONID == ent.ATTENDANCESOLUTIONID select ent11; attendFree.T_HR_ATTENDANCESOLUTION = entSol.FirstOrDefault(); var entSet = from ent11 in dal.GetObjects <T_HR_LEAVETYPESET>() where ent11.LEAVETYPESETID == typeset.LEAVETYPESETID select ent11; attendFree.T_HR_LEAVETYPESET = entSet.FirstOrDefault(); attendFree.REMARK = "自动产生三八节"; attendFree.CREATEDATE = DateTime.Now; attendFree.UPDATEDATE = DateTime.Now; attendFree.CREATEUSERID = ent.OWNERID; attendFree.UPDATEUSERID = ent.OWNERID; string bbb = AddAttendFreeLeave(attendFree); if (bbb == "{SAVESUCCESSED}") { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "产生了三八节,和考勤方案关联了"); } else { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "没有@@@@@@产生三八节,和考勤方案关联了"); continue; } #endregion #region 五四 T_HR_LEAVETYPESET typesetYouth = new T_HR_LEAVETYPESET(); typesetYouth.LEAVETYPESETID = Guid.NewGuid().ToString(); typesetYouth.LEAVETYPENAME = ent.ATTENDANCESOLUTIONNAME + "五四青年节"; typesetYouth.LEAVETYPEVALUE = "12"; typesetYouth.ISFREELEAVEDAY = "2"; typesetYouth.MAXDAYS = (decimal)0.53; typesetYouth.FINETYPE = "1"; typesetYouth.SEXRESTRICT = "2"; typesetYouth.ENTRYRESTRICT = "1"; typesetYouth.OWNERCOMPANYID = ent.OWNERCOMPANYID; typesetYouth.OWNERDEPARTMENTID = ent.OWNERDEPARTMENTID; typesetYouth.OWNERPOSTID = ent.OWNERPOSTID; typesetYouth.OWNERID = ent.OWNERID; typesetYouth.CREATEDATE = DateTime.Now; typesetYouth.UPDATEDATE = DateTime.Now; typesetYouth.UPDATEUSERID = ent.OWNERID; typesetYouth.CREATECOMPANYID = ent.OWNERCOMPANYID; typesetYouth.CREATEDEPARTMENTID = ent.OWNERDEPARTMENTID; typesetYouth.CREATEPOSTID = ent.OWNERPOSTID; typesetYouth.CREATEUSERID = ent.OWNERID; typesetYouth.REMARK = "系统产生五四青年节"; //dal.AddToContext(typesetYouth); var entExistYouth = from ent1 in dal.GetObjects <T_HR_LEAVETYPESET>() where ent1.LEAVETYPEVALUE == "12" && ent1.OWNERCOMPANYID == ent.OWNERCOMPANYID select ent1; if (entExistYouth.Count() == 0) { string bbb1 = bllLeaveTypeSet.AddLeaveTypeSet(typesetYouth); if (bbb1 == "{SAVESUCCESSED}") { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "产生了五四青年节"); } else { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "没有####产生五四青年节"); continue; } } else { typesetYouth = entExistYouth.FirstOrDefault(); } T_HR_FREELEAVEDAYSET freeTypeSetYouth = new T_HR_FREELEAVEDAYSET(); freeTypeSetYouth.FREELEAVEDAYSETID = Guid.NewGuid().ToString(); freeTypeSetYouth.T_HR_LEAVETYPESET = typesetYouth; //freeTypeSetYouth.T_HR_LEAVETYPESETReference.EntityKey = //new System.Data.EntityKey("TM_SaaS_OA_EFModelContext.T_HR_LEAVETYPESET", "LEAVETYPESETID", typesetYouth.LEAVETYPESETID); freeTypeSetYouth.MINIMONTH = 0; freeTypeSetYouth.MAXMONTH = 9999; freeTypeSetYouth.LEAVEDAYS = (decimal)0.53; freeTypeSetYouth.ISPERFECTATTENDANCEFACTOR = "1"; freeTypeSetYouth.OFFESTTYPE = "1"; freeTypeSetYouth.OWNERCOMPANYID = ent.OWNERCOMPANYID; freeTypeSetYouth.OWNERDEPARTMENTID = ent.OWNERDEPARTMENTID; freeTypeSetYouth.OWNERPOSTID = ent.OWNERPOSTID; freeTypeSetYouth.OWNERID = ent.OWNERID; freeTypeSetYouth.CREATEDATE = DateTime.Now; freeTypeSetYouth.UPDATEDATE = DateTime.Now; freeTypeSetYouth.UPDATEUSERID = ent.OWNERID; freeTypeSetYouth.CREATECOMPANYID = ent.OWNERCOMPANYID; freeTypeSetYouth.CREATEDEPARTMENTID = ent.OWNERDEPARTMENTID; freeTypeSetYouth.CREATEPOSTID = ent.OWNERPOSTID; freeTypeSetYouth.CREATEUSERID = ent.OWNERID; freeTypeSetYouth.REMARK = "系统产生五四青年节带薪假"; //dal.AddToContext(freeTypeSetYouth); string bb2 = bllFreeLeaveDaySet.AddFreeLeaveDaySet(freeTypeSetYouth); if (bb2 == "{SAVESUCCESSED}") { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "产生了带薪假五四青年节"); } else { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "没有&&&产生带薪假五四青年节"); continue; } T_HR_ATTENDFREELEAVE attendFreeYouth = new T_HR_ATTENDFREELEAVE(); attendFreeYouth.ATTENDFREELEAVEID = Guid.NewGuid().ToString(); attendFreeYouth.T_HR_ATTENDANCESOLUTION = ent; attendFreeYouth.T_HR_LEAVETYPESET = typesetYouth; //attendFreeYouth.T_HR_LEAVETYPESETReference.EntityKey = // new System.Data.EntityKey("TM_SaaS_OA_EFModelContext.T_HR_LEAVETYPESET", "LEAVETYPESETID", typesetYouth.LEAVETYPESETID); attendFreeYouth.REMARK = "自动产生五四青年节"; attendFreeYouth.CREATEDATE = DateTime.Now; attendFreeYouth.UPDATEDATE = DateTime.Now; attendFreeYouth.CREATEUSERID = ent.OWNERID; attendFreeYouth.UPDATEUSERID = ent.OWNERID; string cc = AddAttendFreeLeave(attendFreeYouth); if (cc == "{SAVESUCCESSED}") { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "产生了五四节,和考勤方案关联了"); } else { SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "没有********了五四节,和考勤方案关联了"); continue; } #endregion SMT.Foundation.Log.Tracer.Debug(ent.ATTENDANCESOLUTIONNAME + "执行完了"); intCount += 1; SMT.Foundation.Log.Tracer.Debug("执行了:" + intCount.ToString()); } } catch (Exception ex) { SMT.Foundation.Log.Tracer.Debug("初始化五四三八出现错误" + ex.ToString()); } }