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

271 lines
13 KiB

3 years ago
3 years ago
3 years ago
3 years ago
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. 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. var jsonDate= Parameter.ToJson();
  52. string a = Parameter;
  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,'{models.User}','{models.User}','{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, '{models.User}', MUSERName, '{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, '{models.User}', '{models.User}', '{models.MTIME}', WorkPoint, EATTRIBUTE1, EATTRIBUTE2, EATTRIBUTE3
  75. FROM ICSWareHouseLotInfoLog WHERE LotNo='{models.LotNo}' ");
  76. sqlString.Append($@" INSERT INTO ICSInventoryLotDetail SELECT '{mode.CurrentLotNo}', TransCode, TransSequence,'{models.User} ', '{models.User}', '{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 msg = "";
  86. //string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTSplit/Create";
  87. //string result = HttpPost(APIURL, Parameter);
  88. //JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  89. //string MessAge = Obj["Message"].ToString();
  90. //string Success = Obj["Success"].ToString();
  91. //if (Success.ToUpper() == "FALSE")
  92. //{
  93. // msg = MessAge;
  94. //}
  95. }
  96. catch (Exception ex)
  97. {
  98. throw new Exception(ex.Message);
  99. }
  100. return msg;
  101. }
  102. //接口api解析
  103. public static string HttpPost(string url, string body)
  104. {
  105. try
  106. {
  107. Encoding encoding = Encoding.UTF8;
  108. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  109. request.Method = "POST";
  110. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  111. request.ContentType = "application/json; charset=utf-8";
  112. byte[] buffer = encoding.GetBytes(body);
  113. request.ContentLength = buffer.Length;
  114. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  115. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  116. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  117. {
  118. return reader.ReadToEnd();
  119. }
  120. }
  121. catch (WebException ex)
  122. {
  123. throw new Exception(ex.Message);
  124. }
  125. }
  126. /// <summary>
  127. /// 根据ID获取条码
  128. /// </summary>
  129. /// <returns></returns>
  130. public DataTable GetLotNoByID(string ID)
  131. {
  132. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  133. string sql = @"select '' as ID,'' as LotNo union all
  134. SELECT ID,LotNo FROM ICSWareHouseLotInfo WITH (NOLOCK) WHERE ID in ({0}) ";
  135. sql = string.Format(sql, ID.TrimEnd(','));
  136. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  137. //if (role != "admin")
  138. //{
  139. // sql += " and b.WorkPoint='" + WorkPoint + "'";
  140. //}
  141. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  142. return dt;
  143. }
  144. //合批
  145. public string Combine(string LotNo, string ID)
  146. {
  147. string msg = "";
  148. try
  149. {
  150. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  151. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  152. string sql = @" select distinct LotNo,Quantity from ICSWareHouseLotInfo WHERE ID IN (" + ID.TrimEnd(',') + ")";
  153. DataTable dt = Repository().FindTableBySql(sql.ToString());
  154. List<LotNoCombineHead> asn = new List<LotNoCombineHead>();
  155. LotNoCombineHead ass = new LotNoCombineHead();
  156. for (int i = 0; i < dt.Rows.Count; i++)
  157. {
  158. if (LotNo == dt.Rows[i]["LotNo"].ToString())
  159. {
  160. continue;
  161. }
  162. LotNoCombineBody DetailList = new LotNoCombineBody();
  163. DetailList.CurrentLotNo = dt.Rows[i]["LotNo"].ToString();
  164. DetailList.CurrentQuantity = dt.Rows[i]["Quantity"].ToString();
  165. ass.detail.Add(DetailList);
  166. }
  167. ass.LotNo = LotNo;
  168. ass.User = MUSER;
  169. ass.WorkPoint = WorkPoint;
  170. ass.MTIME = System.DateTime.Now.ToString("s");
  171. asn.Add(ass);
  172. StringBuilder sqlString = new StringBuilder();
  173. decimal quantity = 0;
  174. foreach (var models in asn)
  175. {
  176. if (models.LotNo == null || models.detail == null)
  177. {
  178. throw new Exception("合并失败");
  179. }
  180. foreach (var mode in models.detail)
  181. {
  182. 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}')
  183. BEGIN
  184. RAISERROR(',',16,1);
  185. END
  186. 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}')
  187. BEGIN
  188. RAISERROR('',16,1);
  189. END; ");
  190. sqlString.Append($@" DELETE FROM ICSInventoryLot WHERE LotNo='{mode.CurrentLotNo}'; ");
  191. sqlString.Append($@" DELETE FROM ICSWareHouseLotInfo WHERE LotNo='{mode.CurrentLotNo}'; ");
  192. sqlString.Append($@" DELETE FROM ICSWareHouseLotInfoLog WHERE LotNo='{mode.CurrentLotNo}'; ");
  193. quantity += mode.CurrentQuantity.ToDecimal();
  194. }
  195. sqlString.Append($@" UPDATE [dbo].[ICSWareHouseLotInfo] SET [Quantity] = Quantity+{quantity} Where [LotNo]='{models.LotNo}'; ");
  196. sqlString.Append($@" UPDATE [dbo].[ICSWareHouseLotInfoLog] SET [Quantity] = Quantity+{quantity} Where [LotNo]='{models.LotNo}'; ");
  197. }
  198. var count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  199. if (count <= 0)
  200. throw new Exception("操作失败");
  201. }
  202. catch (Exception ex)
  203. {
  204. msg = ex.Message;
  205. }
  206. return msg;
  207. }
  208. ////合批
  209. //public string Combine(string LotNo, string ID)
  210. //{
  211. // string msg = "";
  212. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  213. // string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  214. // string sql = @" select distinct LotNo,Quantity from ICSWareHouseLotInfo WHERE ID IN (" + ID.TrimEnd(',') + ")";
  215. // DataTable dt = Repository().FindTableBySql(sql.ToString());
  216. // List<LotNoCombineHead> asn = new List<LotNoCombineHead>();
  217. // LotNoCombineHead ass = new LotNoCombineHead();
  218. // for (int i = 0; i < dt.Rows.Count; i++)
  219. // {
  220. // if (LotNo == dt.Rows[i]["LotNo"].ToString())
  221. // {
  222. // continue;
  223. // }
  224. // LotNoCombineBody DetailList = new LotNoCombineBody();
  225. // DetailList.CurrentLotNo= dt.Rows[i]["LotNo"].ToString();
  226. // DetailList.CurrentQuantity= dt.Rows[i]["Quantity"].ToString();
  227. // ass.detail.Add(DetailList);
  228. // }
  229. // ass.LotNo = LotNo;
  230. // ass.User = MUSER;
  231. // ass.WorkPoint = WorkPoint;
  232. // ass.MTIME= System.DateTime.Now.ToString("s");
  233. // asn.Add(ass);
  234. // string input = JsonConvert.SerializeObject(asn);
  235. // string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTMerge/Create";
  236. // string result = HttpPost(APIURL, input);
  237. // JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  238. // string MessAge = Obj["Message"].ToString();
  239. // string Success = Obj["Success"].ToString();
  240. // if (Success.ToUpper() == "FALSE")
  241. // {
  242. // msg = MessAge;
  243. // }
  244. // return msg;
  245. //}
  246. }
  247. }