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

154 lines
5.7 KiB

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