ConfigFile.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. //文件名
  15. private string m_fileName;
  16. public string FileName
  17. {
  18. get { return this.m_fileName; }
  19. set { this.m_fileName = value; }
  20. }
  21. //文件路径
  22. private string m_filepath;
  23. public string FilePath
  24. {
  25. get { return this.m_filepath; }
  26. set { this.m_filepath = value; }
  27. }
  28. public MeasureParam m_Config;
  29. #endregion
  30. public ConfigFile(MeasureParam mp)
  31. {
  32. this.m_Config = mp;
  33. }
  34. /// <summary>
  35. /// 创建XML文件
  36. /// </summary>
  37. /// <param name="filename">创建XML文件的全路径</param>
  38. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  39. public int CreateXml(String filename)
  40. {
  41. if (!File.Exists(filename))
  42. {
  43. if (XmlManager.CreateXmlFile(filename))
  44. {
  45. return 1;
  46. }
  47. else
  48. {
  49. return 0;
  50. }
  51. }
  52. else
  53. {
  54. XmlManager.CreateXmlFile(filename);
  55. return 2;
  56. }
  57. }
  58. //保存
  59. public bool Save(String filename)
  60. {
  61. CreateXml(filename);
  62. XmlDocument doc = new XmlDocument();
  63. if (File.Exists(filename))
  64. {
  65. doc.Load(filename);//载入xml文件
  66. }
  67. else
  68. {
  69. return false; //当前路径不存在
  70. }
  71. XmlNode root = doc.SelectSingleNode("XMLData");
  72. Serialize(true, doc, root);
  73. doc.Save(filename);
  74. return true;
  75. }
  76. //读取
  77. public bool Read(String filename)
  78. {
  79. XmlDocument doc = new XmlDocument();
  80. if (File.Exists(filename))
  81. {
  82. doc.Load(filename);//载入xml文件
  83. }
  84. else
  85. {
  86. return false; //当前路径不存在
  87. }
  88. XmlNode root = doc.SelectSingleNode("XMLData");
  89. Serialize(false, doc, root);
  90. //doc.Save(filename);
  91. return true;
  92. }
  93. //XML文件保存
  94. //样品孔存储xml文档
  95. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  96. {
  97. Slo sFile = new Slo();
  98. sFile.Register("Param", this.m_Config);
  99. //xBool isPhotograph = new xBool();
  100. //xBool ptDepostion = new xBool();
  101. //isPhotograph.AssignValue(m_Config.Is_Photograph);
  102. //ptDepostion.AssignValue(m_Config.PT);
  103. //sFile.Register("Is_Photograph", isPhotograph);
  104. //sFile.Register("PT_Depostion", ptDepostion);
  105. //xString ptELYFile = new xString();
  106. //xString fibELYFile = new xString();
  107. //ptELYFile.AssignValue(m_Config.PTTemp);
  108. //fibELYFile.AssignValue(m_Config.FIBTemp);
  109. //sFile.Register("PT_ELYFile", ptELYFile);
  110. //sFile.Register("FIB_ELYFile", fibELYFile);
  111. //xDouble stretchMagnification = new xDouble();
  112. //xDouble locationMagnification = new xDouble();
  113. //xDouble locationVoltage = new xDouble();
  114. //xDouble photographMagnification = new xDouble();
  115. //xDouble photographVoltage = new xDouble();
  116. //stretchMagnification.AssignValue(m_Config.Stretch_Magnification);
  117. //locationMagnification.AssignValue(m_Config.Location_Magnification);
  118. //locationVoltage.AssignValue(m_Config.Location_Voltage);
  119. //photographMagnification.AssignValue(m_Config.Photograph_Magnification);
  120. //photographVoltage.AssignValue(m_Config.Photograph_Voltage);
  121. //sFile.Register("Strectch_Magnification", stretchMagnification);
  122. //sFile.Register("Locatio_Magnification", locationMagnification);
  123. //sFile.Register("Location_Voltage", locationVoltage);
  124. //sFile.Register("Photograph_Magnification", photographMagnification);
  125. //sFile.Register("Photograph_Voltage", photographVoltage);
  126. //xDouble correctionAngle = new xDouble();
  127. //correctionAngle.AssignValue(m_Config.Correction_Angle);
  128. //sFile.Register("Correction_Angle", correctionAngle);
  129. //xString sampleType = new xString();
  130. //xString _firm = new xString();
  131. //sampleType.AssignValue(m_Config.SampleName);
  132. //_firm.AssignValue(m_Config.Firm);
  133. //sFile.Register("Sample_Type", sampleType);
  134. //sFile.Register("Firm", _firm);
  135. if (isStoring)
  136. {
  137. sFile.Serialize(true, xml, rootNode);
  138. }
  139. else
  140. {
  141. sFile.Serialize(false, xml, rootNode);
  142. //m_Config.Is_Photograph = isPhotograph.value();
  143. //m_Config.PT = ptDepostion.value();
  144. //m_Config.PTTemp = ptELYFile.value();
  145. //m_Config.FIBTemp = fibELYFile.value();
  146. //m_Config.Stretch_Magnification = stretchMagnification.value();
  147. //m_Config.Location_Magnification = locationMagnification.value();
  148. //m_Config.Location_Voltage = locationVoltage.value();
  149. //m_Config.Photograph_Magnification = photographMagnification.value();
  150. //m_Config.Photograph_Voltage = photographVoltage.value();
  151. //m_Config.Correction_Angle = correctionAngle.value();
  152. //m_Config.SampleName = sampleType.value();
  153. //m_Config.Firm = _firm.value();
  154. }
  155. }
  156. }
  157. }