ConfigManager.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 ConfigManager : 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. //样品配置参数
  36. private MeasureConfigParam m_Config_Param;
  37. public MeasureConfigParam M_Config_Param
  38. {
  39. get { return this.m_Config_Param; }
  40. set { this.m_Config_Param = value; }
  41. }
  42. #endregion
  43. public ConfigManager()
  44. {
  45. this.m_Config_Param = new MeasureConfigParam();
  46. }
  47. /// <summary>
  48. /// 创建XML文件
  49. /// </summary>
  50. /// <param name="filename">创建XML文件的全路径</param>
  51. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  52. public int CreateXml(String filename)
  53. {
  54. if (!File.Exists(filename))
  55. {
  56. if (XmlManager.CreateXmlFile(filename))
  57. {
  58. return 1;
  59. }
  60. else
  61. {
  62. return 0;
  63. }
  64. }
  65. else
  66. {
  67. XmlManager.CreateXmlFile(filename);
  68. return 2;
  69. }
  70. }
  71. //保存
  72. public bool Save(String filename)
  73. {
  74. XmlDocument doc = new XmlDocument();
  75. if (File.Exists(filename))
  76. {
  77. doc.Load(filename);//载入xml文件
  78. }
  79. else
  80. {
  81. return false; //当前路径不存在
  82. }
  83. XmlNode root = doc.SelectSingleNode("XMLData");
  84. Serialize(true, doc, root);
  85. doc.Save(filename);
  86. return true;
  87. }
  88. //读取
  89. public bool Read(String filename)
  90. {
  91. XmlDocument doc = new XmlDocument();
  92. if (File.Exists(filename))
  93. {
  94. doc.Load(filename);//载入xml文件
  95. }
  96. else
  97. {
  98. return false; //当前路径不存在
  99. }
  100. XmlNode root = doc.SelectSingleNode("XMLData");
  101. Serialize(false, doc, root);
  102. //doc.Save(filename);
  103. return true;
  104. }
  105. //XML文件保存
  106. //样品孔存储xml文档
  107. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  108. {
  109. Slo sFile = new Slo();
  110. Slo sParam = new Slo();
  111. xBool pt_depostion = new xBool();
  112. xString template_file = new xString();
  113. xString sample_name = new xString();
  114. pt_depostion.AssignValue(this.pt_Depostion);
  115. template_file.AssignValue(this.template_File);
  116. sample_name.AssignValue(this.sample_Name);
  117. sFile.Register("PT_Depostion", pt_depostion);
  118. sFile.Register("Template_File", template_file);
  119. sFile.Register("Sample_Name", sample_name);
  120. sFile.Register("MeasureConfigParam", m_Config_Param);
  121. if (isStoring)
  122. {
  123. sFile.Serialize(true, xml, rootNode);
  124. }
  125. else
  126. {
  127. sFile.Serialize(false, xml, rootNode);
  128. this.pt_Depostion = pt_depostion.value();
  129. this.template_File = template_file.value();
  130. this.sample_Name = sample_name.value();
  131. }
  132. }
  133. }
  134. }