public void LoadValidators(ValidatorCollection validators)
        {
            // Note: validators should contain all validators under
              // the jurisdiction of the BaseContainerValidator so
              // we can handle both where a control becomes valid and
              // where a control becomes invalid. If we only get
              // the invalid controls, we can't display controls that were
              // valid at the time but become invalid

              // If list currently has items then deregister the
              // Validate event handler
              if( this.validationErrorsList.Items.Count > 0 ) {
            foreach( BaseValidator validator in this.validationErrorsList.Items ) {
              validator.Validated -= new EventHandler(BaseValidator_Validated);
            }
              }

              // Clear the list
              this.validationErrorsList.Items.Clear();

              // Add new validators and register the Validate
              // event handler
              foreach(BaseValidator validator in validators ) {
            if( !validator.IsValid ) {
              this.validationErrorsList.Items.Add(validator);
            }
            validator.Validated += new EventHandler(BaseValidator_Validated);
              }
        }
예제 #2
0
        public void LoadValidators(ValidatorCollection validators)
        {
            // Note: validators should contain all validators under
            // the jurisdiction of the BaseContainerValidator so
            // we can handle both where a control becomes valid and
            // where a control becomes invalid. If we only get
            // the invalid controls, we can't display controls that were
            // valid at the time but become invalid

            // If list currently has items then deregister the
            // Validate event handler
            if (this.validationErrorsList.Items.Count > 0)
            {
                foreach (BaseValidator validator in this.validationErrorsList.Items)
                {
                    validator.Validated -= new EventHandler(BaseValidator_Validated);
                }
            }

            // Clear the list
            this.validationErrorsList.Items.Clear();

            // Add new validators and register the Validate
            // event handler
            foreach (BaseValidator validator in validators)
            {
                if (!validator.IsValid)
                {
                    this.validationErrorsList.Items.Add(validator);
                }
                validator.Validated += new EventHandler(BaseValidator_Validated);
            }
        }
예제 #3
0
 /// <summary>
 ///        Creates a synchronized (thread-safe) wrapper for a
 ///     <c>ValidatorCollection</c> instance.
 /// </summary>
 /// <returns>
 ///     An <c>ValidatorCollection</c> wrapper that is synchronized (thread-safe).
 /// </returns>
 public static ValidatorCollection Synchronized(ValidatorCollection list)
 {
     if (list == null)
     {
         throw new ArgumentNullException("list");
     }
     return(new SyncValidatorCollection(list));
 }
예제 #4
0
 /// <summary>
 ///        Creates a read-only wrapper for a
 ///     <c>ValidatorCollection</c> instance.
 /// </summary>
 /// <returns>
 ///     An <c>ValidatorCollection</c> wrapper that is read-only.
 /// </returns>
 public static ValidatorCollection ReadOnly(ValidatorCollection list)
 {
     if (list == null)
     {
         throw new ArgumentNullException("list");
     }
     return(new ReadOnlyValidatorCollection(list));
 }
예제 #5
0
        /// <summary>
        ///        Creates a shallow copy of the <see cref="ValidatorCollection"/>.
        /// </summary>
        public virtual object Clone()
        {
            ValidatorCollection newColl = new ValidatorCollection(m_count);

            Array.Copy(m_array, 0, newColl.m_array, 0, m_count);
            newColl.m_count   = m_count;
            newColl.m_version = m_version;

            return(newColl);
        }
예제 #6
0
        /// <summary>
        ///        Adds the elements of another <c>ValidatorCollection</c> to the current <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="x">The <c>ValidatorCollection</c> whose elements should be added to the end of the current <c>ValidatorCollection</c>.</param>
        /// <returns>The new <see cref="ValidatorCollection.Count"/> of the <c>ValidatorCollection</c>.</returns>
        public virtual int AddRange(ValidatorCollection x)
        {
            if (m_count + x.Count >= m_array.Length)
            {
                EnsureCapacity(m_count + x.Count);
            }

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

            return(m_count);
        }
예제 #7
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);
        }
예제 #8
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);
    }
예제 #9
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);
                }
            }
        }
예제 #10
0
    public static ValidatorCollection GetValidators(Form hostingForm, Control container, ValidationDepth validationDepth)
    {

      ValidatorCollection validators = ValidatorManager.GetValidators(hostingForm);
      ValidatorCollection contained = new ValidatorCollection();
      foreach (BaseValidator validator in validators)
      {
        // Only validate BaseValidators hosted by the container I reference
        if (IsParent(container, validator.ControlToValidate, validationDepth))
        {
          contained.Add(validator);
        }
      }
      return contained;
    }
예제 #11
0
        public static ValidatorCollection GetValidators(Form hostingForm, Control container, ValidationDepth validationDepth)
        {
            ValidatorCollection validators = ValidatorManager.GetValidators(hostingForm);
            ValidatorCollection contained  = new ValidatorCollection();

            foreach (BaseValidator validator in validators)
            {
                // Only validate BaseValidators hosted by the container I reference
                if (IsParent(container, validator.ControlToValidate, validationDepth))
                {
                    contained.Add(validator);
                }
            }
            return(contained);
        }
예제 #12
0
        // Support validation in flattened tab index order
        protected ValidatorCollection Sort(ValidatorCollection validators)
        {
            // Sort validators into flattened tab index order
            // using the BaseValidatorComparer
            ArrayList sorted = new ArrayList();

            foreach (BaseValidator validator in validators)
            {
                sorted.Add(validator);
            }
            sorted.Sort(new BaseValidatorComparer());
            ValidatorCollection sortedValidators = new ValidatorCollection();

            foreach (BaseValidator validator in sorted)
            {
                sortedValidators.Add(validator);
            }

            return(sortedValidators);
        }
예제 #13
0
        /// <summary>
        ///        Adds the elements of another <c>ValidatorCollection</c> to the current <c>ValidatorCollection</c>.
        /// </summary>
        /// <param name="x">The <c>ValidatorCollection</c> whose elements should be added to the end of the current <c>ValidatorCollection</c>.</param>
        /// <returns>The new <see cref="ValidatorCollection.Count"/> of the <c>ValidatorCollection</c>.</returns>
        public virtual int AddRange(ValidatorCollection x)
        {
            if (m_count + x.Count >= m_array.Length)
            EnsureCapacity(m_count + x.Count);

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

              return m_count;
        }
예제 #14
0
 /// <summary>
 ///        Creates a synchronized (thread-safe) wrapper for a 
 ///     <c>ValidatorCollection</c> instance.
 /// </summary>
 /// <returns>
 ///     An <c>ValidatorCollection</c> wrapper that is synchronized (thread-safe).
 /// </returns>
 public static ValidatorCollection Synchronized(ValidatorCollection list)
 {
     if(list==null)
     throw new ArgumentNullException("list");
       return new SyncValidatorCollection(list);
 }
예제 #15
0
 /// <summary>
 ///        Creates a read-only wrapper for a 
 ///     <c>ValidatorCollection</c> instance.
 /// </summary>
 /// <returns>
 ///     An <c>ValidatorCollection</c> wrapper that is read-only.
 /// </returns>
 public static ValidatorCollection ReadOnly(ValidatorCollection list)
 {
     if(list==null)
     throw new ArgumentNullException("list");
       return new ReadOnlyValidatorCollection(list);
 }
예제 #16
0
 internal ReadOnlyValidatorCollection(ValidatorCollection list)
 {
     m_collection = list;
 }
예제 #17
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);
            }
        }
예제 #18
0
 internal SyncValidatorCollection(ValidatorCollection list)
 {
     m_root = list.SyncRoot;
     m_collection = list;
 }
예제 #19
0
 internal ReadOnlyValidatorCollection(ValidatorCollection list)
 {
     m_collection = list;
 }
예제 #20
0
 public SummarizeEventArgs(ValidatorCollection validators, Form hostingForm)
 {
     Validators  = validators;
     HostingForm = hostingForm;
 }
예제 #21
0
 /// <summary>
 ///        Initializes a new instance of the <c>Enumerator</c> class.
 /// </summary>
 /// <param name="tc"></param>
 internal Enumerator(ValidatorCollection tc)
 {
     m_collection = tc;
     m_index      = -1;
     m_version    = tc.m_version;
 }
예제 #22
0
 internal SyncValidatorCollection(ValidatorCollection list)
 {
     m_root       = list.SyncRoot;
     m_collection = list;
 }
예제 #23
0
 public override int AddRange(ValidatorCollection x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
예제 #24
0
        /// <summary>
        ///        Creates a shallow copy of the <see cref="ValidatorCollection"/>.
        /// </summary>
        public virtual object Clone()
        {
            ValidatorCollection newColl = new ValidatorCollection(m_count);
              Array.Copy(m_array, 0, newColl.m_array, 0, m_count);
              newColl.m_count = m_count;
              newColl.m_version = m_version;

              return newColl;
        }
예제 #25
0
 /// <summary>
 ///        Initializes a new instance of the <c>Enumerator</c> class.
 /// </summary>
 /// <param name="tc"></param>
 internal Enumerator(ValidatorCollection tc)
 {
     m_collection = tc;
     m_index = -1;
     m_version = tc.m_version;
 }
예제 #26
0
 /// <summary>
 ///        Initializes a new instance of the <c>ValidatorCollection</c> class
 ///        that contains elements copied from the specified <c>ValidatorCollection</c>.
 /// </summary>
 /// <param name="c">The <c>ValidatorCollection</c> whose elements are copied to the new collection.</param>
 public ValidatorCollection(ValidatorCollection c)
 {
     m_array = new BaseValidator[c.Count];
     AddRange(c);
 }
예제 #27
0
 public override int AddRange(ValidatorCollection x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
예제 #28
0
 public SummarizeEventArgs(ValidatorCollection validators, Form hostingForm)
 {
     Validators = validators;
       HostingForm = hostingForm;
 }
예제 #29
0
 public override int AddRange(ValidatorCollection x)
 {
     lock(this.m_root)
       return m_collection.AddRange(x);
 }
예제 #30
0
 /// <summary>
 ///        Initializes a new instance of the <c>ValidatorCollection</c> class
 ///        that contains elements copied from the specified <c>ValidatorCollection</c>.
 /// </summary>
 /// <param name="c">The <c>ValidatorCollection</c> whose elements are copied to the new collection.</param>
 public ValidatorCollection(ValidatorCollection c)
 {
     m_array = new BaseValidator[c.Count];
       AddRange(c);
 }
예제 #31
0
    // Support validation in flattened tab index order
    protected ValidatorCollection Sort(ValidatorCollection validators)
    {

      // Sort validators into flattened tab index order
      // using the BaseValidatorComparer
      ArrayList sorted = new ArrayList();
      foreach (BaseValidator validator in validators)
      {
        sorted.Add(validator);
      }
      sorted.Sort(new BaseValidatorComparer());
      ValidatorCollection sortedValidators = new ValidatorCollection();
      foreach (BaseValidator validator in sorted)
      {
        sortedValidators.Add(validator);
      }

      return sortedValidators;
    }
예제 #32
0
 public override int AddRange(ValidatorCollection x)
 {
     lock (this.m_root)
         return(m_collection.AddRange(x));
 }