Beispiel #1
0
 /// <summary>
 /// 判断是否是工作日,工作日为true
 /// </summary>
 /// <param name="ticks">Date的Ticks</param>
 /// <returns></returns>
 public static bool isworkDay(long ticks)
 {
     DateTime today = new DateTime(ticks);
     BaseService baseService = new BaseService();
     IList holidayList = baseService.loadEntityList("from Holiday where STATE=" + (int)IEntity.stateEnum.Normal + " and StartTime<=" + ticks + " and EndTime>=" + ticks);
     if (holidayList != null && holidayList.Count == 1)
     {
         return false;
     }
     IList workDayList = baseService.loadEntityList("from WorkDay where STATE=" + (int)IEntity.stateEnum.Normal + " and WorkDateTime=" + ticks );
     if (workDayList != null && workDayList.Count == 1)
     {
         return false;
     }
     IList usuallyDayList = baseService.loadEntityList("from UsuallyDay where STATE=" + (int)IEntity.stateEnum.Normal + " and StartTime<=" + ticks + " order by StartTime desc");
     if (usuallyDayList != null && usuallyDayList.Count == 1)
     {
         UsuallyDay u = (UsuallyDay)usuallyDayList[0];
         char[] workDays = u.WorkDay.ToCharArray();
         if (((int)today.DayOfWeek != 0 && workDays[(int)today.DayOfWeek - 1].Equals((char)UsuallyDay.workDayEnum.Holiday)) || ((int)today.DayOfWeek == 0 && workDays[6].Equals((char)UsuallyDay.workDayEnum.Holiday)))
         {
             return false;
         }
         else if (((int)today.DayOfWeek != 0 && workDays[(int)today.DayOfWeek - 1].Equals((char)UsuallyDay.workDayEnum.WorkDay)) || ((int)today.DayOfWeek == 0 && workDays[6].Equals((char)UsuallyDay.workDayEnum.WorkDay)))
         {
             return true;
         }
     }
     return true;
 }
Beispiel #2
0
        public static List<long> getWorkDayNum(DateTime startDate, DateTime endDate)
        {
            BaseService baseService = new BaseService();
            IList workDays = new List<int>();
            IList holidayList = baseService.loadEntityList("from Holiday where STATE=" + (int)IEntity.stateEnum.Normal + " and StartTime<=" + startDate.Date.Ticks + " and EndTime>=" + endDate.Date.Ticks);
            if (holidayList == null || holidayList.Count == 0)
            {
                holidayList = new List<long>();
            }
            IList workDayList = baseService.loadEntityList("from WorkDay where STATE=" + (int)IEntity.stateEnum.Normal + " and WorkDateTime<=" + startDate.Date.Ticks + " and WorkDateTime>=" + endDate.Date.Ticks);
            if (workDayList == null || holidayList.Count == 0)
            {
                workDayList = new List<long>();
            }
            IList usuallyDayList = baseService.loadEntityList("from UsuallyDay where STATE=" + (int)IEntity.stateEnum.Normal + " and StartTime<=" + startDate.Date.Ticks + " order by StartTime desc");
            if (usuallyDayList != null && usuallyDayList.Count == 1)
            {
                UsuallyDay u = (UsuallyDay)usuallyDayList[0];
                char[] wd = u.WorkDay.ToCharArray();
                for(int i=0;i<wd.Length;i++)
                {
                    if(wd[i].Equals((char)UsuallyDay.workDayEnum.WorkDay))
                    {
                        workDays.Add(i);
                    }
                }
            }
            List<long> dateList = new List<long>();
            long ticks = startDate.Date.Ticks;
            while (ticks <= endDate.Date.Ticks)
            {
                DateTime date = new DateTime(ticks);
                if (holidayList.Contains(ticks))
                {
                    ticks = new DateTime(ticks).AddDays(1).Date.Ticks;
                    continue;
                }
                if (workDayList.Contains(ticks))
                {
                    dateList.Add(ticks);
                    ticks = new DateTime(ticks).AddDays(1).Date.Ticks;
                    continue;
                }

                if (IsInWorkDay(date, workDays))
                {
                    dateList.Add(ticks);

                }
                //foreach (int dayOfWeek in workDays)
                //{
                //    if ((dayOfWeek + 1 == (int)date.DayOfWeek)||(dayOfWeek == 6 && (int)date.DayOfWeek == 0)) //一个星期中的第几天
                //    {
                //        ticks = new DateTime(ticks).AddDays(1).Date.Ticks;
                //        break;
                //        continue;
                //    }
                //}

                ticks = new DateTime(ticks).AddDays(1).Date.Ticks;

            }
            return dateList;
        }