public void SetErrorMessage(BaseContainerValidator extendee, string value) { if (value != null) { _errorMessages[extendee] = value; } else { _errorMessages.Remove(extendee); } }
public string GetErrorCaption(BaseContainerValidator extendee) { if (_errorCaptions.Contains(extendee)) { return((string)_errorCaptions[extendee]); } else { return(""); } }
public string GetErrorMessage(BaseContainerValidator extendee) { if (_errorMessages.Contains(extendee)) { return((string)_errorMessages[extendee]); } else { return(""); } }
public ValidationSummaryDisplayMode GetDisplayMode(BaseContainerValidator extendee) { if (_displayModes.Contains(extendee)) { return((ValidationSummaryDisplayMode)_displayModes[extendee]); } else { return(ValidationSummaryDisplayMode.Simple); } }
public bool GetShowSummary(BaseContainerValidator extendee) { if (_showSummaries.Contains(extendee)) { return((bool)_showSummaries[extendee]); } else { return(false); } }
public ValidationSummaryDisplayMode GetDisplayMode(BaseContainerValidator extendee) { if (_displayModes.Contains(extendee)) { return (ValidationSummaryDisplayMode)_displayModes[extendee]; } else { return ValidationSummaryDisplayMode.Simple; } }
public string GetErrorMessage(BaseContainerValidator extendee) { if (_errorMessages.Contains(extendee)) { return (string)_errorMessages[extendee]; } else { return ""; } }
public bool GetShowSummary(BaseContainerValidator extendee) { if (_showSummaries.Contains(extendee)) { return (bool)_showSummaries[extendee]; } else { return false; } }
public void SetShowSummary(BaseContainerValidator extendee, bool value) { if (value == true) { _showSummaries[extendee] = value; extendee.Summarize += new SummarizeEventHandler(Summarize); } else { _showSummaries.Remove(extendee); } }
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(); }
public string GetErrorCaption(BaseContainerValidator extendee) { if (_errorCaptions.Contains(extendee)) { return (string)_errorCaptions[extendee]; } else { return ""; } }
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); } }
public void SetDisplayMode(BaseContainerValidator extendee, ValidationSummaryDisplayMode value) { _displayModes[extendee] = value; }