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

195 lines
7.4 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 System.Net;
  18. using System.IO;
  19. using Newtonsoft.Json.Linq;
  20. namespace NFine.Application.WMS
  21. {
  22. public class BlitemApp : RepositoryFactory<ICSVendor>
  23. {
  24. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  25. {
  26. DataTable dt = new DataTable();
  27. var queryParam = queryJson.ToJObject();
  28. List<DbParameter> parameter = new List<DbParameter>();
  29. #region [SQL]
  30. string sql = @"select DISTINCT
  31. a.ID,
  32. a.CheckCode,
  33. a.MTIME,
  34. a.InvCode,
  35. b.InvName,
  36. b.InvStd ,
  37. b.InvDesc,
  38. d.ContainerID,
  39. a.Quantity,
  40. a.ActualQuantity,
  41. a.MuserName,
  42. a.WHCode
  43. from ICSCheck a with (nolock)
  44. LEFT JOIN ICSCheckDetail c with (nolock) ON a.CheckCode=c.CheckCode AND a.WorkPoint=c.WorkPoint
  45. LEFT JOIN ICSContainerLot d with (nolock) ON c.LotNo=d.LotNo AND c.WorkPoint =d.WorkPoint
  46. left join ICSInventory b with (nolock) on a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint";
  47. sql += " WHERE 1=1";
  48. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  49. #endregion
  50. if (!string.IsNullOrWhiteSpace(queryJson))
  51. {
  52. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  53. {
  54. sql += " and a.CheckCode like '%" + queryParam["POCode"].ToString() + "%' ";
  55. }
  56. }
  57. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  58. {
  59. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  60. }
  61. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  62. {
  63. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  64. }
  65. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  66. }
  67. public DataTable GetSubGridJson(string CheckCode, string Sequence, ref Pagination jqgridparam)
  68. {
  69. DataTable dt = new DataTable();
  70. //var queryParam = queryJson.ToJObject();
  71. List<DbParameter> parameter = new List<DbParameter>();
  72. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  73. string sql = @" SELECT distinct a.ID, b.InvCode,
  74. b.InvName ,
  75. b.InvStd ,
  76. a.LotNo,
  77. a.Quantity,
  78. a.ActualQuantity,
  79. d.WarehouseCode,
  80. d.LocationCode
  81. FROM ICSCheckDetail a
  82. left join ICSInventoryLot c on a.LotNo=c.LotNO
  83. left join ICSInventory b on c.InvCode=b.InvCode
  84. left join ICSWareHouseLotInfo d on c.LotNO=d.LotNO
  85. WHERE a.CheckCode='" + CheckCode + "' and a.WorkPoint in (" + WorkPoint + ")";
  86. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  87. }
  88. public string DeleteICSCheckDetail(string ID)
  89. {
  90. //站点信息
  91. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  92. string msg = "";
  93. string sql = string.Empty;
  94. try
  95. {
  96. sql = string.Format(@"DELETE FROM ICSCheckDetail WHERE ID ='{0}' and WorkPoint ='{1}'", ID, WorkPoint);
  97. SqlHelper.ExecuteNonQuery(sql);
  98. }
  99. catch (Exception ex)
  100. {
  101. throw new Exception(ex.Message);
  102. }
  103. return msg;
  104. }
  105. /// <summary>
  106. /// 获取仓库
  107. /// </summary>
  108. /// <returns></returns>
  109. public DataTable GetWHCode()
  110. {
  111. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  112. string sql = @" select '' as WarehouseCode,'' as WarehouseName union all
  113. SELECT WarehouseCode,WarehouseName FROM ICSWarehouse WITH (NOLOCK) WHERE WorkPoint = {0} ";
  114. sql = string.Format(sql, WorkPoint);
  115. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  116. //if (role != "admin")
  117. //{
  118. // sql += " and b.WorkPoint='" + WorkPoint + "'";
  119. //}
  120. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  121. return dt;
  122. }
  123. public string AddICSCheck(string Parameter)
  124. {
  125. string msg = "";
  126. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/Create";
  127. string result = HttpPost(APIURL, Parameter);
  128. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  129. string MessAge = Obj["Message"].ToString();
  130. string Success = Obj["Success"].ToString();
  131. if (Success.ToUpper() == "FALSE")
  132. {
  133. msg = MessAge;
  134. }
  135. return msg;
  136. }
  137. //接口api解析
  138. public static string HttpPost(string url, string body)
  139. {
  140. try
  141. {
  142. Encoding encoding = Encoding.UTF8;
  143. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  144. request.Method = "POST";
  145. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  146. request.ContentType = "application/json; charset=utf-8";
  147. byte[] buffer = encoding.GetBytes(body);
  148. request.ContentLength = buffer.Length;
  149. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  150. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  151. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  152. {
  153. return reader.ReadToEnd();
  154. }
  155. }
  156. catch (WebException ex)
  157. {
  158. throw new Exception(ex.Message);
  159. }
  160. }
  161. public string DeleteICSCheck(string keyValue)
  162. {
  163. //站点信息
  164. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  165. string msg = "";
  166. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  167. string sql = string.Empty;
  168. try
  169. {
  170. sql += string.Format(@"DELETE FROM dbo.ICSCheck WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  171. sql += string.Format(@"DELETE FROM dbo.ICSCheckDetail WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  172. SqlHelper.ExecuteNonQuery(sql);
  173. }
  174. catch (Exception ex)
  175. {
  176. throw new Exception(ex.Message);
  177. }
  178. return msg;
  179. }
  180. }
  181. }