Ejemplo n.º 1
0
        /// <summary>
        /// Gets the date range represented by the listing mode,
        /// to allow migrating from old settings (<see cref="ListingMode"/>) to new settings (<see cref="DateRange"/>).
        /// </summary>
        /// <param name="moduleControl">The module control for which to get the date range.</param>
        /// <returns>A new <see cref="DateRange"/> instance</returns>
        private static DateRange GetDateRangeForListingMode(IModuleControlBase moduleControl)
        {
            DateRangeBound startRangeBound;
            DateRangeBound endRangeBound;

#pragma warning disable 618
            switch (DisplayModeOption.GetValueAsEnumFor <ListingMode>(moduleControl))
            {
            case ListingMode.CurrentMonth:
                startRangeBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Day);
                endRangeBound   = DateRangeBound.CreateRelativeBound(0, DateInterval.Month);
                break;

            case ListingMode.Future:
                startRangeBound = DateRangeBound.CreateRelativeBound(1, DateInterval.Month);
                endRangeBound   = DateRangeBound.CreateUnboundedBound();
                break;

            case ListingMode.Past:
                startRangeBound = DateRangeBound.CreateUnboundedBound();
                endRangeBound   = DateRangeBound.CreateRelativeBound(0, DateInterval.Day);
                break;

            ////case ListingMode.All:
            default:
                startRangeBound = DateRangeBound.CreateUnboundedBound();
                endRangeBound   = DateRangeBound.CreateUnboundedBound();
                break;
            }
#pragma warning restore 618

            return(new DateRange(startRangeBound, endRangeBound));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the specified values into a <see cref="DateRangeBound"/>.
        /// </summary>
        /// <param name="value">The "main" selected value, containing either a pipe-delimited pair of relative amount and relative interval, or an indication of the other type of range represented.</param>
        /// <param name="specificDate">The specific date, or <c>null</c>.</param>
        /// <param name="windowAmount">The window amount as an integer, or <c>null</c>.</param>
        /// <param name="windowInterval">The window interval as a <see cref="DateInterval"/> value, or <c>null</c>.</param>
        /// <returns>A new <see cref="DateRangeBound"/> instance</returns>
        public static DateRangeBound Parse(string value, DateTime?specificDate, double?windowAmount, string windowInterval)
        {
            var dateRangeBound = new DateRangeBound();

            if (value == "specific-date")
            {
                if (specificDate == null)
                {
                    throw new ArgumentNullException("specificDate");
                }

                dateRangeBound.SpecificDate = specificDate;
            }
            else if (value == "window")
            {
                if (windowAmount == null)
                {
                    throw new ArgumentNullException("windowAmount");
                }

                if (windowInterval == null)
                {
                    throw new ArgumentNullException("windowInterval");
                }

                dateRangeBound.WindowAmount   = (int)windowAmount.Value;
                dateRangeBound.WindowInterval = (DateInterval)Enum.Parse(typeof(DateInterval), windowInterval);
            }
            else if (!string.IsNullOrEmpty(value))
            {
                var relativeRangeParts = value.Split('|');
                if (relativeRangeParts.Length != 2)
                {
                    throw new ArgumentException("Value must be relative amount and relative interval, separated by pipe", "value");
                }

                int relativeAmount;
                if (!int.TryParse(relativeRangeParts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out relativeAmount))
                {
                    throw new ArgumentException("First part of value must be an integer", "value");
                }

                if (!Enum.IsDefined(typeof(DateInterval), relativeRangeParts[1]))
                {
                    throw new ArgumentException("Second part of value must be a DateInterval value", "value");
                }

                dateRangeBound.RelativeAmount   = relativeAmount;
                dateRangeBound.RelativeInterval = (DateInterval)Enum.Parse(typeof(DateInterval), relativeRangeParts[1]);
            }

            return(dateRangeBound);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DateRangeBoundJsonTransferObject"/> struct.
        /// </summary>
        /// <param name="bound">The bound.</param>
        public DateRangeBoundJsonTransferObject([NotNull] DateRangeBound bound)
            : this()
        {
            if (bound == null)
            {
                throw new ArgumentNullException("bound");
            }

            this.value          = GetListValueForBound(bound);
            this.specificDate   = bound.SpecificDate;
            this.windowAmount   = bound.WindowAmount;
            this.windowInterval = bound.WindowInterval.HasValue ? bound.WindowInterval.Value.ToString() : null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DateRange"/> class.
        /// </summary>
        /// <param name="start">The starting bound of the date range.</param>
        /// <param name="end">The ending bound of the date range.</param>
        public DateRange(DateRangeBound start, DateRangeBound end)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            this.Start = start;
            this.End   = end;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DateRange"/> class.
        /// </summary>
        /// <param name="start">The starting bound of the date range.</param>
        /// <param name="end">The ending bound of the date range.</param>
        public DateRange(DateRangeBound start, DateRangeBound end)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            if (end == null)
            {
                throw new ArgumentNullException("end");
            }

            this.Start = start;
            this.End = end;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the value for the main drop down list for the given <paramref name="bound"/>.
        /// </summary>
        /// <param name="bound">The date range bound.</param>
        /// <returns>The value from the drop down list matching the bound</returns>
        public static string GetListValueForBound([NotNull] DateRangeBound bound)
        {
            if (bound == null)
            {
                throw new ArgumentNullException("bound");
            }

            return(bound.IsUnbounded
                       ? string.Empty
                       : bound.IsWindow
                             ? "window"
                             : bound.IsSpecificDate
                                   ? "specific-date"
                                   : string.Format(
                       CultureInfo.InvariantCulture,
                       "{0}|{1}",
                       bound.RelativeAmount.Value,
                       bound.RelativeInterval.Value));
        }
Ejemplo n.º 7
0
        public object FormatDateRange(DateRangeBoundJsonTransferObject start, DateRangeBoundJsonTransferObject end)
        {
            DateRangeBound startRangeBound;
            DateRangeBound endRangeBound;

            try
            {
                startRangeBound = DateRangeBound.Parse(start.value, start.specificDate, start.windowAmount, start.windowInterval);
                endRangeBound   = DateRangeBound.Parse(end.value, end.specificDate, end.windowAmount, end.windowInterval);
            }
            catch (ArgumentNullException exc)
            {
                return(new { isError = true, message = Localization.GetString("Missing " + exc.ParamName, ResourceFileRoot) });
            }

            var dateRange = new DateRange(startRangeBound, endRangeBound);

            if (!string.IsNullOrEmpty(dateRange.ErrorMessage))
            {
                return(new { isError = true, message = Localization.GetString(dateRange.ErrorMessage, ResourceFileRoot) });
            }

            var dateRangeResourceKey = startRangeBound.IsUnbounded && endRangeBound.IsUnbounded
                                           ? "Date Range Without Bounds.Text"
                                           : startRangeBound.IsUnbounded
                                                 ? "Date Range Without Start.Format"
                                                 : endRangeBound.IsUnbounded ? "Date Range Without End.Format" : "Date Range.Format";

            var dateRangeText = string.Format(
                CultureInfo.CurrentCulture,
                Localization.GetString(dateRangeResourceKey, ResourceFileRoot),
                dateRange.GetStartDate(),
                dateRange.GetEndDate());

#if DEBUG
            dateRangeText = dateRangeText.Replace("[L]", string.Empty);
#endif

            return(new { isError = false, message = dateRangeText });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the date range for the given module.
        /// </summary>
        /// <param name="moduleControl">The module control.</param>
        /// <returns>The date range</returns>
        public static DateRange GetDateRangeFor(IModuleControlBase moduleControl)
        {
            if (!RangeStartRelativeAmount.IsSettingDefinedFor(moduleControl) && DisplayModeOption.IsSettingDefinedFor(moduleControl))
            {
                var dateRange = GetDateRangeForListingMode(moduleControl);
                SetDateRangeSettings(moduleControl, dateRange);
                return(dateRange);
            }

            var startRangeBound = new DateRangeBound(
                GetValueAsNullableInt32(RangeStartRelativeAmount, moduleControl),
                GetValueAsNullableEnum(RangeStartRelativeInterval, moduleControl),
                GetValueAsNullableDateTime(RangeStartSpecificDate, moduleControl),
                GetValueAsNullableInt32(RangeStartWindowAmount, moduleControl),
                GetValueAsNullableEnum(RangeStartWindowInterval, moduleControl));
            var endRangeBound = new DateRangeBound(
                GetValueAsNullableInt32(RangeEndRelativeAmount, moduleControl),
                GetValueAsNullableEnum(RangeEndRelativeInterval, moduleControl),
                GetValueAsNullableDateTime(RangeEndSpecificDate, moduleControl),
                GetValueAsNullableInt32(RangeEndWindowAmount, moduleControl),
                GetValueAsNullableEnum(RangeEndWindowInterval, moduleControl));

            return(new DateRange(startRangeBound, endRangeBound));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Parses the specified values into a <see cref="DateRangeBound"/>.
        /// </summary>
        /// <param name="value">The "main" selected value, containing either a pipe-delimited pair of relative amount and relative interval, or an indication of the other type of range represented.</param>
        /// <param name="specificDate">The specific date, or <c>null</c>.</param>
        /// <param name="windowAmount">The window amount as an integer, or <c>null</c>.</param>
        /// <param name="windowInterval">The window interval as a <see cref="DateInterval"/> value, or <c>null</c>.</param>
        /// <returns>A new <see cref="DateRangeBound"/> instance</returns>
        public static DateRangeBound Parse(string value, DateTime? specificDate, double? windowAmount, string windowInterval)
        {
            var dateRangeBound = new DateRangeBound();

            if (value == "specific-date")
            {
                if (specificDate == null)
                {
                    throw new ArgumentNullException("specificDate");
                }

                dateRangeBound.SpecificDate = specificDate;
            }
            else if (value == "window")
            {
                if (windowAmount == null)
                {
                    throw new ArgumentNullException("windowAmount");
                }

                if (windowInterval == null)
                {
                    throw new ArgumentNullException("windowInterval");
                }

                dateRangeBound.WindowAmount = (int)windowAmount.Value;
                dateRangeBound.WindowInterval = (DateInterval)Enum.Parse(typeof(DateInterval), windowInterval);
            }
            else if (!string.IsNullOrEmpty(value))
            {
                var relativeRangeParts = value.Split('|');
                if (relativeRangeParts.Length != 2)
                {
                    throw new ArgumentException("Value must be relative amount and relative interval, separated by pipe", "value");
                }

                int relativeAmount;
                if (!int.TryParse(relativeRangeParts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out relativeAmount))
                {
                    throw new ArgumentException("First part of value must be an integer", "value");
                }

                if (!Enum.IsDefined(typeof(DateInterval), relativeRangeParts[1]))
                {
                    throw new ArgumentException("Second part of value must be a DateInterval value", "value");
                }

                dateRangeBound.RelativeAmount = relativeAmount;
                dateRangeBound.RelativeInterval = (DateInterval)Enum.Parse(typeof(DateInterval), relativeRangeParts[1]);
            }

            return dateRangeBound;
        }