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.

210 lines
6.4 KiB

  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,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. sql += " WHERE 1=1 and a.SDNCode='" + queryParam["Code"].ToString() + "'";
  52. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  53. //{
  54. // sql += " and c.DepName='" + User + "'";
  55. //}
  56. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  57. #endregion
  58. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  59. }
  60. public DataTable GetMoPicksByCode(string queryJson, ref Pagination jqgridparam)
  61. {
  62. DataTable dt = new DataTable();
  63. var queryParam = queryJson.ToJObject();
  64. List<DbParameter> parameter = new List<DbParameter>();
  65. #region [SQL]
  66. 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
  67. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint";
  68. sql += " WHERE 1=1 and a.MODetailID='" + queryParam["MODetailID"].ToString() + "'";
  69. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  70. #endregion
  71. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  72. }
  73. public object GetLotNotInfo(string keyValue)
  74. {
  75. DataTable dt = new DataTable();
  76. string msg = "";
  77. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "AMBarCodeInformation/Get";
  78. string result = HttpPost(APIURL, keyValue);
  79. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  80. string MessAge = Obj["Message"].ToString();
  81. string Success = Obj["Success"].ToString();
  82. if (Success.ToUpper() == "FALSE")
  83. {
  84. msg = MessAge;
  85. }
  86. else
  87. {
  88. if (msg == "")
  89. {
  90. string Data = Obj["Data"].ToString();
  91. dt = JsonConvert.DeserializeObject<DataTable>(Data);
  92. // dt = dataSet.Tables[0];
  93. }
  94. }
  95. var Header = new
  96. {
  97. msg = msg,
  98. dt = dt,
  99. };
  100. return Header;
  101. }
  102. public string SaveSalesDelivery(string ICSASN)
  103. {
  104. string msg = "";
  105. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockDown/Create";
  106. string result = HttpPost(APIURL, ICSASN);
  107. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  108. string MessAge = Obj["Message"].ToString();
  109. string Success = Obj["Success"].ToString();
  110. if (Success.ToUpper() == "FALSE")
  111. {
  112. msg = MessAge;
  113. }
  114. return msg;
  115. }
  116. //接口api解析
  117. public static string HttpPost(string url, string body)
  118. {
  119. try
  120. {
  121. Encoding encoding = Encoding.UTF8;
  122. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  123. request.Method = "POST";
  124. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  125. request.ContentType = "application/json; charset=utf-8";
  126. byte[] buffer = encoding.GetBytes(body);
  127. request.ContentLength = buffer.Length;
  128. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  129. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  130. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  131. {
  132. return reader.ReadToEnd();
  133. }
  134. }
  135. catch (WebException ex)
  136. {
  137. throw new Exception(ex.Message);
  138. }
  139. }
  140. }
  141. }