Exemple #1
0
 protected override void OnParsing(
     ParseEventArgs e)
 {
     if (SuppressTextInput)
     {
         // this is readonly control like ImageEdit, BackgroundEdit, text
         // of such control can not be changed by the user
         // so parsing is not needed
         e.Value     = null;
         e.Succeeded = false;
     }
     else
     {
         var ttva = new TextToValueArgs(e.Text);
         if (TextToValue(ttva))
         {
             e.Value     = ttva.Value;
             e.Succeeded = true;
         }
         else
         {
             e.Succeeded = false;
             e.ParseInfo.ErrorMessage = ttva.ErrorMessage;
         }
     }
     base.OnParsing(e);
 }
Exemple #2
0
        protected override bool TextToValue(
            TextToValueArgs e)
        {
            if (string.IsNullOrEmpty(e.Text))
            {
                e.Value = Color.Transparent;
                return(true);
            }

            Color color;

            if (!Utils.TryParseColorFromDisplayText(e.Text, _emptyColorCaption, out color))
            {
                return(false);
            }

            if (color == Color.Transparent && !AllowTransparent)
            {
                return(false);
            }
            if (color.IsEmpty && !AllowEmpty)
            {
                return(false);
            }

            e.Value = color;
            return(true);
        }
Exemple #3
0
        protected override bool TextToValue(
            TextToValueArgs e)
        {
            if (string.IsNullOrEmpty(e.Text))
            {
                return(false);
            }

            string s = e.Text;

            if (!string.IsNullOrEmpty(_format))
            {
                foreach (char c in _format.Replace("{0}", string.Empty))
                {
                    s = s.Replace(new string(c, 1), string.Empty);
                }
            }
            decimal v;

            if (!decimal.TryParse(s, out v))
            {
                if (!decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out v))
                {
                    return(false);
                }
            }

            //
            if (_minValue.HasValue && v < _minValue.Value)
            {
                e.Value = ToDataTypeValue(_minValue.Value);
            }
            else if (_maxValue.HasValue && v > _maxValue.Value)
            {
                e.Value = ToDataTypeValue(_maxValue.Value);
            }
            else
            {
                e.Value = ToDataTypeValue(ToActualValue(v));
            }

            return(true);
        }
Exemple #4
0
        protected override bool TextToValue(TextToValueArgs e)
        {
            if (string.IsNullOrEmpty(e.Text))
            {
                return(false);
            }

            try
            {
                object v = Enum.Parse(_enumType, e.Text);
                if (IndexOfValue(v) == -1)
                {
                    return(false);
                }
                e.Value = v;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #5
0
 /// <summary>
 /// Should be overridden in deviced class and convert string to value.
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 protected virtual bool TextToValue(
     TextToValueArgs e)
 {
     throw new Exception("TextToValue() should be overridden in derived class.");
 }