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.

156 lines
6.0 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 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 LotNO as NewLotNo FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}'
  34. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  35. sql = string.Format(sql, LotNO);
  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. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "AMLOTSplit/Create";
  52. string result = HttpPost(APIURL, Parameter);
  53. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  54. string MessAge = Obj["Message"].ToString();
  55. string Success = Obj["Success"].ToString();
  56. if (Success.ToUpper() == "FALSE")
  57. {
  58. msg = MessAge;
  59. }
  60. return msg;
  61. }
  62. //接口api解析
  63. public static string HttpPost(string url, string body)
  64. {
  65. try
  66. {
  67. Encoding encoding = Encoding.UTF8;
  68. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  69. request.Method = "POST";
  70. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  71. request.ContentType = "application/json; charset=utf-8";
  72. byte[] buffer = encoding.GetBytes(body);
  73. request.ContentLength = buffer.Length;
  74. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  75. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  76. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  77. {
  78. return reader.ReadToEnd();
  79. }
  80. }
  81. catch (WebException ex)
  82. {
  83. throw new Exception(ex.Message);
  84. }
  85. }
  86. /// <summary>
  87. /// 根据ID获取条码
  88. /// </summary>
  89. /// <returns></returns>
  90. public DataTable GetLotNoByID(string ID)
  91. {
  92. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  93. string sql = @"select '' as ID,'' as LotNo union all
  94. SELECT ID,LotNo FROM ICSWareHouseLotInfo WITH (NOLOCK) WHERE ID in ({0}) ";
  95. sql = string.Format(sql, ID.TrimEnd(','));
  96. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  97. //if (role != "admin")
  98. //{
  99. // sql += " and b.WorkPoint='" + WorkPoint + "'";
  100. //}
  101. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  102. return dt;
  103. }
  104. //合批
  105. public string Combine(string LotNo, string ID)
  106. {
  107. string msg = "";
  108. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  109. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  110. string sql = @" select distinct LotNo,Quantity from ICSWareHouseLotInfo WHERE ID IN (" + ID.TrimEnd(',') + ")";
  111. DataTable dt = Repository().FindTableBySql(sql.ToString());
  112. List<LotNoCombineHead> asn = new List<LotNoCombineHead>();
  113. LotNoCombineHead ass = new LotNoCombineHead();
  114. for (int i = 0; i < dt.Rows.Count; i++)
  115. {
  116. if (LotNo == dt.Rows[i]["LotNo"].ToString())
  117. {
  118. continue;
  119. }
  120. LotNoCombineBody DetailList = new LotNoCombineBody();
  121. DetailList.CurrentLotNo= dt.Rows[i]["LotNo"].ToString();
  122. DetailList.CurrentQuantity= dt.Rows[i]["Quantity"].ToString();
  123. ass.detail.Add(DetailList);
  124. }
  125. ass.LotNo = LotNo;
  126. ass.User = MUSER;
  127. ass.WorkPoint = WorkPoint;
  128. ass.MTIME= System.DateTime.Now.ToString("s");
  129. asn.Add(ass);
  130. string input = JsonConvert.SerializeObject(asn);
  131. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTMerge/Create";
  132. string result = HttpPost(APIURL, input);
  133. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  134. string MessAge = Obj["Message"].ToString();
  135. string Success = Obj["Success"].ToString();
  136. if (Success.ToUpper() == "FALSE")
  137. {
  138. msg = MessAge;
  139. }
  140. return msg;
  141. }
  142. }
  143. }