Exemple #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);
        }
Exemple #2
0
 /// <summary>
 /// 初始化请假leaveList、补班workDayList、节假日holidayList、周末信息usuallyDay
 /// </summary>
 private void initPanelDate()
 {
     if (dateLabel[dateLabel.Count - 1].Parent.Tag != null && dateLabel[0].Parent.Tag != null)
     {
         DateTime startTime = (DateTime)dateLabel[0].Parent.Tag;
         DateTime endTime   = (DateTime)dateLabel[dateLabel.Count - 1].Parent.Tag;
         holidayList = baseService.loadEntityList("from Holiday where STATE=" + (int)IEntity.stateEnum.Normal + " and ((StartTime>=" + startTime.Date.Ticks + " and StartTime<=" + endTime.Date.Ticks + ") or (EndTime>=" + startTime.Date.Ticks + " and EndTime<=" + endTime.Date.Ticks + ") or (StartTime>=" + startTime.Date.Ticks + " and EndTime<=" + endTime.Date.Ticks + ") or (StartTime<=" + startTime.Date.Ticks + " and EndTime>=" + endTime.Date.Ticks + "))");
         workDayList = baseService.loadEntityList("from WorkDay where STATE=" + (int)IEntity.stateEnum.Normal + " and workDateTime>=" + startTime.Date.Ticks + " and workDateTime<=" + endTime.Date.Ticks);
         leaveList   = baseService.loadEntityList("from LeaveManage l where l.State=" + (int)IEntity.stateEnum.Normal + " and l.Ku_Id.KuName like '%" + comboBox2.Text.Trim() + "%' and ((l.StartTime>=" + startTime.Date.Ticks + " and l.StartTime<=" + endTime.Date.Ticks + ") or (l.EndTime>=" + startTime.Date.Ticks + " and l.EndTime<=" + endTime.Date.Ticks + ") or (l.StartTime>=" + startTime.Date.Ticks + " and l.EndTime<=" + endTime.Date.Ticks + ") or (l.StartTime<=" + startTime.Date.Ticks + " and l.EndTime>=" + endTime.Date.Ticks + "))");
         IList usuallyDayList = baseService.loadEntityList("from UsuallyDay where STATE=" + (int)IEntity.stateEnum.Normal + " and StartTime<=" + dateTimePicker5.Value.Date.Ticks + " order by StartTime desc");
         if (usuallyDayList != null && usuallyDayList.Count != 0)
         {
             usuallyDay     = (UsuallyDay)usuallyDayList[0];
             usuallyDayChar = usuallyDay.WorkDay.ToCharArray();
         }
     }
 }
Exemple #3
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);
        }