ConfigFile.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 Boolean is_Photograph;
  16. public Boolean Is_Photograph
  17. {
  18. get { return this.is_Photograph; }
  19. set { this.is_Photograph = value; }
  20. }
  21. //是否PT沉积
  22. private Boolean pt_Depostion;
  23. public Boolean PT_Depostion
  24. {
  25. get { return this.pt_Depostion; }
  26. set { this.pt_Depostion = value; }
  27. }
  28. //PT使用的ELY文件
  29. private String pt_ELYFile;
  30. public String PT_ELYFile
  31. {
  32. get { return this.pt_ELYFile; }
  33. set { this.pt_ELYFile = value; }
  34. }
  35. //FIB使用的ELY文件
  36. private String fib_ELYFile;
  37. public String FIB_ELYFile
  38. {
  39. get { return this.fib_ELYFile; }
  40. set { this.fib_ELYFile = value; }
  41. }
  42. //拉直操作需要的放大位数
  43. private double stretch_Magnification;
  44. public double Stretch_Magnification
  45. {
  46. get { return this.stretch_Magnification; }
  47. set { this.stretch_Magnification = value; }
  48. }
  49. //定位切割位置的放大倍数
  50. private double location_Magnification;
  51. public double Location_Magnification
  52. {
  53. get { return this.location_Magnification; }
  54. set { this.location_Magnification = value; }
  55. }
  56. //定位切割位置的工作电压
  57. private double location_Voltage;
  58. public double Location_Voltage
  59. {
  60. get { return this.location_Voltage; }
  61. set { this.location_Voltage = value; }
  62. }
  63. //拍照的放大倍数
  64. private double photograph_Magnification;
  65. public double Photograph_Magnification
  66. {
  67. get { return this.photograph_Magnification; }
  68. set { this.photograph_Magnification = value; }
  69. }
  70. //拍照的工作电压
  71. private double photograph_Voltage;
  72. public double Photograph_Voltage
  73. {
  74. get { return this.photograph_Voltage; }
  75. set { this.photograph_Voltage = value; }
  76. }
  77. //校正角度选择
  78. private double correction_Angle;
  79. public double Correction_Angle
  80. {
  81. get { return this.correction_Angle; }
  82. set { this.correction_Angle = value; }
  83. }
  84. //样品类型
  85. private String sample_Type;
  86. public String Sample_Type
  87. {
  88. get { return this.sample_Type; }
  89. set { this.sample_Type = value; }
  90. }
  91. //厂商
  92. private String firm;
  93. public String Firm
  94. {
  95. get { return this.firm; }
  96. set { this.firm = value; }
  97. }
  98. //对焦参数
  99. //能谱参数
  100. //MeasureParam m_
  101. #endregion
  102. public ConfigFile()
  103. {
  104. }
  105. /// <summary>
  106. /// 创建XML文件
  107. /// </summary>
  108. /// <param name="filename">创建XML文件的全路径</param>
  109. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  110. public int CreateXml(String filename)
  111. {
  112. if (!File.Exists(filename))
  113. {
  114. if (XmlManager.CreateXmlFile(filename))
  115. {
  116. return 1;
  117. }
  118. else
  119. {
  120. return 0;
  121. }
  122. }
  123. else
  124. {
  125. XmlManager.CreateXmlFile(filename);
  126. return 2;
  127. }
  128. }
  129. //保存
  130. public bool Save(String filename)
  131. {
  132. CreateXml(filename);
  133. XmlDocument doc = new XmlDocument();
  134. if (File.Exists(filename))
  135. {
  136. doc.Load(filename);//载入xml文件
  137. }
  138. else
  139. {
  140. return false; //当前路径不存在
  141. }
  142. XmlNode root = doc.SelectSingleNode("XMLData");
  143. Serialize(true, doc, root);
  144. doc.Save(filename);
  145. return true;
  146. }
  147. //读取
  148. public bool Read(String filename)
  149. {
  150. XmlDocument doc = new XmlDocument();
  151. if (File.Exists(filename))
  152. {
  153. doc.Load(filename);//载入xml文件
  154. }
  155. else
  156. {
  157. return false; //当前路径不存在
  158. }
  159. XmlNode root = doc.SelectSingleNode("XMLData");
  160. Serialize(false, doc, root);
  161. //doc.Save(filename);
  162. return true;
  163. }
  164. //XML文件保存
  165. //样品孔存储xml文档
  166. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  167. {
  168. Slo sFile = new Slo();
  169. xBool isPhotograph = new xBool();
  170. xBool ptDepostion = new xBool();
  171. isPhotograph.AssignValue(this.is_Photograph);
  172. ptDepostion.AssignValue(this.pt_Depostion);
  173. sFile.Register("Is_Photograph", isPhotograph);
  174. sFile.Register("PT_Depostion", ptDepostion);
  175. xString ptELYFile = new xString();
  176. xString fibELYFile = new xString();
  177. ptELYFile.AssignValue(this.pt_ELYFile);
  178. fibELYFile.AssignValue(this.fib_ELYFile);
  179. sFile.Register("PT_ELYFile", ptELYFile);
  180. sFile.Register("FIB_ELYFile", fibELYFile);
  181. xDouble stretchMagnification = new xDouble();
  182. xDouble locationMagnification = new xDouble();
  183. xDouble locationVoltage = new xDouble();
  184. xDouble photographMagnification = new xDouble();
  185. xDouble photographVoltage = new xDouble();
  186. stretchMagnification.AssignValue(this.stretch_Magnification);
  187. locationMagnification.AssignValue(this.location_Magnification);
  188. locationVoltage.AssignValue(this.location_Voltage);
  189. photographMagnification.AssignValue(this.photograph_Magnification);
  190. photographVoltage.AssignValue(this.photograph_Voltage);
  191. sFile.Register("Strectch_Magnification", stretchMagnification);
  192. sFile.Register("Locatio_Magnification", locationMagnification);
  193. sFile.Register("Location_Voltage", locationVoltage);
  194. sFile.Register("Photograph_Magnification", photographMagnification);
  195. sFile.Register("Photograph_Voltage", photographVoltage);
  196. xDouble correctionAngle = new xDouble();
  197. correctionAngle.AssignValue(this.correction_Angle);
  198. sFile.Register("Correction_Angle", correctionAngle);
  199. xString sampleType = new xString();
  200. xString _firm = new xString();
  201. sampleType.AssignValue(this.sample_Type);
  202. _firm.AssignValue(this.firm);
  203. sFile.Register("Sample_Type", sampleType);
  204. sFile.Register("Firm", _firm);
  205. if (isStoring)
  206. {
  207. sFile.Serialize(true, xml, rootNode);
  208. }
  209. else
  210. {
  211. sFile.Serialize(false, xml, rootNode);
  212. this.is_Photograph = isPhotograph.value();
  213. this.pt_Depostion = ptDepostion.value();
  214. this.pt_ELYFile = ptELYFile.value();
  215. this.fib_ELYFile = fibELYFile.value();
  216. this.stretch_Magnification = stretchMagnification.value();
  217. this.location_Magnification = locationMagnification.value();
  218. this.location_Voltage = locationVoltage.value();
  219. this.photograph_Magnification = photographMagnification.value();
  220. this.photograph_Voltage = photographVoltage.value();
  221. this.correction_Angle = correctionAngle.value();
  222. this.sample_Type = sampleType.value();
  223. this.firm = _firm.value();
  224. }
  225. }
  226. }
  227. }