private void UpdateParam(XElement tmp, ParamModel param) { tmp.Attribute("Name").Value = param.Name; tmp.Attribute("Type").Value = param.Type.ToString(); tmp.Attribute("Val").Value = param.Val; tmp.Attribute("Comment").Value = param.Comment; }
public void SaveParam(ParamModel param) { XDocument xDoc = XDocument.Load(NameFile); // записать foreach (XElement tmp in xDoc.Element("ProgramParam").Elements("level")) { foreach (XElement tmp1 in tmp.Elements("level")) { if ((tmp1.Attribute("Id").Value.ToString() == param.ParamID.ToString()) && (param.Id == 0)) { WriteParam(tmp1, param); break; } foreach (XElement tmp2 in tmp1.Elements("Param")) { if (param.Id != 0) { if (tmp2.Attribute("Id").Value.ToString() == param.Id.ToString()) { UpdateParam(tmp2, param); break; } } } } } xDoc.Save(NameFile); LoadData(); }
private void WriteParam(XElement tmp, ParamModel param) { tmp.Add(new XElement("Param", new XAttribute("Id", GetNewIndexParam()), new XAttribute("ParamID", param.ParamID), new XAttribute("Name", param.Name), new XAttribute("Type", param.Type), new XAttribute("Val", param.Val), new XAttribute("Comment", param.Comment) )); }