private static bool IsEnabled(IScreen instance, ValidationAttribute validator, string propertyName)
        {
            // Get the IValidationControl interface
            IValidationControl ivc = validator as IValidationControl;

            // If the option is set to validate while disabled it doesn't matter what other conditions exist.
            if (ivc != null && ivc.ValidateWhileDisabled)
            {
                return(true);
            }

            // Find a property with the name Can<propertyName>
            PropertyInfo pi = instance.GetType().GetProperty(
                ivc == null || string.IsNullOrEmpty(ivc.GuardProperty)
                                ? "Can" + propertyName
                                : ivc.GuardProperty
                );

            if (pi == null)
            {
                return(true);                        // There is no such guard property
            }
            // Get the result
            object result = pi.GetValue(instance, null);

            if (result == null || !(result is bool))
            {
                return(true);                                                  // No result or the guard property does not return a bool
            }
            return((bool)result);
        }
Ejemplo n.º 2
0
		private void RemoveValidationControl(IValidationControl ctrl)
		{
			if (_controls.Contains(ctrl))
			{
				ctrl.ValidationChanged -= OnValidationChanged;
				_controls.Remove(ctrl);
				Update();
			}
		}
Ejemplo n.º 3
0
		private void AddValidationControl(IValidationControl ctrl)
		{
			if (!_controls.Contains(ctrl))
			{
				ctrl.ValidationChanged += OnValidationChanged;
				_controls.Add(ctrl);
				Update();
			}
		}
Ejemplo n.º 4
0
 private void RemoveValidationControl(IValidationControl ctrl)
 {
     if (_controls.Contains(ctrl))
     {
         ctrl.ValidationChanged -= OnValidationChanged;
         _controls.Remove(ctrl);
         Update();
     }
 }
Ejemplo n.º 5
0
 private void AddValidationControl(IValidationControl ctrl)
 {
     if (!_controls.Contains(ctrl))
     {
         ctrl.ValidationChanged += OnValidationChanged;
         _controls.Add(ctrl);
         Update();
     }
 }
Ejemplo n.º 6
0
		public static void Register(IValidationControl ctrl)
		{
			var container = GetParent((DependencyObject)ctrl);
			if (container != null)
			{
				container.AddValidationControl(ctrl);
				container.Update();
				((FrameworkElement)ctrl).Loaded += delegate { container.AddValidationControl(ctrl); };
				((FrameworkElement)ctrl).Unloaded += delegate { container.RemoveValidationControl(ctrl); };
			}
		}
Ejemplo n.º 7
0
        public static void Register(IValidationControl ctrl)
        {
            var container = GetParent((DependencyObject)ctrl);

            if (container != null)
            {
                container.AddValidationControl(ctrl);
                container.Update();
                ((FrameworkElement)ctrl).Loaded   += delegate { container.AddValidationControl(ctrl); };
                ((FrameworkElement)ctrl).Unloaded += delegate { container.RemoveValidationControl(ctrl); };
            }
        }
Ejemplo n.º 8
0
 private bool validateControls()
 {
     foreach (TabItemViewModel tabPage in Tabs)
     {
         IValidationControl entryControl = tabPage.Content as IValidationControl;
         if (entryControl != null)
         {
             if (!entryControl.ValidateControl())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 9
0
 private bool validateControls()
 {
     foreach (XtraTabPage tabPage in xtraTabControl1.TabPages)
     {
         IValidationControl entryControl = tabPage.Controls[0] as IValidationControl;
         if (entryControl != null)
         {
             if (!entryControl.ValidateControl())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 验证智能窗体控件并执行验证逻辑,失败将用提示框提示错误信息
        /// </summary>
        /// <param name="controls">智能控件列表</param>
        /// <returns></returns>
        public static bool ValidateIBControls(IList <IDataControl> controls)
        {
            foreach (IDataControl item in controls)
            {
                if (!item.IsValid)
                {
                    if (item is IValidationControl)
                    {
                        IValidationControl dtb = item as IValidationControl;
                        if (dtb.MessageType == PWMIS.Windows.Validate.EnumMessageType.提示框)
                        {
                            Control ctr = item as Control;
                            if (!dtb.IsNull && string.IsNullOrEmpty(ctr.Text.Trim()))
                            {
                                MessageBox.Show("[" + dtb.RegexName + "]不能为空!");
                                ctr.Focus();
                            }
                            else
                            {
                                MessageBox.Show("[" + dtb.RegexName + "]" + dtb.ErrorMessage);
                                ctr.Focus();
                                if (item is TextBox)
                                {
                                    ((TextBox)item).SelectAll();
                                }
                            }
                        }
                    }
                    else if (item is IDataCheckBox)
                    {
                        IDataCheckBox dcb = item as IDataCheckBox;
                        if (!dcb.IsNull && !string.IsNullOrEmpty(dcb.Text))
                        {
                            MessageBox.Show("[" + dcb.Text + "]不能为空选项!");
                        }
                    }

                    return(false);
                }
            }
            return(true);
        }