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(out string message) { message = string.Empty; HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() {URL = sanhuaLoginInfo.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.password, sanhuaLoginInfo.resourceCode, sanhuaLoginInfo.staffCode); 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; Log.WriteInfoLog(string.Format("CheckLogin Html:{0}", result.Html)); try { JObject jObject = JObject.Parse(ParseText); bool success = jObject["success"].Value(); message = jObject["message"].Value(); if (!success) { Log.WriteErrorLog(string.Format("CheckLogin Error:{0}", message)); return false; } } catch (Exception e) { message = e.Message; Log.WriteErrorLog(string.Format("CheckLogin Error:{0}", e.Message)); return false; } return true; } public static bool ProductRouteCheck(string productSN, out string message) { message = string.Empty; HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.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; Log.WriteInfoLog(string.Format("ProductRouteCheck Html:{0}", result.Html)); try { JObject jObject = JObject.Parse(ParseText); bool success = jObject["success"].Value(); message = jObject["message"].Value(); if (!success) { Log.WriteErrorLog(string.Format("ProductRouteCheck Error:{0}", message)); return false; } } catch (Exception e) { message = e.Message; Log.WriteErrorLog(string.Format("ProductRouteCheck Error:{0}", e.Message)); return false; } return true; } public static bool UploadIdcData(string productSN, string acasId, out string message) { message = string.Empty; HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.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; Log.WriteInfoLog(string.Format("UploadIdcData Html:{0}", result.Html)); try { JObject jObject = JObject.Parse(ParseText); bool success = jObject["success"].Value(); message = jObject["message"].Value(); if (!success) { Log.WriteErrorLog(string.Format("UploadIdcData Error:{0}", message)); return false; } } catch (Exception e) { message = e.Message; Log.WriteErrorLog(string.Format("UploadIdcData Error:{0}", e.Message)); return false; } return true; } public static bool ProductMoveNext(string productSN, string result, string defectCode, out string message) { message = string.Empty; HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = sanhuaLoginInfo.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; Log.WriteInfoLog(string.Format("ProductMoveNext Html:{0}", hResult.Html)); try { JObject jObject = JObject.Parse(ParseText); bool success = jObject["success"].Value(); message = jObject["message"].Value(); if (!success) { Log.WriteErrorLog(string.Format("ProductMoveNext Error:{0}", message)); return false; } } catch (Exception e) { message = e.Message; Log.WriteErrorLog(string.Format("ProductMoveNext Error:{0}", e.Message)); return false; } return true; } } }