/// <summary> /// Operates the XML node information. /// </summary> /// <param name="powerEnable">The qc enable para.</param> /// <param name="powerPara">The qc control para.</param> public static void OperateXmlNodeInfo(AlarmEnablePara powerEnable, PowerAlarmPara powerPara) { List <string> qcParaFields = (from fieldinfo in powerPara.GetType().GetFields() select fieldinfo.Name).ToList(); XElement rootNode = XElement.Load(PowerConfigPath); foreach (string qcname in qcParaFields) { XElement xElement = rootNode.Element(qcname); string str1 = powerEnable.GetType().GetField(qcname).GetValue(powerEnable).ToString(); string str2 = powerPara.GetType().GetField(qcname).GetValue(powerPara).ToString().Equals("false") ? string.Empty : powerPara.GetType().GetField(qcname).GetValue(powerPara).ToString(); if (xElement != null) { xElement.SetAttributeValue("Enable", str1); xElement.SetValue(str2); } else { XElement newNode = new XElement(qcname, new XAttribute("Enable", str1)); newNode.SetValue(str2); rootNode.Add(newNode); } } rootNode.Save(PowerConfigPath); }
/// <summary> /// Gets the XML node information. /// </summary> public void GetXmlNodeInfo() { try { Object objqcPara = _powerAlarm; Object objqcEnablePara = _powerEnable; List <string> qcParaFields = (from fieldinfo in _powerAlarm.GetType().GetFields() select fieldinfo.Name).ToList(); XElement rootNode = XElement.Load(PowerConfigPath); foreach (string qcname in qcParaFields) { XElement xElement = rootNode.Element(qcname); _powerAlarm.GetType().GetField(qcname).SetValue(objqcPara, (xElement == null || string.IsNullOrEmpty(xElement.Value)) ? 9999 : decimal.Parse(xElement.Value)); _powerEnable.GetType().GetField(qcname).SetValue(objqcEnablePara, xElement != null && !string.IsNullOrEmpty(xElement.Attribute("Enable").Value) && bool.Parse(xElement.Attribute("Enable").Value)); } _powerAlarm = (PowerAlarmPara)objqcPara; _powerEnable = (AlarmEnablePara)objqcEnablePara; } catch { throw; } }