ConfigFile.cs 8.0 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. #endregion
  101. public ConfigFile()
  102. {
  103. }
  104. /// <summary>
  105. /// 创建XML文件
  106. /// </summary>
  107. /// <param name="filename">创建XML文件的全路径</param>
  108. /// <returns>0:失败;1:成功;2:文件已存在</returns>
  109. public int CreateXml(String filename)
  110. {
  111. if (!File.Exists(filename))
  112. {
  113. if (XmlManager.CreateXmlFile(filename))
  114. {
  115. return 1;
  116. }
  117. else
  118. {
  119. return 0;
  120. }
  121. }
  122. else
  123. {
  124. XmlManager.CreateXmlFile(filename);
  125. return 2;
  126. }
  127. }
  128. //保存
  129. public bool Save(String filename)
  130. {
  131. CreateXml(filename);
  132. XmlDocument doc = new XmlDocument();
  133. if (File.Exists(filename))
  134. {
  135. doc.Load(filename);//载入xml文件
  136. }
  137. else
  138. {
  139. return false; //当前路径不存在
  140. }
  141. XmlNode root = doc.SelectSingleNode("XMLData");
  142. Serialize(true, doc, root);
  143. doc.Save(filename);
  144. return true;
  145. }
  146. //读取
  147. public bool Read(String filename)
  148. {
  149. XmlDocument doc = new XmlDocument();
  150. if (File.Exists(filename))
  151. {
  152. doc.Load(filename);//载入xml文件
  153. }
  154. else
  155. {
  156. return false; //当前路径不存在
  157. }
  158. XmlNode root = doc.SelectSingleNode("XMLData");
  159. Serialize(false, doc, root);
  160. //doc.Save(filename);
  161. return true;
  162. }
  163. //XML文件保存
  164. //样品孔存储xml文档
  165. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  166. {
  167. Slo sFile = new Slo();
  168. xBool isPhotograph = new xBool();
  169. xBool ptDepostion = new xBool();
  170. isPhotograph.AssignValue(this.is_Photograph);
  171. ptDepostion.AssignValue(this.pt_Depostion);
  172. sFile.Register("Is_Photograph", isPhotograph);
  173. sFile.Register("PT_Depostion", ptDepostion);
  174. xString ptELYFile = new xString();
  175. xString fibELYFile = new xString();
  176. ptELYFile.AssignValue(this.pt_ELYFile);
  177. fibELYFile.AssignValue(this.fib_ELYFile);
  178. sFile.Register("PT_ELYFile", ptELYFile);
  179. sFile.Register("FIB_ELYFile", fibELYFile);
  180. xDouble stretchMagnification = new xDouble();
  181. xDouble locationMagnification = new xDouble();
  182. xDouble locationVoltage = new xDouble();
  183. xDouble photographMagnification = new xDouble();
  184. xDouble photographVoltage = new xDouble();
  185. stretchMagnification.AssignValue(this.stretch_Magnification);
  186. locationMagnification.AssignValue(this.location_Magnification);
  187. locationVoltage.AssignValue(this.location_Voltage);
  188. photographMagnification.AssignValue(this.photograph_Magnification);
  189. photographVoltage.AssignValue(this.photograph_Voltage);
  190. sFile.Register("Strectch_Magnification", stretchMagnification);
  191. sFile.Register("Locatio_Magnification", locationMagnification);
  192. sFile.Register("Location_Voltage", locationVoltage);
  193. sFile.Register("Photograph_Magnification", photographMagnification);
  194. sFile.Register("Photograph_Voltage", photographVoltage);
  195. xDouble correctionAngle = new xDouble();
  196. correctionAngle.AssignValue(this.correction_Angle);
  197. sFile.Register("Correction_Angle", correctionAngle);
  198. xString sampleType = new xString();
  199. xString _firm = new xString();
  200. sampleType.AssignValue(this.sample_Type);
  201. _firm.AssignValue(this.firm);
  202. sFile.Register("Sample_Type", sampleType);
  203. sFile.Register("Firm", _firm);
  204. if (isStoring)
  205. {
  206. sFile.Serialize(true, xml, rootNode);
  207. }
  208. else
  209. {
  210. sFile.Serialize(false, xml, rootNode);
  211. this.is_Photograph = isPhotograph.value();
  212. this.pt_Depostion = ptDepostion.value();
  213. this.pt_ELYFile = ptELYFile.value();
  214. this.fib_ELYFile = fibELYFile.value();
  215. this.stretch_Magnification = stretchMagnification.value();
  216. this.location_Magnification = locationMagnification.value();
  217. this.location_Voltage = locationVoltage.value();
  218. this.photograph_Magnification = photographMagnification.value();
  219. this.photograph_Voltage = photographVoltage.value();
  220. this.correction_Angle = correctionAngle.value();
  221. this.sample_Type = sampleType.value();
  222. this.firm = _firm.value();
  223. }
  224. }
  225. }
  226. }