123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //时间: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<CutHole> m_listCutHole;
- public List<CutHole> ListCutHole
- {
- get { return this.m_listCutHole; }
- set { this.m_listCutHole = value; }
- }
- /// <summary>
- /// 创建XML文件
- /// </summary>
- /// <returns>0:失败;1:成功;2:文件已存在</returns>
- 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<MeasureFile> slo_msf = new Slo<MeasureFile>();
- Slo<CutHole> slo_cuthole = new Slo<CutHole>();
- Collection<CutHole> cot_cuthole = new Collection<CutHole>();
- 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<CutHole>();
- }
- #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
- }
- }
|