纽威
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.

104 lines
3.9 KiB

  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using System.Net;
  18. using System.IO;
  19. using Newtonsoft.Json.Linq;
  20. using NFine.Domain._03_Entity.WMS;
  21. namespace NFine.Application.WMS
  22. {
  23. public class ICSHGErrorHandleApp : RepositoryFactory<ICSVendor>
  24. {
  25. //销售出库过账SAP
  26. public string WMSInterfaceReCall(string IDList, string WorkPoint)
  27. {
  28. string msg = "";
  29. try
  30. {
  31. string result = "";
  32. string postUrlStr = System.Configuration.ConfigurationManager.AppSettings["WMSpostUrlStr"].ToString();
  33. string LogIDList = "";
  34. foreach (string ID in IDList.TrimEnd(',').Split(','))
  35. {
  36. LogIDList += "'" + ID + "',";
  37. }
  38. #region 再次调用货柜用WMS接口
  39. string sql = @"select ID,DocNO,InputJSON from ICSHG_WMSEorrorLog
  40. where ID in ({0}) AND WorkPoint='{1}'";
  41. sql = string.Format(sql, LogIDList.TrimEnd(','), WorkPoint);
  42. DataTable Sapdt = SqlHelper.GetDataTableBySql(sql);
  43. foreach (DataRow dr in Sapdt.Rows)
  44. {
  45. result = HTTPHelper.HttpPost("WMS手动回传货柜数据接口", postUrlStr, dr["InputJSON"].ToString());
  46. WMSResult wmsresult = JsonConvert.DeserializeObject<WMSResult>(result);
  47. if (wmsresult.Success == true)
  48. {
  49. sql = @"update ICSHG_WMSEorrorLog set EATTRIBUTE1='已完成'
  50. where DocNO='{0}' and WorkPoint='{1}'";
  51. sql = string.Format(sql, dr["DocNO"].ToString(), WorkPoint);
  52. SqlHelper.CmdExecuteNonQueryLi(sql);
  53. }
  54. else
  55. {
  56. sql = @"update ICSHG_WMSEorrorLog set ErrorMessage='{0}'
  57. where DocNO='{1}' and WorkPoint='{2}'";
  58. sql = string.Format(sql, wmsresult.Message, dr["DocNO"].ToString(), WorkPoint);
  59. SqlHelper.CmdExecuteNonQueryLi(sql);
  60. }
  61. }
  62. #endregion
  63. return msg;
  64. }
  65. catch (Exception ex)
  66. {
  67. msg = ex.Message;
  68. return msg;
  69. }
  70. }
  71. public static string HttpPost(string url, string body)
  72. {
  73. try
  74. {
  75. Encoding encoding = Encoding.UTF8;
  76. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  77. request.Method = "POST";
  78. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  79. request.ContentType = "application/json; charset=utf-8";
  80. byte[] buffer = encoding.GetBytes(body);
  81. request.ContentLength = buffer.Length;
  82. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  83. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  84. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  85. {
  86. return reader.ReadToEnd();
  87. }
  88. }
  89. catch (WebException ex)
  90. {
  91. throw new Exception(ex.Message);
  92. }
  93. }
  94. public class WMSResult
  95. {
  96. public bool Success { get; set; }
  97. public string Message { get; set; }
  98. }
  99. }
  100. }