SajectConnectSajet2.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace MesAdaptor
  7. {
  8. public class SajectConnectSajet2 : ISajetConnect
  9. {
  10. private enum CMD
  11. {
  12. Signin = 1,
  13. SnCheck = 2,
  14. Report = 3,
  15. ValueReport = 4,
  16. }
  17. private readonly string _MechineCode;
  18. public SajectConnectSajet2(string MechineCode)
  19. {
  20. if (string.IsNullOrEmpty(_MechineCode))
  21. {
  22. throw new Exception("MechineCode cannot not be empty");
  23. }
  24. _MechineCode = MechineCode;
  25. }
  26. public bool SajetTransStart() => SajetConnectAdapter.SajetTransStart();
  27. public bool SajetTransClose() => SajetConnectAdapter.SajetTransClose();
  28. private string userId = "";
  29. public bool SajetTransSignIn(ref string data)
  30. {
  31. var attemptId = data;
  32. var msg = data + ";";
  33. if (SajetTransData(CMD.Signin, ref data))
  34. {
  35. if (string.IsNullOrEmpty(data) || data.StartsWith("NG"))
  36. {
  37. userId = "";
  38. return false;
  39. }
  40. else
  41. {
  42. userId = attemptId;
  43. return true;
  44. }
  45. }
  46. userId = "";
  47. return false;
  48. }
  49. [Obsolete]
  50. public bool SajetTransWoCheck(ref string workOrder)
  51. {
  52. return true;
  53. }
  54. private PhihongSystemID.SystemID systemID;
  55. public bool SajetTransSnCheck(ref string serialNumber)
  56. {
  57. if (!PhihongSystemID.SystemID.TryParse(serialNumber, out var id))
  58. {
  59. return false;
  60. }
  61. var msg = string.Format("{0};{1};;", id.ModelName.ToString(), id.ToString());
  62. if (SajetTransData(CMD.SnCheck, ref msg))
  63. {
  64. if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
  65. {
  66. systemID = null;
  67. return false;
  68. }
  69. systemID = id;
  70. return true;
  71. }
  72. systemID = null;
  73. return false;
  74. }
  75. public bool SajetTranFinishSuccess()
  76. {
  77. if (string.IsNullOrEmpty(userId))
  78. return false;
  79. if (systemID == null)
  80. return false;
  81. //string msg = userId + ";" + systemID.ToString() + ";";
  82. string msg = string.Format("{0};{1};{2}:0;", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString());
  83. if (string.IsNullOrEmpty(msg))
  84. return false;
  85. #if DEBUG
  86. return true;
  87. #endif
  88. return SajetTransData(CMD.Report, ref msg);
  89. }
  90. public bool SajetTranFinishFail(MesErrorCode errorCode)
  91. {
  92. if (string.IsNullOrEmpty(userId))
  93. return false;
  94. if (systemID == null)
  95. return false;
  96. //string msg = userId + ";" + systemID.ToString() + ";";
  97. string msg = string.Format("{0};{1};{2}:{3};", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString(), errorCode);
  98. if (string.IsNullOrEmpty(msg))
  99. return false;
  100. msg += $"NG;{errorCode};"; //E114
  101. #if DEBUG
  102. return true;
  103. #endif
  104. return SajetTransData(CMD.Report, ref msg);
  105. }
  106. [Obsolete]
  107. public string SajetTransRegisterHeader(string model, string header)
  108. {
  109. return "";
  110. }
  111. public bool SajetTransReport(Dictionary<string, string> reportPair)
  112. {
  113. var totalResult = true;
  114. foreach(var pair in reportPair)
  115. {
  116. var msg = string.Format("{0};{1};{2};{3};{4}:{5};", userId,_MechineCode,systemID.ModelName.ToString(),systemID.ToString(),pair.Key,pair.Value);
  117. var result = SajetTransData(CMD.ValueReport, ref msg);
  118. totalResult &= result;
  119. }
  120. return totalResult;
  121. }
  122. [Obsolete]
  123. public bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
  124. {
  125. return true;
  126. }
  127. [Obsolete]
  128. public bool SajetTransReport(Dictionary<string, string> resultPair, Dictionary<string, string> codePair)
  129. {
  130. return true;
  131. }
  132. [Obsolete]
  133. public bool SajetTransLog(string data)
  134. {
  135. return true;
  136. }
  137. private bool SajetTransData(CMD command, ref string data)
  138. {
  139. return SajetConnectAdapter.SajetTransData((int)command, ref data);
  140. }
  141. }
  142. }