using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Collections;
|
using System.IO;
|
using System.Net;
|
using System.Web;
|
using System.Xml;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using DeviceITisation;
|
|
namespace ClassLibrary1
|
{
|
public class Class1
|
{
|
public string Get_BaseConfigData(string Header, string Category)
|
{
|
try
|
{
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.126.28.11:21021/api/services/app/TPM_BaseConfigData/GetAll?Category=" + Category);
|
SetWebRequest(request);
|
request.Method = "GET";
|
request.ContentType = "application/json";
|
request.Headers.Add("Authorization", Header);
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
//StreamReader redr = null;
|
//redr = new StreamReader(stream, Encoding.UTF8);
|
string sHtml = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
|
return sHtml;
|
|
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
|
}
|
|
public string Userlogin(string UserName, string PassWord)
|
{
|
|
string requestBody = "{\"userNameOrEmailAddress\":\"" + UserName + "\",\"password\":\"" + PassWord + "\"}";
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.126.28.11:21021/api/TokenAuth/Authenticate");
|
SetWebRequest(request);
|
request.Method = "POST";
|
|
request.ServicePoint.Expect100Continue = false;
|
try
|
{
|
using (var postStream = new StreamWriter(request.GetRequestStream()))
|
{
|
postStream.Write(requestBody);
|
}
|
}
|
catch (WebException ex)
|
{
|
|
return "INT ERR";
|
}
|
request.ContentType = "application/json";
|
|
try
|
{
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
string sHtml = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
|
RootObject2 rb = JsonConvert.DeserializeObject<RootObject2>(sHtml);
|
|
return "Bearer " + rb.result.accessToken;
|
}
|
catch (WebException EX)
|
{
|
|
return "password err";
|
//throw new WxPayException(EX.ToString());
|
}
|
|
}
|
|
public static string GetTVinfo(string SN)
|
{
|
try
|
{
|
GetWebserver GET1 = new GetWebserver();
|
Hashtable ht = new Hashtable();
|
string xx = GET1.GetTVInfo("http://10.222.16.22:9006/api/PE", "GetTVInfo", SN);//
|
return xx;
|
}
|
catch { return "Erro"; }
|
}
|
|
public static bool GetTVInfo(string SN, out GetTVInfo TVInfo)
|
{
|
TVInfo = new GetTVInfo();
|
try
|
{
|
string GetTVInfoMessage = GetTVinfo(SN);
|
if ("Erro" != GetTVInfoMessage && "null" != GetTVInfoMessage)
|
{
|
List<GetTVInfo> GetTVInfo1 = JsonConvert.DeserializeObject<List<GetTVInfo>>("[" + GetTVInfoMessage + "]");
|
|
if (GetTVInfo1.Count > 0)
|
{
|
TVInfo = GetTVInfo1[0];
|
return true;
|
}
|
else
|
return false;
|
}
|
return false;
|
}
|
catch { return false; }
|
}
|
|
public static string GetMainfo(string SN)
|
{
|
try
|
{
|
string xx = Class1.PostXml(" http://10.222.16.22:9002/SAPService.asmx?op=GetMaInfo", SN);
|
return xx;
|
}
|
catch { return "Erro"; }
|
}
|
|
public static bool GetMaInfo(string SN, out RootObject5 MaInfo)
|
{
|
MaInfo = new RootObject5();
|
try
|
{
|
string sHtml = GetMainfo(SN);
|
if ("Erro" != sHtml && "null" != sHtml)
|
{
|
RootObject5 rb = JsonConvert.DeserializeObject<RootObject5>(sHtml);
|
|
if (rb != null)
|
{
|
MaInfo = rb;
|
return true;
|
}
|
else
|
return false;
|
}
|
return false;
|
}
|
catch { return false; }
|
}
|
|
public static bool GetBOMAndODF(string SN, out string BOM, out string ODF)
|
{
|
BOM = string.Empty;
|
ODF = string.Empty;
|
if (GetTVInfo(SN, out GetTVInfo info))
|
{
|
BOM = info.ProductCode;
|
ODF = info.ODF;
|
return true;
|
}
|
else if (GetMaInfo(SN, out RootObject5 rb5))
|
{
|
BOM = rb5.BOM;
|
ODF = rb5.ODF;
|
return true;
|
}
|
return false;
|
}
|
|
private static void SetWebRequest(HttpWebRequest request)
|
{
|
request.Proxy = null;
|
request.KeepAlive = false;
|
request.Credentials = CredentialCache.DefaultCredentials;
|
request.Timeout = 2000;
|
// WebRequest.Proxy = null;
|
System.Net.ServicePointManager.DefaultConnectionLimit = 50;
|
|
}
|
|
public string CHECKSTATUS(string Header, string StatusType, string Line, string Device, string Station, string StationNumber)
|
{
|
try
|
{
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.126.28.11:21021/api/services/app/TPM_DeviceStatusConfigHis/GetAllByCondition?StatusType=" + StatusType + "&Line=" + Line + "&Device=" + Device + "&Station=" + Station + "&StationNumber=" + StationNumber);
|
request.Method = "GET";
|
request.ContentType = "application/json";
|
request.Headers.Add("Authorization", Header);
|
SetWebRequest(request);
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
StreamReader redr = null;
|
redr = new StreamReader(stream, Encoding.UTF8);
|
string sHtml = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
|
RootObject1 rb = JsonConvert.DeserializeObject<RootObject1>(sHtml);
|
if (rb.success == "true")
|
{
|
return rb.result.status;
|
}
|
else { return rb.error.message; }
|
|
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
|
}
|
|
public string RunmsgData(string Header, string SoftWare, string TvSn, string MessageType, string Message, bool ProcessStatus, string Line, string Device, string Station, string StationNumber, string HostName, string Mac)
|
{
|
try
|
{
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.126.28.11:21021/api/services/app/TPM_SoftwareRunMsgData/Create");
|
SetWebRequest(request);
|
request.Method = "POST";
|
|
request.Headers.Add("Authorization", Header);
|
StringWriter sw = new StringWriter();
|
JsonWriter writer = new JsonTextWriter(sw);
|
writer.WriteStartObject();
|
writer.WritePropertyName("softWare");
|
writer.WriteValue(SoftWare);
|
writer.WritePropertyName("tvSn");
|
writer.WriteValue(TvSn);
|
writer.WritePropertyName("messageType");
|
writer.WriteValue(MessageType);
|
writer.WritePropertyName("message");
|
writer.WriteValue(Message);
|
writer.WritePropertyName("processStatus");
|
writer.WriteValue(ProcessStatus);
|
writer.WritePropertyName("line");
|
writer.WriteValue(Line);
|
writer.WritePropertyName("device");
|
writer.WriteValue(Device);
|
writer.WritePropertyName("station");
|
writer.WriteValue(Station);
|
//writer.WritePropertyName("softWare");
|
//writer.WriteValue(SoftWare);
|
writer.WritePropertyName("stationNumber");
|
writer.WriteValue(StationNumber);
|
writer.WritePropertyName("hostName");
|
writer.WriteValue(HostName);
|
writer.WritePropertyName("mac");
|
writer.WriteValue(Mac);
|
//writer.WritePropertyName("id");
|
//writer.WriteValue(Id);
|
writer.WriteEndObject();
|
writer.Flush();
|
string jsonText = sw.GetStringBuilder().ToString();
|
string requestBody = jsonText;
|
using (var postStream = new StreamWriter(request.GetRequestStream()))
|
{
|
postStream.Write(requestBody);
|
}
|
request.ContentType = "application/json";
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
string sHtml = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
|
RootObject1 rb = JsonConvert.DeserializeObject<RootObject1>(sHtml);
|
if (rb.success == "true")
|
{
|
return "UpDateOk";
|
}
|
else { return rb.error.message; }
|
}
|
catch (Exception ex)
|
{
|
return "TPM上传失败!";
|
}
|
|
}
|
|
public string getCheckStatusHistResult(string Header, string Line, string Station, string StationNumber)
|
{
|
try
|
{
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.126.28.11:21021/api/services/app/TPM_SoftwareRunMsgData/getCheckStatusHistResult?LINE=" + Line + "&Station=" + Station + "&StationNumber=" + StationNumber);
|
|
request.Method = "GET";
|
request.ContentType = "application/json";
|
request.Headers.Add("Authorization", Header);
|
SetWebRequest(request);
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
StreamReader redr = null;
|
redr = new StreamReader(stream, Encoding.UTF8);
|
string sHtml = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
|
|
RootObject3 rb = JsonConvert.DeserializeObject<RootObject3>(sHtml);
|
if (rb.success == "true")
|
{
|
return rb.result;
|
}
|
else { return "false"; }
|
}
|
catch (Exception ex)
|
{
|
return "false";
|
}
|
}
|
|
public string getDeviceStatusConfigHis(string Header, string Line, string Station, string StationNumber)
|
{
|
try
|
{
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.126.28.11:21021/api/services/app/TPM_DeviceStatusConfigHis/GetAllByCondition?LINE=" + Line + "&Station=" + Station + "&StationNumber=" + StationNumber);
|
request.Method = "GET";
|
request.ContentType = "application/json";
|
request.Headers.Add("Authorization", Header);
|
SetWebRequest(request);
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
StreamReader redr = null;
|
redr = new StreamReader(stream, Encoding.UTF8);
|
string sHtml = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
|
RootObject1 rb = JsonConvert.DeserializeObject<RootObject1>(sHtml);
|
if (rb.success == "true")
|
{ return rb.result.isCheck; }
|
else { return "false"; }
|
}
|
catch (Exception ex)
|
{
|
return "false";
|
}
|
}
|
|
public string getstate(string sn)
|
{
|
try
|
{
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.222.16.22/FireTVApi/api/SMES/getOrderProductStatus?SN=" + sn);
|
request.Method = "POST";
|
request.ContentType = "application/json";
|
request.ContentLength = 0;
|
SetWebRequest(request);
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
Stream stream = response.GetResponseStream();
|
StreamReader redr = null;
|
redr = new StreamReader(stream, Encoding.UTF8);
|
string sHtml = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd().Replace("[", "").Replace("]", "");
|
RootObject rb = JsonConvert.DeserializeObject<RootObject>(sHtml);
|
if (rb.Result == "true")
|
{ return rb.returnObject.ProdStatus; }
|
else { return "false"; }
|
}
|
catch (Exception ex)
|
{
|
return "false";
|
}
|
}
|
|
public static string PostXml(string url, string SN)
|
{
|
string result = "";
|
string strPost;
|
Stream myWriter = null;
|
strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetMaInfo xmlns=\"http://tempuri.org/\"><sn>" + SN + "</sn></GetMaInfo></soap:Body></soap:Envelope>";
|
|
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
|
objRequest.Method = "POST";
|
objRequest.ContentLength = strPost.Length;
|
objRequest.ContentType = "text/xml";//提交xml
|
//objRequest.ContentType = "application/x-www-form-urlencoded";//提交表单
|
objRequest.KeepAlive = false;
|
objRequest.Credentials = CredentialCache.DefaultCredentials;
|
objRequest.Timeout = 7000;
|
Encoding encoding = Encoding.GetEncoding("UTF-8");
|
byte[] data = encoding.GetBytes(strPost);
|
try
|
{
|
myWriter = objRequest.GetRequestStream();
|
}
|
catch (Exception ex)
|
{
|
return "INT ERR";
|
}
|
myWriter.Write(data, 0, strPost.Length);
|
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
|
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
|
{
|
result = sr.ReadToEnd();
|
sr.Close();
|
}
|
result = result.Substring(0, result.LastIndexOf("}</GetMaInfoResult>") + 1);
|
result = result.Substring(result.LastIndexOf("<GetMaInfoResult>{") + 17);
|
RootObject4 rb = JsonConvert.DeserializeObject<RootObject4>(result);
|
if (rb.IsSuccess == "true")
|
{ return rb.Msg; }
|
else
|
{ return "error" + rb.Msg; }
|
}
|
|
public static string getBOMDesc(string BOM)
|
{
|
string JSON = "{\"FuncCode\":\"FA_MM0001\",\"FuncData\":{\"MATNR\":\"" + BOM + "\"},\"Token\":\"SCBCSMESAPI2021!@#\"}";
|
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://10.222.16.22/SMESCommAPI/api/SAPEDI/SAPExchage");
|
req.Timeout = 8000;
|
req.Method = "POST";
|
req.ContentType = "application/json";
|
try
|
{
|
using (var reqStream = new StreamWriter(req.GetRequestStream()))
|
{
|
reqStream.Write(JSON);
|
}
|
}
|
catch (Exception ex)
|
{
|
return "ERROR:网络无连接";
|
}
|
HttpWebResponse hwr = req.GetResponse() as HttpWebResponse;
|
System.IO.StreamReader myreader = new System.IO.StreamReader(hwr.GetResponseStream(), Encoding.UTF8);
|
string responseText = myreader.ReadToEnd();
|
RootObject6 rb2 = JsonConvert.DeserializeObject<RootObject6>(responseText);
|
if (rb2.Result.Contains("true"))
|
{
|
return rb2.Data;
|
}
|
else
|
{
|
return "不存在此BOM号或你的操作有误!";
|
}
|
|
}
|
|
public static string UploadResult(string sn, string station, string function, string result, string remark, string costtime)
|
{
|
string JSON = "{\"USERCODE\":\"SAPEDI\",\"TOKEN\":\"SCBCSMESAPI2021!@#\",\"METHOD\":\"UploadResult\",\"PARAS\":{\"SN\":\"" + sn + "\",\"Station\":\"" + station + "\",\"FunctionName\":\"" + function + "\",\"TestResult\":\"" + result + "\",\"CostTime\":\"" + costtime + "\",\"Remark\":\"" + remark + "\"}}";
|
MemoryStream stream = new MemoryStream();
|
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://10.222.16.22/SMESCommAPI/API/SAPEDI/SMESDataExchage");
|
req.Timeout = 8000;
|
req.Method = "POST";
|
req.ContentType = "application/json";
|
try
|
{
|
using (var reqStream = new StreamWriter(req.GetRequestStream()))
|
{
|
reqStream.Write(JSON);
|
}
|
}
|
catch (Exception ex)
|
{
|
return $"ERROR:网络无连接[{ex.Message}]";
|
}
|
HttpWebResponse hwr = req.GetResponse() as HttpWebResponse;
|
System.IO.StreamReader myreader = new System.IO.StreamReader(hwr.GetResponseStream(), Encoding.UTF8);
|
string responseText = myreader.ReadToEnd();
|
|
RootObject6 rb2 = JsonConvert.DeserializeObject<RootObject6>(responseText);
|
if (rb2.Result.Contains("true"))
|
return "TRUE";
|
else
|
return "ERROR防呆上传失败:" + rb2.Error;
|
}
|
public static string getResult(string sn, string function)
|
{
|
string JSON = "{\"USERCODE\":\"SAPEDI\",\"TOKEN\":\"SCBCSMESAPI2021!@#\",\"METHOD\":\"getResult\",\"PARAS\":[{\"SN\":\"" + sn + "\",\"FunctionName\":\"" + function + "\" }] }";
|
//MemoryStream stream = new MemoryStream();
|
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://10.222.16.22/SMESCommAPI/API/SAPEDI/SMESDataExchage");
|
req.Timeout = 5000;
|
req.Method = "POST";
|
req.ContentType = "application/json";
|
try
|
{
|
using (var reqStream = new StreamWriter(req.GetRequestStream()))
|
{
|
reqStream.Write(JSON);
|
}
|
}
|
catch (Exception ex)
|
{
|
return "ERROR:网络无连接" + JSON;
|
}
|
HttpWebResponse hwr = req.GetResponse() as HttpWebResponse;
|
System.IO.StreamReader myreader = new System.IO.StreamReader(hwr.GetResponseStream(), Encoding.UTF8);
|
string responseText = myreader.ReadToEnd();
|
|
|
JObject jsonObject = JObject.Parse(responseText);
|
// 第一层检查:是否存在 Data 字段
|
if (jsonObject["Data"] == null || jsonObject["Data"].Type == JTokenType.Null)
|
{
|
return "false";
|
}
|
if (jsonObject["Data"] is JObject dataObj && dataObj["TableInfo"] == null
|
&& dataObj["TableInfo"].Type == JTokenType.Array)
|
{
|
return "false";
|
}
|
JArray tableInfoArray = (JArray)jsonObject["Data"]["TableInfo"];
|
JToken testResultToken = tableInfoArray[0]["TestResult"];
|
// 假设我们只关心第一个元素的 TestResult
|
if (tableInfoArray.Count > 0)
|
{
|
//testResultToken = tableInfoArray[0]["TestResult"];
|
Console.WriteLine(testResultToken.ToString()); // 输出: OK
|
}
|
else
|
{
|
Console.WriteLine("TableInfo 数组为空");
|
}
|
|
// RootObject6 rb2 = JsonConvert.DeserializeObject<RootObject6>(responseText);
|
if (responseText.Contains(sn) && (testResultToken.ToString().Equals("OK", StringComparison.OrdinalIgnoreCase)))
|
{
|
return "TRUE";
|
|
}
|
else
|
{
|
return "ERROR:未找到SN";
|
}
|
}
|
|
public static string IsExitTVSN(string TVSN)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "IsExitTVSN", new Hashtable {
|
{
|
"TVSN",
|
TVSN.Trim()
|
} });
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string GetTVInfo(string SN)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "GetTVInfo", new Hashtable { { "SN", SN } });
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string IsExitParts(int PFlowId, string NextProcessCode)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "IsExitParts", new Hashtable
|
{
|
{ "PFlowId", PFlowId },
|
{ "NextProcessCode", NextProcessCode }
|
});
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string UpcCheck(string SN, string UpcCode)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "UpcCheck", new Hashtable
|
{
|
{ "SN", SN },
|
{ "UpcCode", UpcCode }
|
});
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string GetPartsBySN(int PFID, string NextProcessCode, string PWNo)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "GetPartsBySN", new Hashtable
|
{
|
{ "PFID", PFID },
|
{ "NextProcessCode", NextProcessCode },
|
{ "PWNo", PWNo }
|
});
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string GetNextProcessCode(string TVSN)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "GetNextProcessCode", new Hashtable {
|
{
|
"TVSN",
|
TVSN.Trim()
|
} });
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string UserLoginRs(string UserAccount, string Pwd)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "UserLoginRs", new Hashtable
|
{
|
{
|
"UserAccount",
|
UserAccount.Trim()
|
},
|
{
|
"Pwd",
|
Pwd.Trim()
|
}
|
});
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string Scan(string TVSN, string LineCode, string PcProcessCode, string Host, string IP, string User, string UserName, string PartStrs)
|
{
|
try
|
{
|
return QueryGetWebService("http://10.222.16.22:9006/api/PE", "Scan", new Hashtable
|
{
|
{ "TVSN", TVSN },
|
{ "LineCode", LineCode },
|
{ "PcProcessCode", PcProcessCode },
|
{ "Host", Host },
|
{ "IP", IP },
|
{ "User", User },
|
{ "UserName", UserName },
|
{ "PartStrs", PartStrs }
|
});
|
}
|
catch (Exception ex)
|
{
|
return ex.ToString();
|
}
|
}
|
|
public static string QueryGetWebService(string URL, string MethodName, Hashtable Pars)
|
{
|
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL + "/" + MethodName + "?" + ParsToString(Pars));
|
httpWebRequest.Method = "GET";
|
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
|
SetWebRequest(httpWebRequest);
|
return ReadXmlResponse(httpWebRequest.GetResponse());
|
}
|
|
private static string ReadXmlResponse(WebResponse response)
|
{
|
StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
string result = streamReader.ReadToEnd();
|
streamReader.Close();
|
XmlDocument xmlDocument = new XmlDocument();
|
return result;
|
}
|
|
private static string ParsToString(Hashtable Pars)
|
{
|
StringBuilder stringBuilder = new StringBuilder();
|
foreach (string key in Pars.Keys)
|
{
|
if (stringBuilder.Length > 0)
|
{
|
stringBuilder.Append("&");
|
}
|
stringBuilder.Append(HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(Pars[key].ToString()));
|
}
|
return stringBuilder.ToString();
|
}
|
|
public string GetBOMList(string ODF = "DAA2506010", string WorkOrderNo = "000080858216", string url = "http://10.222.16.22:9002/SAPService.asmx?op=GetMaInfo", int Timeout = 10000)
|
{
|
try
|
{
|
string text = "";
|
Stream stream = null;
|
string text2 =
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
|
"<soap12:Body>" +
|
"<GetBOMList xmlns=\"http://tempuri.org/\">" +
|
"<odf>" + ODF + "</odf>" +
|
"<workorder>" + WorkOrderNo + "</workorder>" +
|
"</GetBOMList>" +
|
"</soap12:Body>" +
|
"</soap12:Envelope>";
|
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
httpWebRequest.Method = "POST";
|
httpWebRequest.ContentLength = text2.Length;
|
httpWebRequest.ContentType = "text/xml";
|
httpWebRequest.KeepAlive = false;
|
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
|
httpWebRequest.Timeout = Timeout;
|
Encoding encoding = Encoding.GetEncoding("UTF-8");
|
byte[] bytes = encoding.GetBytes(text2);
|
try
|
{
|
stream = httpWebRequest.GetRequestStream();
|
}
|
catch (Exception)
|
{
|
return "INT ERR";
|
}
|
|
stream.Write(bytes, 0, text2.Length);
|
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
|
using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
|
{
|
text = streamReader.ReadToEnd();
|
streamReader.Close();
|
}
|
|
//text = text.Substring(0, text.LastIndexOf("}</GetBOMListResponse>") + 1);
|
//text = text.Substring(text.LastIndexOf("<GetBOMListResponse>{") + 17);
|
|
int start = text.IndexOf("<GetBOMListResult>") + "<GetBOMListResult>".Length;
|
int end = text.IndexOf("</GetBOMListResult>");
|
string json = text.Substring(start, end - start);
|
|
RootObject4 rootObject = JsonConvert.DeserializeObject<RootObject4>(json);
|
if (rootObject.IsSuccess == "true")
|
return rootObject.Msg;
|
|
return "error" + rootObject.Msg;
|
}
|
catch { return "exception"; }
|
}
|
}
|
public class Items
|
{
|
public string name { get; set; }
|
public string desc { get; set; }
|
public string category { get; set; }
|
public string no { get; set; }
|
public string createTime { get; set; }
|
public string updateTime { get; set; }
|
public string id { get; set; }
|
}
|
|
public class Error
|
{
|
public string code { get; set; }
|
public string message { get; set; }
|
public string details { get; set; }
|
public string validationErrors { get; set; }
|
}
|
public class RootObject
|
{
|
public string Result { get; set; }
|
public string EroMsg { get; set; }
|
public returnObject returnObject { get; set; }
|
|
}
|
public class returnObject
|
{
|
public string ODF { get; set; }
|
public string ProdStatus { get; set; }
|
|
}
|
public class RootObject1
|
{
|
public Result result { get; set; }
|
public string targetUrl { get; set; }
|
public string success { get; set; }
|
public Error error { get; set; }
|
public string unAuthorizedRequest { get; set; }
|
public string __abp { get; set; }
|
}
|
|
public class RootObject4
|
{
|
public string Guid { get; set; }
|
|
public string IsSuccess { get; set; }
|
|
public string Msg { get; set; }
|
|
public string UpdateUser { get; set; }
|
}
|
|
public class Result
|
{
|
public string accessToken { get; set; }
|
public string encryptedAccessToken { get; set; }
|
public string expireInSeconds { get; set; }
|
public string userId { get; set; }
|
public string totalCount { get; set; }
|
public string statusType { get; set; }
|
public string status { get; set; }
|
public string line { get; set; }
|
public string device { get; set; }
|
public string station { get; set; }
|
public string stationNumber { get; set; }
|
public string createTime { get; set; }
|
public string updateTime { get; set; }
|
public string isCheck { get; set; }
|
public string isUse { get; set; }
|
public string isPower { get; set; }
|
public string hostName { get; set; }
|
public string mac { get; set; }
|
public string id { get; set; }
|
public List<Items> items { get; set; }
|
}
|
public class RootObject2
|
{
|
public Result result { get; set; }
|
public string targetUrl { get; set; }
|
public string success { get; set; }
|
public string error { get; set; }
|
public string unAuthorizedRequest { get; set; }
|
public string __abp { get; set; }
|
}
|
public class RootObject3
|
{
|
public string result { get; set; }
|
public string targetUrl { get; set; }
|
public string success { get; set; }
|
public string error { get; set; }
|
public string unAuthorizedRequest { get; set; }
|
public string __abp { get; set; }
|
}
|
//public class RootObject4
|
//{
|
// public string Guid { get; set; }
|
// public string IsSuccess { get; set; }
|
// public string Msg { get; set; }
|
// public string UpdateUser { get; set; }
|
|
//}
|
public class RootObject6
|
{
|
public string Result { get; set; }
|
public string Data { get; set; }
|
public string Error { get; set; }
|
public string ReciveTime { get; set; }
|
public string FinishTime { get; set; }
|
}
|
}
|