public static int CompareByLineName(ProductionLineEntity a, ProductionLineEntity b) { if (a == null) { if (b == null) { return(0); } else { return(-1); } } else { if (b == null) { return(1); } else { return(string.Compare(a.Name, b.Name)); } } }
public DeviceEntity(ProductionLineEntity parent) { Parent = parent ?? throw new Exception( "设备对象不能单独存在,必须要依赖于ProductLineEntity对象"); name = $"KnownDevice[{Guid.NewGuid().ToString("N")}]"; Service = new DCSGatewayServiceController(this); }
public static DeviceEntity ImportFromXmlNode( ProductionLineEntity line, XmlNode node, PLCType plcType, PLCEntity plcEntity) { DeviceEntity rlt = null; if (node.Name.ToUpper() != "DEVICE") { return(rlt); } rlt = new DeviceEntity(line) { Name = XMLHelper.GetAttributeStringValue(node, "Name", ""), PLCType = plcType, DBType = (SiemensRegisterType)Enum.Parse( typeof(SiemensRegisterType), XMLHelper.GetAttributeStringValue(node, "DBType", "DB")), DBNumber = XMLHelper.GetAttributeIntValue(node, "DBNumber", 0), CycleReadMode = (CycleReadMode)Enum.Parse( typeof(CycleReadMode), XMLHelper.GetAttributeStringValue(node, "CycleReadBlock", "ControlBlock")), T133LeafID = XMLHelper.GetAttributeIntValue(node, "T133LeafID", 0), T216LeafID = XMLHelper.GetAttributeIntValue(node, "T216LeafID", 0), T107LeafID = XMLHelper.GetAttributeIntValue(node, "T107LeafID", 0), SplitterTime = XMLHelper.GetAttributeIntValue(node, "SplitterTime", 100), }; rlt.BelongPLC.IPAddress = plcEntity.IPAddress; rlt.BelongPLC.Rack = plcEntity.Rack; rlt.BelongPLC.Slot = plcEntity.Slot; XmlNode xmlGroup = node.FirstChild; while (xmlGroup != null) { GroupEntity group = GroupEntity.ImportFromXmlNode( rlt, xmlGroup); if (group != null) { rlt.Groups.Add(group); } xmlGroup = xmlGroup.NextSibling; } return(rlt); }
public void Add( ProductionLineEntity line, AddToWholeEntityQueueHandler addToWholeEntityQueueHandler) { if (this[line.ID] != null) { throw new Exception($"已经存在[{line.Name}]的产线"); } else { lines.Add(line.ID, line); addToWholeEntityQueueHandler?.Invoke(line); } }
public void Remove(ProductionLineEntity line) { line.RemoveChildren(); lines.Remove(line.ID); DataHelper.Instance.AllEntities.Remove(line.ID); }
public DeviceEntity( XmlNode node, ProductionLineEntity parent, AddToWholeEntityQueueHandler addToWholeEntityQueueHandler) : this(parent) { this.addToWholeEntityQueueHandler = addToWholeEntityQueueHandler; #region 从Xml节点属性中获取属性值 if (node.Attributes["Name"] != null) { Name = node.Attributes["Name"].Value; } if (node.Attributes["T133LeafID"] != null) { if (int.TryParse(node.Attributes["T133LeafID"].Value, out int rlt)) { T133LeafID = rlt; } } if (node.Attributes["T216LeafID"] != null) { if (int.TryParse(node.Attributes["T216LeafID"].Value, out int rlt)) { T216LeafID = rlt; } } if (node.Attributes["T107LeafID"] != null) { if (int.TryParse(node.Attributes["T107LeafID"].Value, out int rlt)) { T107LeafID = rlt; } } if (node.Attributes["DBType"] != null) { try { DBType = (SiemensRegisterType)Enum.Parse( typeof(SiemensRegisterType), node.Attributes["DBType"].Value); } catch { string enumValues = ""; foreach (var value in Enum.GetValues(typeof(SiemensRegisterType))) { enumValues += $"[{value}]"; } throw new Exception( $"{node.Name}.{Name}节点中[DBType]属性值错误,只支持[{enumValues}]"); } } if (node.Attributes["DBNumber"] != null) { if (int.TryParse(node.Attributes["DBNumber"].Value, out int rlt)) { DBNumber = rlt; } } if (node.Attributes["CycleReadMode"] != null) { try { CycleReadMode = (CycleReadMode)Enum.Parse( typeof(CycleReadMode), node.Attributes["CycleReadMode"].Value); } catch { string enumValues = ""; foreach (var value in Enum.GetValues(typeof(CycleReadMode))) { enumValues += $"[{value}]"; } throw new Exception( $"{node.Name}.{Name}节点中[CycleReadMode]属性值错误,只支持[{enumValues}]"); } } if (node.Attributes["PLCType"] != null) { try { PLCType = (PLCType)Enum.Parse( typeof(PLCType), node.Attributes["PLCType"].Value); } catch { string enumValues = ""; foreach (var value in Enum.GetValues(typeof(PLCType))) { enumValues += $"[{value}]"; } throw new Exception( $"{node.Name}.{Name}节点中[PLCType]属性值错误,只支持[{enumValues}]"); } } if (node.Attributes["SplitterTime"] != null) { if (int.TryParse(node.Attributes["SplitterTime"].Value, out int rlt)) { SplitterTime = rlt; } } #endregion XmlNode childNode = node.FirstChild; while (childNode != null) { if (childNode.Name == "PLC") { BelongPLC.LoadFromXmlNode(childNode); } else if (childNode.Name == "TagGroup") { try { GroupEntity group = new GroupEntity(childNode, this); if (group != null) { Groups.Add(group); } } catch (Exception error) { XtraMessageBox.Show( error.Message, "出错啦", MessageBoxButtons.OK); } } childNode = childNode.NextSibling; } }