using System.ComponentModel;
using System.Drawing.Design;
using Telerik.WinControls;
//using System.Linq;
using Telerik.WinControls.Data;
namespace Pilz.UI.Telerik.Controls.RadValidationProvider;
///
/// RadCompositeValidationRule evaluates two or more RadValidationRules or RadValidationRuleWithTargetControl
/// and combines their with AND or OR operator.
///
public class RadCompositeValidationRuleEx : CompositeFilterDescriptor, IRadValidationRuleEx
{
private bool caseSensitive = false;
private string toolTipText = "";
private string toolTipTitle = "Validation Failed";
private bool autoToolTip = true;
///
/// Gets or Sets a collection with RadControl descendants that belongs this Rule.
///
[Editor(DesignerConsts.RadValidationRuleAssociatedControlsEditorString, typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public List Controls
{
get
{
List controls = [];
foreach (IRadValidationRuleEx validationRule in ValidationRules)
{
foreach (Control control in validationRule.Controls)
{
if (!controls.Contains(control))
{
controls.Add(control);
}
}
}
return controls;
}
set
{
foreach (RadControl control in value)
{
AddControl(control);
}
}
}
///
/// Associates this rule and all controls in ValidationRules collection with the specified RadControl descendant.
///
/// A RadControl descendant that represents the editor.
public virtual void AddControl(RadControl control)
{
if (control == null)
{
return;
}
foreach (IRadValidationRuleEx validationRule in ValidationRules)
{
if (!validationRule.Controls.Contains(control))
{
validationRule.AddControl(control);
}
}
}
///
/// Removes the specified RadControl descendant from this rule and from all controls in ValidationRules collection .
///
/// A RadControl descendant that represents the editor.
public void RemoveControl(RadControl control)
{
if (control == null)
{
return;
}
foreach (IRadValidationRuleEx validationRule in ValidationRules)
{
while (validationRule.Controls.Contains(control))
{
validationRule.RemoveControl(control);
}
}
}
///
/// Inherit property. Not used in RadCompositeValidationRule.
///
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public override FilterDescriptorCollection FilterDescriptors { get { return base.FilterDescriptors; } }
///
/// Gets or Sets the collection of ValidationRules that belongs to this RadValidationProvider.
///
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(DesignerConsts.RadValidationProviderCompositeConditionsCollectionEditorString, typeof(UITypeEditor)),
Category(RadDesignCategory.DataCategory),
Description("Gets a collection representing the Rules in this CompositeValidationRule.")]
public FilterDescriptorCollection ValidationRules
{
get
{
return base.FilterDescriptors;
}
}
///
/// Gets the Rule expression.
///
/// The Rule expression.
public override string Expression { get { return base.Expression; } }
///
/// Gets or Sets the ToolTip Text.
///
[DefaultValue("")]
public string ToolTipText { get { return toolTipText; } set { toolTipText = value; } }
///
/// Gets or Sets the ToolTip Title Text. This text will be shown as ToolTip Title text when rule validation fails.
///
[DefaultValue("Validation Failed")]
public string ToolTipTitle { get { return toolTipTitle; } set { toolTipTitle = value; } }
///
/// Inherited property. Not used in the Rule.
///
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public override bool IsFilterEditor
{
get { return base.IsFilterEditor; }
set { base.IsFilterEditor = value; }
}
///
/// Enable or Disable the ToolTip when validation fails.
///
[DefaultValue(true)]
public bool AutoToolTip
{
get { return autoToolTip; }
set { autoToolTip = value; }
}
///
/// Inherited property. Not used in the Rule.
///
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override object Value { get { return base.Value; } set { base.Value = value; } }
///
/// Enable or Disable the case sensitive Rule's Like operator.
///
[DefaultValue(false)]
public bool CaseSensitive
{
get
{
return caseSensitive;
}
set
{
caseSensitive = value;
}
}
}