using System; using System.Collections.Generic; using System.Windows; using Caliburn.Micro.Core; using ExtendedGrid.Microsoft.Windows.Controls; using MECF.Framework.UI.Client.ClientBase; namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params { public abstract class Param : PropertyChangedBase, IParam { #region Variables protected string _name; protected string _displayName; protected string _unitName; protected MenuPermissionEnum _perm; protected MenuPermissionEnum _permStep; protected MenuPermissionEnum _permColumn; protected bool _isEnabled; protected bool _isSaved; protected bool _isColumnSelected; protected Visibility _visibility; protected bool _isValid; protected string _validationError; protected bool _isEqualsToPrevious; protected bool _isHighlighted; #endregion #region Constructors protected Param() { _isSaved = true; _isEnabled = true; _isValid = true; _validationError = null; _isEqualsToPrevious = true; _visibility = Visibility.Visible; _isHighlighted = false; } #endregion #region Properties /// /// 设置或返回当前参数所在的列的访问权限变更时,执行的回调函数。 /// public Action ColumnPermChangedCallback { 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(); } } /// public string DisplayName { get => _displayName; set { _displayName = value; NotifyOfPropertyChange(); } } /// /// 设置或返回当前参数的单位。 /// public string UnitName { get => _unitName; set { _unitName = value; NotifyOfPropertyChange(); } } /// public MenuPermissionEnum StepPermission { get => _permStep; set { _permStep = value; NotifyOfPropertyChange(nameof(Permission)); } } /// public MenuPermissionEnum ColumnPermission { get => _permColumn; set { _permColumn = value; NotifyOfPropertyChange(nameof(Permission)); } } /// public virtual MenuPermissionEnum Permission => (MenuPermissionEnum)Math.Min((int)StepPermission, (int)ColumnPermission); /// public bool IsEnabled { get => _isEnabled; set { _isEnabled = value; NotifyOfPropertyChange(); } } /// public virtual bool IsSaved { get => _isSaved; set { _isSaved = value; NotifyOfPropertyChange(); } } /// public bool IsEqualsToPrevious { get => _isEqualsToPrevious; set { _isEqualsToPrevious = value; NotifyOfPropertyChange(); } } /// public bool IsValid { get => _isValid; internal set { _isValid = value; NotifyOfPropertyChange(); } } /// public string ValidationError { get => _validationError; protected set { _validationError = value; NotifyOfPropertyChange(); } } /// public bool IsHighlighted { get => _isHighlighted; private set { _isHighlighted = value; NotifyOfPropertyChange(); } } public bool IsColumnSelected { get => _isColumnSelected; set { _isColumnSelected = value; NotifyOfPropertyChange(); } } public Visibility Visible { get => _visibility; set { _visibility = value; NotifyOfPropertyChange(); } } public bool EnableConfig { get; set; } public bool EnableTolerance { get; set; } public Visibility StepCheckVisibility { get; set; } #region Methods /// /// 高亮显示当前参数。 /// public void Highlight() { IsHighlighted = true; } /// /// 取消高亮显示。 /// public void ResetHighlight() { IsHighlighted = false; } /// /// 将当前参数所对应的前序、后续参数链表转换为数组。 /// /// 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() { IsValid = true; ValidationError = ""; } /// /// 将当前参数标记为已保存状态。 /// public virtual void Save() { IsSaved = true; } public override string ToString() { return $"{DisplayName}, ControlName={Name}"; } #endregion #endregion } }