Beispiel #1
0
        /// <summary>
        /// 周文斌添加
        /// 获取一个时间段内的考勤方案,
        /// 例如:员工请假从5月10-8月30日
        /// 这里跨越了5,6,7,8三个月的考勤时间段
        /// StartToEndDate的格式为:StartDate|EndDate; yyyy-MM-dd|yyyy-MM-dd
        ///
        /// </summary>
        /// <param name="EmployeeID"></param>
        /// <param name="StartToEndDate"></param>
        /// <returns></returns>
        public List <T_HR_ATTENDANCESOLUTION> GetAttendenceSolutionByEmployeeIDAndStartDateAndEndDate(string EmployeeID, List <string> StartToEndDate)
        {
            List <T_HR_ATTENDANCESOLUTION> solutionList = new List <T_HR_ATTENDANCESOLUTION>();

            foreach (string str in StartToEndDate)
            {
                DateTime StartDate = Convert.ToDateTime(str.Split('|')[0]);
                DateTime EndDate   = Convert.ToDateTime(str.Split('|')[1]);

                AttendanceSolutionDAL   dalAttendanceSolution = new AttendanceSolutionDAL();
                T_HR_ATTENDANCESOLUTION entAttSol             = dalAttendanceSolution.GetAttendanceSolutionByEmployeeIDAndDate(EmployeeID, StartDate, EndDate);

                if (entAttSol != null)
                {
                    solutionList.Add(entAttSol);
                }
                else
                {
                    StartDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-01"));
                    AttendanceSolutionAsignBLL   bllAttSolAsign = new AttendanceSolutionAsignBLL();
                    T_HR_ATTENDANCESOLUTIONASIGN entAttSolAsign = bllAttSolAsign.GetAttendanceSolutionAsignByEmployeeIDAndDate(EmployeeID, StartDate);
                    solutionList.Add(entAttSolAsign.T_HR_ATTENDANCESOLUTION);
                }
            }
            return(solutionList);
        }
Beispiel #2
0
        /// <summary>
        /// 根据考勤初始化记录获取考勤方案,获取不到则获取员工最新分配的考勤方案
        /// </summary>
        /// <param name="strEmployeeID">员工ID</param>
        /// <param name="dtStart">考勤记录参考起始日期</param>
        /// <param name="dtEnd">考勤记录参考截止日期</param>
        /// <returns></returns>
        public T_HR_ATTENDANCESOLUTION GetAttendanceSolutionByEmployeeIDAndDate(string strEmployeeID, DateTime dtStart, DateTime dtEnd)
        {
            if (string.IsNullOrEmpty(strEmployeeID))
            {
                return(null);
            }

            AttendanceSolutionDAL   dalAttendanceSolution = new AttendanceSolutionDAL();
            T_HR_ATTENDANCESOLUTION entAttSol             = dalAttendanceSolution.GetAttendanceSolutionByEmployeeIDAndDate(strEmployeeID, dtStart, dtEnd);

            if (entAttSol == null)
            {
                dtStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-01"));
                AttendanceSolutionAsignBLL   bllAttSolAsign = new AttendanceSolutionAsignBLL();
                T_HR_ATTENDANCESOLUTIONASIGN entAttSolAsign = bllAttSolAsign.GetAttendanceSolutionAsignByEmployeeIDAndDate(strEmployeeID, dtStart);

                if (entAttSolAsign == null)
                {
                    return(null);
                }

                return(entAttSolAsign.T_HR_ATTENDANCESOLUTION);
            }

            return(entAttSol);
        }
Beispiel #3
0
        private T_HR_ATTENDANCESOLUTION GetAttendanceSolution(string employeeid, DateTime?dtOTStartDate)
        {
            if (dtOTStartDate == null || string.IsNullOrWhiteSpace(employeeid))
            {
                return(null);
            }

            AttendanceSolutionAsignBLL   bllAttSolAsign = new AttendanceSolutionAsignBLL();
            T_HR_ATTENDANCESOLUTIONASIGN entAttSolAsign = bllAttSolAsign.GetAttendanceSolutionAsignByEmployeeIDAndDate(employeeid, dtOTStartDate.Value);

            if (entAttSolAsign == null)
            {
                return(null);
            }

            return(entAttSolAsign.T_HR_ATTENDANCESOLUTION);
        }
Beispiel #4
0
        /// <summary>
        /// 根据员工ID获取其应用的考勤方案(解决一个员工在系统内多个公司入职的情况)
        /// </summary>
        /// <param name="strEmployeeID"></param>
        /// <returns></returns>
        public T_HR_ATTENDANCESOLUTION GetAttendanceSolutionByEmployeeID(string strCompanyID, string strEmployeeID)
        {
            if (string.IsNullOrEmpty(strCompanyID) || string.IsNullOrEmpty(strEmployeeID))
            {
                return(null);
            }

            AttendanceSolutionAsignBLL   bllAttendSolAsign = new AttendanceSolutionAsignBLL();
            T_HR_ATTENDANCESOLUTIONASIGN entAttendSolAsign = bllAttendSolAsign.GetAttendanceSolutionAsignByEmployeeID(strCompanyID, strEmployeeID);

            if (entAttendSolAsign == null)
            {
                return(null);
            }

            return(entAttendSolAsign.T_HR_ATTENDANCESOLUTION);
        }
Beispiel #5
0
        /// <summary>
        /// 根据员工ID获取该员工所有未签卡记录
        /// </summary>
        /// <param name="EmployeeID">员工ID</param>
        /// <returns></returns>
        public IQueryable <T_HR_EMPLOYEEABNORMRECORD> GetAbnormRecordByEmployeeID(string employeeID)
        {
            AttendanceSolutionAsignBLL bll = new AttendanceSolutionAsignBLL();
            string strAbnormCategory       = (Convert.ToInt32(Common.AbnormCategory.Absent) + 1).ToString();
            string strSingInState          = (Convert.ToInt32(Common.IsChecked.No) + 1).ToString();

            var temp = bll.GetAttendanceSolutionAsignByEmployeeID(employeeID);

            if (temp == null)
            {
                return(null);
            }

            DateTime currDate = DateTime.Now.Date;
            DateTime dStart;
            //是否当月结算:1表示否,2表示是
            string strTag = temp.T_HR_ATTENDANCESOLUTION.ISCURRENTMONTH;

            if (strTag == "1")
            {
                if (currDate.Day <= Convert.ToInt32(temp.T_HR_ATTENDANCESOLUTION.SETTLEMENTDATE))
                {
                    dStart = currDate.AddMonths(-1).AddDays(-currDate.Day + 1);
                }
                else
                {
                    dStart = DateTime.Parse(currDate.AddMonths(-1).ToString("yyyy-MM") + "-1");
                }
            }
            else
            {
                dStart = DateTime.Parse(currDate.ToString("yyyy-MM") + "-1");
            }
            return(dal.GetObjects().Include("T_HR_ATTENDANCERECORD").Where(s =>
                                                                           s.T_HR_ATTENDANCERECORD.EMPLOYEEID == employeeID && s.ABNORMCATEGORY == strAbnormCategory && s.SINGINSTATE == strSingInState &&
                                                                           (s.ABNORMALDATE >= dStart && s.ABNORMALDATE <= currDate)).OrderBy("ABNORMALDATE"));
        }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
        public string OutApplySetValue(string msg, T_HR_OUTAPPLYCONFIRM entity)
        {
            if (!entity.T_HR_OUTAPPLYRECORDReference.IsLoaded)
            {
                entity.T_HR_OUTAPPLYRECORDReference.Load();
            }

            #region 非当天往返或者实际返回未打卡,设置外出结束时间为当天下班时间
            if (entity.T_HR_OUTAPPLYRECORD.ISSAMEDAYRETURN == "0" ||
                entity.ENDDATE == new DateTime(2001, 1, 1))   //
            {
                if (GetAttendanceSolution(entity.EMPLOYEEID, entity.T_HR_OUTAPPLYRECORD.STARTDATE) == null)
                {
                    return("未获取到用户的考勤方案,保存失败");
                }

                AttendanceSolutionAsignBLL   bllAttendSolAsign = new AttendanceSolutionAsignBLL();
                T_HR_ATTENDANCESOLUTIONASIGN entAttendSolAsign = bllAttendSolAsign.GetAttendanceSolutionAsignByEmployeeIDAndDate(entity.EMPLOYEEID, entity.T_HR_OUTAPPLYRECORD.STARTDATE.Value);

                if (entAttendSolAsign.T_HR_ATTENDANCESOLUTION == null)
                {
                    //当前员工没有分配考勤方案,无法提交外出申请
                    msg = msg + "当前员工没有分配考勤方案,无法提交外出申请";
                    Tracer.Debug(msg);
                    return(msg);
                }
                else
                {
                    var entAttendSol = entAttendSolAsign.T_HR_ATTENDANCESOLUTION;

                    var tempMaster = from ent in dal.GetObjects <T_HR_SCHEDULINGTEMPLATEMASTER>()
                                     where ent.TEMPLATEMASTERID == entAttendSol.T_HR_SCHEDULINGTEMPLATEMASTER.TEMPLATEMASTERID
                                     select ent;

                    if (!entAttendSol.T_HR_SCHEDULINGTEMPLATEMASTERReference.IsLoaded)
                    {
                        entAttendSol.T_HR_SCHEDULINGTEMPLATEMASTERReference.Load();
                    }

                    var entsched = from a in dal.GetObjects <T_HR_SCHEDULINGTEMPLATEMASTER>()
                                   join b in dal.GetObjects <T_HR_SCHEDULINGTEMPLATEDETAIL>()
                                   on a.TEMPLATEMASTERID equals b.T_HR_SCHEDULINGTEMPLATEMASTER.TEMPLATEMASTERID
                                   join c in dal.GetObjects <T_HR_SHIFTDEFINE>()
                                   on b.T_HR_SHIFTDEFINE.SHIFTDEFINEID equals c.SHIFTDEFINEID
                                   where a.TEMPLATEMASTERID == entAttendSol.T_HR_SCHEDULINGTEMPLATEMASTER.TEMPLATEMASTERID
                                   select c;
                    if (entsched.Count() > 0)
                    {
                        var      defineTime          = entsched.FirstOrDefault();
                        DateTime ShiftFirstStartTime = new DateTime();
                        if (defineTime.NEEDTHIRDOFFCARD == "2" && !string.IsNullOrEmpty(defineTime.THIRDENDTIME))
                        {
                            ShiftFirstStartTime = DateTime.Parse(defineTime.THIRDENDTIME);//设置3段打卡,第2段下班打卡时间:一般为17:50
                        }
                        else if (defineTime.NEEDSECONDOFFCARD == "2" && !string.IsNullOrEmpty(defineTime.SECONDENDTIME))
                        {
                            ShiftFirstStartTime = DateTime.Parse(defineTime.SECONDENDTIME);//设置2段打卡,第2段下班打卡时间:一般为17:50
                        }
                        else
                        {
                            msg = msg + "外出申请班次定义设置错误,没有找到下班时间定义" + " 考勤方案名:" + entAttendSolAsign.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME;
                            Tracer.Debug(msg);
                            return(msg);
                        }
                        DateTime dtstar = entity.T_HR_OUTAPPLYRECORD.STARTDATE.Value;
                        DateTime ShiftstartDateAndTime = new DateTime(dtstar.Year, dtstar.Month, dtstar.Day
                                                                      , ShiftFirstStartTime.Hour, ShiftFirstStartTime.Minute, ShiftFirstStartTime.Second);
                        if (entity.ENDDATE == new DateTime(2001, 1, 1))//实际出发时间选择为未打卡不计算外出时长
                        {
                            entity.ENDDATE = ShiftstartDateAndTime;
                        }
                    }
                    else
                    {
                        msg = msg + "外出申请班次定义未找到" + " 考勤方案名:" + entAttendSolAsign.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME;
                        Tracer.Debug(msg);
                        return(msg);
                    }
                }

                if (entity.ENDDATE == null)
                {
                    msg = msg + "外出申请为非当天往返,但是结束时间未找到,请检查考勤方案排版设置是否正确。" + " 考勤方案名:" + entAttendSolAsign.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME;
                    Tracer.Debug(msg);
                    return(msg);
                }
            }
            #endregion

            #region 计算外出时长
            string strMsg = string.Empty;
            //
            string dTotalHours = string.Empty;
            if (entity.STARTDATE == new DateTime(2001, 1, 1))//实际出发时间选择为未打卡不计算外出时长
            {
                entity.OUTAPLLYTIMES = "外出确认实际出发时间未打卡";
            }
            else
            {
                strMsg = CalculateOverTimeHours(entity.EMPLOYEEID, entity.STARTDATE.Value, entity.ENDDATE.Value, ref dTotalHours);

                entity.OUTAPLLYTIMES = dTotalHours.ToString();
            }
            #endregion
            return(strMsg);
        }
Beispiel #8
0
        /// <summary>
        /// 重新初始化考勤记录,强制删除未提交签卡记录,异常考勤,考勤记录,重新初始化考勤
        /// </summary>
        /// <param name="objType"></param>
        /// <param name="objId"></param>
        /// <param name="dtStar"></param>
        /// <param name="dtEnd"></param>
        /// <param name="DealType">0处理免打卡人员,1处理打卡人员,2处理所有</param>
        /// <returns></returns>
        public string CompulsoryInitialization(string objType, string objId, DateTime dtStar, DateTime dtEnd, string DealType)
        {
            string strMsg = string.Empty;

            try
            {
                //List<T_HR_EMPLOYEE> employees = new List<T_HR_EMPLOYEE>();
                EmployeeBLL empbll             = new EmployeeBLL();
                AttendanceSolutionAsignBLL bll = new AttendanceSolutionAsignBLL();

                switch (objType)
                {
                case "0":
                    var employees = from ent in dal.GetObjects <T_HR_EMPLOYEE>()
                                    join ep in dal.GetObjects <T_HR_EMPLOYEEPOST>() on ent.EMPLOYEEID equals ep.T_HR_EMPLOYEE.EMPLOYEEID
                                    join p in dal.GetObjects <T_HR_POST>() on ep.T_HR_POST.POSTID equals p.POSTID
                                    where ep.ISAGENCY == "0" && //主岗位
                                    ep.EDITSTATE == "1" &&    //生效中
                                    ep.CHECKSTATE == "2" &&    //审核通过
                                    p.COMPANYID == objId
                                    select ent;

                    if (employees.Count() > 0)
                    {
                        foreach (var emp in employees)
                        {
                            T_HR_ATTENDANCESOLUTIONASIGN entAttendanceSolution = bll.GetAttendanceSolutionAsignByEmployeeIDAndDate(emp.EMPLOYEEID, dtStar);

                            if (DealType == "0")                                                                                                                     //如果是处理需要打卡人员的记录,跳过免打卡记录员工
                            {
                                if (entAttendanceSolution.T_HR_ATTENDANCESOLUTION.ATTENDANCETYPE != (Convert.ToInt32(Common.AttendanceType.NoCheck) + 1).ToString()) //
                                {
                                    Tracer.Debug("" + emp.EMPLOYEECNAME + entAttendanceSolution.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME
                                                 + "," + entAttendanceSolution.T_HR_ATTENDANCESOLUTION.ATTENDANCETYPE);
                                    continue;
                                }
                            }
                            else if (DealType == "1")                                                                                                                //如果是处理免打卡人员的记录,跳过打卡人员
                            {
                                if (entAttendanceSolution.T_HR_ATTENDANCESOLUTION.ATTENDANCETYPE == (Convert.ToInt32(Common.AttendanceType.NoCheck) + 1).ToString()) //
                                {
                                    Tracer.Debug("" + emp.EMPLOYEECNAME + entAttendanceSolution.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONNAME
                                                 + "," + entAttendanceSolution.T_HR_ATTENDANCESOLUTION.ATTENDANCETYPE);

                                    continue;
                                }
                            }
                            else
                            {
                            }
                            strMsg = "开始强制删除考勤初始化记录,员工姓名:" + emp.EMPLOYEECNAME;
                            var q = from ent in dal.GetObjects <T_HR_ATTENDANCERECORD>()
                                    where ent.EMPLOYEEID == emp.EMPLOYEEID &&
                                    ent.ATTENDANCEDATE >= dtStar &&
                                    ent.ATTENDANCEDATE <= dtEnd
                                    select ent;
                            if (q.Count() > 0)
                            {
                                List <T_HR_ATTENDANCERECORD> attlist = q.ToList();
                                RemoveWrongSignRds(attlist);
                                foreach (var att in attlist)
                                {
                                    dal.Delete(att);
                                    strMsg += "强制删除考勤初始化记录,员工姓名:" + att.EMPLOYEENAME
                                              + " 考勤日期:" + att.ATTENDANCEDATE.ToString()
                                              + " 考勤状态:" + att.ATTENDANCESTATE;

                                    Tracer.Debug("强制删除考勤初始化记录,员工姓名:" + att.EMPLOYEENAME
                                                 + " 考勤日期:" + att.ATTENDANCEDATE.ToString()
                                                 + " 考勤状态:" + att.ATTENDANCESTATE);
                                }
                            }

                            bll.AsignAttendanceSolutionForEmployeeByDate(emp, dtStar);
                            strMsg += "强制删除考勤初始化记录,初始化考勤记录成功!,员工姓名:" + emp.EMPLOYEECNAME;
                            Tracer.Debug("强制删除考勤初始化记录,初始化考勤记录成功!,员工姓名:" + emp.EMPLOYEECNAME);
                        }
                    }
                    ;
                    break;

                case "4":
                    //employees.Add(empbll.GetEmployeeByID(objId));
                    break;
                }
            }
            catch (Exception ex)
            {
                Tracer.Debug(ex.ToString());
            }

            return(strMsg);
        }
Beispiel #9
0
        /// <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);
        }
Beispiel #10
0
        /// <summary>
        /// 根据设置的日历重新初始化考勤
        /// </summary>
        /// <param name="entVacRd"></param>
        private void reInitAttandeceRecordWithOutWorkDaySet(string VACATIONID)
        {
            try
            {
                var q = from ent in dal.GetObjects <T_HR_VACATIONSET>().Include("T_HR_OUTPLANDAYS")
                        where ent.VACATIONID == VACATIONID
                        select ent;
                var entVacRd = q.FirstOrDefault();
                if (entVacRd == null)
                {
                    Tracer.Debug("根据设置的日历重新初始化考勤跳过,获取的T_HR_VACATIONSET为空,id:" + VACATIONID);
                }
                List <T_HR_OUTPLANDAYS> entOutPlanDays = entVacRd.T_HR_OUTPLANDAYS.ToList();
                bool   needInitCompanyAttanceDayAgain  = false;
                string strCurYearMonth = string.Empty;
                if (entOutPlanDays.Count == 0)
                {
                    Tracer.Debug("根据设置的日历重新初始化考勤跳过,明细为空");
                }
                foreach (T_HR_OUTPLANDAYS item in entOutPlanDays)
                {
                    #region 处理考勤初始化

                    if (item.DAYTYPE == (Convert.ToInt32(Common.OutPlanDaysType.Vacation) + 1).ToString())
                    {
                        try
                        {
                            string sql    = @"delete smthrm.t_hr_attendancerecord a
                                        where a.ownercompanyid = '" + entVacRd.ASSIGNEDOBJECTID + @"'
                                        and a.attendancedate >= To_Date('" + item.STARTDATE.Value.ToString("yyyy-MM-dd") + @"', 'yyyy-MM-dd')
                                        and a.attendancedate <= To_Date('" + item.ENDDATE.Value.ToString("yyyy-MM-dd") + @"', 'yyyy-MM-dd')";
                            var    attdel = from ent in dal.GetObjects <T_HR_ATTENDANCERECORD>()
                                            where ent.OWNERCOMPANYID == entVacRd.ASSIGNEDOBJECTID &&
                                            ent.ATTENDANCEDATE >= item.STARTDATE &&
                                            ent.ATTENDANCEDATE <= item.ENDDATE
                                            select ent;
                            int i = 0;
                            foreach (var att in attdel)
                            {
                                i = i + dal.Delete(att);
                            }

                            //int i = dal.ExecuteNonQuery(sql);
                            Tracer.Debug("新增假期设置删除设定日期整个公司考勤初始化记录,共删除:" + i.ToString() + " 条数据:转换出的sql" + sql);
                        }
                        catch (Exception ex)
                        {
                            Tracer.Debug("新增假期设置删除设定日期整个公司考勤初始化记录异常:" + ex.ToString());
                        }
                    }


                    //if (item.DAYTYPE == (Convert.ToInt32(Common.OutPlanDaysType.WorkDay) + 1).ToString())
                    //{
                    //如果设置的日期是当月,需要重新初始化公司考勤
                    if (item.STARTDATE.Value <= DateTime.Now.AddMonths(1).AddDays(-1))
                    {
                        needInitCompanyAttanceDayAgain = true;
                        strCurYearMonth = item.STARTDATE.Value.Year + "-" + item.STARTDATE.Value.Month;
                    }
                    if (item.ENDDATE.Value <= DateTime.Now.AddMonths(1).AddDays(-1))
                    {
                        needInitCompanyAttanceDayAgain = true;
                        strCurYearMonth = item.ENDDATE.Value.Year + "-" + item.ENDDATE.Value.Month;
                    }
                    //}

                    #endregion
                }

                if (needInitCompanyAttanceDayAgain)
                {
                    Tracer.Debug("====================================新增假期设置工作日开始初始化整个公司考勤记录");
                    using (AttendanceSolutionAsignBLL bllAttendanceSolutionAsign = new AttendanceSolutionAsignBLL())
                    {
                        bllAttendanceSolutionAsign.AsignAttendanceSolutionByOrgID("1", entVacRd.ASSIGNEDOBJECTID, strCurYearMonth);
                    }
                    Tracer.Debug("====================================新增假期设置工作日初始化整个公司考勤记录完毕");
                }
            }
            catch (Exception ex)
            {
                Tracer.Debug(ex.ToString());
            }
        }
Beispiel #11
0
        /// <summary>
        /// 根据员工ID获取员工的带薪假期的天数,调休假天数,及已休假天数。
        /// </summary>
        /// <param name="employeeID">员工ID</param>
        /// <param name="date">日期</param>
        /// <returns></returns>
        public List <V_EMPLOYEELEAVE> GetEmployeeLeaveByEmployeeID(string employeeID, DateTime date)
        {
            List <V_EMPLOYEELEAVE> leaveList = new List <V_EMPLOYEELEAVE>();

            try
            {
                //获取员工组织架构
                EmployeeBLL    employeeBll  = new EmployeeBLL();
                V_EMPLOYEEPOST employeePost = employeeBll.GetEmployeeDetailByID(employeeID);
                //获取员工的入职信息
                EmployeeEntryBLL   entryBll  = new EmployeeEntryBLL();
                T_HR_EMPLOYEEENTRY entry     = entryBll.GetEmployeeEntryByEmployeeID(employeeID);
                DateTime           entryDate = entry.ENTRYDATE.Value;
                int    m            = Utility.DateDiff(entryDate, date, "M");
                string departmentID = employeePost.EMPLOYEEPOSTS[0].T_HR_POST.T_HR_DEPARTMENT.DEPARTMENTID;
                string comparyID    = employeePost.EMPLOYEEPOSTS[0].T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANY.COMPANYID;


                var ent = from a in dal.GetObjects().Include("T_HR_LEAVETYPESET")
                          join al in dal.GetObjects <T_HR_ATTENDFREELEAVE>().Include("T_HR_ATTENDANCESOLUTION").Include("T_HR_LEAVETYPESET") on a.T_HR_LEAVETYPESET.LEAVETYPESETID equals al.T_HR_LEAVETYPESET.LEAVETYPESETID
                          join ad in dal.GetObjects <T_HR_ATTENDANCESOLUTION>() on al.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONID equals ad.ATTENDANCESOLUTIONID
                          join at in dal.GetObjects <T_HR_ATTENDANCESOLUTIONASIGN>() on ad.ATTENDANCESOLUTIONID equals at.T_HR_ATTENDANCESOLUTION.ATTENDANCESOLUTIONID
                          where (at.ASSIGNEDOBJECTID == departmentID || at.ASSIGNEDOBJECTID == comparyID) &&
                          a.MINIMONTH <= m &&
                          a.MAXMONTH >= m
                          select new V_EMPLOYEELEAVE()
                {
                    EmployeeID                = employeeID,
                    EmployeeCode              = employeePost.T_HR_EMPLOYEE.EMPLOYEECODE,
                    EmployeeName              = employeePost.T_HR_EMPLOYEE.EMPLOYEECNAME,
                    LeaveTypeName             = a.T_HR_LEAVETYPESET.LEAVETYPENAME,
                    LeaveTypeSetID            = a.T_HR_LEAVETYPESET.LEAVETYPESETID,
                    MaxDays                   = a.T_HR_LEAVETYPESET.MAXDAYS.Value,
                    FineType                  = a.T_HR_LEAVETYPESET.FINETYPE,
                    IsPerfectAttendanceFactor = a.ISPERFECTATTENDANCEFACTOR,
                    LeaveDays                 = a.LEAVEDAYS.Value
                };
                leaveList = ent.Count() > 0 ? ent.ToList() : null;

                //获取年度考勤结算日
                AttendanceSolutionAsignBLL bll = new AttendanceSolutionAsignBLL();
                var    tempEnt = bll.GetAttendanceSolutionAsignByEmployeeID(employeeID);
                string strDate = tempEnt.T_HR_ATTENDANCESOLUTION.YEARLYBALANCEDATE;
                string strType = tempEnt.T_HR_ATTENDANCESOLUTION.YEARLYBALANCETYPE; //结算方式
                //获取加班调休假的天数
                EmployeeLevelDayCountBLL leaveDaybll = new EmployeeLevelDayCountBLL();
                AdjustLeaveBLL           adjustbll   = new AdjustLeaveBLL();
                decimal leaveDays = leaveDaybll.GetLevelDayCountByEmployeeID(employeeID, date, strDate);

                V_EMPLOYEELEAVE leave = new V_EMPLOYEELEAVE();
                ent = from a in dal.GetObjects <T_HR_LEAVETYPESET>()
                      where !string.IsNullOrEmpty(a.LEAVETYPEVALUE)
                      select new V_EMPLOYEELEAVE
                {
                    EmployeeID     = employeeID,
                    EmployeeCode   = employeePost.T_HR_EMPLOYEE.EMPLOYEECODE,
                    EmployeeName   = employeePost.T_HR_EMPLOYEE.EMPLOYEECNAME,
                    LeaveTypeName  = a.LEAVETYPENAME,
                    LeaveTypeSetID = a.LEAVETYPESETID,
                    MaxDays        = a.MAXDAYS.Value,
                    FineType       = a.FINETYPE,
                    LeaveDays      = leaveDays
                };
                leave = ent.Count() > 0 ? ent.FirstOrDefault() : null;
                if (leave != null)
                {
                    leaveList.Add(leave);
                }
                //获取已休天数,并算出可休假天数
                foreach (var obj in leaveList)
                {
                    //剩余可休假为累计的情况
                    if (strType == "1")
                    {
                        //往年可休假的总数
                        decimal leaveHistoryDays = leaveDaybll.GetLevelDayCountHistoryByEmployeeID(employeeID, date, strDate);
                        //往年已休假的总数
                        decimal UsedUpDays = adjustbll.GetUseUpHistory(obj.LeaveTypeSetID, obj.EmployeeID, date, strDate);
                        obj.LeaveDays += leaveHistoryDays - UsedUpDays;
                    }
                    obj.UsedLeaveDays    = adjustbll.GetUseUp(obj.LeaveTypeSetID, obj.EmployeeID, date, strDate);
                    obj.UseableLeaveDays = obj.LeaveDays - obj.UsedLeaveDays;
                }
            }
            catch (Exception ex)
            {
                Tracer.Debug(ex.ToString());
            }
            return(leaveList);
        }
Beispiel #12
0
        /// <summary>
        /// 检测并清除指定员工指定时间段内考勤异常记录并重置考勤初始化记录状态
        /// </summary>
        /// <param name="EMPLOYEEID">员工id</param>
        /// <param name="datLevestart">开始时间长日期格式2013/2/16 8:30:00</param>
        /// <param name="dtLeveEnd">结束时间长日期格式2013/2/16 8:30:00</param>
        public void DealEmployeeAbnormRecord(string EMPLOYEEID, DateTime datLevestart, DateTime dtLeveEnd, string attState)
        {
            var emp = (from em in dal.GetObjects <T_HR_EMPLOYEE>()
                       where em.EMPLOYEEID == EMPLOYEEID
                       select em.EMPLOYEEENAME).FirstOrDefault();

            string dealType = string.Empty;

            if (attState == (Convert.ToInt32(Common.AttendanceState.Leave) + 1).ToString())
            {
                dealType = "员工:" + emp + " 请假消除异常," + "时间区间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                           + "----" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss");
            }

            if (attState == (Convert.ToInt32(Common.AttendanceState.Travel) + 1).ToString())
            {
                dealType = "员工:" + emp + " 出差消除异常," + "时间区间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                           + "----" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss");
            }

            if (attState == (Convert.ToInt32(Common.AttendanceState.OutApply) + 1).ToString())
            {
                dealType = "员工:" + emp + " 外出申请消除异常," + "时间区间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                           + "----" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss");
            }
            if (attState == (Convert.ToInt32(Common.AttendanceState.OutApplyConfirm) + 1).ToString())
            {
                dealType = "员工:" + emp + " 外出确认消除异常," + "时间区间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                           + "----" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss");
            }

            Tracer.Debug(dealType + " 开始");

            DateTime dtStart = new DateTime(datLevestart.Year, datLevestart.Month, datLevestart.Day);
            DateTime dtEnd   = new DateTime(dtLeveEnd.Year, dtLeveEnd.Month, dtLeveEnd.Day);

            DateTime dtAtt = new DateTime();
            int      iDate = 0;


            #region 判断是否要初始化考勤
            while (dtAtt < dtEnd)
            {
                dtAtt = dtStart.AddDays(iDate);
                iDate++;
                IQueryable <T_HR_ATTENDANCERECORD> entArs = from r in dal.GetObjects <T_HR_ATTENDANCERECORD>()
                                                            where r.EMPLOYEEID == EMPLOYEEID &&
                                                            r.ATTENDANCEDATE == dtAtt
                                                            select r;
                if (entArs.Count() < 1)
                {
                    string dtInit = datLevestart.Year.ToString() + "-" + datLevestart.Month.ToString();
                    try
                    {
                        Tracer.Debug(dealType + " 没有查到考勤初始化数据,开始初始化员工考勤:" + dtInit);
                        AttendanceSolutionAsignBLL bllAttendanceSolutionAsign = new AttendanceSolutionAsignBLL();
                        //初始化该员工当月考勤记录
                        bllAttendanceSolutionAsign.AsignAttendanceSolutionByOrgID("4", EMPLOYEEID, dtInit);

                        Tracer.Debug(dealType + " 初始化员工考勤成功,初始化月份:" + dtInit);
                        break;
                    }
                    catch (Exception ex)
                    {
                        Tracer.Debug(dealType + " 初始化考勤失败:月份:" + dtInit + "失败原因:" + ex.ToString());
                        return;
                    }
                }
            }
            #endregion

            #region 循环检查考勤初始化记录状态

            IQueryable <T_HR_ATTENDANCERECORD> entAttAll = from r in dal.GetObjects <T_HR_ATTENDANCERECORD>()
                                                           where r.EMPLOYEEID == EMPLOYEEID &&
                                                           r.ATTENDANCEDATE >= dtStart &&
                                                           r.ATTENDANCEDATE <= dtEnd
                                                           select r;


            foreach (T_HR_ATTENDANCERECORD item in entAttAll)
            {
                string strAbnormCategory = (Convert.ToInt32(AbnormCategory.Absent) + 1).ToString();
                //获取请假当天所有异常考勤(针对补请假的情况,用于删除异常考勤)
                List <T_HR_EMPLOYEEABNORMRECORD> entAbnormRecords
                    = (from a in dal.GetObjects <T_HR_EMPLOYEEABNORMRECORD>().Include("T_HR_ATTENDANCERECORD")
                       where a.T_HR_ATTENDANCERECORD.ATTENDANCERECORDID == item.ATTENDANCERECORDID &&
                       a.ABNORMCATEGORY == strAbnormCategory
                       select a).ToList();
                int i = 0;
                i = entAbnormRecords.Count();
                #region 如果当天没有异常,直接更新此考勤记录的考勤状态
                if (i == 0)
                {
                    //Tracer.Debug(strMsg);
                    item.ATTENDANCESTATE = attState;
                    item.UPDATEDATE      = DateTime.Now;

                    string strMsg = item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + dealType + " ,无考勤异常,查询时间:" + item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd")
                                    + ",没有查到异常记录,修改考勤记录状态为:" + attState;
                    item.REMARK = dealType + strMsg;
                    int iUpdate = dal.Update(item);
                    if (iUpdate == 1)
                    {
                        Tracer.Debug(dealType + strMsg + " 成功");
                    }
                    else
                    {
                        Tracer.Debug(dealType + strMsg + " 失败");
                    }
                    continue;
                }
                #endregion
                try
                {
                    Tracer.Debug(dealType + " 日期:" + item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + ",发现当天有异常考勤,需要重新检查当天出勤状态,检查到异常记录共:" + i + "条记录"
                                 + "开始处理重新检查考勤异常——————————————————————————————————————Start");

                    Dictionary <AttendPeriod, AttendanceState> thisDayAttendState = new Dictionary <AttendPeriod, AttendanceState>();//考勤时间段1上午,2中午,3下午 考勤异常状态 1 缺勤 2 请假
                    foreach (T_HR_EMPLOYEEABNORMRECORD AbnormRecorditem in entAbnormRecords.ToList())
                    {
                        //需根据请假时间判断是否要删除掉考勤异常
                        //DateTime datLevestart = entLeaveRecord.STARTDATETIME.Value;//长日期格式2013/2/16 8:30:00
                        //DateTime datLeveEnd = entLeaveRecord.ENDDATETIME.Value;//长日期格式2013/2/16 8:30:00
                        DateTime dtDateAbnorm = AbnormRecorditem.ABNORMALDATE.Value;//短日期格式2013/3/8
                        #region 循环当天考勤异常检查出勤状态并修改考勤记录状态
                        var q = (from entsf in dal.GetObjects <T_HR_SHIFTDEFINE>()
                                 join ab in dal.GetObjects <T_HR_ATTENDANCERECORD>()
                                 on entsf.SHIFTDEFINEID equals ab.T_HR_SHIFTDEFINE.SHIFTDEFINEID
                                 where ab.ATTENDANCERECORDID == AbnormRecorditem.T_HR_ATTENDANCERECORD.ATTENDANCERECORDID
                                 select entsf);
                        if (q.Count() > 0)
                        {
                            T_HR_SHIFTDEFINE defineTime = q.FirstOrDefault();
                            if (AbnormRecorditem.ATTENDPERIOD.Trim() == "1")                                            //上午上班8:30异常
                            {
                                if (!string.IsNullOrEmpty(defineTime.NEEDFIRSTCARD) && defineTime.NEEDFIRSTCARD == "2") //以集团打卡举例,第一段上班打卡8:30
                                {
                                    Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第一段开始上班时间需打卡");
                                    if (!string.IsNullOrEmpty(defineTime.FIRSTSTARTTIME))
                                    {
                                        //定义的开始上班时间8:30
                                        DateTime ShiftFirstStartTime   = DateTime.Parse(defineTime.FIRSTSTARTTIME);
                                        DateTime ShiftstartDateAndTime = new DateTime(dtDateAbnorm.Year, dtDateAbnorm.Month, dtDateAbnorm.Day, ShiftFirstStartTime.Hour, ShiftFirstStartTime.Minute, ShiftFirstStartTime.Second);
                                        //定义的第一段上班结束时间12:00
                                        if (!string.IsNullOrEmpty(defineTime.FIRSTENDTIME))
                                        {
                                            DateTime FirstEndTime        = DateTime.Parse(defineTime.FIRSTENDTIME);
                                            DateTime FirstEndDateAndTime = new DateTime(dtDateAbnorm.Year, dtDateAbnorm.Month, dtDateAbnorm.Day, FirstEndTime.Hour, FirstEndTime.Minute, FirstEndTime.Second);

                                            //如果请假时间包括了第一段上班时间,那么消除异常
                                            if (datLevestart <= ShiftstartDateAndTime &&
                                                dtLeveEnd >= ShiftstartDateAndTime)
                                            {
                                                Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第一段开始上班时间需打卡时间被请假时间覆盖,消除异常"
                                                             + " 消除异常,开始时间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                                                             + " 结束时间:" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss") + "定义的上班开始时间:" +
                                                             ShiftstartDateAndTime.ToString("yyyy-MM-dd HH:mm:ss") + "定义的上班结束时间:" + FirstEndDateAndTime.ToString("yyyy-MM-dd HH:mm:ss"));
                                                //消除第一段异常生成的签卡
                                                DeleteSigFromAbnormal(AbnormRecorditem);
                                                //消除第一段打卡时间异常考勤
                                                dal.Delete(AbnormRecorditem);
                                                //第一段考勤时间标记为请假
                                                thisDayAttendState.Add(AttendPeriod.Morning, AttendanceState.Leave);
                                            }
                                            else
                                            {   //第一段考勤时间标记为异常
                                                thisDayAttendState.Add(AttendPeriod.Morning, AttendanceState.Abnormal);
                                            }
                                        }
                                        else
                                        {
                                            Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第一段开始上班时间需打卡,但班次定义中的FIRSTSTARTTIME为空");
                                        }
                                    }
                                    else
                                    {
                                        Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第一段开始上班时间需打卡,但班次定义中的FIRSTSTARTTIME为空");
                                    }
                                }
                            }
                            if (AbnormRecorditem.ATTENDPERIOD.Trim() == "2")                                              //中午上班13:30异常
                            {
                                if (!string.IsNullOrEmpty(defineTime.NEEDSECONDCARD) && defineTime.NEEDSECONDCARD == "2") //以集团打卡举例,第二段上班打卡13:30
                                {
                                    Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段开始上班时间需打卡");
                                    if (!string.IsNullOrEmpty(defineTime.SECONDSTARTTIME))
                                    {
                                        DateTime SecondStartTime        = DateTime.Parse(defineTime.SECONDSTARTTIME);
                                        DateTime SecondStartDateAndTime = new DateTime(dtDateAbnorm.Year, dtDateAbnorm.Month, dtDateAbnorm.Day, SecondStartTime.Hour, SecondStartTime.Minute, SecondStartTime.Second);
                                        if (!string.IsNullOrEmpty(defineTime.SECONDENDTIME))
                                        {
                                            DateTime SencondEndTime        = DateTime.Parse(defineTime.SECONDENDTIME);
                                            DateTime SencondEndDateAndTime = new DateTime(dtDateAbnorm.Year, dtDateAbnorm.Month, dtDateAbnorm.Day, SencondEndTime.Hour, SencondEndTime.Minute, SencondEndTime.Second);

                                            if (datLevestart <= SecondStartDateAndTime &&
                                                dtLeveEnd >= SecondStartDateAndTime)
                                            {
                                                Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段开始上班时间需打卡时间被请假时间覆盖,消除异常"
                                                             + " 消除异常,开始时间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                                                             + " 结束时间:" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss") + "定义的上班开始时间:" +
                                                             SecondStartDateAndTime.ToString("yyyy-MM-dd HH:mm:ss") + "定义的上班结束时间:" + SencondEndDateAndTime.ToString("yyyy-MM-dd HH:mm:ss"));

                                                //消除第二段异常生成的签卡
                                                DeleteSigFromAbnormal(AbnormRecorditem);
                                                //消除第二段打卡时间异常考勤
                                                dal.Delete(AbnormRecorditem);
                                                thisDayAttendState.Add(AttendPeriod.Midday, AttendanceState.Leave);
                                            }
                                            else
                                            {
                                                thisDayAttendState.Add(AttendPeriod.Midday, AttendanceState.Abnormal);
                                            }
                                        }
                                        else
                                        {
                                            Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段开始上班时间需打卡,但班次定义中的SECONDENDTIME为空");
                                        }
                                    }
                                    else
                                    {
                                        Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段开始上班时间需打卡,但班次定义中的SECONDSTARTTIME为空");
                                    }
                                }
                            }
                            if (AbnormRecorditem.ATTENDPERIOD.Trim() == "3")                                                    //下午17:30下班异常
                            {
                                if (!string.IsNullOrEmpty(defineTime.NEEDSECONDOFFCARD) && defineTime.NEEDSECONDOFFCARD == "2") //以集团打卡举例,第二段下班打卡17:30
                                {
                                    Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段结束上班时间需打卡");
                                    if (!string.IsNullOrEmpty(defineTime.SECONDSTARTTIME))
                                    {
                                        DateTime SecondStartTime        = DateTime.Parse(defineTime.SECONDSTARTTIME);
                                        DateTime SecondStartDateAndTime = new DateTime(dtDateAbnorm.Year, dtDateAbnorm.Month, dtDateAbnorm.Day, SecondStartTime.Hour, SecondStartTime.Minute, SecondStartTime.Second);

                                        if (!string.IsNullOrEmpty(defineTime.SECONDENDTIME))
                                        {
                                            DateTime SencondEndTime        = DateTime.Parse(defineTime.SECONDENDTIME);
                                            DateTime SencondEndDateAndTime = new DateTime(dtDateAbnorm.Year, dtDateAbnorm.Month, dtDateAbnorm.Day, SencondEndTime.Hour, SencondEndTime.Minute, SencondEndTime.Second);

                                            if (datLevestart <= SencondEndDateAndTime &&
                                                dtLeveEnd >= SencondEndDateAndTime)
                                            {
                                                Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段结束上班时间需打卡时间被请假时间覆盖,消除异常"
                                                             + " 消除异常,开始时间:" + datLevestart.ToString("yyyy-MM-dd HH:mm:ss")
                                                             + " 结束时间:" + dtLeveEnd.ToString("yyyy-MM-dd HH:mm:ss") + "定义的上班开始时间:" +
                                                             SecondStartDateAndTime.ToString("yyyy-MM-dd HH:mm:ss") + "定义的上班结束时间:" + SencondEndDateAndTime.ToString("yyyy-MM-dd HH:mm:ss"));

                                                //消除第三段异常生成的签卡
                                                DeleteSigFromAbnormal(AbnormRecorditem);
                                                //消除第三段打卡时间异常考勤
                                                dal.Delete(AbnormRecorditem);
                                                thisDayAttendState.Add(AttendPeriod.Evening, AttendanceState.Leave);
                                            }
                                            else
                                            {
                                                thisDayAttendState.Add(AttendPeriod.Evening, AttendanceState.Abnormal);
                                            }
                                        }
                                        else
                                        {
                                            Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段结束上班时间需打卡,但班次定义中的SECONDENDTIME为空");
                                        }
                                    }
                                    else
                                    {
                                        Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "考勤班次定义T_HR_SHIFTDEFINE第二段结束上班时间需打卡,但班次定义中的SECONDSTARTTIME为空");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + "消除异常,通过异常记录获取到考勤初始化记录但通过考勤初始化记录获取的考勤班次定义T_HR_SHIFTDEFINE为空");
                        }
                        #endregion
                    }
                    #region 修改考勤记录状态
                    if (thisDayAttendState.Count() > 0) //如果当天存在异常或请假情况
                    {                                   //如果当天存在请假,同时也存在异常
                        if (thisDayAttendState.Values.Contains(AttendanceState.Leave) && thisDayAttendState.Values.Contains(AttendanceState.Abnormal))
                        {                               //标记当天出勤状况为Mix状态
                            if (attState == (Convert.ToInt32(Common.AttendanceState.Leave) + 1).ToString())
                            {
                                item.ATTENDANCESTATE = (Convert.ToInt32(Common.AttendanceState.MixLeveAbnormal) + 1).ToString();
                            }
                            if (attState == (Convert.ToInt32(Common.AttendanceState.Travel) + 1).ToString())
                            {
                                item.ATTENDANCESTATE = (Convert.ToInt32(Common.AttendanceState.MixTravelAbnormal) + 1).ToString();
                            }
                            if (attState == (Convert.ToInt32(Common.AttendanceState.OutApply) + 1).ToString())
                            {
                                item.ATTENDANCESTATE = (Convert.ToInt32(Common.AttendanceState.MixOutApplyAbnormal) + 1).ToString();
                            }
                            item.UPDATEDATE = DateTime.Now;

                            string strMsg = item.ATTENDANCEDATE.Value.ToString("yyy-MM-dd") + " 消除异常修改状态完成,员工姓名:" + item.EMPLOYEENAME
                                            + ",修改的状态为:" + item.ATTENDANCESTATE;

                            item.REMARK = dealType + strMsg;
                            int iUpdate = dal.Update(item);
                            if (iUpdate == 1)
                            {
                                Tracer.Debug(dealType + strMsg + " 成功");
                            }
                            else
                            {
                                Tracer.Debug(dealType + strMsg + " 失败");
                            }
                        }
                        else if (thisDayAttendState.Values.Contains(AttendanceState.Leave) && !thisDayAttendState.Values.Contains(AttendanceState.Abnormal))
                        {
                            //如果当天异常时间已全部被请假时间涵盖,删除签卡提醒并标记考勤为请假
                            EmployeeSignInRecordBLL bllSignInRd = new EmployeeSignInRecordBLL();
                            bllSignInRd.ClearNoSignInRecord("T_HR_EMPLOYEEABNORMRECORD", item.EMPLOYEEID, entAbnormRecords);
                            item.ATTENDANCESTATE = attState;
                            item.UPDATEDATE      = DateTime.Now;

                            string strMsg = item.ATTENDANCEDATE.Value.ToString("yyy-MM-dd") + " 消除异常修改状态完成,员工姓名:" + item.EMPLOYEENAME
                                            + ",修改的状态为:" + item.ATTENDANCESTATE;
                            item.REMARK = dealType + strMsg;
                            int iUpdate = dal.Update(item);
                            if (iUpdate == 1)
                            {
                                Tracer.Debug(dealType + strMsg + " 成功");
                            }
                            else
                            {
                                Tracer.Debug(dealType + strMsg + " 失败");
                            }
                        }
                    }
                    #endregion

                    Tracer.Debug(dealType + " 日期:" + item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + ",发现当天有异常考勤,需要重新检查当天出勤状态,检查到异常记录共:" + i + "条记录"
                                 + "开始处理重新检查考勤异常——————————————————————————————————————End");
                }
                catch (Exception ex)
                {
                    Tracer.Debug(item.ATTENDANCEDATE.Value.ToString("yyyy-MM-dd") + " " + dealType + " 异常:" + ex.ToString());
                }
            }//for each T_HR_ATTENDANCERECORD End
            #endregion

            Tracer.Debug(dealType + " 结束!");
        }