using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace Kingo.Plugin.YJJK.ModelEntity { public class ResultsCatalog : INotifyPropertyChanged { public string Name { get; set; } public string Path { get; set; } public string Desc { get; set; } /// /// 拷贝文件原始路径 /// public string CopyFile { get; set; } /// /// IsChecked /// /// private bool? _isChecked = false; public bool? IsChecked { set { _isChecked = value; if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsChecked")); SetIsCheckedByParent(value); if (Parent != null) Parent.SetIsCheckedByChild(value); } get { return this._isChecked; } } public ResultsCatalog Parent { get; set; } public bool IsExpanded { get; set; } public string Type { get; set; } /// /// 文件类型(只有当Type=File时有效) /// public string FileType { get; set; } /// /// 文件模板(只有当Type=File时有效) /// public string FileTempalate { get; set; } public List SubCatalog { get; set; } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } /// /// 子节点的isChecked改变了, 通知父节点是否要跟着改变 isChecked /// /// public virtual void SetIsCheckedByChild(bool? value) { if (this._isChecked == value) { return; } bool isAllChildrenChecked = this.SubCatalog.All(c => c.IsChecked == value); if (!isAllChildrenChecked) { this._isChecked = null; } else { this._isChecked = value; } if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsChecked")); if (Parent != null) Parent.SetIsCheckedByChild(value); } /// /// 父节点isChecked改变了, 所有子节点跟着改变 /// /// public virtual void SetIsCheckedByParent(bool? value) { this._isChecked = value; if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsChecked")); if (SubCatalog == null) { return; } foreach (var child in SubCatalog) { child.SetIsCheckedByParent(value); } } } }