Beispiel #1
0
        /// <summary>
        /// 检查是否在活动持续时间内
        /// </summary>
        public override bool InActivityTime()
        {
            if (string.IsNullOrEmpty(FromDate) || string.IsNullOrEmpty(ToDate))
            {
                return(false);
            }

            int NowDayOfWeek = (int)TimeUtil.NowDateTime().DayOfWeek;

            string[] DataBeginSplit = FromDate.Split(',');
            string[] DataEndSplit   = ToDate.Split(',');

            // 将DayOfWeek 0~6 转换成 1~7
            if (DayOfWeek.Sunday == (DayOfWeek)NowDayOfWeek)
            {
                NowDayOfWeek = 7;
            }

            int BeginDayOfWeek = Convert.ToInt32(DataBeginSplit[0]);
            int EndDayOfWeek   = Convert.ToInt32(DataEndSplit[0]);

            if (NowDayOfWeek < BeginDayOfWeek)
            {
                return(false);
            }
            else if (NowDayOfWeek > EndDayOfWeek)
            {
                return(false);
            }

            string nowTime = TimeUtil.NowDateTime().ToString("HH:mm:ss");

            // 比较时分秒
            if (BeginDayOfWeek == EndDayOfWeek)
            {
                if (nowTime.CompareTo(DataBeginSplit[1]) > 0 && nowTime.CompareTo(DataEndSplit[1]) < 0)
                {
                    return(true);
                }
            }
            else if (NowDayOfWeek == BeginDayOfWeek)
            {
                if (nowTime.CompareTo(DataBeginSplit[1]) > 0)
                {
                    return(true);
                }
            }
            else if (NowDayOfWeek == EndDayOfWeek)
            {
                if (nowTime.CompareTo(DataEndSplit[1]) < 0)
                {
                    return(true);
                }
            }

            // NowDayOfWeek > BeginDayOfWeek && NowDayOfWeek < EndDayOfWeek && BeginDayOfWeek != EndDayOfWeek
            return(true);
        }