Ejemplo n.º 1
0
        /// <summary>
        /// 日期内的工作日数
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static int WorkDayCount(DateTime begin, DateTime end)
        {
            int count = 0;

            if (begin > end)
            {
                DateTime t = begin;
                begin = end;
                end   = t;
            }
            for (DateTime t = begin; t <= end; t = t.AddDays(1))
            {
                SpecialDay sd = specialDays.Items.FirstOrDefault <SpecialDay>(x => x.DateValue == t);
                if (sd == null && (t.DayOfWeek == DayOfWeek.Saturday || t.DayOfWeek == DayOfWeek.Sunday))
                {
                    continue;
                }
                if (sd != null && sd.DayType != WorkDayType.Work)
                {
                    continue;
                }
                count += 1;
            }
            return(count);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 是否是工作日
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static bool IsWorkDay(DateTime d)
        {
            SpecialDay sd = specialDays.Items.FirstOrDefault <SpecialDay>(x => x.DateValue == d);

            if (sd != null)
            {
                return(sd.DayType == WorkDayType.Work);
            }

            return(d.DayOfWeek != DayOfWeek.Saturday && d.DayOfWeek != DayOfWeek.Sunday);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 取得所有工作日
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static List <DateTime> WorkDayList(DateTime begin, DateTime end)
        {
            List <DateTime> list = new List <DateTime>();

            for (DateTime t = begin; t <= end; t = t.AddDays(1))
            {
                SpecialDay sd = specialDays.Items.FirstOrDefault <SpecialDay>(x => x.DateValue == t);
                if (sd == null && (t.DayOfWeek == DayOfWeek.Saturday || t.DayOfWeek == DayOfWeek.Sunday))
                {
                    continue;
                }
                if (sd != null && sd.DayType != WorkDayType.Work)
                {
                    continue;
                }
                list.Add(t);
            }
            return(list);
        }