示例#1
0
        /// <summary>
        /// Constructs a TimeSpanLabel object. 
        /// </summary>
        public TimeSpanLabel()
        {
            this.AccessibleName = TimeSpanLabelControl.Resources.AccessibleName;
            this.AccessibleDescription = TimeSpanLabelControl.Resources.AccessibleDescription;
            this.AccessibleRole = AccessibleRole.StaticText;

            this.unitLength = TimeSpanUnitLength.Short;

            this.InitializeComponent();
        }
示例#2
0
        /// <summary>
        /// Constructs a TimeSpanLabel object.
        /// </summary>
        public TimeSpanLabel()
        {
            this.AccessibleName        = TimeSpanLabelControl.Resources.AccessibleName;
            this.AccessibleDescription = TimeSpanLabelControl.Resources.AccessibleDescription;
            this.AccessibleRole        = AccessibleRole.StaticText;

            this.unitLength = TimeSpanUnitLength.Short;

            this.InitializeComponent();
        }
示例#3
0
        public void UnitLengthTest()
        {
            TimeSpanUnitLength testValue = TimeSpanUnitLength.Long;

            TimeSpanLabel label = new TimeSpanLabel();

            Assert.AreEqual <TimeSpanUnitLength>(TimeSpanUnitLength.Short, label.UnitLength, "Expected UnitLength to initially be Short");

            label.UnitLength = testValue;
            Assert.AreEqual <TimeSpanUnitLength>(testValue, label.UnitLength, "UnitLength property not set as expected");
        }
示例#4
0
        /// <summary>
        /// Raises the PreRender event.
        /// </summary>
        /// <param name="e">An EventArgs object that contains the event data. </param>
        protected override void OnPreRender(EventArgs e)
        {
            this.state.Value      = this.Value;
            this.state.UnitLength = this.unitLength;

            // Register the NhsCuiValidation.js script with ASP.NET Ajax
            ScriptManager.GetCurrent(this.Page).Scripts.Add(new ScriptReference("NhsCui.Toolkit.Web.Validators.NhsCuiValidation.js", "NhsCui.Toolkit.Web"));

            JavaScriptSerializer jss = new JavaScriptSerializer();

            jss.RegisterConverters(new JavaScriptConverter[] { new NhsTimeSpanJavascriptConverter() });

            this.ClientState = jss.Serialize(this.state);

            base.OnPreRender(e);
        }
示例#5
0
        /// <summary>
        /// Handle loading of client state
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void TimeSpanInputBoxExtender_ClientStateValuesLoaded(object sender, EventArgs e)
        {
            if (this.ClientState != null)
            {
                // this.state = new JavaScriptSerializer().Deserialize<TimeSpanInputClientState>(ClientState);

                // this.Value.From = DateTime.Parse(this.state.From, CultureInfo.CurrentCulture);
                // this.Value.Granularity = (TimeSpanUnit)this.state.Granularity;
                // this.Value.IsAge = (bool)this.state.IsAge;
                // this.text = this.state.Text;
                // this.Value.To = DateTime.Parse(this.state.To, CultureInfo.CurrentCulture);
                // this.Value.Threshold = (TimeSpanUnit)this.state.Threshold;
                // this.value = (NhsTimeSpan)this.state.Value;

                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.RegisterConverters(new JavaScriptConverter[] { new NhsTimeSpanJavascriptConverter() });

                this.state = jss.Deserialize <TimeSpanInputClientState>(ClientState);

                this.value      = this.state.Value;
                this.unitLength = (TimeSpanUnitLength)this.state.UnitLength;
            }
        }
示例#6
0
        /// <summary>
        /// Handle loading of client state
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void TimeSpanInputBoxExtender_ClientStateValuesLoaded(object sender, EventArgs e)
        {
            if (this.ClientState != null)
            {
                // this.state = new JavaScriptSerializer().Deserialize<TimeSpanInputClientState>(ClientState);

                // this.Value.From = DateTime.Parse(this.state.From, CultureInfo.CurrentCulture);
                // this.Value.Granularity = (TimeSpanUnit)this.state.Granularity;
                // this.Value.IsAge = (bool)this.state.IsAge;
                // this.text = this.state.Text;
                // this.Value.To = DateTime.Parse(this.state.To, CultureInfo.CurrentCulture);
                // this.Value.Threshold = (TimeSpanUnit)this.state.Threshold;
                // this.value = (NhsTimeSpan)this.state.Value;

                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.RegisterConverters(new JavaScriptConverter[] { new NhsTimeSpanJavascriptConverter() });

                this.state = jss.Deserialize<TimeSpanInputClientState>(ClientState);

                this.value = this.state.Value;
                this.unitLength = (TimeSpanUnitLength)this.state.UnitLength;
            }
        }
示例#7
0
        /// <summary>
        /// Raises the PreRender event. 
        /// </summary>
        /// <param name="e">An EventArgs object that contains the event data. </param>
        protected override void OnPreRender(EventArgs e)
        {          
            this.state.Value = this.Value;
            this.state.UnitLength = this.unitLength;

            // Register the NhsCuiValidation.js script with ASP.NET Ajax
            ScriptManager.GetCurrent(this.Page).Scripts.Add(new ScriptReference("NhsCui.Toolkit.Web.Validators.NhsCuiValidation.js", "NhsCui.Toolkit.Web"));
           
            JavaScriptSerializer jss = new JavaScriptSerializer();
            jss.RegisterConverters(new JavaScriptConverter[] { new NhsTimeSpanJavascriptConverter() });

            this.ClientState = jss.Serialize(this.state);

            base.OnPreRender(e);
        }
示例#8
0
        public string ToString(TimeSpanUnitLength unitLength, CultureInfo culture)
        {
            StringBuilder workingToStringValue = new StringBuilder();
            bool          longUnits;

            // decide whether to use long or short units
            if (unitLength == TimeSpanUnitLength.Automatic)
            {
                longUnits = this.IsAge && this.Years >= 2;
            }
            else
            {
                longUnits = (unitLength == TimeSpanUnitLength.Long);
            }

            // relevantGranularity holds the Granularity that is relevant for the current state of NhsTimeSpan (see if block below)
            TimeSpanUnit relevantGranularity;

            // relevantThreshold holds the Threshold that is relevant for the current state of NhsTimeSpan (see if block below)
            TimeSpanUnit relevantThreshold;

            if (this.IsAge == true)
            {
                relevantGranularity = this.granularityForAnAge;
                relevantThreshold   = this.thresholdForAnAge;
            }
            else
            {
                relevantGranularity = this.Granularity;
                relevantThreshold   = this.Threshold;
            }

            for (int timeSpanUnit = (int)relevantGranularity; timeSpanUnit >= (int)TimeSpanUnit.Seconds; timeSpanUnit--)
            {
                // Get the relevant part of the TimeSpan, flag up if the is the beginning part of the the ToString()
                long unitValue = this.GetToStringPartValue(timeSpanUnit == (int)relevantGranularity, (TimeSpanUnit)timeSpanUnit, relevantGranularity);

                if (unitValue < 0)
                {
                    unitValue = unitValue * -1;
                }

                if (unitValue > 0)
                {
                    // if necessary append a leading space
                    if (workingToStringValue.Length > 0)
                    {
                        workingToStringValue.Append(" ");
                    }

                    // Get the necessary unit text such as 'd' for days
                    string timeSpanUnitsString = GetTimeSpanUnitsString(unitValue, (TimeSpanUnit)timeSpanUnit, longUnits);

                    workingToStringValue.Append(unitValue.ToString(culture));
                    workingToStringValue.Append(timeSpanUnitsString);
                }

                if (timeSpanUnit == (int)relevantThreshold)
                {
                    break;
                }
            }

            // Negate the unit values if the dateFrom is later than dateTo
            if (this.isnegativeTimeSpan && !string.IsNullOrEmpty(workingToStringValue.ToString()))
            {
                return(string.Format(CultureInfo.CurrentCulture, "-({0})", workingToStringValue.ToString()));
            }

            return(workingToStringValue.ToString());
        }
示例#9
0
 /// <summary>
 /// Returns a string that represents a time span, with the length of units to be used specified.
 /// </summary>
 /// <param name="unitLength">The length of the units to use.</param>
 /// <returns>
 /// A string that represents the NhsTimeSpan Object.
 /// </returns>
 /// <remarks>
 /// The string returned by ToString is dependent on the granularity and threshold of the time span.
 /// If <see cref="P:NhsCui.Toolkit.DateAndTime.NhsTimeSpan.IsAge">IsAge</see> is true,
 /// <see cref="P:NhsCui.Toolkit.DateAndTime.NhsTimeSpan.Granularity">Granularity</see> is set from the time span. If
 /// <see cref="P:NhsCui.Toolkit.DateAndTime.NhsTimeSpan.IsAge">IsAge</see> is false,
 /// <see cref="P:NhsCui.Toolkit.DateAndTime.NhsTimeSpan.Granularity">Granularity</see> is set from the assigned Granularity value.
 /// <see cref="P:NhsCui.Toolkit.DateAndTime.NhsTimeSpan.Granularity">Granularity</see>
 /// may be seconds, minutes, weeks, hours, days,
 /// weeks, months or years.
 /// </remarks>
 public string ToString(TimeSpanUnitLength unitLength)
 {
     return(this.ToString(unitLength, CultureInfo.CurrentCulture));
 }
示例#10
0
        public string ToString(TimeSpanUnitLength unitLength, CultureInfo culture)
        {
            StringBuilder workingToStringValue = new StringBuilder();
            bool longUnits;

            // decide whether to use long or short units
            if (unitLength == TimeSpanUnitLength.Automatic)
            {
                longUnits = this.IsAge && this.Years >= 2;
            }
            else
            {
                longUnits = (unitLength == TimeSpanUnitLength.Long);
            }

            // relevantGranularity holds the Granularity that is relevant for the current state of CuiTimeSpan (see if block below)
            TimeSpanUnit relevantGranularity;

            // relevantThreshold holds the Threshold that is relevant for the current state of CuiTimeSpan (see if block below)
            TimeSpanUnit relevantThreshold;

            if (this.IsAge == true)
            {
                relevantGranularity = this.granularityForAnAge;
                relevantThreshold = this.thresholdForAnAge;
            }
            else
            {
                relevantGranularity = this.Granularity;
                relevantThreshold = this.Threshold;
            }

            for (int timeSpanUnit = (int)relevantGranularity; timeSpanUnit >= (int)TimeSpanUnit.Seconds; timeSpanUnit--)
            {
                // Get the relevant part of the TimeSpan, flag up if the is the beginning part of the the ToString()
                long unitValue = this.GetToStringPartValue(timeSpanUnit == (int)relevantGranularity, (TimeSpanUnit)timeSpanUnit, relevantGranularity);

                if (unitValue < 0)
                {
                    unitValue = unitValue * -1;
                }

                if (unitValue > 0)
                {
                    // if necessary append a leading space
                    if (workingToStringValue.Length > 0)
                    {
                        workingToStringValue.Append(" ");
                    }

                    // Get the necessary unit text such as 'd' for days
                    string timeSpanUnitsString = GetTimeSpanUnitsString(unitValue, (TimeSpanUnit)timeSpanUnit, longUnits);

                    workingToStringValue.Append(unitValue.ToString(culture));
                    workingToStringValue.Append(timeSpanUnitsString);
                }

                if (timeSpanUnit == (int)relevantThreshold)
                {
                    break;
                }
            }

            // Negate the unit values if the dateFrom is later than dateTo
            if (this.isnegativeTimeSpan && !string.IsNullOrEmpty(workingToStringValue.ToString()))
            {
                return string.Format(CultureInfo.CurrentCulture, "-({0})", workingToStringValue.ToString());
            }

            return workingToStringValue.ToString();
        }
示例#11
0
 /// <summary>
 /// Returns a string that represents a time span, with the length of units to be used specified. 
 /// </summary>
 /// <param name="unitLength">The length of the units to use.</param>
 /// <returns>
 /// A string that represents the CuiTimeSpan Object. 
 /// </returns>
 /// <remarks>
 /// The string returned by ToString is dependent on the granularity and threshold of the time span. 
 /// If <see cref="P:Microsoft.Cui.Controls.Common.DateAndTime.CuiTimeSpan.IsAge">IsAge</see> is true, 
 /// <see cref="P:Microsoft.Cui.Controls.Common.DateAndTime.CuiTimeSpan.Granularity">Granularity</see> is set from the time span. If 
 /// <see cref="P:Microsoft.Cui.Controls.Common.DateAndTime.CuiTimeSpan.IsAge">IsAge</see> is false, 
 /// <see cref="P:Microsoft.Cui.Controls.Common.DateAndTime.CuiTimeSpan.Granularity">Granularity</see> is set from the assigned Granularity value. 
 /// <see cref="P:Microsoft.Cui.Controls.Common.DateAndTime.CuiTimeSpan.Granularity">Granularity</see>
 /// may be seconds, minutes, weeks, hours, days, 
 /// weeks, months or years. 
 /// </remarks>
 public string ToString(TimeSpanUnitLength unitLength)
 {
     return this.ToString(unitLength, CultureInfo.CurrentCulture);
 }