313 lines
7.4 KiB
C#
313 lines
7.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Windows;
|
||
using Caliburn.Micro.Core;
|
||
using ExtendedGrid.Microsoft.Windows.Controls;
|
||
|
||
namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params
|
||
{
|
||
public abstract class Param : PropertyChangedBase, IParam
|
||
{
|
||
#region Variables
|
||
|
||
public event EventHandler<object> OnValueChanged;
|
||
|
||
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<Param> Feedback { get; set; }
|
||
|
||
public Func<Param, bool> 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; }
|
||
|
||
/// <summary>
|
||
/// 设置或返回当前参数的控制名称。
|
||
/// <remarks>
|
||
/// 对应RecipeFormat.xml文件中的ControlName。
|
||
/// </remarks>
|
||
/// </summary>
|
||
public string Name
|
||
{
|
||
get => _name;
|
||
set
|
||
{
|
||
_name = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置或返回当前参数的显示名称。
|
||
/// </summary>
|
||
public string DisplayName
|
||
{
|
||
get => _displayName;
|
||
set
|
||
{
|
||
_displayName = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置或返回当前参数的单位。
|
||
/// </summary>
|
||
public string UnitName
|
||
{
|
||
get => _unitName;
|
||
set
|
||
{
|
||
_unitName = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
|
||
public bool IsEnabled
|
||
{
|
||
get => _isEnabled;
|
||
set
|
||
{
|
||
_isEnabled = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置或返回当前参数是否为已保存状态。
|
||
/// </summary>
|
||
public virtual bool IsSaved
|
||
{
|
||
get => _isSaved;
|
||
set
|
||
{
|
||
_isSaved = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 设置或返回当前参数的数值是否和前序参数的数值相等。
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 该属性用于渲染DataGrid单元格文本颜色,当不等于前序参数数值时,当前参数显示为绿色。
|
||
/// </remarks>
|
||
public bool IsEqualsToPrevious
|
||
{
|
||
get => _isEqualsToPrevious;
|
||
set
|
||
{
|
||
_isEqualsToPrevious = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回当前参数是否通过验证。
|
||
/// </summary>
|
||
public bool IsValidated
|
||
{
|
||
get => _isValidated;
|
||
internal set
|
||
{
|
||
_isValidated = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回当前参数校验错误原因。
|
||
/// </summary>
|
||
public string ValidationError
|
||
{
|
||
get => _validationError;
|
||
protected set
|
||
{
|
||
_validationError = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回是否高亮当前参数。
|
||
/// </summary>
|
||
public bool IsHighlighted
|
||
{
|
||
get => _isHighlighted;
|
||
private set
|
||
{
|
||
_isHighlighted = value;
|
||
NotifyOfPropertyChange();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回是否隐藏参数的值。
|
||
/// </summary>
|
||
public virtual bool IsHideValue
|
||
{
|
||
get => _isHideValue;
|
||
set
|
||
{
|
||
_isHideValue = 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
|
||
|
||
/// <summary>
|
||
/// 高亮显示当前参数。
|
||
/// </summary>
|
||
public void Highlight()
|
||
{
|
||
IsHighlighted = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取消高亮显示。
|
||
/// </summary>
|
||
public void ResetHighlight()
|
||
{
|
||
IsHighlighted = false;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Methods
|
||
|
||
/// <summary>
|
||
/// 将当前参数所对应的前序、后续参数链表转换为数组。
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public virtual List<IParam> Flatten()
|
||
{
|
||
if (Previous != null)
|
||
return Previous.Flatten();
|
||
|
||
var list = new List<IParam>();
|
||
IParam p = this;
|
||
while (p != null)
|
||
{
|
||
list.Add(p);
|
||
p = p.Next;
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 校验当前参数的数值。
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public virtual void Validate()
|
||
{
|
||
IsValidated = true;
|
||
ValidationError = "";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将当前参数标记为已保存状态。
|
||
/// </summary>
|
||
public virtual void Save()
|
||
{
|
||
IsSaved = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前参数的数值。
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public virtual object GetValue()
|
||
{
|
||
return default;
|
||
}
|
||
|
||
public void SetValue(object value)
|
||
{
|
||
HandleSetValue(value);
|
||
OnValueChanged?.Invoke(this, value);
|
||
}
|
||
|
||
public override string ToString()
|
||
{
|
||
return $"{DisplayName}, ControlName={Name}";
|
||
}
|
||
|
||
protected virtual void HandleSetValue(object value)
|
||
{
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
#endregion
|
||
}
|
||
}
|