ConfigFile.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using System.IO;
  8. using FileManager;
  9. namespace MeasureData
  10. {
  11. public class ConfigFile : ISlo
  12. {
  13. #region 内容
  14. //是否PT沉积
  15. private Boolean pt_Depostion;
  16. public Boolean PT_Depostion
  17. {
  18. get { return this.pt_Depostion; }
  19. set { this.pt_Depostion = value; }
  20. }
  21. //模板文件
  22. private String template_File;
  23. public String Template_File
  24. {
  25. get { return this.template_File; }
  26. set { this.template_File = value; }
  27. }
  28. //样品名称
  29. private String sample_Name;
  30. public String Sample_Name
  31. {
  32. get { return this.sample_Name; }
  33. set { this.sample_Name = value; }
  34. }
  35. #endregion
  36. public ConfigFile()
  37. {
  38. //this.m_Config_Param = new MeasureConfigParam();
  39. }
  40. /// <summary>
  41. /// 创建XML文件
  42. /// </summary>
  43. /// <param name="filename">创建XML文件的全路径</param>
  44. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  45. public int CreateXml(String filename)
  46. {
  47. if (!File.Exists(filename))
  48. {
  49. if (XmlManager.CreateXmlFile(filename))
  50. {
  51. return 1;
  52. }
  53. else
  54. {
  55. return 0;
  56. }
  57. }
  58. else
  59. {
  60. XmlManager.CreateXmlFile(filename);
  61. return 2;
  62. }
  63. }
  64. //保存
  65. public bool Save(String filename)
  66. {
  67. XmlDocument doc = new XmlDocument();
  68. if (File.Exists(filename))
  69. {
  70. doc.Load(filename);//载入xml文件
  71. }
  72. else
  73. {
  74. return false; //当前路径不存在
  75. }
  76. XmlNode root = doc.SelectSingleNode("XMLData");
  77. Serialize(true, doc, root);
  78. doc.Save(filename);
  79. return true;
  80. }
  81. //读取
  82. public bool Read(String filename)
  83. {
  84. XmlDocument doc = new XmlDocument();
  85. if (File.Exists(filename))
  86. {
  87. doc.Load(filename);//载入xml文件
  88. }
  89. else
  90. {
  91. return false; //当前路径不存在
  92. }
  93. XmlNode root = doc.SelectSingleNode("XMLData");
  94. Serialize(false, doc, root);
  95. //doc.Save(filename);
  96. return true;
  97. }
  98. //XML文件保存
  99. //样品孔存储xml文档
  100. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  101. {
  102. Slo sFile = new Slo();
  103. Slo sParam = new Slo();
  104. xBool pt_depostion = new xBool();
  105. xString template_file = new xString();
  106. xString sample_name = new xString();
  107. pt_depostion.AssignValue(this.pt_Depostion);
  108. template_file.AssignValue(this.template_File);
  109. sample_name.AssignValue(this.sample_Name);
  110. sFile.Register("PT_Depostion", pt_depostion);
  111. sFile.Register("Template_File", template_file);
  112. sFile.Register("Sample_Name", sample_name);
  113. //sFile.Register("MeasureConfigParam", m_Config_Param);
  114. if (isStoring)
  115. {
  116. sFile.Serialize(true, xml, rootNode);
  117. }
  118. else
  119. {
  120. sFile.Serialize(false, xml, rootNode);
  121. this.pt_Depostion = pt_depostion.value();
  122. this.template_File = template_file.value();
  123. this.sample_Name = sample_name.value();
  124. }
  125. }
  126. }
  127. }