LeakCheckResultManager.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using Aitex.Common.Util;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.Util;
  10. namespace MECF.Framework.Common.CommonData
  11. {
  12. public class LeakCheckResultManager : Singleton<LeakCheckResultManager>
  13. {
  14. private string _template = "<?xml version=\"1.0\" encoding=\"utf-16\"?> <LeakCheckResult xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"></LeakCheckResult>";
  15. private Dictionary<string, XmlDocument> _dicXmlFile = new Dictionary<string, XmlDocument>();
  16. string _filePath = PathManager.GetAppDir() + "\\LeakCheckResult\\";
  17. string _fileName = "\\LeakCheckResult.xml";
  18. public void Initialize(string Module)
  19. {
  20. try
  21. {
  22. XmlDocument _dom = new XmlDocument();
  23. if (!Directory.Exists(_filePath + Module))
  24. {
  25. Directory.CreateDirectory(_filePath + Module);
  26. }
  27. if (!File.Exists(_filePath + Module + _fileName))
  28. {
  29. _dom.LoadXml(_template);
  30. _dom.Save(_filePath + Module + _fileName);
  31. }
  32. else
  33. {
  34. _dom.Load(_filePath + Module + _fileName);
  35. }
  36. _dicXmlFile.Add(Module, _dom);
  37. }
  38. catch (Exception ex)
  39. {
  40. LOG.Write(ex);
  41. throw;
  42. }
  43. }
  44. /*
  45. *
  46. *
  47. * Date = Convert.ToDateTime(element.GetAttribute("Date")),
  48. LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
  49. LeakRate = Convert.ToDouble(element.GetAttribute("LeakCheckStatus")),
  50. StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
  51. StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
  52. LeakCheckMode = element.GetAttribute("LeakCheckMode"),
  53. LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
  54. *
  55. */
  56. public void AddLeakCheck(string Module, DateTime date, int leakCheckTime, int beginPressure, int endPressure, double leakRate, string status, string mode)
  57. {
  58. try
  59. {
  60. XmlElement node = _dicXmlFile[Module].CreateNode(XmlNodeType.Element, "LeakCheck", _dicXmlFile[Module].NamespaceURI) as XmlElement;
  61. node.SetAttribute("Id", Guid.NewGuid().ToString());
  62. node.SetAttribute("Date", date.ToString("yyyy-MM-dd HH:mm:ss.fff"));
  63. node.SetAttribute("LeakCheckStatus", status);
  64. node.SetAttribute("LeakRate", leakRate.ToString("F5"));
  65. node.SetAttribute("StartPressure", beginPressure.ToString());
  66. node.SetAttribute("StopPressure", endPressure.ToString());
  67. node.SetAttribute("LeakCheckMode", mode);
  68. node.SetAttribute("LeakCheckTime", leakCheckTime.ToString());
  69. XmlElement root = _dicXmlFile[Module].SelectSingleNode("/LeakCheckResult") as XmlElement;
  70. root.AppendChild(node);
  71. _dicXmlFile[Module].Save(_filePath + Module + _fileName);
  72. }
  73. catch (Exception ex)
  74. {
  75. LOG.Write(ex);
  76. }
  77. }
  78. /*
  79. *
  80. <LeakCheck Date="" StartPressure="" StopPressure
  81. */
  82. public List<LeakCheckResultItem> GetHistoryLeakCheck(string Module)
  83. {
  84. List<LeakCheckResultItem> result = new List<LeakCheckResultItem>();
  85. try
  86. {
  87. XmlNodeList lst = _dicXmlFile[Module].SelectNodes("/LeakCheckResult/LeakCheck");
  88. if (lst != null)
  89. {
  90. foreach (XmlElement element in lst)
  91. {
  92. result.Add(new LeakCheckResultItem()
  93. {
  94. Id = element.GetAttribute("Id"),
  95. Date = Convert.ToDateTime(element.GetAttribute("Date")),
  96. LeakCheckStatus = element.GetAttribute("LeakCheckStatus"),
  97. LeakRate = Convert.ToDouble(element.GetAttribute("LeakRate")),
  98. StartPressure = Convert.ToInt32(element.GetAttribute("StartPressure")),
  99. StopPressure = Convert.ToInt32(element.GetAttribute("StopPressure")),
  100. LeakCheckMode = element.GetAttribute("LeakCheckMode"),
  101. LeakCheckTime = Convert.ToInt32(element.GetAttribute("LeakCheckTime")),
  102. });
  103. }
  104. }
  105. }
  106. catch (Exception ex)
  107. {
  108. LOG.Write(ex);
  109. }
  110. return result;
  111. }
  112. public void Delete(string Module, string id)
  113. {
  114. try
  115. {
  116. XmlElement node = _dicXmlFile[Module].SelectSingleNode(string.Format("/LeakCheckResult/LeakCheck[@Id='{0}']", id)) as XmlElement;
  117. node.ParentNode.RemoveChild(node);
  118. _dicXmlFile[Module].Save(_filePath + Module + _fileName);
  119. }
  120. catch (Exception ex)
  121. {
  122. LOG.Write(ex);
  123. }
  124. }
  125. }
  126. }