using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using SWS.Model; using Telerik.Windows.Controls; namespace SWS.Model { public class SignalManagementInfo : ViewModelBase { public event EventHandler GroupOtherChanged; public event EventHandler CodeChanged; public event EventHandler ParametersChanged; #region 表格字段 private string _Wire_Group_ID; /// /// ID /// public string Wire_Group_ID { get { return _Wire_Group_ID; } set { _Wire_Group_ID = value; RaisePropertyChanged(nameof(Wire_Group_ID)); } } private string _ParentID; /// /// 如果有值表示其为虚拟点 /// public string ParentID { get { return _ParentID; } set { _ParentID = value; } } private string _LinkedID; /// /// 某一个输出的信号,可以关联多个输入的信号。关联的是 /// public string LinkedID { get { return _LinkedID; } set { _LinkedID = value; RaisePropertyChanged(nameof(LinkedID)); } } private string _Status; /// /// 状态 /// public string Status { get { return _Status; } set { _Status = value; RaisePropertyChanged(nameof(Status)); } } private string _serialNumber; /// /// 序号 /// public string serialNumber { get { return _serialNumber; } set { _serialNumber = value; RaisePropertyChanged(nameof(serialNumber)); } } private string _type; /// /// 类型 /// public string type { get { return _type; } set { _type = value; RaisePropertyChanged(nameof(type)); } } private string _Group_Name; /// /// CH.NO /// public string Group_Name { get { return _Group_Name; } set { _Group_Name = value; RaisePropertyChanged(nameof(Group_Name)); } } private string _Group_Desc_EN; /// /// 英文描述 /// public string Group_Desc_EN { get { return _Group_Desc_EN; } set { _Group_Desc_EN = value; RaisePropertyChanged(nameof(Group_Desc_EN)); } } private string _Group_Desc; /// /// 中文描述 /// public string Group_Desc { get { return _Group_Desc; } set { _Group_Desc = value; RaisePropertyChanged(nameof(Group_Desc)); } } private string _BelongingMajor; /// /// 归属专业 /// public string BelongingMajor { get { return _BelongingMajor; } set { _BelongingMajor = value; RaisePropertyChanged(nameof(BelongingMajor)); } } private string _GroupOther; /// /// 组别 /// public string GroupOther { get { return _GroupOther; } set { _GroupOther = value; RaisePropertyChanged(nameof(GroupOther)); ParametersChanged?.Invoke(this, EventArgs.Empty); } } private List _GroupOthers; /// /// 组别列表 /// public List GroupOthers { get { return _GroupOthers; } set { _GroupOthers = value; RaisePropertyChanged(nameof(GroupOthers)); } } private string _Signal_SeqNo; /// /// 编码 /// public string Signal_SeqNo { get { return _Signal_SeqNo; } set { _Signal_SeqNo = value; RaisePropertyChanged(nameof(Signal_SeqNo)); } } private string _Code; /// /// Code /// public string Code { get { return _Code; } set { _Code = value; RaisePropertyChanged(nameof(Code)); ParametersChanged?.Invoke(this, EventArgs.Empty); } } private string _InOrOut; /// /// IO类型 /// public string InOrOut { get { return _InOrOut; } set { _InOrOut = value; RaisePropertyChanged(nameof(InOrOut)); } } private string _IO_Type; /// /// 信号类型 /// public string IO_Type { get { return _IO_Type; } set { _IO_Type = value; RaisePropertyChanged(nameof(IO_Type)); } } private string _Range_Min; /// /// Range_Min /// public string Range_Min { get { return _Range_Min; } set { _Range_Min = value; RaisePropertyChanged(nameof(Range_Min)); } } private string _Range_Max; /// /// Range_Max /// public string Range_Max { get { return _Range_Max; } set { _Range_Max = value; RaisePropertyChanged(nameof(Range_Max)); } } private string _Unit; /// /// 单位 /// public string Unit { get { return _Unit; } set { _Unit = value; RaisePropertyChanged(nameof(Unit)); } } private string _Alarm_LL; public string Alarm_LL { get { return _Alarm_LL; } set { _Alarm_LL = value; RaisePropertyChanged(nameof(Alarm_LL)); } } private string _Alarm_L; public string Alarm_L { get { return _Alarm_L; } set { _Alarm_L = value; RaisePropertyChanged(nameof(Alarm_L)); } } private string _Alarm_H; public string Alarm_H { get { return _Alarm_H; } set { _Alarm_H = value; RaisePropertyChanged(nameof(Alarm_H)); } } private string _Alarm_HH; public string Alarm_HH { get { return _Alarm_HH; } set { _Alarm_HH = value; RaisePropertyChanged(nameof(Alarm_HH)); } } private string _SENSOR_CODE; public string SENSOR_CODE { get { return _SENSOR_CODE; } set { _SENSOR_CODE = value; RaisePropertyChanged(nameof(SENSOR_CODE)); } } private bool _CommunicationPoint; /// /// 是否是通讯点 /// public bool CommunicationPoint { get { return _CommunicationPoint; } set { _CommunicationPoint = value; RaisePropertyChanged(nameof(CommunicationPoint)); } } private string _SeriousType; public string SeriousType { get { return _SeriousType; } set { _SeriousType = value; RaisePropertyChanged(nameof(SeriousType)); } } private string _AL_GRP; public string AL_GRP { get { return _AL_GRP; } set { _AL_GRP = value; RaisePropertyChanged(nameof(AL_GRP)); } } private string _BL_GRP; public string BL_GRP { get { return _BL_GRP; } set { _BL_GRP = value; RaisePropertyChanged(nameof(BL_GRP)); } } private string _Time_Delay; public string Time_Delay { get { return _Time_Delay; } set { _Time_Delay = value; RaisePropertyChanged(nameof(Time_Delay)); } } private string _Supplier; /// /// 供应商 /// public string Supplier { get { return _Supplier; } set { _Supplier = value; RaisePropertyChanged(nameof(Supplier)); } } private string _EquipName; /// /// 设备名 /// public string EquipName { get { return _EquipName; } set { _EquipName = value; RaisePropertyChanged(nameof(EquipName)); } } private bool _VDR_Record; public bool VDR_Record { get { return _VDR_Record; } set { _VDR_Record = value; RaisePropertyChanged(nameof(VDR_Record)); } } private string _WHConsole; public string WHConsole { get { return _WHConsole; } set { _WHConsole = value; RaisePropertyChanged(nameof(WHConsole)); } } private ObservableCollection _WHCPU = new ObservableCollection(); public ObservableCollection WHCPU { get { return _WHCPU; } set { _WHCPU = value; WHCPUs.AddRange(value); RaisePropertyChanged(nameof(WHCPU)); } } private ObservableCollection _WHCPUs = new ObservableCollection(); public ObservableCollection WHCPUs { get { return _WHCPUs; } set { _WHCPUs = value; OnPropertyChanged(nameof(WHCPUs)); } } private string _ECRConsole; public string ECRConsole { get { return _ECRConsole; } set { _ECRConsole = value; RaisePropertyChanged(nameof(ECRConsole)); } } private string _ECRCPU; public string ECRCPU { get { return _ECRCPU; } set { _ECRCPU = value; RaisePropertyChanged(nameof(ECRCPU)); } } private ObservableCollection _ECRCPUs = new ObservableCollection(); public ObservableCollection ECRCPUs { get { return _ECRCPUs; } set { _ECRCPUs = value; RaisePropertyChanged(nameof(ECRCPUs)); } } private string _ShipOfficeConsole; public string ShipOfficeConsole { get { return _ShipOfficeConsole; } set { _ShipOfficeConsole = value; RaisePropertyChanged(nameof(ShipOfficeConsole)); } } private string _ShipOfficeCPU; public string ShipOfficeCPU { get { return _ShipOfficeCPU; } set { _ShipOfficeCPU = value; RaisePropertyChanged(nameof(ShipOfficeCPU)); } } private ObservableCollection _ShipOfficeCPUs = new ObservableCollection(); public ObservableCollection ShipOfficeCPUs { get { return _ShipOfficeCPUs; } set { _ShipOfficeCPUs = value; RaisePropertyChanged(nameof(ShipOfficeCPUs)); } } private bool _SLD; public bool SLD { get { return _SLD; } set { _SLD = value; RaisePropertyChanged(nameof(SLD)); } } private bool _SHD; public bool SHD { get { return _SHD; } set { _SHD = value; RaisePropertyChanged(nameof(SHD)); } } private string _SafetyDelay; /// /// 安保延迟 /// public string SafetyDelay { get { return _SafetyDelay; } set { _SafetyDelay = value; RaisePropertyChanged(nameof(SafetyDelay)); } } private string _AutoCtrl; /// /// 自动控制 /// public string AutoCtrl { get { return _AutoCtrl; } set { _AutoCtrl = value; RaisePropertyChanged(nameof(AutoCtrl)); } } private string _AssociatedCableInfo; /// /// 关联电缆信息 /// public string AssociatedCableInfo { get { return _AssociatedCableInfo; } set { _AssociatedCableInfo = value; RaisePropertyChanged(nameof(AssociatedCableInfo)); } } private string _AssociatedChannelInfo; /// /// 关联通道信息 /// public string AssociatedChannelInfo { get { return _AssociatedChannelInfo; } set { _AssociatedChannelInfo = value; RaisePropertyChanged(nameof(AssociatedChannelInfo)); } } private string _Remarks; /// /// 备注 /// public string Remarks { get { return _Remarks; } set { _Remarks = value; RaisePropertyChanged(nameof(Remarks)); } } private List _Suppliers; /// /// 绑定供应商 /// public List Suppliers { get { return _Suppliers; } set { _Suppliers = value; RaisePropertyChanged(nameof(Suppliers)); } } #region 扩展字段 private bool _IsModified; /// /// 是否修改 /// public bool IsModified { get { return _IsModified; } set { _IsModified = value; RaisePropertyChanged(nameof(IsModified)); } } private List _ActionHistorys; /// /// 操作历史 /// public List ActionHistorys { get { return _ActionHistorys; } set { _ActionHistorys = value; } } private bool _DeleteFlg; /// /// 删除标记 /// public bool DeleteFlg { get { return _DeleteFlg; } set { _DeleteFlg = value; } } private ObservableCollection _ChildSignals = new ObservableCollection(); public ObservableCollection ChildSignals { get { return _ChildSignals; } set { _ChildSignals = value; RaisePropertyChanged(nameof(ChildSignals)); } } #endregion #endregion #region 方法 /// /// 将表格对象转换为数据模型类 /// /// public ec_Wire_Group to_ec_Wire_Group(List sigals) { ec_Wire_Group ent; if (string.IsNullOrEmpty(Wire_Group_ID)) { ent = new ec_Wire_Group(); } else { ent = sigals.Where(e => e.Wire_Group_ID.Equals(Wire_Group_ID)).First(); } switch (Status) { case "ToDelete": ent.Status = WireGroupStatusEnum.ToDelete; break; case "New": ent.Status = WireGroupStatusEnum.New; break; case "Used": ent.Status = WireGroupStatusEnum.Used; break; case "Confirmed": ent.Status = WireGroupStatusEnum.Confirmed; break; case "Reopen": ent.Status = WireGroupStatusEnum.Reopen; break; case "deleted": ent.Status = WireGroupStatusEnum.deleted; break; } ent.Wire_Group_ID = Wire_Group_ID; ent.ParentID = ParentID; ent.LinkedID = LinkedID; ent.Group_Name = Group_Name; ent.Group_Desc_EN = Group_Desc_EN; ent.Group_Desc = Group_Desc; ent.ElecOnly = BelongingMajor.Equals("E") ? true : false; if (GroupOther == null) { ent.Signal_Group = ""; } else { ent.Signal_Group = GroupOthers.Where(g => g.DataItemName == GroupOther).Select(g => g.DataItemCode).FirstOrDefault(); } ent.Signal_SeqNo = Signal_SeqNo; ent.Code = Code; ent.InOrOut = InOrOut; ent.IO_Type = IO_Type; ent.Range_Min = Range_Min; ent.Range_Max = Range_Max; ent.Unit = Unit; ent.Alarm_LL = Alarm_LL; ent.Alarm_L = Alarm_L; ent.Alarm_H = Alarm_H; ent.Alarm_HH = Alarm_HH; ent.SENSOR_CODE = SENSOR_CODE; ent.CommunicationPoint = CommunicationPoint; ent.SeriousType = SeriousType; ent.AL_GRP = AL_GRP; ent.BL_GRP = BL_GRP; ent.Time_Delay = Time_Delay; ent.Supplier = Suppliers.Where(g => g.DataItemName == Supplier).Select(g => g.DataItemCode).FirstOrDefault(); ent.EquipName = EquipName; ent.VDR_Record = VDR_Record; ent.WHConsole = WHConsole; ent.WHCPU = ""; foreach (var item in WHCPUs) { if (item != null) { ent.WHCPU = ent.WHCPU + item.DataItemCode + "|"; } } ent.ECRConsole = ECRConsole; ent.ECRCPU = ""; foreach (var item in ECRCPUs) { if (item != null) { ent.ECRCPU = ent.ECRCPU + item.DataItemCode + "|"; } } ent.ShipOfficeConsole = ShipOfficeConsole; ent.ShipOfficeCPU = ""; foreach (var item in ShipOfficeCPUs) { if (item != null) { ent.ShipOfficeCPU = ent.ShipOfficeCPU + item.DataItemCode + "|"; } } ent.SLD = SLD; ent.SHD = SHD; ent.SafetyDelay = SafetyDelay; ent.AutoCtrl = AutoCtrl; if (string.IsNullOrEmpty(AssociatedCableInfo)) { //// 使用正则表达式匹配模式,并提取每组数据 //var matches = Regex.Matches(AssociatedCableInfo, @"电缆位号:(.*?)\s电缆对:(.*)"); // if (matches.Count > 0) // 确保至少有一个匹配项 // { // string cableNumber = matches[0].Groups[1].Value; // 第一个冒号后的值 // string cableSet = matches[0].Groups[2].Value; // 第二个冒号后的值 // } ent.CableName = ""; ent.CableSetName = ""; } else { ent.CableName = AssociatedCableInfo.Split(' ')[0].Split(':')[1]; ent.CableSetName = (AssociatedCableInfo.Split(' ').Count() > 1) ? AssociatedCableInfo.Split(' ')[1].Split(':')[1] : ""; } if (string.IsNullOrEmpty(AssociatedChannelInfo)) { ent.PanelName = ""; ent.StripName = ""; ent.ChannelName = ""; } else { ent.PanelName = AssociatedChannelInfo.Split(' ')[0].Split(':')[1]; ent.StripName = (AssociatedChannelInfo.Split(' ').Count() > 1) ? AssociatedChannelInfo.Split(' ')[1].Split(':')[1] : ""; ent.ChannelName = (AssociatedChannelInfo.Split(' ').Count() > 2) ? AssociatedChannelInfo.Split(' ')[2].Split(':')[2] : ""; } ent.Remarks = Remarks; ent.ActionHistorys = ActionHistorys; ent.DeleteFlg = DeleteFlg; return ent; } #endregion } }