SajectConnectSajet2.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using PhihongEv.Lib;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace MesAdaptor
  8. {
  9. public class SajectConnectSajet2 : ISajetConnect
  10. {
  11. private enum CMD
  12. {
  13. Signin = 1,
  14. SnCheck = 2,
  15. Report = 3,
  16. ValueReport = 4,
  17. }
  18. private readonly string _MechineCode;
  19. public SajectConnectSajet2(string MechineCode)
  20. {
  21. if (string.IsNullOrEmpty(MechineCode))
  22. {
  23. throw new Exception("MechineCode cannot not be empty");
  24. }
  25. _MechineCode = MechineCode;
  26. }
  27. public bool SajetTransStart() => SajetConnectAdapter.SajetTransStart();
  28. public bool SajetTransClose() => SajetConnectAdapter.SajetTransClose();
  29. private string userId = "";
  30. public bool SajetTransSignIn(ref string data)
  31. {
  32. var attemptId = data;
  33. var msg = data + ";";
  34. if (SajetTransData(CMD.Signin, ref data))
  35. {
  36. if (string.IsNullOrEmpty(data) || data.StartsWith("NG"))
  37. {
  38. userId = "";
  39. return false;
  40. }
  41. else
  42. {
  43. userId = attemptId;
  44. return true;
  45. }
  46. }
  47. userId = "";
  48. return false;
  49. }
  50. [Obsolete]
  51. public bool SajetTransWoCheck(ref string workOrder)
  52. {
  53. return true;
  54. }
  55. private SystemID systemID;
  56. public bool SajetTransSnCheck(ref string serialNumber)
  57. {
  58. if (!SystemID.TryParse(serialNumber, out var id))
  59. {
  60. return false;
  61. }
  62. var msg = string.Format("{0};{1};;", id.ModelName.ToString(), id.ToString());
  63. if (SajetTransData(CMD.SnCheck, ref msg))
  64. {
  65. if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
  66. {
  67. systemID = null;
  68. return false;
  69. }
  70. systemID = id;
  71. return true;
  72. }
  73. systemID = null;
  74. return false;
  75. }
  76. //public bool SajetTransSnCheck(string partNO,string sn)
  77. //{
  78. // var msg = string.Format("{0};{1};;", partNO, sn);
  79. // if (SajetTransData(CMD.SnCheck, ref msg))
  80. // {
  81. // if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
  82. // {
  83. // return false;
  84. // }
  85. // return true;
  86. // }
  87. // return false;
  88. //}
  89. public bool SajetTranFinishSuccess()
  90. {
  91. if (string.IsNullOrEmpty(userId))
  92. return false;
  93. if (systemID == null)
  94. return false;
  95. //string msg = userId + ";" + systemID.ToString() + ";";
  96. string msg = string.Format("{0};{1};{2};{3}:0;", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString());
  97. if (string.IsNullOrEmpty(msg))
  98. return false;
  99. return SajetTransData(CMD.Report, ref msg);
  100. }
  101. //public bool SajetTranFinishSuccess(string partNO, string sn)
  102. //{
  103. // if (string.IsNullOrEmpty(userId))
  104. // return false;
  105. // //string msg = userId + ";" + systemID.ToString() + ";";
  106. // string msg = string.Format("{0};{1};{2};{3}:0;", userId, _MechineCode, partNO, sn);
  107. // if (string.IsNullOrEmpty(msg))
  108. // return false;
  109. // return SajetTransData(CMD.Report, ref msg);
  110. //}
  111. public bool SajetTranFinishFail(MesErrorCode errorCode)
  112. {
  113. if (string.IsNullOrEmpty(userId))
  114. return false;
  115. if (systemID == null)
  116. return false;
  117. //string msg = userId + ";" + systemID.ToString() + ";";
  118. string msg = string.Format("{0};{1};{2};{3}:1:", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString());
  119. if (string.IsNullOrEmpty(msg))
  120. return false;
  121. msg += $"{GetMesCodeString(errorCode)};"; //E114
  122. return SajetTransData(CMD.Report, ref msg);
  123. }
  124. //public bool SajetTranFinishFail(string partNO, string sn, MesErrorCode errorCode)
  125. //{
  126. // if (string.IsNullOrEmpty(userId))
  127. // return false;
  128. // //string msg = userId + ";" + systemID.ToString() + ";";
  129. // string msg = string.Format("{0};{1};{2};{3}:1:", userId, _MechineCode, partNO, sn);
  130. // if (string.IsNullOrEmpty(msg))
  131. // return false;
  132. // msg += $"{errorCode};"; //E114
  133. // return SajetTransData(CMD.Report, ref msg);
  134. //}
  135. [Obsolete]
  136. public string SajetTransRegisterHeader(string model, string header)
  137. {
  138. return "";
  139. }
  140. public bool SajetTransReport(ValueReportDatas reportDatas)
  141. {
  142. if (string.IsNullOrEmpty(userId))
  143. return false;
  144. if (systemID == null)
  145. return false;
  146. var totalResult = true;
  147. foreach (var data in reportDatas)
  148. {
  149. var key = data.Key;
  150. var value = data.Val;
  151. var isSuccess = data.IsSuccess;
  152. value = value.Trim();
  153. if (string.IsNullOrEmpty(value))
  154. {
  155. value = "empty";
  156. }
  157. else if (value.ToLower() == "fail")
  158. {
  159. value = "0";
  160. }
  161. else if (value.ToLower() == "success")
  162. {
  163. value = "1";
  164. }
  165. var msg = string.Format("{0};{1};{2};{3};{4}:{5}:{6};", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString(), key, value, isSuccess);
  166. var result = SajetTransData(CMD.ValueReport, ref msg);
  167. totalResult &= result;
  168. }
  169. return totalResult;
  170. }
  171. //public bool SajetTransReport(string partNO, string no, Dictionary<string, string> reportPair)
  172. //{
  173. // if (string.IsNullOrEmpty(userId))
  174. // return false;
  175. // var totalResult = true;
  176. // foreach (var pair in reportPair)
  177. // {
  178. // var msg = string.Format("{0};{1};{2};{3};{4}:{5};", userId, _MechineCode, partNO, no, pair.Key, pair.Value);
  179. // var result = SajetTransData(CMD.ValueReport, ref msg);
  180. // totalResult &= result;
  181. // }
  182. // return totalResult;
  183. //}
  184. [Obsolete]
  185. public bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
  186. {
  187. return true;
  188. }
  189. [Obsolete]
  190. public bool SajetTransReport(Dictionary<string, string> resultPair, Dictionary<string, string> codePair)
  191. {
  192. return true;
  193. }
  194. [Obsolete]
  195. public bool SajetTransLog(string data)
  196. {
  197. return true;
  198. }
  199. private bool SajetTransData(CMD command, ref string data)
  200. {
  201. return SajetConnectAdapter.SajetTransData((int)command, ref data);
  202. }
  203. private string GetMesCodeString(MesErrorCode mesError)
  204. {
  205. switch (mesError)
  206. {
  207. case MesErrorCode.ChargerConnectFail:
  208. return "A081";
  209. case MesErrorCode.ModelNameUpadateFail:
  210. return "A082";
  211. case MesErrorCode.SerilaNumberUpadateFail:
  212. return "A083";
  213. case MesErrorCode.UtcDatetimeUpdateFail:
  214. return "A084";
  215. case MesErrorCode.FourthGenModelVersionMismatch:
  216. return "A085";
  217. case MesErrorCode.FourthGenSimInstartionMismatch:
  218. return "A086";
  219. case MesErrorCode.FourthGenSimInfoMismatch:
  220. return "A087";
  221. case MesErrorCode.WifiModeNotClient:
  222. return "A088";
  223. case MesErrorCode.WifiRssiLow:
  224. return "A089";
  225. case MesErrorCode.FirmwareUploadFail:
  226. return "A090";
  227. case MesErrorCode.FirmwareUpdateTimeout:
  228. return "A091";
  229. case MesErrorCode.FirmwareVersionCheckFail:
  230. return "A092";
  231. case MesErrorCode.EmergencyButtonTestFail:
  232. return "A093";
  233. case MesErrorCode.GreenButtonTestFail:
  234. return "A094";
  235. case MesErrorCode.BlueButtonTestFail:
  236. return "A095";
  237. case MesErrorCode.FactoryResetFail:
  238. return "A096";
  239. }
  240. return "A081";
  241. }
  242. }
  243. }