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

278 lines
14 KiB

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