You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using NFine.Data.Extensions;using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text;using System.Threading.Tasks;using NFine.Code;using NFine.Repository;using System.Data.Common;using NFine.Domain._03_Entity.SRM;using ICS.Application.Entity;using Newtonsoft.Json;using System.Configuration;using System.Data.SqlClient;using ICS.Data;using System.Net;using System.IO;using Newtonsoft.Json.Linq;using NFine.Domain._03_Entity.WMS;
namespace NFine.Application.WMS{ public class ICSAPIErrorHandleApp : RepositoryFactory<ICSVendor> { public string WMSInterfaceReCall(string IDList, string WorkPoint) { string msg = ""; try { string LogIDList = ""; foreach (string ID in IDList.TrimEnd(',').Split(',')) { LogIDList += "'" + ID + "',"; } string sql = @"select ID,Url,JosnStr from ICSAPIErrorLog
where ID in ({0}) AND Status='0' AND WorkPoint='{1}'";
sql = string.Format(sql, LogIDList.TrimEnd(','), WorkPoint); DataTable Sapdt = SqlHelper.GetDataTableBySql(sql); foreach (DataRow dr in Sapdt.Rows) { string APIURL = dr["Url"].ToString(); string result = HttpPost(APIURL, dr["JosnStr"].ToString()); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { sql = @"update ICSAPIErrorLog set ErrorMsg='{0}'
where ID='{1}' and WorkPoint='{2}'";
sql = string.Format(sql, MessAge, dr["ID"].ToString(), WorkPoint); SqlHelper.CmdExecuteNonQueryLi(sql); throw new Exception(MessAge); } else { sql = @"update ICSAPIErrorLog set Status='1'
where ID='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, dr["ID"].ToString(), WorkPoint); SqlHelper.CmdExecuteNonQueryLi(sql); } } return msg; } catch (Exception ex) { msg = ex.Message; return msg; } } public static string HttpPost(string url, string body) { try { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } catch (WebException ex) { throw new Exception(ex.Message); } }
public class WMSResult { public bool Success { get; set; }
public string Message { get; set; } } }}
|