Exemplo n.º 1
0
        /// <summary>OnValidating
        /// Raises the LostFoOnValidating  event.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void  OnValidating(CancelEventArgs e)

        {
            if (string.IsNullOrEmpty(Text))
            {
                this.BackColor = Color.White;
                Text           = _defaultText;
            }
            else
            {
                if (!Regex.IsMatch(Text, ClsRegex.numericGetRegex(TextType.IsNumber, _NumberType, _NumberPower)))
                {
                    this.BackColor = Color.Red;
                    ClsGlobel.ShowErrorToolTip(" البيان المدخل غير صحيح", this.Location);
                    e.Cancel = true;
                }
                else
                {
                    decimal _newvalue = Convert.ToDecimal(Text);
                    if (_newvalue > _maxValue || _newvalue < _minValue)
                    {
                        ClsGlobel.ShowErrorToolTip("القيمة غير صحيحة", this.Location);
                        this.BackColor = Color.Red;
                        e.Cancel       = true;
                    }
                    else
                    {
                        this.BackColor = Color.White;
                        _value         = _newvalue;
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of the NumericTextBox
 /// </summary>
 public HNumericTextBox()
 {
     TextAlign    = HorizontalAlignment.Right;
     TextType     = TextType.IsNumber;
     _NumberType  = NumberType.Decimal;
     _NumberPower = NumberPower.positiveOrNegative;
     regex        = ClsRegex.numericGetRegex(TextType.IsNumber, _NumberType, _NumberPower);
     _minValue    = -10000000;
     _maxValue    = 10000000;
     if (_required == true)
     {
         BackColor = _requiredColor;
     }
 }
        /// <summary>OnLostFocus
        /// Raises the LostFocus event.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        protected override void OnLostFocus(EventArgs e)
        {
            if (string.IsNullOrEmpty(Text))
            {
                Text = _defaultText;
            }
            else
            if (!Regex.IsMatch(Text, ClsRegex.numericGetRegex(TextType.IsNumber, _NumberType, _NumberPower)))
            {
                this.BackColor = Color.Red;
            }
            else
            {
                this.BackColor = Color.White;
            }

            base.OnLostFocus(e);
        }
 /// <summary>OnValidating
 /// Raises the LostFoOnValidating  event.
 /// </summary>
 /// <param name="e">Event arguments.</param>
 protected override void OnValidating(CancelEventArgs e)
 {
     if (this._DataType == HControls.DataType.String)
     {
     }
     else if (this._DataType == HControls.DataType.Decimal || this._DataType == HControls.DataType.Integer)
     {
         if (string.IsNullOrEmpty(Text))
         {
             this.BackColor = Color.White;
             Text           = _defaultText;
         }
         else
         {
             if (!Regex.IsMatch(Text, ClsRegex.numericGetRegex(TextType.IsNumber, _NumberType, _NumberPower)))
             {
                 this.BackColor = Color.Red;
                 ClsGlobel.ShowErrorToolTip(" البيان المدخل غير صحيح", this.Location);
                 e.Cancel = true;
             }
             else
             {
                 decimal _newvalue = Convert.ToDecimal(Text);
                 //if (_newvalue > _maxValue || _newvalue < _minValue)
                 //{
                 //    ClsGlobel.ShowErrorToolTip("القيمة غير صحيحة", this.Location);
                 //    this.BackColor = Color.Red;
                 //    e.Cancel = true;
                 //}
                 //else
                 //{
                 //    this.BackColor = Color.White;
                 //    _value = _newvalue;
                 //}
             }
         }
     }
     else if (this._DataType == DataType.DateTime && Text != null && Text != "")
     {
         try
         {
             this.Text = Convert.ToDateTime(Text).ToString("yyyy/MM/dd");
         }
         catch (Exception)
         {
             if (Regex.IsMatch(Text, @"^(0?[1-9]|[1][0-9]|[2][0-9]|30|31)$"))
             {
                 this.Text = new DateTime(DateTime.Now.Year, DateTime.Now.Month, Convert.ToInt32(this.Text)).ToString("yyyy/MM/dd");
             }
             else if (Regex.IsMatch(Text, @"^(0?[1-9]|[1][0-9]|[2][0-9]|30|31)[- /.](0?[1-9]|10|11|12)$"))
             {
                 this.Text = new DateTime(DateTime.Now.Year, DateTime.Now.Month, Convert.ToInt32(this.Text)).ToString("yyyy/MM/dd");
             }
             else
             {
                 this.BackColor = Color.Red;
                 ClsGlobel.ShowErrorToolTip(" البيان المدخل غير صحيح", this.Location);
                 e.Cancel = true;
             }
         }
     }
 }