SanhuaMethod.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using Newtonsoft.Json.Linq;
  2. using SufeiUtil;
  3. using SXLibrary;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using HttpHelper = SufeiUtil.HttpHelper;
  10. namespace MOKA_Factory_Tools
  11. {
  12. internal class SanhuaMethod
  13. {
  14. public static SanhuaMESLoginInfo sanhuaLoginInfo = new SanhuaMESLoginInfo();
  15. public static bool CheckLogin(out string message)
  16. {
  17. message = string.Empty;
  18. HttpHelper http = new HttpHelper();
  19. HttpItem item = new HttpItem() {URL = sanhuaLoginInfo.url + "api/MESTestCollect/CheckLogin", Encoding = Encoding.UTF8,Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false};
  20. item.ContentType = "application/json;charset=utf-8";
  21. item.Postdata = string.Format("{{\"password\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\"}}", sanhuaLoginInfo.password, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode);
  22. HttpResult result = http.GetHtml(item);
  23. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  24. {
  25. Log.WriteErrorLog(string.Format("CheckLogin System abnormality, staffCode={0} password={1} resourceCode={2}", sanhuaLoginInfo.staffCode, sanhuaLoginInfo.password, sanhuaLoginInfo.resourceCode));
  26. return false;
  27. }
  28. string ParseText = result.Html;
  29. Log.WriteInfoLog(string.Format("CheckLogin Html:{0}", result.Html));
  30. try
  31. {
  32. JObject jObject = JObject.Parse(ParseText);
  33. bool success = jObject["success"].Value<bool>();
  34. message = jObject["message"].Value<string>();
  35. if (!success)
  36. {
  37. Log.WriteErrorLog(string.Format("CheckLogin Error:{0}", message));
  38. return false;
  39. }
  40. }
  41. catch (Exception e)
  42. {
  43. message = e.Message;
  44. Log.WriteErrorLog(string.Format("CheckLogin Error:{0}", e.Message));
  45. return false;
  46. }
  47. return true;
  48. }
  49. public static bool ProductRouteCheck(string productSN, out string message)
  50. {
  51. message = string.Empty;
  52. HttpHelper http = new HttpHelper();
  53. HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.url + "api/MESTestCollect/ProductRouteCheck", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  54. item.ContentType = "application/json;charset=utf-8";
  55. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\"}}",
  56. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN);
  57. HttpResult result = http.GetHtml(item);
  58. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  59. {
  60. Log.WriteErrorLog(string.Format("ProductRouteCheck System abnormality, productSN={0}", productSN));
  61. return false;
  62. }
  63. string ParseText = result.Html;
  64. Log.WriteInfoLog(string.Format("ProductRouteCheck Html:{0}", result.Html));
  65. try
  66. {
  67. JObject jObject = JObject.Parse(ParseText);
  68. bool success = jObject["success"].Value<bool>();
  69. message = jObject["message"].Value<string>();
  70. if (!success)
  71. {
  72. Log.WriteErrorLog(string.Format("ProductRouteCheck Error:{0}", message));
  73. return false;
  74. }
  75. }
  76. catch (Exception e)
  77. {
  78. message = e.Message;
  79. Log.WriteErrorLog(string.Format("ProductRouteCheck Error:{0}", e.Message));
  80. return false;
  81. }
  82. return true;
  83. }
  84. public static bool UploadIdcData(string productSN, string acasId, out string message)
  85. {
  86. message = string.Empty;
  87. HttpHelper http = new HttpHelper();
  88. HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.url + "api/MESTestCollect/UploadIdcData", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  89. item.ContentType = "application/json;charset=utf-8";
  90. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"attr\":\"{{\"ACASID\":\"{4}\"}}\"}}",
  91. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, acasId);
  92. HttpResult result = http.GetHtml(item);
  93. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  94. {
  95. Log.WriteErrorLog(string.Format("UploadIdcData System abnormality, productSN={0}, ", productSN));
  96. return false;
  97. }
  98. string ParseText = result.Html;
  99. Log.WriteInfoLog(string.Format("UploadIdcData Html:{0}", result.Html));
  100. try
  101. {
  102. JObject jObject = JObject.Parse(ParseText);
  103. bool success = jObject["success"].Value<bool>();
  104. message = jObject["message"].Value<string>();
  105. if (!success)
  106. {
  107. Log.WriteErrorLog(string.Format("UploadIdcData Error:{0}", message));
  108. return false;
  109. }
  110. }
  111. catch (Exception e)
  112. {
  113. message = e.Message;
  114. Log.WriteErrorLog(string.Format("UploadIdcData Error:{0}", e.Message));
  115. return false;
  116. }
  117. return true;
  118. }
  119. public static bool ProductMoveNext(string productSN, string result, string defectCode, out string message)
  120. {
  121. message = string.Empty;
  122. HttpHelper http = new HttpHelper();
  123. HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.url + "api/MESTestCollect/ProductMoveNext", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  124. item.ContentType = "application/json;charset=utf-8";
  125. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"defectCode\":\"{4}\",\"result\":\"{5}\"}}",
  126. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, defectCode, result);
  127. HttpResult hResult = http.GetHtml(item);
  128. if (hResult.StatusCode != System.Net.HttpStatusCode.OK)
  129. {
  130. Log.WriteErrorLog(string.Format("System abnormality, productSN={0} ", productSN));
  131. return false;
  132. }
  133. string ParseText = hResult.Html;
  134. Log.WriteInfoLog(string.Format("ProductMoveNext Html:{0}", hResult.Html));
  135. try
  136. {
  137. JObject jObject = JObject.Parse(ParseText);
  138. bool success = jObject["success"].Value<bool>();
  139. message = jObject["message"].Value<string>();
  140. if (!success)
  141. {
  142. Log.WriteErrorLog(string.Format("ProductMoveNext Error:{0}", message));
  143. return false;
  144. }
  145. }
  146. catch (Exception e)
  147. {
  148. message = e.Message;
  149. Log.WriteErrorLog(string.Format("ProductMoveNext Error:{0}", e.Message));
  150. return false;
  151. }
  152. return true;
  153. }
  154. }
  155. }