123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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<bool>();
- message = jObject["message"].Value<string>();
- if (!success)
- {
- Log.WriteErrorLog("\r\nCheckLogin Error:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return false;
- }
- Log.WriteInfoLog("\r\nCheckLogin OK:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- }
- catch (Exception e)
- {
- message = e.Message;
- Log.WriteErrorLog("\r\nCheckLogin Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- 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;
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- bool success = jObject["success"].Value<bool>();
- message = jObject["message"].Value<string>();
- if (!success)
- {
- Log.WriteErrorLog("\r\nProductRouteCheck Error:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return false;
- }
- Log.WriteInfoLog("\r\nProductRouteCheck OK:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- }
- catch (Exception e)
- {
- message = e.Message;
- Log.WriteErrorLog("\r\nProductRouteCheck Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- 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;
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- bool success = jObject["success"].Value<bool>();
- message = jObject["message"].Value<string>();
- if (!success)
- {
- Log.WriteErrorLog("\r\nUploadIdcData Error:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return false;
- }
- Log.WriteInfoLog("\r\nUploadIdcData OK:" + result.StatusDescription + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- }
- catch (Exception e)
- {
- message = e.Message;
- Log.WriteErrorLog("\r\nUploadIdcData Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- 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;
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- bool success = jObject["success"].Value<bool>();
- message = jObject["message"].Value<string>();
- if (!success)
- {
- Log.WriteErrorLog("\r\nProductMoveNext Error:" + hResult.StatusDescription + hResult.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return false;
- }
- Log.WriteInfoLog("\r\nProductMoveNext OK:" + hResult.StatusDescription + hResult.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- }
- catch (Exception e)
- {
- message = e.Message;
- Log.WriteErrorLog("\r\nProductMoveNext Error:" + e.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return false;
- }
- return true;
- }
- }
- }
|