FileHelper.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. namespace OTSModelSharp.ServiceCenter
  9. {
  10. public static class FileHelper
  11. {
  12. static XmlDocument Hardwareconfigdoc=null;
  13. public static string GetFolderName(string a_strPathName)
  14. {
  15. if (a_strPathName == "Untitled")
  16. {
  17. return null;
  18. }
  19. string folderName = a_strPathName.Substring(0, a_strPathName.LastIndexOf("\\"));
  20. return folderName;
  21. }
  22. public static string GetXMLInformations(string Name)
  23. {
  24. try
  25. {
  26. XmlDocument doc;
  27. string value = string.Empty;
  28. if (Hardwareconfigdoc == null)
  29. {
  30. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  31. Hardwareconfigdoc = new XmlDocument();
  32. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  33. doc = Hardwareconfigdoc;
  34. }
  35. else
  36. {
  37. doc = Hardwareconfigdoc;
  38. }
  39. XmlElement root = doc.DocumentElement; //获取根节点
  40. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  41. foreach (XmlNode node in mainNodes)
  42. {
  43. //获取Name属性值
  44. string name = ((XmlElement)node).GetAttribute("RegName");
  45. if (name.Equals(Name))
  46. {
  47. value = ((XmlElement)node).GetAttribute("Value");
  48. break;
  49. }
  50. }
  51. return value;
  52. }
  53. catch (Exception)
  54. {
  55. return "";
  56. }
  57. }
  58. /// <summary>
  59. /// 获取XML节点参数
  60. /// </summary>
  61. /// <param name="Name">节点参数名称</param>
  62. /// <returns>节点参数</returns>
  63. public static string GetIfDelayQuantify()
  64. {
  65. try
  66. {
  67. XmlDocument doc;
  68. string value = string.Empty;
  69. if (Hardwareconfigdoc == null)
  70. {
  71. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  72. Hardwareconfigdoc = new XmlDocument();
  73. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  74. doc = Hardwareconfigdoc;
  75. }
  76. else
  77. {
  78. doc = Hardwareconfigdoc;
  79. }
  80. XmlElement root = doc.DocumentElement; //获取根节点
  81. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  82. foreach (XmlNode node in mainNodes)
  83. {
  84. //获取Name属性值
  85. string name = ((XmlElement)node).GetAttribute("RegName");
  86. if (name.Equals("EDSName"))
  87. {
  88. value = ((XmlElement)node).GetAttribute("DelayQuantify");
  89. break;
  90. }
  91. }
  92. return value;
  93. }
  94. catch (Exception)
  95. {
  96. return "false";
  97. }
  98. }
  99. public static bool GetIfTranslateWeightPercentageToAtomicPercentage()
  100. {
  101. try
  102. {
  103. XmlDocument doc;
  104. string value = string.Empty;
  105. if (Hardwareconfigdoc == null)
  106. {
  107. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  108. Hardwareconfigdoc = new XmlDocument();
  109. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  110. doc = Hardwareconfigdoc;
  111. }
  112. else
  113. {
  114. doc = Hardwareconfigdoc;
  115. }
  116. XmlElement root = doc.DocumentElement; //获取根节点
  117. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  118. foreach (XmlNode node in mainNodes)
  119. {
  120. //获取Name属性值
  121. string name = ((XmlElement)node).GetAttribute("RegName");
  122. if (name.Equals("EDSName"))
  123. {
  124. value = ((XmlElement)node).GetAttribute("WeightPercentageToAtomicPercentage");
  125. break;
  126. }
  127. }
  128. return Convert.ToBoolean(value);
  129. }
  130. catch (Exception)
  131. {
  132. return false;
  133. }
  134. }
  135. public static bool GetIfAquireClearParticleImage()
  136. {
  137. try
  138. {
  139. XmlDocument doc;
  140. string value = string.Empty;
  141. if (Hardwareconfigdoc == null)
  142. {
  143. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  144. Hardwareconfigdoc = new XmlDocument();
  145. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  146. doc = Hardwareconfigdoc;
  147. }
  148. else
  149. {
  150. doc = Hardwareconfigdoc;
  151. }
  152. XmlElement root = doc.DocumentElement; //获取根节点
  153. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  154. foreach (XmlNode node in mainNodes)
  155. {
  156. //获取Name属性值
  157. string name = ((XmlElement)node).GetAttribute("RegName");
  158. if (name.Equals("AcquireClearParticleImage"))
  159. {
  160. value = ((XmlElement)node).GetAttribute("Value");
  161. break;
  162. }
  163. }
  164. return Convert.ToBoolean(value);
  165. }
  166. catch (Exception)
  167. {
  168. return false;
  169. }
  170. }
  171. public static string GetOxfordInputSourceType()
  172. {
  173. try
  174. {
  175. string value = string.Empty;
  176. XmlDocument doc = new XmlDocument();
  177. if (Hardwareconfigdoc == null)
  178. {
  179. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  180. Hardwareconfigdoc = new XmlDocument();
  181. Hardwareconfigdoc.Load(xmlFilePath); //加载Xml文件
  182. doc = Hardwareconfigdoc;
  183. }
  184. else
  185. {
  186. doc = Hardwareconfigdoc;
  187. }
  188. XmlElement root = doc.DocumentElement; //获取根节点
  189. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  190. foreach (XmlNode node in mainNodes)
  191. {
  192. //获取Name属性值
  193. string name = ((XmlElement)node).GetAttribute("RegName");
  194. if (name.Equals("SemControllerName"))
  195. {
  196. value = ((XmlElement)node).GetAttribute("ImageInputSources");
  197. break;
  198. }
  199. }
  200. return value;
  201. }
  202. catch (Exception)
  203. {
  204. return "";
  205. }
  206. }
  207. }
  208. }