using Newtonsoft.Json.Linq; using SufeiUtil; using SXLibrary; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HttpHelper = SufeiUtil.HttpHelper; namespace MOKA_Factory_Tools { internal class SanhuaMethod { public static SanhuaMESLoginInfo sanhuaLoginInfo = new SanhuaMESLoginInfo(); public static bool CheckLogin(string url) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() {URL = url + "api/MESTestCollect/CheckLogin", Encoding = Encoding.UTF8,Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false}; item.ContentType = "application/json;charset=utf-8"; item.Postdata = string.Format("{{\"password\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\"}}", sanhuaLoginInfo.staffCode, sanhuaLoginInfo.password, sanhuaLoginInfo.resourceCode); HttpResult result = http.GetHtml(item); if (result.StatusCode != System.Net.HttpStatusCode.OK) { Log.WriteErrorLog(string.Format("CheckLogin System abnormality, staffCode={0} password={1} resourceCode={2}", sanhuaLoginInfo.staffCode, sanhuaLoginInfo.password, sanhuaLoginInfo.resourceCode)); return false; } string ParseText = result.Html; try { JObject jObject = JObject.Parse(ParseText); } catch (Exception) { throw; } return true; } public static bool ProductRouteCheck(string url, string productSN) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = url + "api/MESTestCollect/ProductRouteCheck", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false }; item.ContentType = "application/json;charset=utf-8"; item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\"}}", sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN); HttpResult result = http.GetHtml(item); if (result.StatusCode != System.Net.HttpStatusCode.OK) { Log.WriteErrorLog(string.Format("ProductRouteCheck System abnormality, productSN={0}", productSN)); return false; } string ParseText = result.Html; try { JObject jObject = JObject.Parse(ParseText); } catch (Exception) { throw; } return true; } public static bool UploadIdcData(string url, string productSN, string acasId) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = url + "api/MESTestCollect/UploadIdcData", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false }; item.ContentType = "application/json;charset=utf-8"; item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"attr\":\"{{\"ACASID\",\"{4}\"}}\"}}", sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, acasId); HttpResult result = http.GetHtml(item); if (result.StatusCode != System.Net.HttpStatusCode.OK) { Log.WriteErrorLog(string.Format("UploadIdcData System abnormality, productSN={0}, ", productSN)); return false; } string ParseText = result.Html; try { JObject jObject = JObject.Parse(ParseText); } catch (Exception) { throw; } return true; } public static bool ProductMoveNext(string url, string productSN, string result, string defectCode) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = url + "api/MESTestCollect/ProductMoveNext", Encoding = Encoding.UTF8, Method = "post", PostEncoding = Encoding.UTF8, KeepAlive = false }; item.ContentType = "application/json;charset=utf-8"; item.Postdata = string.Format("{{\"jigEdition\":\"{0}\",\"resourceCode\":\"{1}\",\"staffCode\":\"{2}\",\"productSN\":\"{3}\",\"defectCode\":\"{4}\",\"result\":\"{5}\"}}", sanhuaLoginInfo.jigEdtion, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode, productSN, defectCode, result); HttpResult hResult = http.GetHtml(item); if (hResult.StatusCode != System.Net.HttpStatusCode.OK) { Log.WriteErrorLog(string.Format("System abnormality, productSN={0} ", productSN)); return false; } string ParseText = hResult.Html; try { JObject jObject = JObject.Parse(ParseText); } catch (Exception) { throw; } return true; } } }