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.

213 lines
6.7 KiB

12 months ago
1 year ago
12 months ago
12 months ago
1 year ago
1 year ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Text;
  6. using NFine.Code;
  7. using NFine.Repository;
  8. using System.Data.Common;
  9. using NFine.Domain._03_Entity.SRM;
  10. using Newtonsoft.Json;
  11. using System.Configuration;
  12. using System.Net;
  13. using System.IO;
  14. using Newtonsoft.Json.Linq;
  15. namespace NFine.Application.OMAY
  16. {
  17. public class OMAYMoOutboundApp : RepositoryFactory<ICSVendor>
  18. {
  19. public DataTable GetMoInfo( string Code, ref Pagination jqgridparam)
  20. {
  21. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  22. string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  23. string User = UserName.Substring(0, 2);
  24. List<DbParameter> parameter = new List<DbParameter>();
  25. DataTable table = new DataTable();
  26. string sql = @"select Row_Number() OVER (ORDER BY MOCode desc) AS ID,a.MOCode,a.DepName from
  27. (select distinct a.MOCode,b.DepName from dbo.ICSMO a
  28. inner join ICSDepartment b on a.DepCode=b.DepCode and a.WorkPoint=b.WorkPoint where a.ApsStatus='Y' and isnull(a.OrderStatus,'') <> 'Close' )a where 1=1 ";
  29. if (!string.IsNullOrEmpty(Code))
  30. {
  31. sql += " and a.MOCode like '%" + Code + "%'";
  32. }
  33. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  34. {
  35. sql += " and a.DepName='" + User + "'";
  36. }
  37. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  38. }
  39. public DataTable GetMosByCode(string queryJson, ref Pagination jqgridparam)
  40. {
  41. DataTable dt = new DataTable();
  42. var queryParam = queryJson.ToJObject();
  43. List<DbParameter> parameter = new List<DbParameter>();
  44. string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  45. string User = UserName.Substring(0, 2);
  46. #region [SQL]
  47. string sql = @" select a.ID,a.MOCode,a.Sequence,a.InvCode,b.InvName,b.InvDesc,b.InvUnit,b.InvStd,a.Quantity,a.Amount,a.MODetailID,c.DepName from dbo.ICSMO a
  48. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  49. inner join ICSDepartment c on a.DepCode=c.DepCode and a.WorkPoint=c.WorkPoint ";
  50. sql += " WHERE 1=1 and a.MOCode='"+ queryParam["Code"].ToString() + "'";
  51. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  52. {
  53. sql += " and c.DepName='" + User + "'";
  54. }
  55. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  56. #endregion
  57. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  58. }
  59. public DataTable GetMoPicksByCode(string queryJson, ref Pagination jqgridparam)
  60. {
  61. DataTable dt = new DataTable();
  62. var queryParam = queryJson.ToJObject();
  63. List<DbParameter> parameter = new List<DbParameter>();
  64. #region [SQL]
  65. string sql = @"select a.ID,a.MODetailID,a.Sequence,a.InvCode,b.InvName,b.InvDesc,b.InvStd,c.WarehouseName,
  66. case when b.AmountEnable='1' then a.Amount else a.Quantity end as Quantity,
  67. case when b.AmountEnable='1' then b.AmountUnit else b.InvUnit end as InvUnit,
  68. a.IssueQuantity,b.EATTRIBUTE1,a.Amount
  69. from dbo.ICSMOPick a
  70. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  71. left join dbo.ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint";
  72. sql += " WHERE 1=1 and a.EATTRIBUTE1 <> '1' and a.MODetailID='" + queryParam["MODetailID"].ToString() + "'";
  73. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  74. #endregion
  75. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  76. }
  77. public object GetLotNotInfo(string keyValue)
  78. {
  79. DataTable dt = new DataTable();
  80. string msg = "";
  81. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "AMBarCodeInformation/Get";
  82. string result = HttpPost(APIURL, keyValue);
  83. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  84. string MessAge = Obj["Message"].ToString();
  85. string Success = Obj["Success"].ToString();
  86. if (Success.ToUpper() == "FALSE")
  87. {
  88. msg = MessAge;
  89. }
  90. else
  91. {
  92. if (msg == "")
  93. {
  94. string Data = Obj["Data"].ToString();
  95. dt = JsonConvert.DeserializeObject<DataTable>(Data);
  96. // dt = dataSet.Tables[0];
  97. }
  98. }
  99. var Header = new
  100. {
  101. msg = msg,
  102. dt = dt,
  103. };
  104. return Header;
  105. }
  106. public string OutboundShipments(string ICSASN)
  107. {
  108. string msg = "";
  109. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockDownAM/Create";
  110. string result = HttpPost(APIURL, ICSASN);
  111. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  112. string MessAge = Obj["Message"].ToString();
  113. string Success = Obj["Success"].ToString();
  114. if (Success.ToUpper() == "FALSE")
  115. {
  116. msg = MessAge;
  117. }
  118. return msg;
  119. }
  120. //接口api解析
  121. public static string HttpPost(string url, string body)
  122. {
  123. try
  124. {
  125. Encoding encoding = Encoding.UTF8;
  126. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  127. request.Method = "POST";
  128. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  129. request.ContentType = "application/json; charset=utf-8";
  130. byte[] buffer = encoding.GetBytes(body);
  131. request.ContentLength = buffer.Length;
  132. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  133. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  134. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  135. {
  136. return reader.ReadToEnd();
  137. }
  138. }
  139. catch (WebException ex)
  140. {
  141. throw new Exception(ex.Message);
  142. }
  143. }
  144. }
  145. }