public void LoadFromXML() { /// 创建XmlDocument类的实例 XmlDocument myxmldoc = new XmlDocument(); string sPath = CProject.sPrjPath + "\\Alarm.xml"; myxmldoc.Load(sPath); string xpath = "System/" + CProject.sPrjName; XmlElement PrjNode = (XmlElement)myxmldoc.SelectSingleNode(xpath); ListVarAlarm.Clear(); foreach (XmlElement StaNode in PrjNode.ChildNodes) { if (StaNode.Name == "Alarms") { continue; } CStation nSta = frmMain.staComm.GetStaByStaName(StaNode.Name); if (nSta == null) { continue; } xpath = "Alarms/Vars"; XmlElement VarsNode = (XmlElement)StaNode.SelectSingleNode(xpath); if (VarsNode == null) { continue; } foreach (XmlElement VarNode in VarsNode.ChildNodes) { CVar nVar = frmMain.staComm.GetVarByStaNameVarName(nSta.Name, VarNode.Name); if (nVar == null) { continue; } CVarAlarm newAlarm = new CVarAlarm(); newAlarm.LoadFromNode(VarNode); ListVarAlarm.Add(newAlarm); nVar.VarAlarm = newAlarm; }//end foreach (XmlElement VarNode in VarsNode.ChildNodes) } }
//复制实例 public CVarAlarm Clone() { CVarAlarm obj = (CVarAlarm)this.MemberwiseClone(); return(obj); }