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

280 lines
14 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  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 Newtonsoft.Json.Linq;
  18. using System.Net;
  19. using System.IO;
  20. using NFine.Domain._03_Entity.WMS;
  21. namespace NFine.Application.WMS
  22. {
  23. public class DeciliterApp : RepositoryFactory<ICSVendor>
  24. {
  25. /// <summary>
  26. /// 点击委外退料生成条码
  27. /// </summary>
  28. public string GetNewLotNo(string LotNO)
  29. {
  30. DataTable dt = new DataTable();
  31. List<DbParameter> parameter = new List<DbParameter>();
  32. //string sql = @"select max(LotNo) as NewLotNo from ICSInventoryLot where EATTRIBUTE1='{0}' ";
  33. string sql = $@"SELECT TOP 1
  34. LotNO as NewLotNo FROM ICSInventoryLot WHERE EATTRIBUTE1='{LotNO}'
  35. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  36. dt= Repository().FindTableBySql(sql.ToString());
  37. if (dt==null||dt.Rows.Count==0|| dt.Rows[0]["NewLotNo"].ToString()=="")
  38. {
  39. return LotNO+"-1";
  40. }
  41. else
  42. {
  43. string newLotNO = dt.Rows[0]["NewLotNo"].ToString();
  44. int COUNT = Convert.ToInt32(newLotNO.Substring(newLotNO.LastIndexOf('-') + 1)) + 1;
  45. return LotNO + "-"+ COUNT.ToString();
  46. }
  47. }
  48. public string Split(string Parameter)
  49. {
  50. string msg = "";
  51. try
  52. {
  53. string user = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  54. string userName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  55. var models = Parameter.ToObject<List<LotNoCombineHead>>().FirstOrDefault();
  56. //StringBuilder sqlString = new StringBuilder();
  57. //if (models.LotNo == null || models.detail == null)
  58. //{
  59. // msg = "拆分失败,拆分数据不能为空";
  60. // return msg;
  61. //}
  62. //foreach (var mode in models.detail)
  63. //{
  64. // sqlString.Append($@" INSERT INTO ICSInventoryLot (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,PrintTimes,LastPrintUser,
  65. // LastPrintTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 )
  66. // SELECT NEWID(),'{mode.CurrentLotNo}',InvCode,ProductDate,ExpirationDate,CONVERT(NUMERIC(10,2),{mode.CurrentQuantity}),Amount,ExtensionID,Type,PrintTimes,
  67. // LastPrintUser,LastPrintTime,'{user}','{userName}','{models.MTIME}',WorkPoint,'{models.LotNo}'
  68. // FROM ICSInventoryLot
  69. // WHERE LotNo='{models.LotNo}' ");
  70. // sqlString.Append($@" INSERT INTO ICSWareHouseLotInfo
  71. // SELECT
  72. // NEWID(), '{mode.CurrentLotNo}', WarehouseCode, LocationCode, InvCode, CONVERT(NUMERIC(10,2),{mode.CurrentQuantity}), InDate, LockQuantity, '{user}','{userName}', '{models.MTIME}', WorkPoint, EATTRIBUTE1
  73. // FROM ICSWareHouseLotInfo
  74. // WHERE LotNo='{models.LotNo}' ");
  75. // sqlString.Append($@" UPDATE [dbo].[ICSWareHouseLotInfo] SET [Quantity] = Quantity-{mode.CurrentQuantity.ToInt()} Where [LotNo]='{models.LotNo}' ");
  76. // sqlString.Append($@" INSERT INTO ICSWareHouseLotInfoLog SELECT NEWID(), Identification, TransCode, TransSequence, '{mode.CurrentLotNo}', InvCode, FromWarehouseCode, FromLocationCode, ToWarehouseCode, ToLocationCode, CONVERT(NUMERIC(10,2),{mode.CurrentQuantity}), Memo, Lock, '4', BusinessCode, ERPUpload, ERPID, ERPDetailID, ERPCode, ERPSequence, LogID, MergeID, '{user}','{userName}', '{models.MTIME}', WorkPoint, EATTRIBUTE1, EATTRIBUTE2, EATTRIBUTE3
  77. // FROM ICSWareHouseLotInfoLog WHERE LotNo='{models.LotNo}' ");
  78. // sqlString.Append($@" INSERT INTO ICSInventoryLotDetail SELECT '{mode.CurrentLotNo}', TransCode, TransSequence,'{user}','{userName}', '{models.MTIME}', WorkPoint, EATTRIBUTE1 FROM ICSInventoryLotDetail WHERE LotNo='{models.LotNo}';");
  79. // sqlString.Append($@" UPDATE [dbo].[ICSWareHouseLotInfoLog] SET [Quantity] = Quantity-{mode.CurrentQuantity.ToInt()} Where [LotNo]='{models.LotNo}' ");
  80. //}
  81. //var sql = sqlString.ToString();
  82. //var count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  83. //if (count <= 0)
  84. //{
  85. // msg = "操作失败";
  86. //}
  87. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTSplit/Create";
  88. string result = HttpPost(APIURL, Parameter);
  89. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  90. string MessAge = Obj["Message"].ToString();
  91. string Success = Obj["Success"].ToString();
  92. if (Success.ToUpper() == "FALSE")
  93. {
  94. msg = MessAge;
  95. }
  96. }
  97. catch (Exception ex)
  98. {
  99. throw new Exception(ex.Message);
  100. }
  101. return msg;
  102. }
  103. //接口api解析
  104. public static string HttpPost(string url, string body)
  105. {
  106. try
  107. {
  108. Encoding encoding = Encoding.UTF8;
  109. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  110. request.Method = "POST";
  111. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  112. request.ContentType = "application/json; charset=utf-8";
  113. byte[] buffer = encoding.GetBytes(body);
  114. request.ContentLength = buffer.Length;
  115. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  116. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  117. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  118. {
  119. return reader.ReadToEnd();
  120. }
  121. }
  122. catch (WebException ex)
  123. {
  124. throw new Exception(ex.Message);
  125. }
  126. }
  127. /// <summary>
  128. /// 根据ID获取条码
  129. /// </summary>
  130. /// <returns></returns>
  131. public DataTable GetLotNoByID(string ID)
  132. {
  133. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  134. string sql = @"select '' as ID,'' as LotNo union all
  135. SELECT ID,LotNo FROM ICSWareHouseLotInfo WITH (NOLOCK) WHERE ID in ({0}) ";
  136. sql = string.Format(sql, ID.TrimEnd(','));
  137. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  138. //if (role != "admin")
  139. //{
  140. // sql += " and b.WorkPoint='" + WorkPoint + "'";
  141. //}
  142. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  143. return dt;
  144. }
  145. //合批
  146. //public string Combine(string LotNo, string ID)
  147. //{
  148. // string msg = "";
  149. // try
  150. // {
  151. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  152. // string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  153. // string sql = @" select distinct LotNo,Quantity from ICSWareHouseLotInfo WHERE ID IN (" + ID.TrimEnd(',') + ")";
  154. // DataTable dt = Repository().FindTableBySql(sql.ToString());
  155. // List<LotNoCombineHead> asn = new List<LotNoCombineHead>();
  156. // LotNoCombineHead ass = new LotNoCombineHead();
  157. // for (int i = 0; i < dt.Rows.Count; i++)
  158. // {
  159. // if (LotNo == dt.Rows[i]["LotNo"].ToString())
  160. // {
  161. // continue;
  162. // }
  163. // LotNoCombineBody DetailList = new LotNoCombineBody();
  164. // DetailList.CurrentLotNo = dt.Rows[i]["LotNo"].ToString();
  165. // DetailList.CurrentQuantity = dt.Rows[i]["Quantity"].ToString();
  166. // ass.detail.Add(DetailList);
  167. // }
  168. // ass.LotNo = LotNo;
  169. // ass.User = MUSER;
  170. // ass.WorkPoint = WorkPoint;
  171. // ass.MTIME = System.DateTime.Now.ToString("s");
  172. // asn.Add(ass);
  173. // StringBuilder sqlString = new StringBuilder();
  174. // decimal quantity = 0;
  175. // foreach (var models in asn)
  176. // {
  177. // if (models.LotNo == null || models.detail == null)
  178. // {
  179. // throw new Exception("合并失败");
  180. // }
  181. // foreach (var mode in models.detail)
  182. // {
  183. // sqlString.Append($@"IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.WarehouseCode=(SELECT top 1 WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{mode.CurrentLotNo}') AND a.InvCode=(SELECT top 1 InvCode FROM ICSWareHouseLotInfo WHERE LotNo='{mode.CurrentLotNo}') AND a.LotNo='{models.LotNo}')
  184. // BEGIN
  185. // RAISERROR('不同物料、仓库的物料不能合批,',16,1);
  186. // END
  187. // IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.ExtensionID=(SELECT top 1 ExtensionID FROM ICSInventoryLot WHERE LotNo='{mode.CurrentLotNo}') AND a.LotNo='{models.LotNo}')
  188. // BEGIN
  189. // RAISERROR('不同批次的物料不能合批',16,1);
  190. // END; ");
  191. // sqlString.Append($@" DELETE FROM ICSInventoryLot WHERE LotNo='{mode.CurrentLotNo}'; ");
  192. // sqlString.Append($@" DELETE FROM ICSWareHouseLotInfo WHERE LotNo='{mode.CurrentLotNo}'; ");
  193. // sqlString.Append($@" DELETE FROM ICSWareHouseLotInfoLog WHERE LotNo='{mode.CurrentLotNo}'; ");
  194. // quantity += mode.CurrentQuantity.ToDecimal();
  195. // }
  196. // sqlString.Append($@" UPDATE [dbo].[ICSWareHouseLotInfo] SET [Quantity] = Quantity+{quantity} Where [LotNo]='{models.LotNo}'; ");
  197. // sqlString.Append($@" UPDATE [dbo].[ICSWareHouseLotInfoLog] SET [Quantity] = Quantity+{quantity} Where [LotNo]='{models.LotNo}'; ");
  198. // }
  199. // var count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  200. // if (count <= 0)
  201. // throw new Exception("操作失败");
  202. // }
  203. // catch (Exception ex)
  204. // {
  205. // msg = ex.Message;
  206. // }
  207. // return msg;
  208. //}
  209. //合批
  210. public string Combine(string LotNo, string ID)
  211. {
  212. string msg = "";
  213. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  214. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  215. string sql = @" select distinct LotNo,Quantity from ICSWareHouseLotInfo WHERE ID IN (" + ID.TrimEnd(',') + ")";
  216. DataTable dt = Repository().FindTableBySql(sql.ToString());
  217. List<LotNoCombineHead> asn = new List<LotNoCombineHead>();
  218. LotNoCombineHead ass = new LotNoCombineHead();
  219. for (int i = 0; i < dt.Rows.Count; i++)
  220. {
  221. if (LotNo == dt.Rows[i]["LotNo"].ToString())
  222. {
  223. continue;
  224. }
  225. LotNoCombineBody DetailList = new LotNoCombineBody();
  226. DetailList.CurrentLotNo = dt.Rows[i]["LotNo"].ToString();
  227. DetailList.CurrentQuantity = dt.Rows[i]["Quantity"].ToString();
  228. ass.detail.Add(DetailList);
  229. }
  230. ass.LotNo = LotNo;
  231. ass.User = MUSER;
  232. ass.WorkPoint = WorkPoint;
  233. ass.MTIME = System.DateTime.Now.ToString("s");
  234. asn.Add(ass);
  235. string input = JsonConvert.SerializeObject(asn);
  236. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTMerge/Create";
  237. string result = HttpPost(APIURL, input);
  238. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  239. string MessAge = Obj["Message"].ToString();
  240. string Success = Obj["Success"].ToString();
  241. if (Success.ToUpper() == "FALSE")
  242. {
  243. msg = MessAge;
  244. }
  245. return msg;
  246. }
  247. //验证条码是否存在占料
  248. public decimal CheckLotOccupy(string LotNO)
  249. {
  250. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  251. string sql = @" select ISNULL(LockQuantity,0) AS LockQuantity from ICSWareHouseLotInfo
  252. where LotNo='{0}' AND WorkPoint='{1}'";
  253. sql = string.Format(sql, LotNO, WorkPoint);
  254. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  255. decimal LotQTY = Convert.ToDecimal(dt.Rows[0]["LockQuantity"]);
  256. return LotQTY;
  257. }
  258. }
  259. }