using Caliburn.Micro.Core; using System; using System.Collections.Generic; using System.Windows; using ExtendedGrid.Microsoft.Windows.Controls; namespace RecipeEditorLib.RecipeModel.Params { public abstract class Param : PropertyChangedBase, IParam { #region Variables protected string _name; protected string _displayName; protected string _unitName; protected bool _isEnabled; protected bool _isSaved; protected bool _isColumnSelected; protected Visibility _visibility; protected bool _isValidated; protected string _validationError; protected bool _isEqualsToPrevious; protected bool _isHighlighted; protected bool _isHideValue; #endregion #region Constructors protected Param() { _isSaved = true; _isEnabled = true; _isValidated = true; _validationError = null; _isEqualsToPrevious = true; _visibility = Visibility.Visible; _isHighlighted = false; _isHideValue = false; } #endregion #region Properties public Action Feedback { get; set; } public Func Check { get; set; } public RecipeStep Parent { get; set; } public DataGridRow RowOwner { get; set; } public DataGridColumn ColumnOwner { get; set; } public virtual IParam Previous { get; set; } public virtual IParam Next { get; set; } public string Name { get => _name; set { _name = value; NotifyOfPropertyChange(nameof(Name)); } } public string DisplayName { get => _displayName; set { _displayName = value; NotifyOfPropertyChange(nameof(DisplayName)); } } public string UnitName { get => _unitName; set { _unitName = value; NotifyOfPropertyChange(nameof(UnitName)); } } public bool IsEnabled { get => _isEnabled; set { _isEnabled = value; NotifyOfPropertyChange(nameof(IsEnabled)); } } public virtual bool IsSaved { get => _isSaved; set { _isSaved = value; NotifyOfPropertyChange(nameof(IsSaved)); } } /// /// 是否和前序值相等。 /// public bool IsEqualsToPrevious { get => _isEqualsToPrevious; set { _isEqualsToPrevious = value; NotifyOfPropertyChange(nameof(IsEqualsToPrevious)); } } /// /// 是否通过验证。 /// public bool IsValidated { get => _isValidated; internal set { _isValidated = value; NotifyOfPropertyChange(nameof(IsValidated)); } } /// /// 校验错误原因。 /// public string ValidationError { get => _validationError; protected set { _validationError = value; NotifyOfPropertyChange(nameof(ValidationError)); } } /// /// 返回是否高亮当前参数。 /// public bool IsHighlighted { get => _isHighlighted; private set { _isHighlighted = value; NotifyOfPropertyChange(nameof(IsHighlighted)); } } /// /// 返回是否隐藏参数的值。 /// public virtual bool IsHideValue { get => _isHideValue; set { _isHideValue = value; NotifyOfPropertyChange(nameof(IsHideValue)); } } public bool IsColumnSelected { get => _isColumnSelected; set { _isColumnSelected = value; NotifyOfPropertyChange(nameof(IsColumnSelected)); } } public Visibility Visible { get => _visibility; set { _visibility = value; NotifyOfPropertyChange(nameof(Visible)); } } public bool EnableConfig { get; set; } public bool EnableTolerance { get; set; } public Visibility StepCheckVisibility { get; set; } /// /// 高亮显示当前参数。 /// public void Highlight() { IsHighlighted = true; } /// /// 取消高亮显示。 /// public void ResetHighlight() { IsHighlighted = false; } #endregion #region Methods /// /// 将参数链表转换为数组。 /// /// public virtual List Flatten() { if (Previous != null) return Previous.Flatten(); var list = new List(); IParam p = this; while (p != null) { list.Add(p); p = p.Next; } return list; } /// /// 校验数据。 /// /// public virtual void Validate() { IsValidated = true; ValidationError = ""; } public virtual void Save() { IsSaved = true; } public virtual object GetValue() { return "Not Support"; } public override string ToString() { return $"{DisplayName}, ControlName={Name}"; } #endregion } }