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

165 lines
7.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 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. else
  78. {
  79. string lotsql = @"select A.LOTNO,ISNULL(C.BatchCode,'') AS BatchCode from ICSWareHouseLotInfoLog A
  80. INNER JOIN ICSInventoryLot B ON B.LotNo=A.LotNo AND B.WorkPoint=A.WorkPoint
  81. INNER JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  82. where BusinessCode='19' AND TransCode='{0}' and TransSequence='{1}'
  83. and A.WorkPoint='{2}'";
  84. lotsql = string.Format(lotsql, dr["SDNCode"].ToString(), dr["Sequence"].ToString(), WorkPoint);
  85. DataTable lotdt = SqlHelper.GetDataTableBySql(lotsql);
  86. foreach (DataRow lotdr in lotdt.Rows)
  87. {
  88. if (lotdr["BatchCode"].ToString() != "")
  89. {
  90. ItemLine.VBELN = dr["SDNCode"].ToString();
  91. ItemLine.POSNR = dr["SAPSequence"].ToString();
  92. ItemLine.GERNR = lotdr["BatchCode"].ToString();
  93. ItemLineList.Add(ItemLine);
  94. }
  95. }
  96. }
  97. }
  98. }
  99. if (ItemList.Count > 0)
  100. {
  101. Info.T_ITEM = ItemList.ToArray();
  102. if (ItemLineList.Count > 0)
  103. {
  104. Info.T_GERNR = ItemLineList.ToArray();
  105. }
  106. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  107. result = Client.CallZWMS_SK_DO_GZ(Info);
  108. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  109. {
  110. if (resultItem.ZFLG == "N")
  111. {
  112. IsSuccess = "N";
  113. msg += resultItem.ZMESS + "/r/n";
  114. }
  115. }
  116. if (msg == "")
  117. {
  118. string updatesql = @"Update ICSSDN set EATTRIBUTE1='已过账' where SDNCode in ({0}) AND WorkPoint='{1}'";
  119. updatesql = string.Format(updatesql, DocNOList.TrimEnd(','), WorkPoint);
  120. if (SqlHelper.CmdExecuteNonQueryLi(updatesql) > 0)
  121. {
  122. msg = "";
  123. }
  124. else
  125. {
  126. msg = "待过账状态回写失败!";
  127. }
  128. }
  129. }
  130. #endregion
  131. return msg;
  132. }
  133. catch (Exception ex)
  134. {
  135. msg = ex.Message;
  136. return msg;
  137. }
  138. }
  139. public static string HttpPost(string url, string body)
  140. {
  141. try
  142. {
  143. Encoding encoding = Encoding.UTF8;
  144. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  145. request.Method = "POST";
  146. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  147. request.ContentType = "application/json; charset=utf-8";
  148. byte[] buffer = encoding.GetBytes(body);
  149. request.ContentLength = buffer.Length;
  150. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  151. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  152. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  153. {
  154. return reader.ReadToEnd();
  155. }
  156. }
  157. catch (WebException ex)
  158. {
  159. throw new Exception(ex.Message);
  160. }
  161. }
  162. }
  163. }