Esempio n. 1
0
        /// <summary>
        /// 返回一年的非作业的时间
        /// </summary>
        /// <param name="year">年</param>
        /// <param name="WorkWeekValue">工作星期</param>
        /// <param name="NotWorkDates">节假日</param>
        /// <param name="overtime">加班日期</param>
        /// <returns></returns>
        public static List <APSCalendar> CalendarTransformRestDate(int year, string WorkWeekValue, string NotWorkDates = "", string overtime = "")
        {
            List <APSCalendar> itemRestList = new List <APSCalendar>();                                               //非作业时间
            List <APSCalendar> itemList     = CalendarTransformWorkDate(year, WorkWeekValue, NotWorkDates, overtime); //获取一年内的作业时间


            for (int month = 1; month <= 12; month++)
            {
                int monthDays = DateTime.DaysInMonth(year, month);
                for (int day = 1; day <= monthDays; day++)
                {
                    DateTime dt = new DateTime(year, month, day);

                    int dayofWeek = (int)dt.DayOfWeek;
                    if (itemList.Find(x => x.dtYear == dt.Year && x.dtMonth == dt.Month && x.dtDay == dt.Day) == null)
                    {
                        //作业时间以外的日期 认为是休息时间
                        APSCalendar item = new APSCalendar();
                        item.dt         = dt;
                        item.dtYear     = year;
                        item.dtMonth    = month;
                        item.dtDay      = day;
                        item.iDayOfWeek = dayofWeek;
                        item.IsRest     = true;
                        itemRestList.Add(item);
                    }
                }
            }

            return(itemRestList);
        }
Esempio n. 2
0
        /// <summary>
        /// 判断当前日期是否工作时间,精确到秒
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="wdList"></param>
        /// <returns></returns>
        public static bool IsWorkTime(DateTime dt, List <APSCalendar> wdList)
        {
            bool result = false;

            //首先判断是否工作日
            APSCalendar item = wdList.Find(x => x.dtYear == dt.Year && x.dtMonth == dt.Month && x.dtDay == dt.Day);

            if (item != null)
            {
                List <APSAttendanceSlot> acsList = item.ascList;

                //判断是否工作时间
                foreach (var acs in acsList)
                {
                    if (acs.startSlot.hour < acs.endSlot.hour)
                    {
                        //非跨天
                        if (acs.startSlot.hour <= dt.Hour && dt.Hour < acs.endSlot.hour)
                        {
                            result = true;
                        }
                    }

                    else if (acs.startSlot.hour >= acs.endSlot.hour)
                    {
                        //跨天
                        //前半夜
                        if (acs.startSlot.hour < dt.Hour && dt.Hour <= 24)
                        {
                            result = true;
                        }
                        //后半夜
                        if (0 < dt.Hour && dt.Hour < acs.endSlot.hour)
                        {
                            result = true;
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 返回一年的可以作业的时间
        /// </summary>
        /// <param name="year">年</param>
        /// <param name="WorkWeekValue">工作星期</param>
        /// <param name="NotWorkDates">节假日</param>
        /// <param name="overtime">加班日期</param>
        /// <returns></returns>
        public static List <APSCalendar> CalendarTransformWorkDate(int year, string WorkWeekValue, string mode, string NotWorkDates = "", string overtime = "")
        {
            List <APSCalendar> itemList = new List <APSCalendar>();

            // WorkWeekValue 格式 1;2;3;4;5;6;  表示星期一、星期二、星期三、星期五、星期六上班

            string[] lines = WorkWeekValue.Split(SplitHelper.SplitSemicolon);

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

            foreach (string line in lines)
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    weeks.Add(int.Parse(line));
                }
            }

            List <APSCalendar> dtNotWorkDates = new List <APSCalendar>(); //节假日期

            List <APSCalendar> dtOverDates = new List <APSCalendar>();    //加班日期

            #region 节假日
            if (!string.IsNullOrWhiteSpace(NotWorkDates))
            {
                string[] lineNotWorkDates = NotWorkDates.Split(SplitHelper.SplitSemicolon);

                foreach (string line in lineNotWorkDates)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    DateTime    dt        = DateTime.Parse(line);
                    int         dayofWeek = (int)dt.DayOfWeek;
                    APSCalendar item      = new APSCalendar();
                    item.dt         = dt;
                    item.dtYear     = dt.Year;
                    item.dtMonth    = dt.Month;
                    item.dtDay      = dt.Day;
                    item.iDayOfWeek = dayofWeek;
                    item.IsRest     = true;
                    dtNotWorkDates.Add(item);
                }
            }
            #endregion

            #region 加班日期
            if (!string.IsNullOrWhiteSpace(overtime))
            {
                string[] lineovertime = overtime.Split(SplitHelper.SplitSemicolon);

                foreach (string line in lineovertime)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    DateTime    dt        = DateTime.Parse(line);
                    int         dayofWeek = (int)dt.DayOfWeek;
                    APSCalendar item      = new APSCalendar();
                    item.dt         = dt;
                    item.dtYear     = dt.Year;
                    item.dtMonth    = dt.Month;
                    item.dtDay      = dt.Day;
                    item.iDayOfWeek = dayofWeek;
                    item.IsRest     = false;
                    dtOverDates.Add(item);
                }
            }
            #endregion


            for (int month = 1; month <= 12; month++)
            {
                int monthDays = DateTime.DaysInMonth(year, month);
                for (int day = 1; day <= monthDays; day++)
                {
                    DateTime dt = new DateTime(year, month, day);



                    int dayofWeek = (int)dt.DayOfWeek;
                    if (weeks.Contains(dayofWeek))//去掉工厂允许的正常休息时间(例如星期六 星期天)
                    {
                        if (dtNotWorkDates.Find(x => x.dtYear == dt.Year && x.dtMonth == dt.Month && x.dtDay == dt.Day) != null)
                        {
                            //日期是节假日 无法作业(去掉工厂执行的国家法定节假日)
                            continue;
                        }
                        APSCalendar item = new APSCalendar();
                        item.dt         = dt;
                        item.dtYear     = year;
                        item.dtMonth    = month;
                        item.dtDay      = day;
                        item.iDayOfWeek = dayofWeek;
                        item.IsRest     = false;
                        itemList.Add(item);
                    }
                }
            }

            if (dtOverDates.Count > 0)
            {
                //补录加班时间
                foreach (var item in dtOverDates)
                {
                    DateTime dt = item.dt;
                    if (itemList.Find(x => x.dtYear == dt.Year && x.dtMonth == dt.Month && x.dtDay == dt.Day) == null)
                    {
                        itemList.Add(item);
                    }
                }
            }

            #region 追加日作业中时间段
            List <APSAttendanceSlot> ascList = AttendanceModeTransformTime(mode);
            if (ascList != null && ascList.Count > 0)
            {
                foreach (var itemNew in itemList)
                {
                    itemNew.DayWorkSeconds = ascList.Sum(x => x.SlotSeconds);

                    itemNew.ascList = ascList;
                }
            }

            #endregion

            return(itemList);
        }