using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using System.IO; using FileManager; namespace MeasureData { public class ConfigFile : ISlo { #region 内容 //是否PT沉积 private Boolean pt_Depostion; public Boolean PT_Depostion { get { return this.pt_Depostion; } set { this.pt_Depostion = value; } } //模板文件 private String template_File; public String Template_File { get { return this.template_File; } set { this.template_File = value; } } //样品名称 private String sample_Name; public String Sample_Name { get { return this.sample_Name; } set { this.sample_Name = value; } } #endregion public ConfigFile() { //this.m_Config_Param = new MeasureConfigParam(); } /// /// 创建XML文件 /// /// 创建XML文件的全路径 /// 0:失败;1:成功;2:文件已存在 public int CreateXml(String filename) { if (!File.Exists(filename)) { if (XmlManager.CreateXmlFile(filename)) { return 1; } else { return 0; } } else { XmlManager.CreateXmlFile(filename); return 2; } } //保存 public bool Save(String filename) { XmlDocument doc = new XmlDocument(); if (File.Exists(filename)) { doc.Load(filename);//载入xml文件 } else { return false; //当前路径不存在 } XmlNode root = doc.SelectSingleNode("XMLData"); Serialize(true, doc, root); doc.Save(filename); return true; } //读取 public bool Read(String filename) { XmlDocument doc = new XmlDocument(); if (File.Exists(filename)) { doc.Load(filename);//载入xml文件 } else { return false; //当前路径不存在 } XmlNode root = doc.SelectSingleNode("XMLData"); Serialize(false, doc, root); //doc.Save(filename); return true; } //XML文件保存 //样品孔存储xml文档 public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode) { Slo sFile = new Slo(); Slo sParam = new Slo(); xBool pt_depostion = new xBool(); xString template_file = new xString(); xString sample_name = new xString(); pt_depostion.AssignValue(this.pt_Depostion); template_file.AssignValue(this.template_File); sample_name.AssignValue(this.sample_Name); sFile.Register("PT_Depostion", pt_depostion); sFile.Register("Template_File", template_file); sFile.Register("Sample_Name", sample_name); //sFile.Register("MeasureConfigParam", m_Config_Param); if (isStoring) { sFile.Serialize(true, xml, rootNode); } else { sFile.Serialize(false, xml, rootNode); this.pt_Depostion = pt_depostion.value(); this.template_File = template_file.value(); this.sample_Name = sample_name.value(); } } } }