Esempio n. 1
0
        public void BaseValidator_Validated(object sender, EventArgs e)
        {
            BaseValidator validator = (BaseValidator)sender;

            // If validator is valid, remove from list
            if (validator.IsValid)
            {
                this.validationErrorsList.Items.Remove(validator);
            }
            // Add validator to list, in tab index order
            else
            {
                if (!this.validationErrorsList.Items.Contains(validator))
                {
                    decimal tabIndex = validator.FlattenedTabIndex;
                    for (int i = 0; i < this.validationErrorsList.Items.Count; i++)
                    {
                        BaseValidator currentValidator = (BaseValidator)this.validationErrorsList.Items[i];
                        if (tabIndex < currentValidator.FlattenedTabIndex)
                        {
                            this.validationErrorsList.Items.Insert(i, validator);
                            return;
                        }
                    }
                    this.validationErrorsList.Items.Add(validator);
                }
            }
        }
Esempio n. 2
0
        public void Validate()
        {
            // Validate
            BaseValidator firstInTabOrder = null;

            foreach (BaseValidator validator in GetValidators())
            {
                // Validate control
                validator.Validate();

                // Set focus on the control it its invalid and the earliest invalid
                // control in the tab order
                if (!validator.IsValid)
                {
                    if ((firstInTabOrder == null) ||
                        (firstInTabOrder.FlattenedTabIndex > validator.FlattenedTabIndex))
                    {
                        firstInTabOrder = validator;
                    }
                }
            }

            OnSummarize(new SummarizeEventArgs(GetValidators(), HostingForm));

            // Select first invalid control in tab order, if any
            if (firstInTabOrder != null)
            {
                firstInTabOrder.ControlToValidate.Focus();
            }
        }
Esempio n. 3
0
        private void validationErrorsList_DoubleClick(object sender, System.EventArgs e)
        {
            // Set focus on the selected BaseValidator's ControlToValidate ie
            // in the owner form
            BaseValidator selected = (BaseValidator)this.validationErrorsList.SelectedItem;

            selected.ControlToValidate.Focus();
        }
Esempio n. 4
0
 /// <summary>
 ///        Returns the zero-based index of the first occurrence of a <see cref="BaseValidator"/>
 ///        in the <c>ValidatorCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="BaseValidator"/> to locate in the <c>ValidatorCollection</c>.</param>
 /// <returns>
 ///        The zero-based index of the first occurrence of <paramref name="item"/>
 ///        in the entire <c>ValidatorCollection</c>, if found; otherwise, -1.
 ///    </returns>
 public virtual int IndexOf(BaseValidator item)
 {
     for (int i = 0; i != m_count; ++i)
     {
         if (m_array[i].Equals(item))
         {
             return(i);
         }
     }
     return(-1);
 }
Esempio n. 5
0
 /// <summary>
 ///        Determines whether a given <see cref="BaseValidator"/> is in the <c>ValidatorCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="BaseValidator"/> to check for.</param>
 /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>ValidatorCollection</c>; otherwise, <c>false</c>.</returns>
 public virtual bool Contains(BaseValidator item)
 {
     for (int i = 0; i != m_count; ++i)
     {
         if (m_array[i].Equals(item))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
    public static void DeRegister(BaseValidator validator, Form hostingForm)
    {

      // Remove this validator from the list of registered validators
      ValidatorCollection validators = (ValidatorCollection)_validators[hostingForm];
      if (validators != null)
      {
        validators.Remove(validator);
        // Remove form bucket if all validators on the form are de-registered
        if (validators.Count == 0) _validators.Remove(hostingForm);
      }
    }
Esempio n. 7
0
        /// <summary>
        ///        Adds a <see cref="BaseValidator"/> to the end of the <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="BaseValidator"/> to be added to the end of the <c>ValidatorCollection</c>.</param>
        /// <returns>The index at which the value has been added.</returns>
        public virtual int Add(BaseValidator item)
        {
            if (m_count == m_array.Length)
            {
                EnsureCapacity(m_count + 1);
            }

            m_array[m_count] = item;
            m_version++;

            return(m_count++);
        }
Esempio n. 8
0
        /// <summary>
        ///        Removes the first occurrence of a specific <see cref="BaseValidator"/> from the <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="BaseValidator"/> to remove from the <c>ValidatorCollection</c>.</param>
        /// <exception cref="ArgumentException">
        ///        The specified <see cref="BaseValidator"/> was not found in the <c>ValidatorCollection</c>.
        /// </exception>
        public virtual void Remove(BaseValidator item)
        {
            int i = IndexOf(item);

            if (i < 0)
            {
                throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");
            }

            ++m_version;
            RemoveAt(i);
        }
Esempio n. 9
0
    public static void Register(BaseValidator validator, Form hostingForm)
    {

      // Create form bucket if it doesn't exist
      if (_validators[hostingForm] == null)
      {
        _validators[hostingForm] = new ValidatorCollection();
      }

      // Add this validator to the list of registered validators
      ValidatorCollection validators =
        (ValidatorCollection)_validators[hostingForm];
      validators.Add(validator);
    }
Esempio n. 10
0
        public static void Register(BaseValidator validator, Form hostingForm)
        {
            // Create form bucket if it doesn't exist
            if (_validators[hostingForm] == null)
            {
                _validators[hostingForm] = new ValidatorCollection();
            }

            // Add this validator to the list of registered validators
            ValidatorCollection validators =
                (ValidatorCollection)_validators[hostingForm];

            validators.Add(validator);
        }
Esempio n. 11
0
        public int Compare(object x, object y)
        {
            BaseValidator xBaseValidator = (BaseValidator)x;
            BaseValidator yBaseValidator = (BaseValidator)y;

            if (xBaseValidator.FlattenedTabIndex < yBaseValidator.FlattenedTabIndex)
            {
                return(-1);
            }
            if (xBaseValidator.FlattenedTabIndex > yBaseValidator.FlattenedTabIndex)
            {
                return(1);
            }
            return(0);
        }
Esempio n. 12
0
        public static void DeRegister(BaseValidator validator, Form hostingForm)
        {
            // Remove this validator from the list of registered validators
            ValidatorCollection validators = (ValidatorCollection)_validators[hostingForm];

            if (validators != null)
            {
                validators.Remove(validator);
                // Remove form bucket if all validators on the form are de-registered
                if (validators.Count == 0)
                {
                    _validators.Remove(hostingForm);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        ///        Removes the element at the specified index of the <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///        <para><paramref name="index"/> is less than zero</para>
        ///        <para>-or-</para>
        ///        <para><paramref name="index"/> is equal to or greater than <see cref="ValidatorCollection.Count"/>.</para>
        /// </exception>
        public virtual void RemoveAt(int index)
        {
            ValidateIndex(index); // throws

            m_count--;

            if (index < m_count)
            {
                Array.Copy(m_array, index + 1, m_array, index, m_count - index);
            }

            // We can't set the deleted entry equal to null, because it might be a value type.
            // Instead, we'll create an empty single-element array of the right type and copy it
            // over the entry we want to erase.
            BaseValidator[] temp = new BaseValidator[1];
            Array.Copy(temp, 0, m_array, m_count, 1);
            m_version++;
        }
Esempio n. 14
0
        /// <summary>
        ///        Inserts an element into the <c>ValidatorCollection</c> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
        /// <param name="item">The <see cref="BaseValidator"/> to insert.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///        <para><paramref name="index"/> is less than zero</para>
        ///        <para>-or-</para>
        ///        <para><paramref name="index"/> is equal to or greater than <see cref="ValidatorCollection.Count"/>.</para>
        /// </exception>
        public virtual void Insert(int index, BaseValidator item)
        {
            ValidateIndex(index, true); // throws

            if (m_count == m_array.Length)
            {
                EnsureCapacity(m_count + 1);
            }

            if (index < m_count)
            {
                Array.Copy(m_array, index, m_array, index + 1, m_count - index);
            }

            m_array[index] = item;
            m_count++;
            m_version++;
        }
Esempio n. 15
0
 public override void Remove(BaseValidator x)
 {
     lock (this.m_root)
         m_collection.Remove(x);
 }
Esempio n. 16
0
        /// <summary>
        ///        Removes the first occurrence of a specific <see cref="BaseValidator"/> from the <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="BaseValidator"/> to remove from the <c>ValidatorCollection</c>.</param>
        /// <exception cref="ArgumentException">
        ///        The specified <see cref="BaseValidator"/> was not found in the <c>ValidatorCollection</c>.
        /// </exception>
        public virtual void Remove(BaseValidator item)
        {
            int i = IndexOf(item);
              if (i < 0)
            throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");

              ++m_version;
              RemoveAt(i);
        }
Esempio n. 17
0
 public override int IndexOf(BaseValidator x)
 {
     lock(this.m_root)
       return m_collection.IndexOf(x);
 }
Esempio n. 18
0
 public override void Remove(BaseValidator x)
 {
     lock(this.m_root)
       m_collection.Remove(x);
 }
Esempio n. 19
0
 public override void Remove(BaseValidator x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
Esempio n. 20
0
 public override bool Contains(BaseValidator x)
 {
     lock(this.m_root)
       return m_collection.Contains(x);
 }
Esempio n. 21
0
        /// <summary>
        ///        Adds a <see cref="BaseValidator"/> to the end of the <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="BaseValidator"/> to be added to the end of the <c>ValidatorCollection</c>.</param>
        /// <returns>The index at which the value has been added.</returns>
        public virtual int Add(BaseValidator item)
        {
            if (m_count == m_array.Length)
            EnsureCapacity(m_count + 1);

              m_array[m_count] = item;
              m_version++;

              return m_count++;
        }
Esempio n. 22
0
 public override bool Contains(BaseValidator x)
 {
     return m_collection.Contains(x);
 }
Esempio n. 23
0
 public override int Add(BaseValidator x)
 {
     lock (this.m_root)
         return(m_collection.Add(x));
 }
Esempio n. 24
0
 /// <summary>
 ///        Initializes a new instance of the <c>ValidatorCollection</c> class
 ///        that contains elements copied from the specified <see cref="BaseValidator"/> array.
 /// </summary>
 /// <param name="a">The <see cref="BaseValidator"/> array whose elements are copied to the new list.</param>
 public ValidatorCollection(BaseValidator[] a)
 {
     m_array = new BaseValidator[a.Length];
       AddRange(a);
 }
Esempio n. 25
0
 public override bool Contains(BaseValidator x)
 {
     lock (this.m_root)
         return(m_collection.Contains(x));
 }
Esempio n. 26
0
 public override bool Contains(BaseValidator x)
 {
     return(m_collection.Contains(x));
 }
Esempio n. 27
0
 public override int IndexOf(BaseValidator x)
 {
     lock (this.m_root)
         return(m_collection.IndexOf(x));
 }
Esempio n. 28
0
        /// <summary>
        ///        Removes the element at the specified index of the <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///        <para><paramref name="index"/> is less than zero</para>
        ///        <para>-or-</para>
        ///        <para><paramref name="index"/> is equal to or greater than <see cref="ValidatorCollection.Count"/>.</para>
        /// </exception>
        public virtual void RemoveAt(int index)
        {
            ValidateIndex(index); // throws

              m_count--;

              if (index < m_count) {
            Array.Copy(m_array, index + 1, m_array, index, m_count - index);
              }

              // We can't set the deleted entry equal to null, because it might be a value type.
              // Instead, we'll create an empty single-element array of the right type and copy it
              // over the entry we want to erase.
              BaseValidator[] temp = new BaseValidator[1];
              Array.Copy(temp, 0, m_array, m_count, 1);
              m_version++;
        }
Esempio n. 29
0
 public override void CopyTo(BaseValidator[] array, int start)
 {
     m_collection.CopyTo(array,start);
 }
Esempio n. 30
0
 public override int AddRange(BaseValidator[] x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
Esempio n. 31
0
 public override void Remove(BaseValidator x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
Esempio n. 32
0
 public override void CopyTo(BaseValidator[] array)
 {
     m_collection.CopyTo(array);
 }
Esempio n. 33
0
 public override int IndexOf(BaseValidator x)
 {
     return(m_collection.IndexOf(x));
 }
Esempio n. 34
0
 public override int IndexOf(BaseValidator x)
 {
     return m_collection.IndexOf(x);
 }
Esempio n. 35
0
        protected override void Summarize(object sender, SummarizeEventArgs e)
        {
            // Don’t validate if no validators were passed
            if (e.Validators.Count == 0)
            {
                return;
            }

            BaseContainerValidator       extendee    = (BaseContainerValidator)sender;
            ValidationSummaryDisplayMode displayMode = GetDisplayMode(extendee);
            ValidatorCollection          validators  = e.Validators;

            // Make sure there are validators
            if ((validators == null) || (validators.Count == 0))
            {
                return;
            }

            string errorMessage = GetErrorMessage(extendee);
            string errorCaption = GetErrorCaption(extendee);

            // Get error text, if provided
            if (errorMessage == null)
            {
                errorMessage = "";
            }

            // Get error caption, if provided
            if (errorCaption == null)
            {
                errorCaption = "";
            }

            // Build summary message body
            string errors = "";

            if (displayMode == ValidationSummaryDisplayMode.Simple)
            {
                // Build Simple message
                errors = errorMessage;
            }
            else
            {
                // Build List, BulletList or SingleParagraph
                foreach (object validator in base.Sort(validators))
                {
                    BaseValidator current = (BaseValidator)validator;
                    if (!current.IsValid)
                    {
                        switch (displayMode)
                        {
                        case ValidationSummaryDisplayMode.List:
                            errors += string.Format("{0}\n", current.ErrorMessage);
                            break;

                        case ValidationSummaryDisplayMode.BulletList:
                            errors += string.Format("- {0}\n", current.ErrorMessage);
                            break;

                        case ValidationSummaryDisplayMode.SingleParagraph:
                            errors += string.Format("{0}. ", current.ErrorMessage);
                            break;
                        }
                    }
                }
                // Prepend error message, if provided
                if ((errors != "") && (errorMessage != ""))
                {
                    errors = string.Format("{0}\n\n{1}", errorMessage.Trim(), errors);
                }
            }

            // Display summary message
            // "if( errors.Trim().Length > 0 )" thanks to John V. Barone and Jorge Matos
            if (errors.Trim().Length > 0)
            {
                MessageBox.Show(errors, errorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 36
0
 public override int AddRange(BaseValidator[] x)
 {
     lock(this.m_root)
       return m_collection.AddRange(x);
 }
Esempio n. 37
0
        /// <summary>
        ///        Copies the entire <c>ValidatorCollection</c> to a one-dimensional
        ///        <see cref="BaseValidator"/> array, starting at the specified index of the target array.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="BaseValidator"/> array to copy to.</param>
        /// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param>
        public virtual void CopyTo(BaseValidator[] array, int start)
        {
            if (m_count > array.GetUpperBound(0) + 1 - start)
            throw new System.ArgumentException("Destination array was not long enough.");

              Array.Copy(m_array, 0, array, start, m_count);
        }
Esempio n. 38
0
 public override void CopyTo(BaseValidator[] array, int start)
 {
     lock(this.m_root)
       m_collection.CopyTo(array,start);
 }
Esempio n. 39
0
 /// <summary>
 ///        Returns the zero-based index of the first occurrence of a <see cref="BaseValidator"/>
 ///        in the <c>ValidatorCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="BaseValidator"/> to locate in the <c>ValidatorCollection</c>.</param>
 /// <returns>
 ///        The zero-based index of the first occurrence of <paramref name="item"/> 
 ///        in the entire <c>ValidatorCollection</c>, if found; otherwise, -1.
 ///    </returns>
 public virtual int IndexOf(BaseValidator item)
 {
     for (int i=0; i != m_count; ++i)
     if (m_array[i].Equals(item))
       return i;
       return -1;
 }
Esempio n. 40
0
 public override void Insert(int pos, BaseValidator x)
 {
     lock(this.m_root)
       m_collection.Insert(pos,x);
 }
Esempio n. 41
0
        /// <summary>
        ///        Inserts an element into the <c>ValidatorCollection</c> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
        /// <param name="item">The <see cref="BaseValidator"/> to insert.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///        <para><paramref name="index"/> is less than zero</para>
        ///        <para>-or-</para>
        ///        <para><paramref name="index"/> is equal to or greater than <see cref="ValidatorCollection.Count"/>.</para>
        /// </exception>
        public virtual void Insert(int index, BaseValidator item)
        {
            ValidateIndex(index, true); // throws

              if (m_count == m_array.Length)
            EnsureCapacity(m_count + 1);

              if (index < m_count) {
            Array.Copy(m_array, index, m_array, index + 1, m_count - index);
              }

              m_array[index] = item;
              m_count++;
              m_version++;
        }
Esempio n. 42
0
 /// <summary>
 ///        Determines whether a given <see cref="BaseValidator"/> is in the <c>ValidatorCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="BaseValidator"/> to check for.</param>
 /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>ValidatorCollection</c>; otherwise, <c>false</c>.</returns>
 public virtual bool Contains(BaseValidator item)
 {
     for (int i=0; i != m_count; ++i)
     if (m_array[i].Equals(item))
       return true;
       return false;
 }
Esempio n. 43
0
 public override void Insert(int pos, BaseValidator x)
 {
     lock (this.m_root)
         m_collection.Insert(pos, x);
 }
Esempio n. 44
0
        /// <summary>
        ///        Adds the elements of a <see cref="BaseValidator"/> array to the current <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="x">The <see cref="BaseValidator"/> array whose elements should be added to the end of the <c>ValidatorCollection</c>.</param>
        /// <returns>The new <see cref="ValidatorCollection.Count"/> of the <c>ValidatorCollection</c>.</returns>
        public virtual int AddRange(BaseValidator[] x)
        {
            if (m_count + x.Length >= m_array.Length)
            EnsureCapacity(m_count + x.Length);

              Array.Copy(x, 0, m_array, m_count, x.Length);
              m_count += x.Length;
              m_version++;

              return m_count;
        }
Esempio n. 45
0
 /// <summary>
 ///        Copies the entire <c>ValidatorCollection</c> to a one-dimensional
 ///        string array.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="BaseValidator"/> array to copy to.</param>
 public virtual void CopyTo(BaseValidator[] array)
 {
     this.CopyTo(array, 0);
 }