SanhuaMethod.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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(string url)
  16. {
  17. HttpHelper http = new HttpHelper();
  18. HttpItem item = new HttpItem() {URL = url + "api/MESTestCollect/CheckLogin", Encoding = Encoding.UTF8,Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false};
  19. item.ContentType = "application/json;charset=utf-8";
  20. item.Postdata = string.Format("{{\"password\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\"}}", sanhuaLoginInfo.staffCode, sanhuaLoginInfo.password, sanhuaLoginInfo.resourceCode);
  21. HttpResult result = http.GetHtml(item);
  22. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  23. {
  24. Log.WriteErrorLog(string.Format("CheckLogin System abnormality, staffCode={0} password={1} resourceCode={2}", sanhuaLoginInfo.staffCode, sanhuaLoginInfo.password, sanhuaLoginInfo.resourceCode));
  25. return false;
  26. }
  27. string ParseText = result.Html;
  28. try
  29. {
  30. JObject jObject = JObject.Parse(ParseText);
  31. }
  32. catch (Exception)
  33. {
  34. throw;
  35. }
  36. return true;
  37. }
  38. public static bool ProductRouteCheck(string url, string productSN)
  39. {
  40. HttpHelper http = new HttpHelper();
  41. HttpItem item = new HttpItem() { URL = url + "api/MESTestCollect/ProductRouteCheck", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  42. item.ContentType = "application/json;charset=utf-8";
  43. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\"}}",
  44. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN);
  45. HttpResult result = http.GetHtml(item);
  46. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  47. {
  48. Log.WriteErrorLog(string.Format("ProductRouteCheck System abnormality, productSN={0}", productSN));
  49. return false;
  50. }
  51. string ParseText = result.Html;
  52. try
  53. {
  54. JObject jObject = JObject.Parse(ParseText);
  55. }
  56. catch (Exception)
  57. {
  58. throw;
  59. }
  60. return true;
  61. }
  62. public static bool UploadIdcData(string url, string productSN, string acasId)
  63. {
  64. HttpHelper http = new HttpHelper();
  65. HttpItem item = new HttpItem() { URL = url + "api/MESTestCollect/UploadIdcData", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false };
  66. item.ContentType = "application/json;charset=utf-8";
  67. item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"attr\":\"{{\"ACASID\",\"{4}\"}}\"}}",
  68. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, acasId);
  69. HttpResult result = http.GetHtml(item);
  70. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  71. {
  72. Log.WriteErrorLog(string.Format("UploadIdcData System abnormality, productSN={0}, ", productSN));
  73. return false;
  74. }
  75. string ParseText = result.Html;
  76. try
  77. {
  78. JObject jObject = JObject.Parse(ParseText);
  79. }
  80. catch (Exception)
  81. {
  82. throw;
  83. }
  84. return true;
  85. }
  86. public static bool ProductMoveNext(string url, string productSN, string result, string defectCode)
  87. {
  88. HttpHelper http = new HttpHelper();
  89. HttpItem item = new HttpItem() { URL = url + "api/MESTestCollect/ProductMoveNext", 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}\",\"defectCode\":\"{4}\",\"result\":\"{5}\"}}",
  92. sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, defectCode, result);
  93. HttpResult hResult = http.GetHtml(item);
  94. if (hResult.StatusCode != System.Net.HttpStatusCode.OK)
  95. {
  96. Log.WriteErrorLog(string.Format("System abnormality, productSN={0} ", productSN));
  97. return false;
  98. }
  99. string ParseText = hResult.Html;
  100. try
  101. {
  102. JObject jObject = JObject.Parse(ParseText);
  103. }
  104. catch (Exception)
  105. {
  106. throw;
  107. }
  108. return true;
  109. }
  110. }
  111. }