protected void OnSummarize(SummarizeEventArgs e) { if (Summarize != null) { Summarize(this, e); } }
protected override void Summarize(object sender, SummarizeEventArgs e) { // Close form if open and nothing invalid if (e.Validators.Count == 0) { if (_dlg != null) { _dlg.Close(); _dlg = null; currentExtendee = null; } return; } BaseContainerValidator extendee = (BaseContainerValidator)sender; // If the ValidationSummaryForm is open, but refers to a different extendee // (BaseContainerValidator), get rid of it if ((_dlg != null) && (currentExtendee != null) && (extendee != currentExtendee)) { _dlg.Close(); _dlg = null; currentExtendee = extendee; } // Open ValidationSummaryForm if it hasn't been opened, // or has been closed since Summarize was last called if (_dlg == null) { _dlg = new ValidationSummaryForm(); _dlg.ErrorCaption = GetErrorCaption(extendee); _dlg.ErrorMessage = GetErrorMessage(extendee); _dlg.Owner = extendee.HostingForm; // Register Disposed to handle clean up when user closes form _dlg.Disposed += new EventHandler(ValidationSummaryForm_Disposed); } // Get complete set of Validators under the jurisdiction // of the BaseContainerValidator _dlg.LoadValidators(Sort(extendee.GetValidators())); // Show dialog if not already visible if (!_dlg.Visible) { _dlg.Show(); } }
protected override void Summarize(object sender, SummarizeEventArgs e) { // Close form if open and nothing invalid if (e.Validators.Count == 0) { if (_dlg != null) { _dlg.Close(); _dlg = null; currentExtendee = null; } return; } BaseContainerValidator extendee = (BaseContainerValidator)sender; // If the ValidationSummaryForm is open, but refers to a different extendee // (BaseContainerValidator), get rid of it if ((_dlg != null) && (currentExtendee != null) && (extendee != currentExtendee)) { _dlg.Close(); _dlg = null; currentExtendee = extendee; } // Open ValidationSummaryForm if it hasn't been opened, // or has been closed since Summarize was last called if (_dlg == null) { _dlg = new ValidationSummaryForm(); _dlg.ErrorCaption = GetErrorCaption(extendee); _dlg.ErrorMessage = GetErrorMessage(extendee); _dlg.Owner = extendee.HostingForm; // Register Disposed to handle clean up when user closes form _dlg.Disposed += new EventHandler(ValidationSummaryForm_Disposed); } // Get complete set of Validators under the jurisdiction // of the BaseContainerValidator _dlg.LoadValidators(Sort(extendee.GetValidators())); // Show dialog if not already visible if (!_dlg.Visible) _dlg.Show(); }
protected abstract void Summarize(object sender, SummarizeEventArgs e);
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); } }
protected void OnSummarize(SummarizeEventArgs e) { if( Summarize != null ) { Summarize(this, e); } }
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 MessageBox.Show(errors, errorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); }
protected abstract void Summarize(object sender, SummarizeEventArgs e);