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.

169 lines
6.4 KiB

1 year ago
1 year ago
1 year ago
  1. using NFine.Code;
  2. using NFine.Domain._03_Entity.SRM;
  3. using NFine.Repository;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.Common;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Newtonsoft.Json.Linq;
  12. using Newtonsoft.Json;
  13. using NFine.Application.WMS;
  14. using System.Configuration;
  15. using NFine.Data.Extensions;
  16. using System.IO;
  17. using System.Net;
  18. namespace NFine.Application.OMAY
  19. {
  20. public class ICSInvCodeHCApp : RepositoryFactory<ICSVendor>
  21. {
  22. //包装容器关联条码
  23. public DataTable GetSendContainerLot(ref Pagination jqgridparam, string queryJson)
  24. {
  25. DataTable dt = new DataTable();
  26. var queryParam = queryJson.ToJObject();
  27. List<DbParameter> parameter = new List<DbParameter>();
  28. string sql = @"select top 0 a.ID, a.LotNo,a.InvCode,'' AS LocationCode,'' AS WarehouseCode,a.Quantity,'' as LogID from ICSInventoryLot a
  29. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint";
  30. sql = string.Format(sql);
  31. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  32. }
  33. public object GetLotInfo(string keyValue)
  34. {
  35. string LotNo = string.Empty;
  36. string ID = string.Empty;
  37. string InvCode = string.Empty;
  38. decimal Quantity = 0;
  39. string msg = "";
  40. string LogID=string.Empty;
  41. string LocationCode=string.Empty;
  42. string WHCode=string.Empty;
  43. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "BarCodeInformation/Get";
  44. string result =HttpPost(APIURL, keyValue);
  45. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  46. string MessAge = Obj["Message"].ToString();
  47. string Success = Obj["Success"].ToString();
  48. if (Success.ToUpper() == "FALSE")
  49. {
  50. msg = MessAge;
  51. }
  52. else
  53. {
  54. if (msg == "")
  55. {
  56. //JObject dataObj = JObject.Parse(Obj["Data"].ToString());
  57. //AvailQty = decimal.Parse(dataObj["AvailQty"].ToString());
  58. //AllQty = decimal.Parse(dataObj["AllQty"].ToString());
  59. JArray res = (JArray)JsonConvert.DeserializeObject(Obj["Data"].ToString());
  60. foreach (var item in res)
  61. {
  62. JObject jo = (JObject)item;
  63. //var aa= jo["min_lotqty"].ToString();
  64. ID = jo["ID"].ToString();
  65. LotNo = jo["LotNo"].ToString();
  66. InvCode = jo["InvCode"].ToString();
  67. Quantity = Convert.ToDecimal( jo["Quantity"].ToString());
  68. LogID = jo["LogID"].ToString();
  69. LocationCode = jo["LocationCode"].ToString();
  70. WHCode = jo["WHCode"].ToString();
  71. }
  72. }
  73. }
  74. var Header = new
  75. {
  76. msg = msg,
  77. LotNo = LotNo,
  78. ID = ID,
  79. InvCode = InvCode,
  80. Quantity = Quantity,
  81. LogID= LogID,
  82. LocationCode = LocationCode,
  83. };
  84. return Header;
  85. }
  86. public object GetLotLocationCode(string keySendLocationCode)
  87. {
  88. string WarehouseCode = string.Empty;
  89. string msg = "";
  90. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LocationAM/Get";
  91. string result2 = HttpPost(APIURL, keySendLocationCode);
  92. JObject Obj2 = (JObject)JsonConvert.DeserializeObject(result2);//或者JObject jo = JObject.Parse(jsonText);
  93. string MessAge2 = Obj2["Message"].ToString();
  94. string Success2 = Obj2["Success"].ToString();
  95. if (Success2.ToUpper() == "FALSE")
  96. {
  97. msg = MessAge2;
  98. }
  99. else
  100. {
  101. if (msg == "")
  102. {
  103. JArray res = (JArray)JsonConvert.DeserializeObject(Obj2["Data"].ToString());
  104. foreach (var item in res)
  105. {
  106. JObject jo = (JObject)item;
  107. //var aa= jo["min_lotqty"].ToString();
  108. WarehouseCode = jo["WarehouseCode"].ToString();
  109. }
  110. }
  111. }
  112. var Header = new
  113. {
  114. msg = msg,
  115. WarehouseCode = WarehouseCode
  116. };
  117. return Header;
  118. }
  119. public string BindingICSInvCodeHC(string ICSASN)
  120. {
  121. string msg = "";
  122. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockUpAM/Create";
  123. string result = DeciliterApp.HttpPost(APIURL, ICSASN);
  124. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  125. string MessAge = Obj["Message"].ToString();
  126. string Success = Obj["Success"].ToString();
  127. if (Success.ToUpper() == "FALSE")
  128. {
  129. msg = MessAge;
  130. }
  131. return msg;
  132. }
  133. //接口api解析
  134. public static string HttpPost(string url, string body)
  135. {
  136. try
  137. {
  138. Encoding encoding = Encoding.UTF8;
  139. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  140. request.Method = "POST";
  141. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  142. request.ContentType = "application/json; charset=utf-8";
  143. byte[] buffer = encoding.GetBytes(body);
  144. request.ContentLength = buffer.Length;
  145. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  146. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  147. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  148. {
  149. return reader.ReadToEnd();
  150. }
  151. }
  152. catch (WebException ex)
  153. {
  154. throw new Exception(ex.Message);
  155. }
  156. }
  157. }
  158. }