MeasureFile.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //时间:20200610
  2. //作者:郝爽
  3. //功能:测量文件
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using FileManager;
  10. using System.Xml;
  11. using System.IO;
  12. namespace MeasureData
  13. {
  14. public class MeasureFile:ISlo
  15. {
  16. public const string UNTITLED_FILE_NAME = "Untitled";
  17. #region 内容
  18. //文件名
  19. private string m_fileName;
  20. public string FileName
  21. {
  22. get { return this.m_fileName; }
  23. set { this.m_fileName = value; }
  24. }
  25. //文件路径
  26. private string m_filepath;
  27. public string FilePath
  28. {
  29. get { return this.m_filepath; }
  30. set { this.m_filepath = value; }
  31. }
  32. //切孔链表
  33. private List<CutHole> m_listCutHole;
  34. public List<CutHole> ListCutHole
  35. {
  36. get { return this.m_listCutHole; }
  37. set { this.m_listCutHole = value; }
  38. }
  39. /// <summary>
  40. /// 创建XML文件
  41. /// </summary>
  42. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  43. public int CreateXml()
  44. {
  45. if (!File.Exists(this.FilePath + "\\" + this.FileName))
  46. {
  47. if( XmlManager.CreateXmlFile(this.FilePath + "\\" + this.FileName))
  48. {
  49. return 1;
  50. }
  51. else
  52. {
  53. return 0;
  54. }
  55. }
  56. else
  57. {
  58. return 2;
  59. }
  60. }
  61. //XML文件保存
  62. //样品孔存储xml文档
  63. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  64. {
  65. Slo<MeasureFile> slo_msf = new Slo<MeasureFile>();
  66. Slo<CutHole> slo_cuthole = new Slo<CutHole>();
  67. Collection<CutHole> cot_cuthole = new Collection<CutHole>();
  68. for (int i = 0; i < this.ListCutHole.Count; i++)
  69. {
  70. cot_cuthole.addItem(ListCutHole[i]);
  71. }
  72. xString FileName = new xString();
  73. xString FilePath = new xString();
  74. FileName.AssignValue(this.FileName);
  75. FilePath.AssignValue(this.FilePath);
  76. slo_cuthole.Register("FileName", FileName);
  77. slo_cuthole.Register("FilePath", FilePath);
  78. slo_cuthole.Register("ListCutHole", cot_cuthole);
  79. slo_msf.Register("MeasureFile", slo_cuthole);
  80. if (isStoring)
  81. {
  82. slo_msf.Serialize(true, xml, rootNode);
  83. }
  84. else
  85. {
  86. slo_msf.Serialize(false, xml, rootNode);
  87. this.FileName = FileName.value();
  88. this.FilePath = FilePath.value();
  89. for (int i = 0; i < cot_cuthole.m_vCollection.Count; i++)
  90. {
  91. this.ListCutHole.Add(cot_cuthole.getItem(i));
  92. }
  93. }
  94. }
  95. #endregion
  96. //构造函数
  97. public MeasureFile()
  98. {
  99. Init();
  100. }
  101. public void Init()
  102. {
  103. this.ListCutHole = new List<CutHole>();
  104. }
  105. #region 操作
  106. //新建
  107. public void New()
  108. {
  109. int ret = CreateXml();
  110. if(ret>0)
  111. {
  112. XmlDocument doc = new XmlDocument();
  113. doc.Load(this.FilePath + "\\" + this.FileName);//载入xml文件
  114. XmlNode root = doc.SelectSingleNode("XMLData");
  115. Serialize(true, doc, root);
  116. doc.Save(this.FilePath + "\\" + this.FileName);
  117. }
  118. }
  119. //打开
  120. public void Open()
  121. {
  122. }
  123. //保存
  124. public void Save()
  125. {
  126. //Serialize();
  127. }
  128. //另存为
  129. public void SaveAs()
  130. {
  131. }
  132. #endregion
  133. }
  134. }