//时间:20200610 //作者:郝爽 //功能:测量文件 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FileManager; using System.Xml; using System.IO; namespace MeasureData { public class MeasureFile:ISlo { public const string UNTITLED_FILE_NAME = "Untitled"; #region 内容 //文件名 private string m_fileName; public string FileName { get { return this.m_fileName; } set { this.m_fileName = value; } } //文件路径 private string m_filepath; public string FilePath { get { return this.m_filepath; } set { this.m_filepath = value; } } //切孔链表 private List m_listCutHole; public List ListCutHole { get { return this.m_listCutHole; } set { this.m_listCutHole = value; } } /// /// 创建XML文件 /// /// 0:失败;1:成功;2:文件已存在 public int CreateXml() { if (!File.Exists(this.FilePath + "\\" + this.FileName)) { if( XmlManager.CreateXmlFile(this.FilePath + "\\" + this.FileName)) { return 1; } else { return 0; } } else { return 2; } } //XML文件保存 //样品孔存储xml文档 public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode) { Slo slo_msf = new Slo(); Slo slo_cuthole = new Slo(); Collection cot_cuthole = new Collection(); for (int i = 0; i < this.ListCutHole.Count; i++) { cot_cuthole.addItem(ListCutHole[i]); } xString FileName = new xString(); xString FilePath = new xString(); FileName.AssignValue(this.FileName); FilePath.AssignValue(this.FilePath); slo_cuthole.Register("FileName", FileName); slo_cuthole.Register("FilePath", FilePath); slo_cuthole.Register("ListCutHole", cot_cuthole); slo_msf.Register("MeasureFile", slo_cuthole); if (isStoring) { slo_msf.Serialize(true, xml, rootNode); } else { slo_msf.Serialize(false, xml, rootNode); this.FileName = FileName.value(); this.FilePath = FilePath.value(); for (int i = 0; i < cot_cuthole.m_vCollection.Count; i++) { this.ListCutHole.Add(cot_cuthole.getItem(i)); } } } #endregion //构造函数 public MeasureFile() { Init(); } public void Init() { this.ListCutHole = new List(); } #region 操作 //新建 public void New() { int ret = CreateXml(); if(ret>0) { XmlDocument doc = new XmlDocument(); doc.Load(this.FilePath + "\\" + this.FileName);//载入xml文件 XmlNode root = doc.SelectSingleNode("XMLData"); Serialize(true, doc, root); doc.Save(this.FilePath + "\\" + this.FileName); } } //打开 public void Open() { } //保存 public void Save() { //Serialize(); } //另存为 public void SaveAs() { } #endregion } }