SanhuaMethod.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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("\r\nCheckLogin Error:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  38. return false;
  39. }
  40. Log.WriteInfoLog("\r\nCheckLogin OK:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  41. }
  42. catch (Exception e)
  43. {
  44. message = e.Message;
  45. Log.WriteErrorLog("\r\nCheckLogin Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  46. return false;
  47. }
  48. return true;
  49. }
  50. public static bool ProductRouteCheck(string productSN, out string message)
  51. {
  52. message = string.Empty;
  53. HttpHelper http = new HttpHelper();
  54. HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.url + "api/MESTestCollect/ProductRouteCheck", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  55. item.ContentType = "application/json;charset=utf-8";
  56. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\"}}",
  57. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN);
  58. HttpResult result = http.GetHtml(item);
  59. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  60. {
  61. Log.WriteErrorLog(string.Format("ProductRouteCheck System abnormality, productSN={0}", productSN));
  62. return false;
  63. }
  64. string ParseText = 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("\r\nProductRouteCheck Error:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  73. return false;
  74. }
  75. Log.WriteInfoLog("\r\nProductRouteCheck OK:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  76. }
  77. catch (Exception e)
  78. {
  79. message = e.Message;
  80. Log.WriteErrorLog("\r\nProductRouteCheck Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  81. return false;
  82. }
  83. return true;
  84. }
  85. public static bool UploadIdcData(string productSN, string acasId, out string message)
  86. {
  87. message = string.Empty;
  88. HttpHelper http = new HttpHelper();
  89. HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.url + "api/MESTestCollect/UploadIdcData", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  90. item.ContentType = "application/json;charset=utf-8";
  91. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"attr\":{{\"ACASID\":\"{4}\"}}}}",
  92. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, acasId);
  93. HttpResult result = http.GetHtml(item);
  94. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  95. {
  96. Log.WriteErrorLog(string.Format("UploadIdcData System abnormality, productSN={0}, ", productSN));
  97. return false;
  98. }
  99. string ParseText = 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("\r\nUploadIdcData Error:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  108. return false;
  109. }
  110. Log.WriteInfoLog("\r\nUploadIdcData OK:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  111. }
  112. catch (Exception e)
  113. {
  114. message = e.Message;
  115. Log.WriteErrorLog("\r\nUploadIdcData Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  116. return false;
  117. }
  118. return true;
  119. }
  120. public static bool ProductMoveNext(string productSN, string result, string defectCode, out string message)
  121. {
  122. message = string.Empty;
  123. HttpHelper http = new HttpHelper();
  124. HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.url + "api/MESTestCollect/ProductMoveNext", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  125. item.ContentType = "application/json;charset=utf-8";
  126. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"defectCode\":\"{4}\",\"result\":\"{5}\"}}",
  127. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, defectCode, result);
  128. HttpResult hResult = http.GetHtml(item);
  129. if (hResult.StatusCode != System.Net.HttpStatusCode.OK)
  130. {
  131. Log.WriteErrorLog(string.Format("System abnormality, productSN={0} ", productSN));
  132. return false;
  133. }
  134. string ParseText = 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("\r\nProductMoveNext Error:" + hResult.StatusDescription + hResult.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  143. return false;
  144. }
  145. Log.WriteInfoLog("\r\nProductMoveNext OK:" + hResult.StatusDescription + hResult.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  146. }
  147. catch (Exception e)
  148. {
  149. message = e.Message;
  150. Log.WriteErrorLog("\r\nProductMoveNext Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  151. return false;
  152. }
  153. return true;
  154. }
  155. }
  156. }