using DataEntity.Device; using SqlSugar; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using XImagingXhandler.XDAL; using Newtonsoft.Json; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace XImagingXhandler.XDAL { /// /// 绑定到实验方法流程节点的实体基类 /// public class MethodEx : Method, ICloneable { /// /// 构造函数 /// public MethodEx() { Children = new ObservableCollection(); Parent = null; Level = 0; } /// /// 带参构造函数,初始化参数属性值 /// /// 命令方法实体对象 public MethodEx(Method method) { this.method_id = method.method_id; this.method_name = method.method_name; this.method_status = method.method_status; this.method_content = method.method_content; this.method_Tipcontent = method.method_Tipcontent; this.method_ico = method.method_ico; this.method_group_id = method.method_group_id; this.method_support = method.method_support; this.method_type = method.method_type; Children = new ObservableCollection(); Parent = null; Level = 0; Moveable = true; canDrop = true; control = null; tag = null; isEnabled = true; } /// /// 带参构造函数,初始化参数属性值 /// /// 命令方法实体对象 /// 父节点命令对象 public MethodEx(Method method, MethodEx parentItem) { this.method_id = method.method_id; this.method_name = method.method_name; this.method_status = method.method_status; this.method_content = method.method_content; this.method_Tipcontent = method.method_Tipcontent; this.method_ico = method.method_ico; this.method_group_id = method.method_group_id; this.method_support = method.method_support; this.method_type = method.method_type; Children = new ObservableCollection(); Parent = parentItem; Level = parentItem.Level + 1; Moveable = true; canDrop = true; control = null; tag = null; isEnabled = true; } /// /// 带参构造函数,初始化参数属性值 /// /// 命令方法实体对象 /// 父节点命令对象 /// 是否深拷贝,true:false public MethodEx(MethodEx method, MethodEx parentItem,bool isDeepCopy) { this.method_id = method.method_id; this.method_name = method.method_name; this.method_status = method.method_status; this.method_content = method.method_content; this.method_Tipcontent = method.method_Tipcontent; this.method_ico = method.method_ico; this.method_group_id = method.method_group_id; this.method_support = method.method_support; this.method_type = method.method_type; Children = new ObservableCollection(); Parent = parentItem; Level = parentItem.Level + 1; Moveable = true; canDrop = true; control = method.control; tag = method.tag; isEnabled = true; } /// /// 运行起点 /// private string _method_isrun = ""; public string method_isrun { get { return _method_isrun; } set { _method_isrun = value; OnPropertyChanged(nameof(method_isrun)); } } /// /// 索引值 /// private int _index; public int Index { get { return _index; } set { _index = value; OnPropertyChanged("Index"); } } private string _strIndex; /// /// 实验流程中节点位置编号 /// public string strIndex { get { return _strIndex; } set { _strIndex = value; OnPropertyChanged("strIndex"); } } /// /// 方法的层级 /// private int _level; public int Level { get { return _level; } set { _level = value; OnPropertyChanged("Level"); } } /// /// 该方法是否可以移动 /// public bool Moveable { get; set; } /// /// 父节点对象 /// public MethodEx Parent { get; set; } /// /// 该方法是否能drop /// public bool canDrop { get; set; } /// /// 孩子节点对象集合 /// public ObservableCollection Children { get; set; } /// /// 加载Shared.AllNodeMethod所有子方法时,子方法存储位置。不能存在Children里,不然页面加载会有异常!!! /// public MethodEx SubMethod { get; set; } /// /// 设置节点的父节点 /// /// public void SetParent(MethodEx parent) { this.Parent = parent; this.Level = parent.Level + 1; } private bool _isSelected = false; /// /// 节点是否被选中 /// public bool isSelected { get { return _isSelected; } set { _isSelected = value; OnPropertyChanged("isSelected"); } } private bool _isEnabled; /// /// 是否被禁用 /// public bool isEnabled { get { return _isEnabled; } set { _isEnabled = value; OnPropertyChanged("isEnabled"); } } private string _groupID; /// /// 用以标注这个方法的开始和结束2个节点是同一组节点 /// public string groupID { get { return _groupID; } set { _groupID = value; OnPropertyChanged("groupID"); } } private int _isError; /// /// 产生错误节点 /// public int IsError { get { return _isError; } set { _isError = value; OnPropertyChanged("IsError"); } } /// /// UI对象 /// public object control { get; set; } /// /// 保存属性实体 /// public object tag { get; set; } /// /// 设备信息 /// public DeviceConfigModel device { get; set; } public object Clone() { return (object)this.MemberwiseClone(); } public object CloneDeep() { // 将对象转换为JSON字符串 string json = JsonConvert.SerializeObject(this); // 将JSON字符串转换回对象 return JsonConvert.DeserializeObject(json, this.GetType()); } public static T DeepCopy(T obj) { object retval; using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); //序列化成流 bf.Serialize(ms, obj); ms.Seek(0, SeekOrigin.Begin); //反序列化成对象 retval = bf.Deserialize(ms); ms.Close(); } return (T)retval; } } }