コード例 #1
0
        /// <summary>
        /// 根据主键索引,删除公共假期设置信息(注:暂定为物理删除)
        /// </summary>
        /// <param name="strVacationId">主键索引</param>
        /// <returns></returns>
        public string DeleteVacationSet(string strVacationId)
        {
            string strMsg = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(strVacationId))
                {
                    return("{REQUIREDFIELDS}");
                }

                bool          flag      = false;
                StringBuilder strFilter = new StringBuilder();
                List <string> objArgs   = new List <string>();

                strFilter.Append(" VACATIONID == @0");

                objArgs.Add(strVacationId);

                VacationSetDAL dalVacationSet = new VacationSetDAL();
                flag = dalVacationSet.IsExistsRd(strFilter.ToString(), objArgs.ToArray());

                if (!flag)
                {
                    return("{NOTFOUND}");
                }

                OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
                bllOutPlanDays.DeleteByVacationID(strVacationId);

                T_HR_VACATIONSET entDel = dalVacationSet.GetVacationSetRdByMultSearch(strFilter.ToString(), objArgs.ToArray());
                dalVacationSet.Delete(entDel);

                strMsg = "{DELETESUCCESSED}";
            }
            catch (Exception ex)
            {
                strMsg = ex.Message.ToString();
            }

            return(strMsg);
        }
コード例 #2
0
ファイル: OutApplyConfirmBLL.cs プロジェクト: jjg0519/OA
        /// <summary>
        /// 计算外出确认时长
        /// </summary>
        /// <param name="strEmployeeId"></param>
        /// <param name="dtOTStart"></param>
        /// <param name="dtOTEnd"></param>
        /// <param name="dOverTimeHours"></param>
        /// <returns></returns>
        public string CalculateOverTimeHours(string strEmployeeId, DateTime dtOTStart, DateTime dtOTEnd, ref string dOverTimeHours)
        {
            string  strRes = string.Empty;
            decimal dTotalOverTimeHours = 0;

            DateTime dtStart, dtEnd = new DateTime();

            dtStart = dtOTStart;
            dtEnd   = dtOTEnd;
            //DateTime.TryParse(dtOTStart.ToString("yyyy-MM-dd"), out dtStart);        //获取请假起始日期
            //DateTime.TryParse(dtOTEnd.ToString("yyyy-MM-dd"), out dtEnd);            //获取请假截止日期
            AttendanceSolutionAsignBLL   bllAttendSolAsign = new AttendanceSolutionAsignBLL();
            T_HR_ATTENDANCESOLUTIONASIGN entAttendSolAsign = bllAttendSolAsign.GetAttendanceSolutionAsignByEmployeeIDAndDate(strEmployeeId, dtStart);

            if (entAttendSolAsign == null)
            {
                //当前员工没有分配考勤方案,无法提交请假申请
                return("没有找到员工分配的考勤方案!");
            }

            //获取考勤方案
            T_HR_ATTENDANCESOLUTION entAttendSol = entAttendSolAsign.T_HR_ATTENDANCESOLUTION;
            decimal dWorkTimePerDay = entAttendSol.WORKTIMEPERDAY.Value;
            decimal dWorkMode       = entAttendSol.WORKMODE.Value;
            int     iWorkMode       = 0;

            int.TryParse(dWorkMode.ToString(), out iWorkMode);//获取工作制(工作天数/周)

            List <int> iWorkDays = new List <int>();

            Utility.GetWorkDays(iWorkMode, ref iWorkDays);

            OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
            IQueryable <T_HR_OUTPLANDAYS> entOutPlanDays = bllOutPlanDays.GetOutPlanDaysRdListByEmployeeID(strEmployeeId);

            string strVacDayType  = (Convert.ToInt32(Common.OutPlanDaysType.Vacation) + 1).ToString();
            string strWorkDayType = (Convert.ToInt32(Common.OutPlanDaysType.WorkDay) + 1).ToString();
            IQueryable <T_HR_OUTPLANDAYS> entVacDays  = entOutPlanDays.Where(s => s.DAYTYPE == strVacDayType);
            IQueryable <T_HR_OUTPLANDAYS> entWorkDays = entOutPlanDays.Where(s => s.DAYTYPE == strWorkDayType && s.STARTDATE >= dtStart && s.ENDDATE <= dtEnd);

            SchedulingTemplateDetailBLL bllTemplateDetail = new SchedulingTemplateDetailBLL();
            IQueryable <T_HR_SCHEDULINGTEMPLATEDETAIL> entTemplateDetails = bllTemplateDetail.GetTemplateDetailRdListByAttendanceSolutionId(entAttendSol.ATTENDANCESOLUTIONID);
            T_HR_SCHEDULINGTEMPLATEMASTER entTemplateMaster = entTemplateDetails.FirstOrDefault().T_HR_SCHEDULINGTEMPLATEMASTER;

            dtEnd   = new DateTime(dtEnd.Year, dtEnd.Month, dtEnd.Day, dtEnd.Hour, dtEnd.Minute, 0);
            dtStart = new DateTime(dtStart.Year, dtStart.Month, dtStart.Day, dtStart.Hour, dtStart.Minute, 0);
            TimeSpan ts      = dtEnd.Subtract(dtStart);
            int      iOTDays = ts.Days;
            string   strMsg  = string.Empty;

            dTotalOverTimeHours = iOTDays * dWorkTimePerDay + ts.Hours;
            if (dTotalOverTimeHours > 0)
            {
                dOverTimeHours = Math.Round(dTotalOverTimeHours, 0) + "小时";
            }
            if (ts.Minutes > 0)
            {
                dOverTimeHours = dOverTimeHours + ts.Minutes + "分";
            }
            return(strRes + strMsg);
        }
コード例 #3
0
        /// <summary>
        /// 检测申请加班的相关信息
        /// </summary>
        /// <param name="request">结果数据实体</param>
        /// <returns>返回结果数据实体</returns>
        public CalculateOTHoursResponse CalculateOTHours(CalculateOTHoursRequest request)
        {
            CalculateOTHoursResponse response = new CalculateOTHoursResponse();

            DateTime dtStartDate = Convert.ToDateTime(request.StartDate + " " + request.StartTime);
            DateTime dtEndDate   = Convert.ToDateTime(request.EndDate + " " + request.EndTime);

            DateTime dtTempStartDate = dtStartDate;
            DateTime dtTempEndDate   = dtEndDate;

            List <string> sWorkArr    = new List <string>(); //工作时间
            List <string> sNotWorkArr = new List <string>(); //休息时间
            List <string> tempWorkArr = new List <string>();

            DateTime FirstCardStartDate  = DateTime.MinValue;
            DateTime FirstCardEndDate    = DateTime.MinValue;
            DateTime SecondCardStartDate = DateTime.MinValue;
            DateTime SecondCardEndDate   = DateTime.MinValue;

            DateTime ThirdCardStartDate  = DateTime.MinValue;
            DateTime ThirdCardEndDate    = DateTime.MinValue;
            DateTime FourthCardStartDate = DateTime.MinValue;
            DateTime FourthCardEndDate   = DateTime.MinValue;

            double totalHours       = 0;
            int    hasFirstSetting  = 1; //0,未设置;1,已设置
            int    hasSecondSetting = 1; //0,未设置;1,已设置
            int    hasThirdSetting  = 1; //0,未设置;1,已设置
            int    hasFourthSetting = 1; //0,未设置;1,已设置

            response.Result         = Enums.Result.Success.GetHashCode();
            response.Message        = string.Empty;
            response.OTHours        = 0;
            response.OTDays         = 0;
            response.Month          = string.Empty;
            response.AttendSolution = string.Empty;
            response.WorkPerDay     = 0;
            response.StartTime      = Convert.ToDateTime(request.StartTime).ToString("HH:mm");

            //判断加班申请是否重复
            T_HR_EMPLOYEEOVERTIMERECORD otEntity = dal.GetObjects <T_HR_EMPLOYEEOVERTIMERECORD>().Where(t => t.OVERTIMERECORDID != request.OverTimeRecordID &&
                                                                                                        t.EMPLOYEEID == request.EmployeeID &&
                                                                                                        ((dtStartDate > t.STARTDATE && dtStartDate < t.ENDDATE) ||//起始时间在已有时间段内
                                                                                                         (dtEndDate > t.STARTDATE && dtEndDate < t.ENDDATE) ||//结束时间在已有时间段内
                                                                                                         (dtStartDate == t.STARTDATE && dtEndDate > t.STARTDATE) ||//当dtStartDate与开始时间重叠时,dtEndDate需大于开始时间
                                                                                                         (dtEndDate == t.ENDDATE && dtStartDate < t.ENDDATE) ||//当dtEndDate与最后时间重叠时dtStartDate需小于束时间
                                                                                                         (dtStartDate <t.STARTDATE && dtEndDate> t.ENDDATE)//新增加班完成包含已有加班
                                                                                                        ) &&
                                                                                                        t.CHECKSTATE != "3" && t.CHECKSTATE != "0"
                                                                                                        ).FirstOrDefault();

            if (otEntity != null)
            {
                response.Result  = Enums.Result.HasDuplicateOTRecord.GetHashCode();//结果:失败
                response.Message = Constants.HasDuplicateOTRecord + ";"
                                   + otEntity.STARTDATE.Value.ToString("yyyy-MM-dd") + " " + otEntity.STARTDATETIME + " ~ "
                                   + otEntity.ENDDATE.Value.ToString("yyyy-MM-dd") + "  " + otEntity.ENDDATETIME;//加班申请重复
                return(response);
            }

            #region "   获取考勤方案,排班明细,排班时间段   "

            AttendanceSolutionBLL   bllAttendanceSolution  = new AttendanceSolutionBLL();
            T_HR_ATTENDANCESOLUTION OTPeriodAttendSolution = bllAttendanceSolution.GetAttendanceSolutionByEmployeeIDAndDate(request.EmployeeID,
                                                                                                                            Convert.ToDateTime(request.StartDate), Convert.ToDateTime(request.EndDate));

            SchedulingTemplateDetailBLL bllTemplateDetail = new SchedulingTemplateDetailBLL();
            IQueryable <T_HR_SCHEDULINGTEMPLATEDETAIL> scheduleSetDetail =
                bllTemplateDetail.GetTemplateDetailRdListByAttendanceSolutionId(OTPeriodAttendSolution.ATTENDANCESOLUTIONID);
            T_HR_SCHEDULINGTEMPLATEMASTER scheduleSetting = scheduleSetDetail.FirstOrDefault().T_HR_SCHEDULINGTEMPLATEMASTER;

            int      iCycleDays       = 0;
            DateTime dtCycleStartDate = Convert.ToDateTime(Convert.ToDateTime(request.StartDate).ToString("yyyy-MM-01"));//按月为周期的排班表
            DateTime dtCurCycleOTDate = Convert.ToDateTime(DateTime.Parse(request.StartDate).ToString("yyyy-MM-dd"));
            //找出加班时间与循环排班详细中对应的日历号,然后通过T_HR_SCHEDULINGTEMPLATEDETAIL找到对应的 打卡时间段: T_HR_SHIFTDEFINE
            if (scheduleSetting.SCHEDULINGCIRCLETYPE == (Common.SchedulingCircleType.Month.GetHashCode() + 1).ToString())
            {//按月循环的排班打卡方式
                iCycleDays = 31;
            }

            if ((scheduleSetting.SCHEDULINGCIRCLETYPE == (Common.SchedulingCircleType.Week.GetHashCode() + 1).ToString()))
            {//按周排班打卡方式
                iCycleDays = 7;
                //如果是按周统计,则从当前算起
                dtCycleStartDate = Convert.ToDateTime(DateTime.Parse(request.StartDate).ToString("yyyy-MM-dd"));
            }

            T_HR_SHIFTDEFINE dayCardSetting = null; //具体的排班明细,最多包括了4个时段的打卡设置,用于计算加班小时数
            for (int i = 0; i < iCycleDays; i++)    //找出加班日期对应的日历中对应明细排班: T_HR_SHIFTDEFINE
            {
                string   strSchedulingDate = (i + 1).ToString();
                DateTime dtCurDate         = new DateTime();

                dtCurDate = dtCycleStartDate.AddDays(i);

                if (dtCurDate != dtCurCycleOTDate)
                {
                    continue;
                }

                T_HR_SCHEDULINGTEMPLATEDETAIL item = scheduleSetDetail.Where(c => c.SCHEDULINGDATE == strSchedulingDate).FirstOrDefault();
                if (item != null)
                {
                    dayCardSetting = item.T_HR_SHIFTDEFINE;//具体的排班明细
                }
            }

            #endregion

            string strMonth = Convert.ToDateTime(request.StartDate).ToString("yyyy年MM月");
            if (OTPeriodAttendSolution != null)
            {
                if (dayCardSetting != null)
                {
                    #region "   休息时间段的设置,以最大四个班次计算  "
                    DateTime notWorkTimeStart = DateTime.MinValue;
                    DateTime notWorkTimeEnd   = DateTime.MinValue;

                    DateTime notWorkTimeStart1 = DateTime.MinValue;
                    DateTime notWorkTimeEnd1   = DateTime.MinValue;

                    DateTime notWorkTimeStart2 = DateTime.MinValue;
                    DateTime notWorkTimeEnd2   = DateTime.MinValue;
                    #endregion

                    #region "   第一时段打卡起始时间  "
                    if (!string.IsNullOrEmpty(dayCardSetting.FIRSTSTARTTIME) && !string.IsNullOrEmpty(dayCardSetting.FIRSTENDTIME))
                    {
                        FirstCardStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FIRSTSTARTTIME).ToString("HH:mm:ss"));
                        FirstCardEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FIRSTENDTIME).ToString("HH:mm:ss"));

                        notWorkTimeStart = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FIRSTENDTIME).ToString("HH:mm:ss"));

                        sWorkArr.Add(FirstCardStartDate.ToString() + "|" + FirstCardEndDate.ToString());

                        response.FirstStartTime = Convert.ToDateTime(dayCardSetting.FIRSTSTARTTIME).ToString("HH:mm:ss");
                        response.FirstEndTime   = Convert.ToDateTime(dayCardSetting.FIRSTENDTIME).ToString("HH:mm:ss");
                    }
                    else
                    {
                        hasFirstSetting = 0;
                    }
                    #endregion
                    #region "   第二时段打卡起始时间  "
                    if (!string.IsNullOrEmpty(dayCardSetting.SECONDSTARTTIME) && !string.IsNullOrEmpty(dayCardSetting.SECONDENDTIME))
                    {
                        SecondCardStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDSTARTTIME).ToString("HH:mm:ss"));
                        SecondCardEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDENDTIME).ToString("HH:mm:ss"));

                        notWorkTimeEnd    = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDSTARTTIME).ToString("HH:mm:ss"));
                        notWorkTimeStart1 = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDENDTIME).ToString("HH:mm:ss"));

                        sWorkArr.Add(SecondCardStartDate.ToString() + "|" + SecondCardEndDate.ToString());
                        sNotWorkArr.Add(notWorkTimeStart.ToString() + "|" + notWorkTimeEnd.ToString());

                        response.SecondStartTime = Convert.ToDateTime(dayCardSetting.SECONDSTARTTIME).ToString("HH:mm:ss");
                        response.SecondEndTime   = Convert.ToDateTime(dayCardSetting.SECONDENDTIME).ToString("HH:mm:ss");
                    }
                    else
                    {
                        hasSecondSetting = 0;
                    }
                    #endregion
                    #region "   第三时段打卡起始时间  "
                    if (!string.IsNullOrEmpty(dayCardSetting.THIRDSTARTTIME) && !string.IsNullOrEmpty(dayCardSetting.THIRDENDTIME))
                    {
                        ThirdCardStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.THIRDSTARTTIME).ToString("HH:mm:ss"));
                        ThirdCardEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.THIRDENDTIME).ToString("HH:mm:ss"));

                        notWorkTimeEnd1   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.THIRDSTARTTIME).ToString("HH:mm:ss"));
                        notWorkTimeStart2 = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.THIRDENDTIME).ToString("HH:mm:ss"));

                        sWorkArr.Add(ThirdCardStartDate.ToString() + "|" + ThirdCardEndDate.ToString());
                        sNotWorkArr.Add(notWorkTimeStart1.ToString() + "|" + notWorkTimeEnd1.ToString());

                        response.ThirdStartTime = string.IsNullOrEmpty(dayCardSetting.THIRDSTARTTIME) ? string.Empty : Convert.ToDateTime(dayCardSetting.THIRDSTARTTIME).ToString("HH:mm:ss");
                        response.ThirdEndTime   = string.IsNullOrEmpty(dayCardSetting.THIRDENDTIME) ? string.Empty : Convert.ToDateTime(dayCardSetting.THIRDENDTIME).ToString("HH:mm:ss");
                    }
                    else
                    {
                        hasThirdSetting = 0;
                    }
                    #endregion
                    #region "   第四时段打卡起始时间  "
                    if (!string.IsNullOrEmpty(dayCardSetting.FOURTHSTARTTIME) && !string.IsNullOrEmpty(dayCardSetting.FOURTHENDTIME))
                    {
                        FourthCardStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FOURTHSTARTTIME).ToString("HH:mm:ss"));
                        FourthCardEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FOURTHENDTIME).ToString("HH:mm:ss"));

                        notWorkTimeEnd2 = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FOURTHSTARTTIME).ToString("HH:mm:ss"));

                        sWorkArr.Add(FourthCardStartDate.ToString() + "|" + FourthCardEndDate.ToString());
                        sNotWorkArr.Add(notWorkTimeStart2.ToString() + "|" + notWorkTimeEnd2.ToString());

                        response.FourthStartTime = string.IsNullOrEmpty(dayCardSetting.FOURTHSTARTTIME) ? string.Empty : Convert.ToDateTime(dayCardSetting.FOURTHSTARTTIME).ToString("HH:mm:ss");
                        response.FourthEndTime   = string.IsNullOrEmpty(dayCardSetting.FOURTHENDTIME) ? string.Empty : Convert.ToDateTime(dayCardSetting.FOURTHENDTIME).ToString("HH:mm:ss");
                    }
                    else
                    {
                        hasFourthSetting = 0;
                    }
                    #endregion

                    #region "   判断是否设置了至少两个的打卡时间段   "
                    //为设置打卡时间段,至少设置两个打卡时间段
                    if (hasFirstSetting == 0)
                    {
                        response.Result         = Enums.Result.NonFirstSetting.GetHashCode();
                        response.Month          = strMonth;
                        response.AttendSolution = OTPeriodAttendSolution.ATTENDANCESOLUTIONNAME;
                        response.WorkPerDay     = OTPeriodAttendSolution.WORKTIMEPERDAY.HasValue ? OTPeriodAttendSolution.WORKTIMEPERDAY.Value : 0;
                        response.Message        = Constants.NonFirstSetting;
                        return(response);
                    }

                    if (hasSecondSetting == 0)
                    {
                        response.Result         = Enums.Result.NonSecondSetting.GetHashCode();
                        response.Month          = strMonth;
                        response.AttendSolution = OTPeriodAttendSolution.ATTENDANCESOLUTIONNAME;
                        response.WorkPerDay     = OTPeriodAttendSolution.WORKTIMEPERDAY.HasValue ? OTPeriodAttendSolution.WORKTIMEPERDAY.Value : 0;
                        response.Message        = Constants.NonSecondSetting;
                        return(response);
                    }
                    #endregion

                    #region "   检查加班时间是否在公共假期,或是工作日,或是三八,或是五四     "

                    decimal dWorkMode = OTPeriodAttendSolution.WORKMODE.Value;
                    int     iWorkMode = 0;
                    int.TryParse(dWorkMode.ToString(), out iWorkMode);//获取工作制(工作天数/周)

                    List <int> iWorkDays = new List <int>();
                    SMT.HRM.BLL.Utility.GetWorkDays(iWorkMode, ref iWorkDays);

                    OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
                    IQueryable <T_HR_OUTPLANDAYS> entOutPlanDays = bllOutPlanDays.GetOutPlanDaysRdListByEmployeeID(request.EmployeeID);
                    string strVacDayType  = (Convert.ToInt32(SMT.HRM.BLL.Common.OutPlanDaysType.Vacation) + 1).ToString();
                    string strWorkDayType = (Convert.ToInt32(SMT.HRM.BLL.Common.OutPlanDaysType.WorkDay) + 1).ToString();
                    //获取公共假期设置
                    DateTime vacTempStartDate = Convert.ToDateTime(request.StartDate);
                    DateTime vacTempEndDate   = Convert.ToDateTime(request.EndDate);
                    //加班只可能在一天内
                    IQueryable <T_HR_OUTPLANDAYS> entVacDays = entOutPlanDays.Where(s => s.DAYTYPE == strVacDayType &&
                                                                                    vacTempStartDate >= s.STARTDATE && vacTempEndDate <= s.ENDDATE);

                    //获取工作日设置
                    DateTime workTempStartDate = Convert.ToDateTime(request.StartDate);
                    DateTime workTempEndDate   = Convert.ToDateTime(request.EndDate);
                    //加班只可能在一天内
                    IQueryable <T_HR_OUTPLANDAYS> entWorkDays = entOutPlanDays.Where(s => s.DAYTYPE == strWorkDayType &&
                                                                                     workTempStartDate >= s.STARTDATE && workTempEndDate <= s.ENDDATE);
                    //当前星期几,是否要工作
                    //Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6.
                    int  iDayOfWeek = Convert.ToDateTime(request.StartDate).DayOfWeek.GetHashCode();
                    bool iDayCount  = iWorkDays.Contains(iDayOfWeek);

                    DateTime WorkDayEndDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDENDTIME).ToString("HH:mm:ss"));
                    //工作日加班,要在第二时间段以后
                    if (dayCardSetting != null)
                    {
                        if (hasThirdSetting == 1)
                        {
                            WorkDayEndDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.THIRDENDTIME).ToString("HH:mm:ss"));
                        }
                        if (hasFourthSetting == 1)
                        {
                            WorkDayEndDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FOURTHENDTIME).ToString("HH:mm:ss"));
                        }
                    }

                    #region "   不是假期    "
                    if (entVacDays.Count() == 0)
                    {     //也不是设置的工作日,
                        if (entWorkDays.Count() == 0)
                        { //并且在上班时间列表中
                            if (iDayCount)
                            {
                                //工作日加班,要在第二时间段以后
                                if (dayCardSetting != null)
                                {
                                    #region 梁杰文 平时加班,加班起始时间要在工作日结束之后
                                    //改判断逻辑dtEndDate <= WorkDayEndDate为WorkDayEndDate>dtStartDate
                                    #endregion
                                    if (WorkDayEndDate > dtStartDate)
                                    {
                                        #region "   在上班时间列表中,这天要上班,不算加班  "
                                        //这天要上班,不算加班
                                        response.Result  = Enums.Result.IsWorkDay.GetHashCode();
                                        response.Message = Constants.IsWorkDay;//是工作日,不算加班
                                        return(response);

                                        #endregion
                                    }
                                }
                            }
                        }
                        else
                        {
                            //工作日加班,要在第二时间段以后
                            if (dayCardSetting != null)
                            {
                                #region 梁杰文 平时加班,加班起始时间要在工作日结束之后
                                //改判断逻辑dtEndDate <= WorkDayEndDate为WorkDayEndDate>dtStartDate
                                #endregion
                                if (WorkDayEndDate > dtStartDate)
                                {
                                    #region "   设置为工作日,这天要上班,不算加班   "
                                    //这天要上班,不算加班
                                    response.Result  = Enums.Result.IsWorkDay.GetHashCode();
                                    response.Message = Constants.IsWorkDay;//是工作日,不算加班
                                    return(response);

                                    #endregion
                                }
                            }
                        }
                    }
                    else
                    {
                        //加班时间在假期设置中,但只是半天的设置
                        foreach (var vac in entVacDays)
                        {
                            #region "   半天公共假期,三八妇女节,青年节    "
                            if (vac.ISHALFDAY == "1")
                            {
                                if (vac.PEROID == "1")//下午
                                {
                                    if (dayCardSetting != null)
                                    {
                                        DateTime HalfMorningStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FIRSTSTARTTIME).ToString("HH:mm:ss"));
                                        DateTime HalfMorningEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FIRSTENDTIME).ToString("HH:mm:ss"));
                                        //四个时间中,上午时间的开始与结束
                                        if (hasThirdSetting == 1 && hasFourthSetting == 1)
                                        {
                                            HalfMorningEndDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDENDTIME).ToString("HH:mm:ss"));
                                        }
                                        //如果填写的加班时间段在上午,则不算加班
                                        if (dtEndDate <= HalfMorningEndDate)
                                        {
                                            response.Result         = Enums.Result.IsHalfDayMorningWork.GetHashCode();
                                            response.Month          = strMonth;
                                            response.AttendSolution = OTPeriodAttendSolution.ATTENDANCESOLUTIONNAME;
                                            response.WorkPerDay     = OTPeriodAttendSolution.WORKTIMEPERDAY.HasValue ? OTPeriodAttendSolution.WORKTIMEPERDAY.Value : 0;
                                            response.Message        = Constants.IsHalfDayMorningWork;
                                            return(response);
                                        }
                                    }
                                }
                                else//上午
                                {
                                    if (dayCardSetting != null)
                                    {
                                        DateTime HalfNoonStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDSTARTTIME).ToString("HH:mm:ss"));
                                        DateTime HalfNoonEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.SECONDENDTIME).ToString("HH:mm:ss"));
                                        //四个时间中,下午时间的开始与结束
                                        if (hasThirdSetting == 1 && hasFourthSetting == 1)
                                        {
                                            HalfNoonStartDate = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.THIRDSTARTTIME).ToString("HH:mm:ss"));
                                            HalfNoonEndDate   = Convert.ToDateTime(request.StartDate + " " + Convert.ToDateTime(dayCardSetting.FOURTHENDTIME).ToString("HH:mm:ss"));
                                        }
                                        //如果填写的加班时间段在下午,则不算加班
                                        if (dtStartDate >= HalfNoonStartDate && dtStartDate <= HalfNoonEndDate)
                                        {
                                            response.Result         = Enums.Result.IsHalfDayNoonWork.GetHashCode();
                                            response.Month          = strMonth;
                                            response.AttendSolution = OTPeriodAttendSolution.ATTENDANCESOLUTIONNAME;
                                            response.WorkPerDay     = OTPeriodAttendSolution.WORKTIMEPERDAY.HasValue ? OTPeriodAttendSolution.WORKTIMEPERDAY.Value : 0;
                                            response.Message        = Constants.IsHalfDayNoonWork;
                                            return(response);
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion
                    #endregion

                    //填写的加班时段都在4个设置的上班时间段里面,则直接用结束时间减去开始时间
                    if (
                        (dtStartDate >= FirstCardStartDate && dtStartDate <= FirstCardEndDate &&
                         dtEndDate >= FirstCardStartDate && dtEndDate <= FirstCardEndDate)
                        ||
                        (dtStartDate >= SecondCardStartDate && dtStartDate <= SecondCardEndDate &&
                         dtEndDate >= SecondCardStartDate && dtEndDate <= SecondCardEndDate)
                        ||
                        (dtStartDate >= ThirdCardStartDate && dtStartDate <= ThirdCardEndDate &&
                         dtEndDate >= ThirdCardStartDate && dtEndDate <= ThirdCardEndDate)
                        ||
                        (dtStartDate >= FourthCardStartDate && dtStartDate <= FourthCardEndDate &&
                         dtEndDate >= FourthCardStartDate && dtEndDate <= FourthCardEndDate)
                        )
                    {
                        totalHours = dtEndDate.Subtract(dtStartDate).TotalHours;
                    }
                    else
                    {
                        #region "   计算加班时间     "

                        //早7:50打开,将计算加班的有效开始时间设置为8:30,也就是dtCardStartDate
                        //23:00下班,假定四个工作时间段
                        if (dtStartDate < FirstCardStartDate)
                        {
                            dtTempStartDate    = FirstCardStartDate;
                            response.StartTime = dtTempStartDate.ToString("HH:mm:ss");
                        }

                        #region "   找出开始计算加班的时间点    "
                        DateTime tempOTDate = new DateTime();
                        foreach (string str in sWorkArr)
                        {
                            string[] s             = str.Split('|');
                            DateTime WorkStartDate = Convert.ToDateTime(s[0]);
                            DateTime WorkEndDate   = Convert.ToDateTime(s[1]);
                            //如果开始时间在工作时间范围内,那就从开始时间算加班
                            if (dtTempStartDate >= WorkStartDate && dtTempStartDate <= WorkEndDate)
                            {
                                tempOTDate = dtTempStartDate;
                            }
                            //如果开始时间大于工作时间段的结束时间,则属于休息时间段的时间点
                            //找出里他最近的上班时间点作为加班开始时间
                            if (dtTempStartDate > WorkEndDate)
                            {
                                foreach (string str1 in sNotWorkArr)
                                {
                                    string[] sn = str1.Split('|');
                                    DateTime notWorkStartDate = Convert.ToDateTime(sn[0]);
                                    DateTime notWorkEndDate   = Convert.ToDateTime(sn[1]);
                                    //加班开始时间在休息时间点内,则加班的开始时间从休息时间的结束点开始
                                    if (dtTempStartDate >= notWorkStartDate && dtTempStartDate <= notWorkEndDate)
                                    {
                                        tempOTDate = notWorkEndDate;
                                    }
                                    else
                                    {
                                        //不在所有的休息时间段内,则说明加班是在
                                        //一天正常的上班时间段以外进行
                                        tempOTDate = dtTempStartDate;
                                    }
                                }
                            }
                        }
                        #endregion

                        #region "   设置具体的加班是时间段     "
                        for (int i = 0; i < sWorkArr.Count(); i++)
                        {
                            string[] ss            = sWorkArr[i].Split('|');
                            DateTime WorkStartDate = Convert.ToDateTime(ss[0]);
                            DateTime WorkEndDate   = Convert.ToDateTime(ss[1]);
                            //工作时间段的开始时间大于加班开始时间
                            if (WorkStartDate >= tempOTDate)
                            {
                                //加班结束时间大于工作时间段的结束时间
                                //则说明加班时间包含这段工作时间段,计算完整的加班时间段
                                if (dtTempEndDate >= WorkEndDate)
                                {
                                    if (sNotWorkArr.Count() == 0)
                                    {
                                        tempWorkArr.Add(WorkStartDate.ToString() + "|" + dtTempEndDate.ToString());
                                    }

                                    foreach (string str3 in sNotWorkArr)
                                    {
                                        string[] sn = str3.Split('|');
                                        DateTime notWorkStartDate = Convert.ToDateTime(sn[0]);
                                        DateTime notWorkEndDate   = Convert.ToDateTime(sn[1]);
                                        if (dtTempEndDate >= notWorkStartDate && dtTempEndDate <= notWorkEndDate)
                                        {
                                            tempWorkArr.Add(WorkStartDate.ToString() + "|" + WorkEndDate.ToString());
                                        }
                                        else if (dtTempEndDate >= WorkEndDate)
                                        {
                                            if (i == sWorkArr.Count() - 1)
                                            {
                                                WorkEndDate = dtTempEndDate;
                                            }
                                            tempWorkArr.Add(WorkStartDate.ToString() + "|" + WorkEndDate.ToString());
                                            sNotWorkArr.Remove(str3);
                                            break;
                                        }
                                        else
                                        {
                                            tempWorkArr.Add(WorkStartDate.ToString() + "|" + notWorkStartDate.ToString());
                                            sNotWorkArr.Remove(str3);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    if (sNotWorkArr.Count() == 0)
                                    {
                                        tempWorkArr.Add(WorkStartDate.ToString() + "|" + dtTempEndDate.ToString());
                                    }

                                    foreach (string str3 in sNotWorkArr)
                                    {
                                        string[] sn = str3.Split('|');
                                        DateTime notWorkStartDate = Convert.ToDateTime(sn[0]);
                                        DateTime notWorkEndDate   = Convert.ToDateTime(sn[1]);
                                        if (dtTempEndDate >= notWorkStartDate && dtTempEndDate <= notWorkEndDate)
                                        {
                                        }
                                        else if (dtTempEndDate >= WorkEndDate)
                                        {
                                            tempWorkArr.Add(WorkStartDate.ToString() + "|" + WorkEndDate.ToString());
                                            sNotWorkArr.Remove(str3);
                                            break;
                                        }
                                        else
                                        {
                                            tempWorkArr.Add(WorkStartDate.ToString() + "|" + dtTempEndDate.ToString());
                                            sNotWorkArr.Remove(str3);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (i == sWorkArr.Count() - 1)
                                {
                                    WorkEndDate = dtTempEndDate;
                                }
                                tempWorkArr.Add(tempOTDate.ToString() + "|" + WorkEndDate.ToString());
                            }
                        }
                        #endregion

                        #region "   计算加班时长  "
                        tempWorkArr = tempWorkArr.Distinct().ToList();
                        foreach (string str4 in tempWorkArr)
                        {
                            string[] sss           = str4.Split('|');
                            DateTime WorkStartDate = Convert.ToDateTime(sss[0]);
                            DateTime WorkEndDate   = Convert.ToDateTime(sss[1]);
                            if (WorkStartDate <= WorkEndDate)
                            {
                                totalHours += Math.Round(WorkEndDate.Subtract(WorkStartDate).TotalHours, 1);
                            }
                        }
                        #endregion

                        #endregion
                    }
                }


                response.Result         = Enums.Result.Success.GetHashCode();
                response.OTHours        = totalHours;
                response.OTDays         = Math.Round(totalHours / Convert.ToDouble(OTPeriodAttendSolution.WORKTIMEPERDAY), 2);
                response.Month          = strMonth;
                response.AttendSolution = OTPeriodAttendSolution.ATTENDANCESOLUTIONNAME;
                response.WorkPerDay     = OTPeriodAttendSolution.WORKTIMEPERDAY.HasValue ? OTPeriodAttendSolution.WORKTIMEPERDAY.Value : 0;
                response.Message        = "";
                return(response);
            }


            response.Result         = Enums.Result.NonAttendenceSolution.GetHashCode();
            response.Message        = Constants.NonAttendenceSolution;
            response.OTHours        = 0;
            response.OTDays         = 0;
            response.Month          = strMonth;
            response.AttendSolution = string.Format("未找到{0}对应的考勤方案", strMonth);
            response.WorkPerDay     = 0;
            return(response);
        }
コード例 #4
0
ファイル: EmployeeCancelLeaveBLL.cs プロジェクト: jjg0519/OA
        /// <summary>
        /// 获取指定员工的实际销假天数(实际销假天数=销假天数-公休假天数-每周休息天数),实际销假时长(按小时计,实际销假合计时长=非整天销假时长-当日作息间隙休息时间+整天销假时长)
        /// </summary>
        /// <param name="strCancelLeaveId">当前销假记录的ID</param>
        /// <param name="strEmployeeID">员工ID</param>
        /// <param name="dtLeaveStartTime">销假起始时间</param>
        /// <param name="dtLeaveEndTime">销假截止时间</param>
        /// <param name="dLeaveDay">实际销假天数</param>
        /// <param name="dLeaveTime">实际销假时长</param>
        /// <param name="dLeaveTotalTime">实际销假合计时长</param>
        public string GetRealCancelLeaveDayByEmployeeIdAndDate(string strCancelLeaveId, string strEmployeeID, DateTime dtCancelLeaveStartTime, DateTime dtCancelLeaveEndTime, ref decimal dCancelLeaveDay, ref decimal dCancelLeaveTime, ref decimal dCancelLeaveTotalTime)
        {
            string strMsg = string.Empty;

            try
            {
                T_HR_EMPLOYEECANCELLEAVE entCancelLeaveRecord = GetEmployeeCancelLeaveByID(strCancelLeaveId);
                bool flag = false;

                if (entCancelLeaveRecord != null)
                {
                    if (entCancelLeaveRecord.STARTDATETIME == dtCancelLeaveStartTime && entCancelLeaveRecord.ENDDATETIME == dtCancelLeaveEndTime)
                    {
                        if (entCancelLeaveRecord.LEAVEDAYS == null)
                        {
                            dCancelLeaveDay = 0;
                        }
                        else
                        {
                            dCancelLeaveDay = entCancelLeaveRecord.LEAVEDAYS.Value;
                        }

                        if (entCancelLeaveRecord.LEAVEHOURS == null)
                        {
                            dCancelLeaveTime = 0;
                        }
                        else
                        {
                            dCancelLeaveTime = entCancelLeaveRecord.LEAVEHOURS.Value;
                        }

                        if (entCancelLeaveRecord.TOTALHOURS == null)
                        {
                            dCancelLeaveTotalTime = 0;
                        }
                        else
                        {
                            dCancelLeaveTotalTime = entCancelLeaveRecord.TOTALHOURS.Value;
                        }

                        flag = true;
                    }
                }

                if (flag)
                {
                    return(strMsg);
                }

                DateTime dtStart, dtEnd = new DateTime();
                decimal  dTotalLeaveDay = 0;                                                   //起止时间的时长

                DateTime.TryParse(dtCancelLeaveStartTime.ToString("yyyy-MM-dd"), out dtStart); //获取销假起始日期
                DateTime.TryParse(dtCancelLeaveEndTime.ToString("yyyy-MM-dd"), out dtEnd);     //获取销假截止日期

                AttendanceSolutionAsignBLL   bllAttendSolAsign = new AttendanceSolutionAsignBLL();
                T_HR_ATTENDANCESOLUTIONASIGN entAttendSolAsign = bllAttendSolAsign.GetAttendanceSolutionAsignByEmployeeIDAndDate(strEmployeeID, dtStart);
                if (entAttendSolAsign == null)
                {
                    //当前员工没有分配考勤方案,无法提交销假申请
                    return("{NONEXISTASIGNEDATTENSOL}");
                }

                //获取考勤方案
                T_HR_ATTENDANCESOLUTION entAttendSol = entAttendSolAsign.T_HR_ATTENDANCESOLUTION;
                decimal dWorkTimePerDay = entAttendSol.WORKTIMEPERDAY.Value;
                decimal dWorkMode       = entAttendSol.WORKMODE.Value;
                int     iWorkMode       = 0;
                int.TryParse(dWorkMode.ToString(), out iWorkMode);//获取工作制(工作天数/周)

                List <int> iWorkDays = new List <int>();
                Utility.GetWorkDays(iWorkMode, ref iWorkDays);//获取每周上班天数

                OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
                IQueryable <T_HR_OUTPLANDAYS> entOutPlanDays = bllOutPlanDays.GetOutPlanDaysRdListByEmployeeID(strEmployeeID);

                string strVacDayType  = (Convert.ToInt32(Common.OutPlanDaysType.Vacation) + 1).ToString();
                string strWorkDayType = (Convert.ToInt32(Common.OutPlanDaysType.WorkDay) + 1).ToString();
                IQueryable <T_HR_OUTPLANDAYS> entVacDays = entOutPlanDays.Where(s => s.DAYTYPE == strVacDayType);
                //IQueryable<T_HR_OUTPLANDAYS> entWorkDays = entOutPlanDays.Where(s => s.DAYTYPE == strWorkDayType && s.STARTDATE >= dtStart && s.ENDDATE <= dtEnd);
                // 销假时间要在开始时间和结束时间之间
                //注释掉没考虑某一区间的情况
                //IQueryable<T_HR_OUTPLANDAYS> entWorkDays = entOutPlanDays.Where(s => s.DAYTYPE == strWorkDayType && s.STARTDATE <= dtStart && s.ENDDATE >= dtEnd);
                //条件过滤有四种情况
                //1:在区间内
                //2:大于开始时间且结束时间小于销假结束时间
                //3:开始日期大于 销假开始日期且结束日期处于有效期之间
                //4:开始日期小于销假开始日期且结束日期在开始时间和结束时间
                IQueryable <T_HR_OUTPLANDAYS> entWorkDays = entOutPlanDays.Where(s => s.DAYTYPE == strWorkDayType &&
                                                                                 ((s.STARTDATE <= dtStart && s.ENDDATE >= dtEnd) ||
                                                                                  (s.STARTDATE >= dtStart && s.ENDDATE <= dtEnd) ||
                                                                                  (s.STARTDATE >= dtStart && s.STARTDATE <= dtEnd && s.ENDDATE >= dtEnd) ||
                                                                                  (s.STARTDATE <= dtStart && s.ENDDATE >= dtStart && s.ENDDATE <= dtEnd)));
                SchedulingTemplateDetailBLL bllTemplateDetail = new SchedulingTemplateDetailBLL();
                IQueryable <T_HR_SCHEDULINGTEMPLATEDETAIL> entTemplateDetails = bllTemplateDetail.GetTemplateDetailRdListByAttendanceSolutionId(entAttendSol.ATTENDANCESOLUTIONID);
                T_HR_SCHEDULINGTEMPLATEMASTER entTemplateMaster = entTemplateDetails.FirstOrDefault().T_HR_SCHEDULINGTEMPLATEMASTER;

                TimeSpan ts = dtEnd.Subtract(dtStart);

                decimal dVacDay = 0, dWorkDay = 0;
                decimal dLeaveFirstDayTime = 0, dLeaveLastDayTime = 0, dLeaveFirstLastTime = 0;//请假第一天的时长,请假最后一天的时长,请假首尾两天合计时长
                if (dtCancelLeaveStartTime != dtCancelLeaveEndTime)
                {
                    EmployeeLeaveRecordBLL bllLeaveRecord = new EmployeeLeaveRecordBLL();
                    bllLeaveRecord.CalculateNonWholeDayLeaveTime(dtCancelLeaveStartTime, dtStart, entTemplateMaster, entTemplateDetails, entVacDays, entWorkDays, iWorkDays, "S", ref dLeaveFirstDayTime);
                    bllLeaveRecord.CalculateNonWholeDayLeaveTime(dtCancelLeaveEndTime, dtEnd, entTemplateMaster, entTemplateDetails, entVacDays, entWorkDays, iWorkDays, "E", ref dLeaveLastDayTime);

                    dLeaveFirstLastTime = dLeaveFirstDayTime + dLeaveLastDayTime;

                    if (dtStart == dtEnd)
                    {
                        dLeaveFirstLastTime = dLeaveFirstLastTime - dWorkTimePerDay * 60;
                    }
                }
                else
                {
                    dLeaveFirstLastTime = dWorkTimePerDay * 60;
                }


                dTotalLeaveDay = ts.Days;
                if (ts.Days > 0)
                {
                    //取得总的请假天数(此天数扣除了首尾两天的时间,根据请假的情况,可能包含了公休假及周假天数,扣除首尾两天的计算只适合请三天以上的)
                    int iDays = ts.Days - 1;
                    dTotalLeaveDay = iDays;

                    for (int i = 0; i < iDays; i++)
                    {
                        int      j         = i + 1;
                        bool     isVacDay  = false;
                        DateTime dtCurDate = dtStart.AddDays(j);
                        if (iWorkDays.Contains(Convert.ToInt32(dtCurDate.DayOfWeek)) == false)
                        {
                            dVacDay += 1;
                        }

                        if (entVacDays.Count() > 0)
                        {
                            foreach (T_HR_OUTPLANDAYS item_Vac in entVacDays)
                            {
                                if (item_Vac.STARTDATE.Value <= dtCurDate && item_Vac.ENDDATE >= dtCurDate)
                                {
                                    isVacDay = true;
                                    break;
                                }
                            }
                        }

                        if (isVacDay)
                        {
                            dVacDay += 1;
                        }

                        if (entWorkDays.Count() > 0)
                        {
                            foreach (T_HR_OUTPLANDAYS item_Work in entWorkDays)
                            {
                                if (item_Work.STARTDATE.Value <= dtCurDate && item_Work.ENDDATE >= dtCurDate)
                                {
                                    dWorkDay += 1;
                                    break;
                                }
                            }
                        }
                    }
                }

                dCancelLeaveDay = dTotalLeaveDay - dVacDay + dWorkDay;    //请假天数 = 请假天数-首尾两天 - 总休假天数 + 休假调剂工作天数
                decimal dTempTime = decimal.Round((dLeaveFirstLastTime) / 60, 1);
                if (dTempTime >= dWorkTimePerDay)
                {
                    decimal  dTempDay = decimal.Round(dTempTime / dWorkTimePerDay, 2);
                    string[] strList  = dTempDay.ToString().Split('.');
                    if (strList.Length == 2)
                    {
                        dCancelLeaveDay += decimal.Parse(strList[0].ToString());
                        dCancelLeaveTime = dTempTime - dWorkTimePerDay * decimal.Parse(strList[0].ToString());
                    }
                    else
                    {
                        dCancelLeaveDay += dTempDay;
                    }
                }
                else if (dTempTime < dWorkTimePerDay)
                {
                    dCancelLeaveTime = dTempTime;
                }

                dCancelLeaveTotalTime = dCancelLeaveDay * dWorkTimePerDay + dCancelLeaveTime;
            }
            catch (Exception ex)
            {
                strMsg = ex.Message;
                Utility.SaveLog(ex.ToString());
            }

            return(strMsg);
        }
コード例 #5
0
ファイル: AttendInitForEmployees.cs プロジェクト: jjg0519/OA
        /// <summary>
        /// 对指定公司,指定的员工,按照指定的考勤方案应用生成指定时段内的考勤初始化记录
        /// </summary>
        /// <param name="entTemp"></param>
        /// <param name="entCompany"></param>
        /// <param name="entEmployees"></param>
        /// <param name="dtAsignDate"></param>
        /// <returns></returns>
        private string AsignAttendSolForEmployees(T_HR_ATTENDANCESOLUTIONASIGN entTemp, T_HR_COMPANY entCompany, List <T_HR_EMPLOYEE> entEmployees, DateTime dtAsignDate)
        {
            string strRes = string.Empty;

            try
            {
                decimal dWorkMode = entTemp.T_HR_ATTENDANCESOLUTION.WORKMODE.Value;
                string  strAttendanceSolutionID = entTemp.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONID;

                int iWorkMode = 0;
                int.TryParse(dWorkMode.ToString(), out iWorkMode);

                List <int> iWorkDays = new List <int>();
                Utility.GetWorkDays(iWorkMode, ref iWorkDays);

                SchedulingTemplateDetailBLL          bllTemplateDetail  = new SchedulingTemplateDetailBLL();
                List <T_HR_SCHEDULINGTEMPLATEDETAIL> entTemplateDetails = new List <T_HR_SCHEDULINGTEMPLATEDETAIL>();

                var q = bllTemplateDetail.GetTemplateDetailRdListByAttendanceSolutionId(strAttendanceSolutionID);

                if (q == null)
                {
                    Tracer.Debug("考勤初始化考勤班次不存在");
                    return("{NOTFOUND}");
                }

                entTemplateDetails = q.ToList();

                if (entTemplateDetails == null)
                {
                    Tracer.Debug("考勤初始化考勤班次不存在");
                    return("{NOTFOUND}");
                }

                if (entTemplateDetails.Count == 0)
                {
                    Tracer.Debug("考勤初始化考勤班次不存在");
                    return("{NOTFOUND}");
                }

                int iTotalDay = 0;
                //DateTime dtCheck = new DateTime();
                DateTime dtStart = DateTime.Parse(dtAsignDate.ToString("yyyy-MM") + "-1");

                //DateTime dtStart = DateTime.Parse("2012-10-1");

                if (entTemp.STARTDATE > dtStart)
                {
                    dtStart = entTemp.STARTDATE.Value;
                }

                DateTime dtInitAttandRecordEndDate = dtStart.AddMonths(1).AddDays(-1);

                AttendanceRecordBLL      bllAttRd         = new AttendanceRecordBLL();
                EmployeeLevelDayCountBLL bllLevelDayCount = new EmployeeLevelDayCountBLL();
                EmployeeEntryBLL         bllEntry         = new EmployeeEntryBLL();
                LeftOfficeConfirmBLL     bllConfirm       = new LeftOfficeConfirmBLL();

                //操作表T_HR_EMPLOYEELEVELDAYCOUNT数据的方式:0:直接逐条新增或修改;
                //1:先把要新增或修改的记录存到内存,然后一次性提交到数据库修改

                Tracer.Debug("开始生成员工考勤初始化记录,总员工数:" + entEmployees.Count());
                for (int n = 0; n < entEmployees.Count(); n++)
                {
                    bool AttendNoCheck = false;
                    try
                    {
                        T_HR_EMPLOYEE item_emp = entEmployees[n];
                        DateTime      dtInitAttandRecordStartDate = new DateTime();

                        #region 判断是否免打卡
                        //如果是免打卡的用户,在这里还是需要初始化,因为结算的时候需要计算出勤天数
                        if (!entTemp.T_HR_ATTENDANCESOLUTIONReference.IsLoaded)
                        {
                            entTemp.T_HR_ATTENDANCESOLUTIONReference.Load();
                        }
                        if (entTemp.T_HR_ATTENDANCESOLUTION.ATTENDANCETYPE == (Convert.ToInt32(Common.AttendanceType.NoCheck) + 1).ToString())//考勤方案设置为不考勤
                        {
                            AttendNoCheck = true;
                            Tracer.Debug("初始化员工,考勤方案设置为免打卡,员工姓名:"
                                         + entEmployees.FirstOrDefault().EMPLOYEECNAME
                                         + " 考勤方案名:" + entTemp.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME);
                        }

                        #endregion

                        #region 初始化开始日期大于结束日期
                        dtInitAttandRecordStartDate = dtStart;

                        if (dtInitAttandRecordStartDate >= dtInitAttandRecordEndDate)
                        {
                            Tracer.Debug("初始化员工考勤记录被跳过,dtInitAttandRecordStartDate >= dtEnd" + ",员工姓名" + item_emp.EMPLOYEECNAME);
                            continue;
                        }
                        #endregion

                        #region 判断员工状态,是否有入职记录,是否已离职,入职,离职日期
                        string usedAttendSolutionName = ",使用的考勤方案:" + entTemp.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME
                                                        + ",当前线程id:" + Thread.CurrentThread.ManagedThreadId;
                        Tracer.Debug("初始化员工考勤记录:员工状态:" + item_emp.EMPLOYEESTATE + ",员工姓名" + item_emp.EMPLOYEECNAME
                                     + usedAttendSolutionName);
                        if (item_emp.EMPLOYEESTATE == "0")
                        {
                            T_HR_EMPLOYEEENTRY entEntry = bllEntry.GetEmployeeEntryByEmployeeID(item_emp.EMPLOYEEID);
                            if (entEntry == null)
                            {
                                Tracer.Debug("初始化员工考勤记录被跳过,该员工入职为空" + ",员工姓名" + item_emp.EMPLOYEECNAME);
                                continue;
                            }
                            TimeSpan tsStart = entEntry.ONPOSTDATE.Value - dtInitAttandRecordStartDate;
                            TimeSpan tsEnd   = dtInitAttandRecordEndDate - entEntry.ONPOSTDATE.Value;
                            if (tsStart.Days >= 0 && tsEnd.Days >= 0)
                            {
                                Tracer.Debug("初始化员工考勤记录开始日期被修改:entEntry.ONPOSTDATE.Value > dtInitAttandRecordStartDate" + ",员工姓名" + item_emp.EMPLOYEECNAME
                                             + " 入职日期:" + entEntry.ENTRYDATE.Value.ToString("yyyy-MM-dd")
                                             + " 到岗日期:" + entEntry.ONPOSTDATE.Value.ToString("yyyy-MM-dd"));
                                dtInitAttandRecordStartDate = new DateTime(entEntry.ONPOSTDATE.Value.Year, entEntry.ONPOSTDATE.Value.Month, entEntry.ONPOSTDATE.Value.Day);
                            }

                            if (tsEnd.Days < 0)
                            {
                                Tracer.Debug("初始化员工考勤记录被跳过:员工到岗日期大于考勤初始化结束日期entEntry.ONPOSTDATE.Value > dtEnd" + ",员工姓名" + item_emp.EMPLOYEECNAME
                                             + " 入职日期:" + entEntry.ENTRYDATE.Value.ToString("yyyy-MM-dd")
                                             + " 到岗日期:" + entEntry.ONPOSTDATE.Value.ToString("yyyy-MM-dd")
                                             + " 考勤初始化结束日期:" + dtInitAttandRecordEndDate);
                                continue;
                            }
                        }
                        if (item_emp.EMPLOYEESTATE == "1")
                        {
                            T_HR_EMPLOYEEENTRY entEntry = bllEntry.GetEmployeeEntryByEmployeeID(item_emp.EMPLOYEEID);
                            if (entEntry == null)
                            {
                                Tracer.Debug("该员工入职为空" + ",员工姓名" + item_emp.EMPLOYEECNAME);
                                continue;
                            }

                            if (entEntry.ONPOSTDATE.Value > dtInitAttandRecordStartDate && entEntry.ONPOSTDATE.Value < dtInitAttandRecordEndDate)
                            {
                                Tracer.Debug("初始化员工考勤记录开始日期被修改:entEntry.ONPOSTDATE.Value > dtInitAttandRecordStartDate" + ",员工姓名" + item_emp.EMPLOYEECNAME
                                             + " 入职日期:" + entEntry.ENTRYDATE.Value.ToString("yyyy-MM-dd")
                                             + " 到岗日期:" + entEntry.ONPOSTDATE.Value.ToString("yyyy-MM-dd"));
                                dtInitAttandRecordStartDate = new DateTime(entEntry.ONPOSTDATE.Value.Year, entEntry.ONPOSTDATE.Value.Month, entEntry.ONPOSTDATE.Value.Day);
                            }

                            TimeSpan ts3 = entEntry.ONPOSTDATE.Value - dtInitAttandRecordEndDate;
                            if (ts3.Days > 0)
                            {
                                Tracer.Debug("初始化员工考勤记录被跳过,员工入职日期大于本月最后一天" + ",员工姓名" + item_emp.EMPLOYEECNAME);
                                continue;
                            }
                        }
                        else if (item_emp.EMPLOYEESTATE == "2")
                        {
                            T_HR_LEFTOFFICECONFIRM entConfirm = bllConfirm.GetLeftOfficeConfirmByEmployeeId(item_emp.EMPLOYEEID);
                            if (entConfirm.STOPPAYMENTDATE != null && entConfirm.STOPPAYMENTDATE.Value < dtStart)
                            {
                                Tracer.Debug("初始化员工考勤记录被跳过,entConfirm.STOPPAYMENTDATE !=null && entConfirm.STOPPAYMENTDATE.Value < dtStart" + ",员工姓名" + item_emp.EMPLOYEECNAME);
                                continue;
                            }

                            if (entConfirm.STOPPAYMENTDATE != null && entConfirm.STOPPAYMENTDATE.Value > dtStart && entConfirm.STOPPAYMENTDATE.Value < dtInitAttandRecordEndDate)
                            {
                                dtInitAttandRecordEndDate = new DateTime(entConfirm.STOPPAYMENTDATE.Value.Year, entConfirm.STOPPAYMENTDATE.Value.Month, entConfirm.STOPPAYMENTDATE.Value.Day);
                            }

                            if (entConfirm.STOPPAYMENTDATE != null && entConfirm.STOPPAYMENTDATE.Value < dtStart)
                            {
                                Tracer.Debug("初始化员工考勤记录被跳过,entConfirm.STOPPAYMENTDATE != null && entConfirm.STOPPAYMENTDATE.Value < dtStart" + ",员工姓名" + item_emp.EMPLOYEECNAME);
                                continue;
                            }
                        }
                        #endregion

                        TimeSpan ts = dtInitAttandRecordEndDate.Subtract(dtInitAttandRecordStartDate);
                        iTotalDay = ts.Days;

                        T_HR_SCHEDULINGTEMPLATEMASTER entTemplateMaster = entTemplateDetails[0].T_HR_SCHEDULINGTEMPLATEMASTER;
                        int iCircleDay = 0;
                        if (entTemplateMaster.SCHEDULINGCIRCLETYPE == (Convert.ToInt32(Common.SchedulingCircleType.Month) + 1).ToString())
                        {
                            iCircleDay = 31;
                        }
                        else if (entTemplateMaster.SCHEDULINGCIRCLETYPE == (Convert.ToInt32(Common.SchedulingCircleType.Week) + 1).ToString())
                        {
                            iCircleDay = 7;
                        }

                        int iPeriod = iTotalDay / iCircleDay;
                        if (iTotalDay % iCircleDay >= 0)
                        {
                            iPeriod += 1;
                        }

                        OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
                        IQueryable <T_HR_OUTPLANDAYS> entOutPlanDays = bllOutPlanDays.GetOutPlanDaysRdListByEmployeeID(item_emp.EMPLOYEEID);

                        string strVacDayType  = (Convert.ToInt32(Common.OutPlanDaysType.Vacation) + 1).ToString();
                        string strWorkDayType = (Convert.ToInt32(Common.OutPlanDaysType.WorkDay) + 1).ToString();
                        IQueryable <T_HR_OUTPLANDAYS> entVacDays  = entOutPlanDays.Where(s => s.DAYTYPE == strVacDayType);
                        IQueryable <T_HR_OUTPLANDAYS> entWorkDays = entOutPlanDays.Where(s => s.DAYTYPE == strWorkDayType && s.STARTDATE >= dtInitAttandRecordStartDate && s.ENDDATE <= dtInitAttandRecordEndDate);
                        //IQueryable<T_HR_OUTPLANDAYS> entVacWorkDays = entOutPlanDays.Where(s => s.STARTDATE >= dtInitAttandRecordStartDate && s.ENDDATE <= dtInitAttandRecordEndDate);
                        //例外工作日考勤初始化记录公共假期
                        CreateOutPlanWorkDay(entCompany, item_emp, entTemp, entTemplateDetails, entWorkDays, AttendNoCheck);
                        //IQueryable<T_HR_OUTPLANDAYS> entVacWorkHalfDays
                        //    = entVacDays.Where(s => s.STARTDATE >= dtInitAttandRecordStartDate
                        //    && s.ENDDATE <= dtInitAttandRecordEndDate && s.ISHALFDAY=="1");
                        int addCount    = 0;
                        int updateCount = 0;
                        for (int i = 0; i < iPeriod; i++)
                        {
                            for (int j = 0; j < iCircleDay; j++)
                            {
                                #region 开始生成员工考勤初始化记录
                                try
                                {
                                    int      m         = (i * iCircleDay) + j;
                                    DateTime dtCurDate = dtInitAttandRecordStartDate.AddDays(m);

                                    if (dtCurDate > entTemp.ENDDATE.Value)
                                    {
                                        break;
                                    }

                                    bool isVacDay = false;

                                    if (iWorkDays.Contains(Convert.ToInt32(dtCurDate.DayOfWeek)) == false)
                                    {
                                        continue;
                                    }

                                    if (entVacDays.Count() > 0)
                                    {
                                        foreach (T_HR_OUTPLANDAYS item_Vac in entVacDays)
                                        {
                                            if (item_Vac.STARTDATE.Value <= dtCurDate && item_Vac.ENDDATE >= dtCurDate)
                                            {
                                                //如果是公共假期并未设置半天,设为公共假期不考勤
                                                if (string.IsNullOrEmpty(item_Vac.ISHALFDAY))
                                                {
                                                    isVacDay = true;
                                                    break;
                                                }
                                                if (!string.IsNullOrEmpty(item_Vac.ISHALFDAY) &&
                                                    item_Vac.ISHALFDAY == "0")
                                                {
                                                    isVacDay = true;
                                                    break;
                                                }
                                                else
                                                { //例外工作日考勤初始化记录(公共假期半天休息,还有半天上班也需要初始化考勤记录)
                                                }
                                            }
                                        }
                                    }

                                    if (isVacDay)
                                    {
                                        continue;
                                    }

                                    T_HR_SCHEDULINGTEMPLATEDETAIL item = entTemplateDetails.Where(c => c.SCHEDULINGDATE == (j + 1).ToString()).FirstOrDefault();

                                    var qc = from ar in dal.GetObjects <T_HR_ATTENDANCERECORD>()
                                             where //ar.OWNERCOMPANYID == entCompany.COMPANYID &&
                                             ar.EMPLOYEEID == item_emp.EMPLOYEEID && ar.ATTENDANCEDATE == dtCurDate
                                             select ar;

                                    T_HR_ATTENDANCERECORD entUpdate = qc.FirstOrDefault();
                                    if (entUpdate == null)
                                    {
                                        T_HR_ATTENDANCERECORD entAttRd = new T_HR_ATTENDANCERECORD();
                                        entAttRd.ATTENDANCERECORDID   = System.Guid.NewGuid().ToString().ToUpper();
                                        entAttRd.ATTENDANCESOLUTIONID = entTemp.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONID;
                                        entAttRd.EMPLOYEEID           = item_emp.EMPLOYEEID;
                                        entAttRd.EMPLOYEECODE         = item_emp.EMPLOYEECODE;
                                        entAttRd.EMPLOYEENAME         = item_emp.EMPLOYEECNAME;
                                        entAttRd.ATTENDANCEDATE       = dtCurDate;

                                        //外键实体
                                        //entAttRd.T_HR_SHIFTDEFINE = item.T_HR_SHIFTDEFINE;
                                        entAttRd.T_HR_SHIFTDEFINEReference.EntityKey = new EntityKey("TM_SaaS_OA_EFModelContext.T_HR_SHIFTDEFINE", "SHIFTDEFINEID", item.T_HR_SHIFTDEFINE.SHIFTDEFINEID);

                                        //第一段工作时间
                                        entAttRd.FIRSTSTARTTIME = item.T_HR_SHIFTDEFINE.FIRSTSTARTTIME;
                                        entAttRd.FIRSTENDTIME   = item.T_HR_SHIFTDEFINE.FIRSTENDTIME;

                                        //第二段工作时间
                                        entAttRd.SECONDSTARTTIME = item.T_HR_SHIFTDEFINE.SECONDSTARTTIME;
                                        entAttRd.SECONDENDTIME   = item.T_HR_SHIFTDEFINE.SECONDENDTIME;

                                        //第三段工作时间
                                        entAttRd.THIRDSTARTTIME = item.T_HR_SHIFTDEFINE.THIRDSTARTTIME;
                                        entAttRd.THIRDENDTIME   = item.T_HR_SHIFTDEFINE.THIRDENDTIME;

                                        //第四段工作时间
                                        entAttRd.FOURTHENDTIME   = item.T_HR_SHIFTDEFINE.FOURTHENDTIME;
                                        entAttRd.FOURTHSTARTTIME = item.T_HR_SHIFTDEFINE.FOURTHSTARTTIME;
                                        //查询公共假期设置判断是否只上半天班公共假期
                                        var qVacDay = from ent in entVacDays
                                                      where ent.STARTDATE == entAttRd.ATTENDANCEDATE
                                                      select ent;
                                        if (qVacDay.Count() > 0)
                                        {
                                            var set = qVacDay.FirstOrDefault();
                                            if (!string.IsNullOrEmpty(set.ISHALFDAY))
                                            {
                                                if (set.ISHALFDAY == "1")
                                                {
                                                    if (set.PEROID == "0")//上午
                                                    {
                                                        string msg = "考勤初始化(新增)-检测到假期设置了休假(半天):"
                                                                     + " 员工:" + entAttRd.EMPLOYEENAME
                                                                     + " 日期:" + entAttRd.ATTENDANCEDATE
                                                                     + " 休假分段(0上午):" + set.PEROID;
                                                        Tracer.Debug(msg);
                                                        entAttRd.REMARK           = msg;
                                                        entAttRd.NEEDFRISTATTEND  = "0"; //上午不上班
                                                        entAttRd.NEEDSECONDATTEND = "1"; //下午上班
                                                    }
                                                    else if (set.PEROID == "1")
                                                    {
                                                        string msg = "考勤初始化(新增)-检测到假期设置了休假(半天):"
                                                                     + " 员工:" + entAttRd.EMPLOYEENAME
                                                                     + " 日期:" + entAttRd.ATTENDANCEDATE
                                                                     + " 休假分段(1下午):" + set.PEROID;
                                                        Tracer.Debug(msg);
                                                        entAttRd.REMARK           = msg;
                                                        entAttRd.NEEDFRISTATTEND  = "1"; //上午上班
                                                        entAttRd.NEEDSECONDATTEND = "0"; //下午不上班
                                                    }
                                                }
                                            }
                                        }

                                        //权限
                                        entAttRd.OWNERCOMPANYID    = item_emp.OWNERCOMPANYID;
                                        entAttRd.OWNERDEPARTMENTID = item_emp.OWNERDEPARTMENTID;
                                        entAttRd.OWNERPOSTID       = item_emp.OWNERPOSTID;
                                        entAttRd.OWNERID           = item_emp.OWNERID;

                                        entAttRd.CREATEUSERID       = entTemp.CREATEUSERID;
                                        entAttRd.CREATEDATE         = DateTime.Now;
                                        entAttRd.REMARK            += entTemp.REMARK;
                                        entAttRd.UPDATEUSERID       = entTemp.UPDATEUSERID;
                                        entAttRd.UPDATEDATE         = DateTime.Now;
                                        entAttRd.CREATECOMPANYID    = entTemp.CREATECOMPANYID;
                                        entAttRd.CREATEDEPARTMENTID = entTemp.CREATEDEPARTMENTID;
                                        entAttRd.CREATEPOSTID       = entTemp.CREATEPOSTID;

                                        if (AttendNoCheck)
                                        {
                                            entAttRd.ATTENDANCESTATE = "1";//免打卡员工
                                            Tracer.Debug("设置为免打孔员工,考勤默认为已出勤," + " 员工姓名" + item_emp.EMPLOYEECNAME + " 考勤初始化日期:" + entAttRd.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd")
                                                         + usedAttendSolutionName);
                                        }
                                        else
                                        {
                                            entAttRd.ATTENDANCESTATE = string.Empty;    //新生成的考勤记录,出勤状态为空
                                        }
                                        Tracer.Debug("开始新增员工T_HR_ATTENDANCERECORD记录,日期:" + dtCurDate.ToString("yyyy-MM-dd") + ",员工姓名:" + item_emp.EMPLOYEECNAME
                                                     + ",初始化考勤状态:" + entAttRd.ATTENDANCESTATE + usedAttendSolutionName);
                                        addCount += dal.Add(entAttRd);
                                    }
                                    else
                                    {
                                        if (AttendNoCheck)                   //免打孔
                                        {
                                            entUpdate.ATTENDANCESTATE = "1"; //免打卡员工  //非免打卡员工,跳过
                                            Tracer.Debug("设置为免打孔员工,考勤默认为已出勤," + " 员工姓名" + item_emp.EMPLOYEECNAME + " 考勤初始化日期:" + entUpdate.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd")
                                                         + usedAttendSolutionName);
                                        }
                                        else
                                        {
                                            if (!string.IsNullOrEmpty(entUpdate.ATTENDANCESTATE))
                                            {
                                                Tracer.Debug("更新考勤初始化记录,已存在的考勤初始化记录状态为: " + entUpdate.ATTENDANCESTATE + " ,跳过不再生成" + ",员工姓名:" + item_emp.EMPLOYEECNAME
                                                             + ",考勤状态:" + entUpdate.ATTENDANCESTATE + usedAttendSolutionName);
                                                continue;                             //如果存在直接跳过
                                            }
                                            entUpdate.ATTENDANCESTATE = string.Empty; //新生成的考勤记录,出勤状态为空
                                        }
                                        Tracer.Debug("更新考勤初始化记录,ATTENDANCESTATE考勤状态为空,日期:" + dtCurDate.ToString("yyyy-MM-dd") + ",员工姓名:" + item_emp.EMPLOYEECNAME
                                                     + ",初始化考勤状态:" + entUpdate.ATTENDANCESTATE + usedAttendSolutionName);
                                        entUpdate.ATTENDANCESOLUTIONID = entTemp.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONID;
                                        entUpdate.EMPLOYEEID           = item_emp.EMPLOYEEID;
                                        entUpdate.EMPLOYEECODE         = item_emp.EMPLOYEECODE;
                                        entUpdate.EMPLOYEENAME         = item_emp.EMPLOYEECNAME;
                                        entUpdate.ATTENDANCEDATE       = dtCurDate;

                                        entUpdate.T_HR_SHIFTDEFINE = item.T_HR_SHIFTDEFINE;

                                        //第一段工作时间
                                        entUpdate.FIRSTSTARTTIME = item.T_HR_SHIFTDEFINE.FIRSTSTARTTIME;
                                        entUpdate.FIRSTENDTIME   = item.T_HR_SHIFTDEFINE.FIRSTENDTIME;

                                        //第二段工作时间
                                        entUpdate.SECONDSTARTTIME = item.T_HR_SHIFTDEFINE.SECONDSTARTTIME;
                                        entUpdate.SECONDENDTIME   = item.T_HR_SHIFTDEFINE.SECONDENDTIME;

                                        //第三段工作时间
                                        entUpdate.THIRDSTARTTIME = item.T_HR_SHIFTDEFINE.THIRDSTARTTIME;
                                        entUpdate.THIRDENDTIME   = item.T_HR_SHIFTDEFINE.THIRDENDTIME;

                                        //第四段工作时间
                                        entUpdate.FOURTHENDTIME   = item.T_HR_SHIFTDEFINE.FOURTHENDTIME;
                                        entUpdate.FOURTHSTARTTIME = item.T_HR_SHIFTDEFINE.FOURTHSTARTTIME;

                                        //查询公共假期设置判断是否只上半天班
                                        var qVacDay = from ent in entVacDays
                                                      where ent.STARTDATE == entUpdate.ATTENDANCEDATE
                                                      select ent;
                                        if (qVacDay.Count() > 0)
                                        {
                                            var set = qVacDay.FirstOrDefault();
                                            if (!string.IsNullOrEmpty(set.ISHALFDAY))
                                            {
                                                if (set.ISHALFDAY == "1")
                                                {
                                                    if (set.PEROID == "0")//上午
                                                    {
                                                        string msg = "考勤初始化(修改)-检测到假期设置了休假(半天):"
                                                                     + " 员工:" + entUpdate.EMPLOYEENAME
                                                                     + " 日期:" + entUpdate.ATTENDANCEDATE
                                                                     + " 上班分段(0上午):" + set.PEROID;
                                                        Tracer.Debug(msg);
                                                        entUpdate.REMARK           = msg;
                                                        entUpdate.NEEDFRISTATTEND  = "0"; //上午不上班休息
                                                        entUpdate.NEEDSECONDATTEND = "1"; //下午上班
                                                    }
                                                    else if (set.PEROID == "1")
                                                    {
                                                        string msg = "考勤初始化(修改)-检测到假期设置了休假(半天):"
                                                                     + " 员工:" + entUpdate.EMPLOYEENAME
                                                                     + " 日期:" + entUpdate.ATTENDANCEDATE
                                                                     + " 上班分段(1下午):" + set.PEROID;
                                                        Tracer.Debug(msg);
                                                        entUpdate.REMARK           = msg;
                                                        entUpdate.NEEDFRISTATTEND  = "1"; //上午上班
                                                        entUpdate.NEEDSECONDATTEND = "0"; //下午不上班休息
                                                    }
                                                }
                                            }
                                        }

                                        //权限
                                        entUpdate.OWNERCOMPANYID    = item_emp.OWNERCOMPANYID;
                                        entUpdate.OWNERDEPARTMENTID = item_emp.OWNERDEPARTMENTID;
                                        entUpdate.OWNERPOSTID       = item_emp.OWNERPOSTID;
                                        entUpdate.OWNERID           = item_emp.OWNERID;

                                        entUpdate.REMARK      += entTemp.REMARK;
                                        entUpdate.UPDATEUSERID = entTemp.UPDATEUSERID;
                                        entUpdate.UPDATEDATE   = DateTime.Now;

                                        updateCount += dal.Update(entUpdate);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Tracer.Debug("生成考勤初始化记录出错:" + item_emp.EMPLOYEECNAME + ex.ToString() + usedAttendSolutionName);
                                    continue;
                                }
                                #endregion
                            }
                        }
                        //bllLevelDayCount.CalculateEmployeeLevelDayCount(entTemp, item_emp, strOperationType);
                        //int saveCount=dal.SaveContextChanges();
                        Tracer.Debug(n + "生成员工:" + item_emp.EMPLOYEECNAME + " 考勤记录成功,开始日期" + dtStart.ToString("yyyy-MM-dd") + "结束日期:"
                                     + dtInitAttandRecordEndDate.ToString("yyyy-MM-dd") + "共新增考勤记录" + addCount.ToString() + " 更新记录条数:" + updateCount
                                     + usedAttendSolutionName);
                    }
                    catch (Exception ex)
                    {
                        Tracer.Debug("生成考勤初始化记录出错:" + entEmployees[n].EMPLOYEECNAME + ex.ToString());
                        continue;
                    }
                }
                Tracer.Debug("生成所有员工考勤记录成功,开始日期" + dtStart.ToString("yyyy-MM-dd") + "结束日期:" + dtInitAttandRecordEndDate.ToString("yyyy-MM-dd"));
                strRes = "{SAVESUCCESSED}";
            }
            catch (Exception ex)
            {
                Tracer.Debug("生成考勤初始化记录出错:" + ex.ToString());
                strRes = ex.Message.ToString();
            }

            return(strRes);
        }
コード例 #6
0
        /// <summary>
        /// 修改公共假期设置信息
        /// </summary>
        /// <param name="entVacRd"></param>
        /// <returns></returns>
        public string ModifyVacationSet(T_HR_VACATIONSET entVacRd)
        {
            string strMsg = string.Empty;

            try
            {
                if (entVacRd == null)
                {
                    return("{REQUIREDFIELDS}");
                }


                bool          flag      = false;
                StringBuilder strFilter = new StringBuilder();
                List <string> objArgs   = new List <string>();

                strFilter.Append(" VACATIONID == @0");

                objArgs.Add(entVacRd.VACATIONID);

                VacationSetDAL dalVacationSet = new VacationSetDAL();
                flag = dalVacationSet.IsExistsRd(strFilter.ToString(), objArgs.ToArray());

                if (!flag)
                {
                    return("{NOTFOUND}");
                }

                List <T_HR_OUTPLANDAYS> entOutPlanDays = entVacRd.T_HR_OUTPLANDAYS.ToList();

                T_HR_VACATIONSET entUpdate = dalVacationSet.GetVacationSetRdByMultSearch(strFilter.ToString(), objArgs.ToArray());
                Utility.CloneEntity(entVacRd, entUpdate);
                entUpdate.UPDATEDATE = DateTime.Now;
                dalVacationSet.Update(entUpdate);
                strMsg = "{SAVESUCCESSED}";

                if (entOutPlanDays == null)
                {
                    return(strMsg);
                }

                OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
                bllOutPlanDays.DeleteByVacationID(entVacRd.VACATIONID);

                if (entOutPlanDays.Count() == 0)
                {
                    return(strMsg);
                }

                foreach (T_HR_OUTPLANDAYS item in entOutPlanDays)
                {
                    if (item.EntityKey != null)
                    {
                        item.EntityKey = null;  //清除EntityKey不为null的情况
                    }

                    if (item.T_HR_VACATIONSET == null)
                    {
                        item.T_HR_VACATIONSET = entVacRd;
                    }

                    if (!string.IsNullOrEmpty(item.ISADJUSTLEAVE))
                    {
                        if (item.ISADJUSTLEAVE.ToUpper() == "TRUE" || item.ISADJUSTLEAVE == "1")
                        {
                            item.ISADJUSTLEAVE = "1";
                        }
                        else
                        {
                            item.ISADJUSTLEAVE = "0";
                        }
                    }

                    bllOutPlanDays.AddOutPlanDays(item);
                }

                AsyncEventHandler asy = new AsyncEventHandler(reInitAttandeceRecordWithOutWorkDaySet);
                IAsyncResult      ia  = asy.BeginInvoke(entUpdate.VACATIONID, null, null);
                //reInitAttandeceRecordWithOutWorkDaySet(entUpdate.VACATIONID);
            }
            catch (Exception ex)
            {
                strMsg = ex.Message.ToString();
            }

            return(strMsg);
        }
コード例 #7
0
        /// <summary>
        /// 新增公共假期设置信息
        /// </summary>
        /// <param name="entVacRd"></param>
        /// <returns></returns>
        public string AddVacationSet(T_HR_VACATIONSET entVacRd)
        {
            string strMsg = string.Empty;

            try
            {
                if (entVacRd == null)
                {
                    return("{REQUIREDFIELDS}");
                }

                bool          flag      = false;
                StringBuilder strFilter = new StringBuilder();
                List <string> objArgs   = new List <string>();

                strFilter.Append(" VACATIONNAME == @0");
                strFilter.Append(" && COUNTYTYPE == @1");
                strFilter.Append(" && VACATIONYEAR == @2");

                objArgs.Add(entVacRd.VACATIONNAME);
                objArgs.Add(entVacRd.COUNTYTYPE);
                objArgs.Add(entVacRd.VACATIONYEAR);

                VacationSetDAL dalVacationSet = new VacationSetDAL();
                flag = dalVacationSet.IsExistsRd(strFilter.ToString(), objArgs.ToArray());

                if (flag)
                {
                    return("{ALREADYEXISTSRECORD}");
                }

                List <T_HR_OUTPLANDAYS> entOutPlanDays = entVacRd.T_HR_OUTPLANDAYS.ToList();

                T_HR_VACATIONSET entAdd = new T_HR_VACATIONSET();
                Utility.CloneEntity(entVacRd, entAdd);
                entAdd.CREATEDATE = DateTime.Now;
                entAdd.UPDATEDATE = DateTime.Now;
                dalVacationSet.Add(entAdd);

                OutPlanDaysBLL bllOutPlanDays = new OutPlanDaysBLL();
                if (entOutPlanDays.Count() > 0)
                {
                    foreach (T_HR_OUTPLANDAYS item in entOutPlanDays)
                    {
                        if (item.EntityKey != null)
                        {
                            item.EntityKey = null;  //清除EntityKey不为null的情况
                        }

                        if (item.T_HR_VACATIONSET == null)
                        {
                            item.T_HR_VACATIONSET = entAdd;
                        }

                        if (!string.IsNullOrEmpty(item.ISADJUSTLEAVE))
                        {
                            if (item.ISADJUSTLEAVE.ToUpper() == "TRUE" || item.ISADJUSTLEAVE == "1")
                            {
                                item.ISADJUSTLEAVE = "1";
                            }
                            else
                            {
                                item.ISADJUSTLEAVE = "0";
                            }
                        }

                        bllOutPlanDays.AddOutPlanDays(item);
                    }
                }

                AsyncEventHandler asy = new AsyncEventHandler(reInitAttandeceRecordWithOutWorkDaySet);
                IAsyncResult      ia  = asy.BeginInvoke(entVacRd.VACATIONID, null, null);

                strMsg = "{SAVESUCCESSED}";
            }
            catch (Exception ex)
            {
                strMsg = ex.Message.ToString();
                Tracer.Debug(ex.ToString());
            }

            return(strMsg);
        }