Beispiel #1
0
        /// <summary>
        /// Builds the RegEx that allows us to preParse a time span string.
        /// </summary>
        /// <returns>regular expression string</returns>
        private static string BuildParseRegularExpression()
        {
            StringBuilder regExPattern = new StringBuilder();

            regExPattern.Append("^");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "years",
                                    GetResourceString("YearsUnit"),
                                    GetResourceString("YearUnit"),
                                    GetResourceString("YearsLongUnit"),
                                    GetResourceString("YearLongUnit")));
            regExPattern.Append("\\s*");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "months",
                                    GetResourceString("MonthsUnit"),
                                    GetResourceString("MonthUnit"),
                                    GetResourceString("MonthsLongUnit"),
                                    GetResourceString("MonthLongUnit")));
            regExPattern.Append("\\s*");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "weeks",
                                    GetResourceString("WeeksUnit"),
                                    GetResourceString("WeekUnit"),
                                    GetResourceString("WeeksLongUnit"),
                                    GetResourceString("WeekLongUnit")));
            regExPattern.Append("\\s*");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "days",
                                    GetResourceString("DaysUnit"),
                                    GetResourceString("DayUnit"),
                                    GetResourceString("DaysLongUnit"),
                                    GetResourceString("DayLongUnit")));
            regExPattern.Append("\\s*");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "hours",
                                    GetResourceString("HoursUnit"),
                                    GetResourceString("HourUnit"),
                                    GetResourceString("HoursLongUnit"),
                                    GetResourceString("HourLongUnit")));
            regExPattern.Append("\\s*");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "minutes",
                                    GetResourceString("MinutesUnit"),
                                    GetResourceString("MinuteUnit"),
                                    GetResourceString("MinutesLongUnit"),
                                    GetResourceString("MinuteLongUnit")));
            regExPattern.Append("\\s*");
            regExPattern.Append(TimeSpanInputBox.BuildUnitRegEx(
                                    "seconds",
                                    GetResourceString("SecondsUnit"),
                                    GetResourceString("SecondUnit"),
                                    GetResourceString("SecondsLongUnit"),
                                    GetResourceString("SecondLongUnit")));
            regExPattern.Append("$");
            return(regExPattern.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Implements the extra parsing logic to recognise truncated forms of long TimeSpanUnits
        /// </summary>
        /// <param name="value">Input string to preparse for truncated TSUs</param>
        /// <returns>A string regularised to the long TimeSpanUnits version of the input string</returns>
        private static string PreParseUnits(string value)
        {
            // NOT the same as the NhsTimeSpan version...
            string parseExpression = TimeSpanInputBox.BuildParseRegularExpression();
            Regex  regEx           = new Regex(parseExpression, RegexOptions.IgnoreCase);
            Match  wordMatch       = regEx.Match(value);
            string returnValue     = "";

            if (wordMatch != null)
            {
                // now convert to full length versions for easier parsing by NhsTimeSpan...
                if (wordMatch.Groups["years"] != null && string.IsNullOrEmpty(wordMatch.Groups["years"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["years"].Value, CultureInfo.InvariantCulture) + GetResourceString("YearsLongUnit") + " ";
                }

                if (wordMatch.Groups["months"] != null && string.IsNullOrEmpty(wordMatch.Groups["months"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["months"].Value, CultureInfo.InvariantCulture) + GetResourceString("MonthsLongUnit") + " ";
                }

                if (wordMatch.Groups["weeks"] != null && string.IsNullOrEmpty(wordMatch.Groups["weeks"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["weeks"].Value, CultureInfo.InvariantCulture) + GetResourceString("WeeksLongUnit") + " ";
                }

                if (wordMatch.Groups["days"] != null && string.IsNullOrEmpty(wordMatch.Groups["days"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["days"].Value, CultureInfo.InvariantCulture) + GetResourceString("DaysLongUnit") + " ";
                }

                if (wordMatch.Groups["hours"] != null && string.IsNullOrEmpty(wordMatch.Groups["hours"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["hours"].Value, CultureInfo.InvariantCulture) + GetResourceString("HoursLongUnit") + " ";
                }

                if (wordMatch.Groups["minutes"] != null && string.IsNullOrEmpty(wordMatch.Groups["minutes"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["minutes"].Value, CultureInfo.InvariantCulture) + GetResourceString("MinutesLongUnit") + " ";
                }

                if (wordMatch.Groups["seconds"] != null && string.IsNullOrEmpty(wordMatch.Groups["seconds"].Value) == false)
                {
                    returnValue += int.Parse(wordMatch.Groups["seconds"].Value, CultureInfo.InvariantCulture) + GetResourceString("SecondsLongUnit") + " ";
                }
            }

            if (returnValue != null && returnValue.Length > 0)
            {
                return(returnValue.TrimEnd());
            }
            else
            {
                return(value);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Called when the associated control changes.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="ce">A ComponentChangedEventArgs that contains the event data. </param>
        public override void OnComponentChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs ce)
        {
            if (ce == null)
            {
                throw new ArgumentNullException("ce");
            }

            base.OnComponentChanged(sender, ce);

            if (ce.Member.Name == "Value")
            {
                // user has edited Value property make sure the designer knows that
                // this means other properties need serializing
                TimeSpanInputBox control = (TimeSpanInputBox)this.Component;

                this.RaiseComponentChanged("IsAge", control.IsAge);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether the control specified by the ControlToValidate property is a valid control.
        /// </summary>
        /// <returns>True if control properties is valid</returns>
        protected override bool ControlPropertiesValid()
        {
            // Call the base implementation of ControlPropertiesValid first.
            // If that passes run the extra checks

            if (base.ControlPropertiesValid() == true)
            {
                TimeSpanInputBox control = this.NamingContainer.FindControl(this.ControlToValidate) as TimeSpanInputBox;

                if (control == null)
                {
                    throw new HttpException(TimeSpanInputBoxControl.TimeSpanInputBoxValidatorResources.ControlToValidateInvalid);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }