Пример #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;
                    }
                }
            }
        }
 /// <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;
             }
         }
     }
 }