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

145 lines
6.5 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 ICSToSAPApp : RepositoryFactory<ICSVendor>
  24. {
  25. //销售出库过账SAP
  26. public string DisPatchToSAP(string DisPatchCodeList, string WorkPoint)
  27. {
  28. string msg = "";
  29. try
  30. {
  31. string DocNOList = "";
  32. foreach (string DocNO in DisPatchCodeList.TrimEnd(',').Split(','))
  33. {
  34. DocNOList += "'" + DocNO + "',";
  35. }
  36. #region SAP(三层结构)
  37. string IsSuccess = "";
  38. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  39. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  40. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  41. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  42. string sql = @"select DISTINCT SDNCode from ICSSDN where SDNCode IN ({0}) AND WorkPoint='{1}'";
  43. sql = string.Format(sql, DocNOList.TrimEnd(','), WorkPoint);
  44. DataTable Sapdt = SqlHelper.GetDataTableBySql(sql);
  45. foreach (DataRow dr in Sapdt.Rows)
  46. {
  47. head.VBELN = dr["SDNCode"].ToString();
  48. headlist.Add(head);
  49. }
  50. Info.T_HEAD = headlist.ToArray();
  51. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  52. List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR> ItemLineList = new List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR>();
  53. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  54. sql = @" select A.SDNCode,A.InvCode,A.SAPSequence,A.Sequence,A.Quantity,A.SDNQuantity
  55. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A
  56. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  57. WHERE SDNCode IN ({0}) AND A.WorkPoint='{1}'";
  58. sql = string.Format(sql, DocNOList.TrimEnd(','), WorkPoint);
  59. Sapdt = SqlHelper.GetDataTableBySql(sql);
  60. foreach (DataRow dr in Sapdt.Rows)
  61. {
  62. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["SDNQuantity"].ToString()))
  63. {
  64. SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
  65. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  66. Item.VBELN = dr["SDNCode"].ToString();
  67. Item.POSNR = dr["SAPSequence"].ToString();
  68. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  69. ItemList.Add(Item);
  70. if (dr["BatchCode"].ToString() != "")
  71. {
  72. ItemLine.VBELN = dr["SDNCode"].ToString();
  73. ItemLine.POSNR = dr["SAPSequence"].ToString();
  74. ItemLine.GERNR = dr["BatchCode"].ToString();
  75. ItemLineList.Add(ItemLine);
  76. }
  77. }
  78. }
  79. if (ItemList.Count > 0)
  80. {
  81. Info.T_ITEM = ItemList.ToArray();
  82. if (ItemLineList.Count > 0)
  83. {
  84. Info.T_GERNR = ItemLineList.ToArray();
  85. }
  86. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  87. result = Client.CallZWMS_SK_DO_GZ(Info);
  88. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  89. {
  90. if (resultItem.ZFLG == "N")
  91. {
  92. IsSuccess = "N";
  93. msg += resultItem.ZMESS + "/r/n";
  94. }
  95. }
  96. if (msg == "")
  97. {
  98. string updatesql = @"Update ICSSDN set EATTRIBUTE1='已过账' where SDNCode in ({0}) AND WorkPoint='{1}'";
  99. updatesql = string.Format(updatesql, DocNOList.TrimEnd(','), WorkPoint);
  100. if (SqlHelper.CmdExecuteNonQueryLi(updatesql) > 0)
  101. {
  102. msg = "";
  103. }
  104. else
  105. {
  106. msg = "待过账状态回写失败!";
  107. }
  108. }
  109. }
  110. #endregion
  111. return msg;
  112. }
  113. catch (Exception ex)
  114. {
  115. msg = ex.Message;
  116. return msg;
  117. }
  118. }
  119. public static string HttpPost(string url, string body)
  120. {
  121. try
  122. {
  123. Encoding encoding = Encoding.UTF8;
  124. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  125. request.Method = "POST";
  126. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  127. request.ContentType = "application/json; charset=utf-8";
  128. byte[] buffer = encoding.GetBytes(body);
  129. request.ContentLength = buffer.Length;
  130. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  131. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  132. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  133. {
  134. return reader.ReadToEnd();
  135. }
  136. }
  137. catch (WebException ex)
  138. {
  139. throw new Exception(ex.Message);
  140. }
  141. }
  142. }
  143. }