Exemplo n.º 1
0
 private static void DatePickerOnDateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     var datePicker = sender as DatePicker;
     if (datePicker != null)
     {
         var text = e.Text;
         DateTime dateTime;
         if (DateTime.TryParseExact(text, "yyyyMMdd", CultureInfo.CurrentUICulture, DateTimeStyles.None, out dateTime))
         {
             datePicker.SelectedDate = dateTime;
         }
     }
 }
    protected override void OnDateValidationError( DatePickerDateValidationErrorEventArgs e )
    {
      base.OnDateValidationError( e );

      // This validation error may have been raised by the "CommitInput()" call.
      // If this is the case, use the _commitException member.
      if( InputValidationError != null )
      {
        InputValidationErrorEventArgs args = ( _commitException != null )
          ? new InputValidationErrorEventArgs( _commitException )
          : new InputValidationErrorEventArgs( e.Exception );

        InputValidationError( this, args );
        if( args.ThrowException )
        {
          throw args.Exception;
        }
      }
    }
Exemplo n.º 3
0
        // iT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID

        /// <summary>
        /// Input text is parsed in the correct format and changed into a DateTime object.
        /// If the text can not be parsed TextParseError Event is thrown.
        /// </summary>
        private DateTime?ParseText(string text)
        {
            DateTime newSelectedDate;

            // TryParse is not used in order to be able to pass the exception to the TextParseError event
            try
            {
                newSelectedDate = DateTime.Parse(text, DateTimeHelper.GetDateFormat(DateTimeHelper.GetCulture(this)));

                if (Calendar.IsValidDateSelection(this._calendar, newSelectedDate))
                {
                    return(newSelectedDate);
                }
                else
                {
                    DatePickerDateValidationErrorEventArgs dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text", SR.Get(SRID.Calendar_OnSelectedDateChanged_InvalidValue)), text);
                    OnDateValidationError(dateValidationError);

                    if (dateValidationError.ThrowException)
                    {
                        throw dateValidationError.Exception;
                    }
                }
            }
            catch (FormatException ex)
            {
                DatePickerDateValidationErrorEventArgs textParseError = new DatePickerDateValidationErrorEventArgs(ex, text);
                OnDateValidationError(textParseError);

                if (textParseError.ThrowException && textParseError.Exception != null)
                {
                    throw textParseError.Exception;
                }
            }

            return(null);
        }
Exemplo n.º 4
0
 private void DatePicker_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     lblError.Text = "'" + e.Text +
         "' is not a valid value because " + e.Exception.Message;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Issue: The OOB DatePicker does not allow re-setting the picker to a null-value. Erasing the complete
 /// contents of the textbox does not cause any validation errors wherein you would have re-setted the SelectedDate to null
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dtEndDate_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Raises the DateValidationError event.
 /// </summary>
 /// <param name="e">A DatePickerDateValidationErrorEventArgs that contains the event data.</param> 
 protected virtual void OnDateValidationError(DatePickerDateValidationErrorEventArgs e) {
     var handler = DateValidationError;
     if (handler != null)
         handler(this, e);
 }
Exemplo n.º 7
0
        // IT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID 
        /// <summary>
        /// Input text is parsed in the correct format and changed into a DateTime object. 
        /// If the text can not be parsed TextParseError Event is thrown.
        /// </summary>
        private DateTime? ParseText(string text) {
            // TryParse is not used in order to be able to pass the exception to the TextParseError event 
            try {
                var newSelectedDate = DateTime.Parse(text, Engine.GetDateFormat(Engine.GetCulture(this)));

                if (Calendar.IsValidDateSelection(_calendar, newSelectedDate)) {
                    return newSelectedDate;
                }
                var dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text"), text);
                OnDateValidationError(dateValidationError);
                if (dateValidationError.ThrowException)
                    throw dateValidationError.Exception;
            } catch (FormatException ex) {
                var textParseError = new DatePickerDateValidationErrorEventArgs(ex, text);
                OnDateValidationError(textParseError);
                if (textParseError.ThrowException && textParseError.Exception != null)
                    throw textParseError.Exception;
            }
            return null;
        }
 /// <summary>
 /// Raises the
 /// <see cref="E:System.Windows.Controls.DatePicker.DateValidationError" />
 /// event.
 /// </summary>
 /// <param name="e">
 /// A
 /// <see cref="T:System.Windows.Controls.DatePickerDateValidationErrorEventArgs" />
 /// that contains the event data.
 /// </param>
 protected virtual void OnDateValidationError(DatePickerDateValidationErrorEventArgs e)
 {
     EventHandler<DatePickerDateValidationErrorEventArgs> handler = this.DateValidationError;
     if (handler != null)
     {
         handler(this, e);
     }
 }
        /// <summary>
        /// Input text is parsed in the correct format and changed into a
        /// DateTime object.  If the text can not be parsed TextParseError Event
        /// is thrown.
        /// </summary>
        /// <param name="text">Inherited code: Requires comment.</param>
        /// <returns>
        /// IT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE
        /// DATETIME VALUE IF IT IS VALID.
        /// </returns>
        private DateTime? ParseText(string text)
        {
            DateTime newSelectedDate;

            // TryParse is not used in order to be able to pass the exception to
            // the TextParseError event
            try
            {
                newSelectedDate = DateTime.Parse(text, DateTimeHelper.GetCurrentDateFormat());

                if (Calendar.IsValidDateSelection(this._calendar, newSelectedDate))
                {
                    return newSelectedDate;
                }
                else
                {
                    DatePickerDateValidationErrorEventArgs dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text", System.Windows.Controls.Properties.Resources.Calendar_OnSelectedDateChanged_InvalidValue), text);
                    OnDateValidationError(dateValidationError);

                    if (dateValidationError.ThrowException)
                    {
                        throw dateValidationError.Exception;
                    }
                }
            }
            catch (FormatException ex)
            {
                DatePickerDateValidationErrorEventArgs textParseError = new DatePickerDateValidationErrorEventArgs(ex, text);
                OnDateValidationError(textParseError);

                if (textParseError.ThrowException)
                {
                    throw textParseError.Exception;
                }
            }
            return null;
        }
Exemplo n.º 10
0
 private void DatePicker_DateValidationError_1(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     e.ThrowException = false;
 }
 protected virtual new void OnDateValidationError(DatePickerDateValidationErrorEventArgs e)
 {
 }
Exemplo n.º 12
0
 protected virtual new void OnDateValidationError(DatePickerDateValidationErrorEventArgs e)
 {
 }