/// <summary> /// Default constructor /// </summary> public TimeSpanInputBoxExtender() { this.EnableClientState = true; this.state = new TimeSpanInputClientState(); this.value = new NhsTimeSpan(); this.ClientStateValuesLoaded += new EventHandler(this.TimeSpanInputBoxExtender_ClientStateValuesLoaded); }
/// <summary> /// Parses a string that represents a time span, with CultureInfo used to parse the string. /// </summary> /// <param name="timeSpan">A string containing the value to be parsed. </param> /// <param name="result">A container for a successfully-parsed time span. </param> /// <param name="cultureInfo">The culture that should be used to parse the string.</param> /// <param name="age">Specifies whether the timespan should be considered as an age or not.</param> /// <returns>True if the value was successfully converted; otherwise, false. .</returns> /// /// <remarks> /// If the string could be parsed, the result parameter is set to an /// NhsTimeSpan object corresponding to the parsed timeSpanString. If it could not be parsed, the result is set to null. /// </remarks> public static bool TryParse(string timeSpan, out NhsTimeSpan result, CultureInfo cultureInfo, bool age) { if (timeSpan == null) { throw new ArgumentNullException("timeSpan"); } string parseExpression = BuildParseRegularExpression(); Regex regEx = new Regex(parseExpression); Match m = regEx.Match(timeSpan); if (m.Success) { DateTime from = DateTime.Now; DateTime to = from; DateTime span = from; long value; if (ParseGroupIntegerValue(m.Groups["seconds"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddSeconds(value); } if (ParseGroupIntegerValue(m.Groups["minutes"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddMinutes(value); } if (ParseGroupIntegerValue(m.Groups["hours"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddHours(value); } if (ParseGroupIntegerValue(m.Groups["weeks"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddDays(value * 7); } if (ParseGroupIntegerValue(m.Groups["days"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddDays(value); } if (ParseGroupIntegerValue(m.Groups["months"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddMonths((int)value); } if (ParseGroupIntegerValue(m.Groups["years"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddYears((int)value); } if (age) { from = span; } else { to = span; } result = new NhsTimeSpan(from, to); return(true); } result = null; return(false); }
/// <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; } }
/// <summary> /// Parses a string that represents a time span. /// </summary> /// <param name="timeSpan">A string containing the value to be parsed. </param> /// <param name="result">A container for a successfully-parsed time span. </param> /// <returns>True if the value was successfully parsed; otherwise, false. </returns> /// <remarks> /// If the string could be parsed, the result parameter is set to an /// NhsTimeSpan object corresponding to the parsed timeSpanString. If it could not be parsed, the result is set to null. /// </remarks> public static bool TryParse(string timeSpan, out NhsTimeSpan result) { return(TryParse(timeSpan, out result, CultureInfo.InvariantCulture, false)); }
/// <summary> /// Parses a string that represents a time span, with CultureInfo used to parse the string. /// </summary> /// <param name="timeSpan">A string containing the value to be parsed. </param> /// <param name="result">A container for a successfully-parsed time span. </param> /// <param name="cultureInfo">The culture that should be used to parse the string.</param> /// <returns>True if the value was successfully converted; otherwise, false. .</returns> /// /// <remarks> /// If the string could be parsed, the result parameter is set to an /// NhsTimeSpan object corresponding to the parsed timeSpanString. If it could not be parsed, the result is set to null. /// </remarks> public static bool TryParse(string timeSpan, out NhsTimeSpan result, CultureInfo cultureInfo) { return(TryParse(timeSpan, out result, cultureInfo, false)); }
/// <summary> /// Converts the provided dictionary into an object of the specified type /// </summary> /// <param name="dictionary">An IDictionary instance of property data stored as name/value pairs</param> /// <param name="type">The Type of the resulting object</param> /// <param name="serializer">The JavaScriptSerializer instance</param> /// <returns>The deserialized Object</returns> /// <remarks>KeyboardShortcut is never sent back up to the server so we do not support Deserialization</remarks> /// <exception cref="NotImplementedException">Always returns this exception</exception> public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) { NhsTimeSpan deserialisationTarget = new NhsTimeSpan(); deserialisationTarget.From = (dictionary.ContainsKey("_from") ? ((DateTime)dictionary["_from"]).ToLocalTime() : ((DateTime)dictionary["from"]).ToLocalTime()); deserialisationTarget.To = (dictionary.ContainsKey("_to") ? ((DateTime)dictionary["_to"]).ToLocalTime() : ((DateTime)dictionary["to"]).ToLocalTime()); deserialisationTarget.Granularity = (dictionary.ContainsKey("_granularity") ? (TimeSpanUnit)dictionary["_granularity"] : (TimeSpanUnit)dictionary["granularity"]); deserialisationTarget.IsAge = (dictionary.ContainsKey("_isAge") ? (bool)dictionary["_isAge"] : (bool)dictionary["isAge"]); deserialisationTarget.Threshold = (dictionary.ContainsKey("_threshold") ? (TimeSpanUnit)dictionary["_threshold"] : (TimeSpanUnit)dictionary["threshold"]); return deserialisationTarget; }
/// <summary> /// Parses a string that represents a time span, with CultureInfo used to parse the string. /// </summary> /// <param name="timeSpan">A string containing the value to be parsed. </param> /// <param name="result">A container for a successfully-parsed time span. </param> /// <param name="cultureInfo">The culture that should be used to parse the string.</param> /// <param name="age">Specifies whether the timespan should be considered as an age or not.</param> /// <returns>True if the value was successfully converted; otherwise, false. .</returns> /// /// <remarks> /// If the string could be parsed, the result parameter is set to an /// NhsTimeSpan object corresponding to the parsed timeSpanString. If it could not be parsed, the result is set to null. /// </remarks> public static bool TryParse(string timeSpan, out NhsTimeSpan result, CultureInfo cultureInfo, bool age) { if (timeSpan == null) { throw new ArgumentNullException("timeSpan"); } string parseExpression = BuildParseRegularExpression(); Regex regEx = new Regex(parseExpression); Match m = regEx.Match(timeSpan); if (m.Success) { DateTime from = DateTime.Now; DateTime to = from; DateTime span = from; long value; if (ParseGroupIntegerValue(m.Groups["seconds"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddSeconds(value); } if (ParseGroupIntegerValue(m.Groups["minutes"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddMinutes(value); } if (ParseGroupIntegerValue(m.Groups["hours"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddHours(value); } if (ParseGroupIntegerValue(m.Groups["weeks"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddDays(value * 7); } if (ParseGroupIntegerValue(m.Groups["days"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddDays(value); } if (ParseGroupIntegerValue(m.Groups["months"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddMonths((int)value); } if (ParseGroupIntegerValue(m.Groups["years"], cultureInfo, out value)) { value = age ? value * -1 : value; span = span.AddYears((int)value); } if (age) { from = span; } else { to = span; } result = new NhsTimeSpan(from, to); return true; } result = null; return false; }
/// <summary> /// Parses a string that represents a time span, with CultureInfo used to parse the string. /// </summary> /// <param name="timeSpan">A string containing the value to be parsed. </param> /// <param name="result">A container for a successfully-parsed time span. </param> /// <param name="cultureInfo">The culture that should be used to parse the string.</param> /// <returns>True if the value was successfully converted; otherwise, false. .</returns> /// /// <remarks> /// If the string could be parsed, the result parameter is set to an /// NhsTimeSpan object corresponding to the parsed timeSpanString. If it could not be parsed, the result is set to null. /// </remarks> public static bool TryParse(string timeSpan, out NhsTimeSpan result, CultureInfo cultureInfo) { return TryParse(timeSpan, out result, cultureInfo, false); }
/// <summary> /// Parses a string that represents a time span. /// </summary> /// <param name="timeSpan">A string containing the value to be parsed. </param> /// <param name="result">A container for a successfully-parsed time span. </param> /// <returns>True if the value was successfully parsed; otherwise, false. </returns> /// <remarks> /// If the string could be parsed, the result parameter is set to an /// NhsTimeSpan object corresponding to the parsed timeSpanString. If it could not be parsed, the result is set to null. /// </remarks> public static bool TryParse(string timeSpan, out NhsTimeSpan result) { return TryParse(timeSpan, out result, CultureInfo.InvariantCulture, false); }
/// <summary> /// Apply the resource strings for the labels /// </summary> private void SetDefaultValues() { this.dateOfBirth = new NhsDate(DateTime.MinValue); this.dateOfDeath = new NhsDate(DateTime.MinValue); this.age = new NhsTimeSpan(this.dateOfBirth.DateValue, DateTime.Now); this.subsectionOneTitleLabel.Text = PatientBannerControl.Resources.SubsectionOneTitle; this.dateOfBirthLabel.Text = PatientBannerControl.Resources.DateOfBirthLabelText; this.dateOfDeathLabel.Text = PatientBannerControl.Resources.DateOfDeathLabelText; this.dateOfDeathData.Visible = false; this.dateOfDeathLabel.Visible = false; this.identifierLabel.Text = PatientBannerControl.Resources.IdentifierLabelText; this.subsectionTwoTitleLabel.Text = PatientBannerControl.Resources.SubsectionTwoTitle; this.genderLabel.Text = PatientBannerControl.Resources.GenderLabelText; this.ageAtDeathLabel.Text = PatientBannerControl.Resources.AgeAtDeathLabelText; this.preferredNameLabel.Text = PatientBannerControl.Resources.PreferredNameLabelText; this.addressField.AddressType = AddressLabelControl.Resources.AddressType; this.viewAllContactDetailsLink.Text = PatientBannerControl.Resources.ViewAllContactDetailsLinkText; this.viewAllergyRecordLink.Text = PatientBannerControl.Resources.ViewAllergyRecordLinkText; this.viewAllAddressesLink.Text = PatientBannerControl.Resources.ViewAllAddressLinkText; this.ApplyDefaultDeceasedPatientBackgroundImage(); this.ApplyDefaultCollapsedImage(); this.ApplyDefaultExpandedImage(); this.ApplyZoneOneTooltip(); this.ApplyZoneTwoTooltip(); this.ApplyZoneOneBorderColor(); this.ApplyDefaultAllergyIcons(); }