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.

211 lines
6.5 KiB

12 months ago
12 months 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 OMAYSalesDeliveryApp : RepositoryFactory<ICSVendor>
  18. {
  19. public DataTable GetSalesDeliveryInfo(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 SDNCode desc) AS ID, SDNCode,CusCode,CusName,CreatePerson from (
  27. select distinct SDNCode,CusCode,CusName,CreatePerson from ICSSDN where Type='1' ) a where 1=1 ";
  28. if (!string.IsNullOrEmpty(Code))
  29. {
  30. sql += " and SDNCode like '%" + Code + "%'";
  31. }
  32. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  33. //{
  34. // sql += " and a.DepName='" + User + "'";
  35. //}
  36. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  37. }
  38. public DataTable GetSalesByCode(string queryJson, ref Pagination jqgridparam)
  39. {
  40. DataTable dt = new DataTable();
  41. var queryParam = queryJson.ToJObject();
  42. List<DbParameter> parameter = new List<DbParameter>();
  43. string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  44. string User = UserName.Substring(0, 2);
  45. #region [SQL]
  46. string sql = @"
  47. select a.ID,a.SDNCode,a.Sequence,a.InvCode,b.InvName,b.InvDesc,b.InvUnit,b.InvStd,d.WarehouseName,a.Quantity,a.Amount,a.SDNQuantity,c.BatchCode
  48. from dbo.ICSSDN a
  49. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  50. left join dbo.ICSExtension c on a.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
  51. left join dbo.ICSWarehouse d on a.WHCode=d.WarehouseCode and a.WorkPoint=d.WorkPoint";
  52. sql += " WHERE 1=1 and a.SDNCode='" + queryParam["Code"].ToString() + "'";
  53. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  54. //{
  55. // sql += " and c.DepName='" + User + "'";
  56. //}
  57. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  58. #endregion
  59. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  60. }
  61. public DataTable GetMoPicksByCode(string queryJson, ref Pagination jqgridparam)
  62. {
  63. DataTable dt = new DataTable();
  64. var queryParam = queryJson.ToJObject();
  65. List<DbParameter> parameter = new List<DbParameter>();
  66. #region [SQL]
  67. string sql = @" select a.ID,a.MODetailID,a.Sequence,a.InvCode,b.InvName,b.InvDesc,b.InvUnit,b.InvStd,a.Quantity,a.IssueQuantity from dbo.ICSMOPick a
  68. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint";
  69. sql += " WHERE 1=1 and a.MODetailID='" + queryParam["MODetailID"].ToString() + "'";
  70. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  71. #endregion
  72. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  73. }
  74. public object GetLotNotInfo(string keyValue)
  75. {
  76. DataTable dt = new DataTable();
  77. string msg = "";
  78. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "AMBarCodeInformation/Get";
  79. string result = HttpPost(APIURL, keyValue);
  80. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  81. string MessAge = Obj["Message"].ToString();
  82. string Success = Obj["Success"].ToString();
  83. if (Success.ToUpper() == "FALSE")
  84. {
  85. msg = MessAge;
  86. }
  87. else
  88. {
  89. if (msg == "")
  90. {
  91. string Data = Obj["Data"].ToString();
  92. dt = JsonConvert.DeserializeObject<DataTable>(Data);
  93. // dt = dataSet.Tables[0];
  94. }
  95. }
  96. var Header = new
  97. {
  98. msg = msg,
  99. dt = dt,
  100. };
  101. return Header;
  102. }
  103. public string SaveSalesDelivery(string ICSASN)
  104. {
  105. string msg = "";
  106. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockDownAM/Create";
  107. string result = HttpPost(APIURL, ICSASN);
  108. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  109. string MessAge = Obj["Message"].ToString();
  110. string Success = Obj["Success"].ToString();
  111. if (Success.ToUpper() == "FALSE")
  112. {
  113. msg = MessAge;
  114. }
  115. return msg;
  116. }
  117. //接口api解析
  118. public static string HttpPost(string url, string body)
  119. {
  120. try
  121. {
  122. Encoding encoding = Encoding.UTF8;
  123. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  124. request.Method = "POST";
  125. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  126. request.ContentType = "application/json; charset=utf-8";
  127. byte[] buffer = encoding.GetBytes(body);
  128. request.ContentLength = buffer.Length;
  129. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  130. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  131. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  132. {
  133. return reader.ReadToEnd();
  134. }
  135. }
  136. catch (WebException ex)
  137. {
  138. throw new Exception(ex.Message);
  139. }
  140. }
  141. }
  142. }