爱思开
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.

245 lines
10 KiB

2 years 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.WMS
  16. {
  17. public class BlitemApp : RepositoryFactory<ICSVendor>
  18. {
  19. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  20. {
  21. DataTable dt = new DataTable();
  22. var queryParam = queryJson.ToJObject();
  23. List<DbParameter> parameter = new List<DbParameter>();
  24. #region [SQL]
  25. string sql = @"SELECT isnull(c.SumQty,0) as SumQty ,a.Quantity,a.ID, a.CheckCode, a.SelectLevel,a.InvCode,b.InvName,a.Batchcode,a.Status, a.Amount, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint
  26. from dbo.ICSCheck a
  27. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  28. left join (select a.CheckCode,a.BatchCode,b.InvCode,sum(a.Quantity) as SumQty from dbo.ICSCheckDetail a left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo group by a.CheckCode,a.BatchCode,b.InvCode) c on a.CheckCode=c.CheckCode and a.InvCode=c.InvCode and c.BatchCode = a.BatchCode";
  29. sql += " WHERE 1=1";
  30. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  31. #endregion
  32. if (!string.IsNullOrWhiteSpace(queryJson))
  33. {
  34. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  35. {
  36. sql += " and a.CheckCode like '%" + queryParam["POCode"].ToString() + "%' ";
  37. }
  38. }
  39. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  40. {
  41. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  42. }
  43. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  44. {
  45. sql += " and VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  46. }
  47. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  48. }
  49. public DataTable GetSubGridJson(string CheckCode, string InvCode,string BatchCode ,ref Pagination jqgridparam)
  50. {
  51. DataTable dt = new DataTable();
  52. //var queryParam = queryJson.ToJObject();
  53. List<DbParameter> parameter = new List<DbParameter>();
  54. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  55. string sql = @" SELECT distinct a.ID, b.InvCode,
  56. b.InvName ,
  57. b.InvStd ,
  58. a.LotNo,
  59. a.Quantity,
  60. d.WarehouseCode,
  61. d.LocationCode,
  62. a.PrimaryQuantity,
  63. a.PrimaryAmount,
  64. a.ReplayQuantity,
  65. a.ReplayAmount,
  66. a.CheckQuantity,
  67. a.CheckAmount
  68. FROM ICSCheckDetail a
  69. left join ICSInventoryLot c on a.LotNo=c.LotNO and a.WorkPoint=c.WorkPoint
  70. left join ICSInventory b on c.InvCode=b.InvCode AND c.WorkPoint=b.WorkPoint
  71. left join ICSWareHouseLotInfo d on c.LotNO=d.LotNO AND c.WorkPoint=d.WorkPoint
  72. WHERE a.CheckCode='" + CheckCode + "'and b.InvCode='"+ InvCode + "' and isnull(a.BatchCode,'')='" + BatchCode + "' and a.WorkPoint in ('" + WorkPoint + "')";
  73. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  74. }
  75. public string DeleteICSCheckDetail(string ID)
  76. {
  77. //站点信息
  78. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  79. string msg = "";
  80. string sql = string.Empty;
  81. try
  82. {
  83. sql = string.Format(@"DELETE FROM ICSCheckDetail WHERE ID ='{0}' and WorkPoint ='{1}'", ID, WorkPoint);
  84. SqlHelper.ExecuteNonQuery(sql);
  85. }
  86. catch (Exception ex)
  87. {
  88. throw new Exception(ex.Message);
  89. }
  90. return msg;
  91. }
  92. /// <summary>
  93. /// 获取仓库
  94. /// </summary>
  95. /// <returns></returns>
  96. public DataTable GetWHCode()
  97. {
  98. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  99. string sql = @" select '' as ID,'' as WarehouseName union all
  100. SELECT ID+'|'+WarehouseCode,WarehouseName FROM ICSWarehouse WITH (NOLOCK) WHERE WorkPoint = '{0}' ";
  101. sql = string.Format(sql, WorkPoint);
  102. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  103. //if (role != "admin")
  104. //{
  105. // sql += " and b.WorkPoint='" + WorkPoint + "'";
  106. //}
  107. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  108. return dt;
  109. }
  110. public DataTable GetQU(string WHCodeID)
  111. {
  112. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  113. string sql = @" select '' as QUValue,'' as QUName union all
  114. SELECT Region as QUValue,Region+'区' as QUName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}'
  115. ";
  116. sql = string.Format(sql, WHCodeID, WorkPoint);
  117. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  118. return dt;
  119. }
  120. public DataTable GetPai(string WHCodeID, string Qu)
  121. {
  122. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  123. string sql = @" select '' as PaiValue,'' as PaiName union all
  124. SELECT Row as PaiValue,Row+'排' as PaiName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}'
  125. ";
  126. sql = string.Format(sql, WHCodeID, WorkPoint, Qu);
  127. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  128. return dt;
  129. }
  130. public DataTable GetHuoJia(string WHCodeID, string Qu,string Pai)
  131. {
  132. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  133. string sql = @" select '' as HuoJiaValue,'' as HuoJiaName union all
  134. SELECT GoodsShelf as HuoJiaValue,GoodsShelf +'' as HuoJiaName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}'
  135. ";
  136. sql = string.Format(sql, WHCodeID, WorkPoint, Qu,Pai);
  137. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  138. return dt;
  139. }
  140. public DataTable GetCeng(string WHCodeID, string Qu, string Pai,string HuoJia)
  141. {
  142. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  143. string sql = @" select '' as CengValue,'' as CengName union all
  144. SELECT Tier as CengValue,Tier +'层' as CengName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}' and GoodsShelf ='{4}'
  145. ";
  146. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai,HuoJia);
  147. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  148. return dt;
  149. }
  150. public DataTable GetGe(string WHCodeID, string Qu, string Pai, string HuoJia,string Ceng)
  151. {
  152. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  153. string sql = @" select '' as GeValue,'' as GeName union all
  154. SELECT Grid as GeValue,Grid +'格' as GeName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}' and GoodsShelf ='{4}' and Tier='{5}'
  155. ";
  156. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai, HuoJia,Ceng);
  157. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  158. return dt;
  159. }
  160. public string AddICSCheck(string Parameter)
  161. {
  162. string msg = "";
  163. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/Create";
  164. string result = HttpPost(APIURL, Parameter);
  165. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  166. string MessAge = Obj["Message"].ToString();
  167. string Success = Obj["Success"].ToString();
  168. if (Success.ToUpper() == "FALSE")
  169. {
  170. msg = MessAge;
  171. }
  172. return msg;
  173. }
  174. //接口api解析
  175. public static string HttpPost(string url, string body)
  176. {
  177. try
  178. {
  179. Encoding encoding = Encoding.UTF8;
  180. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  181. request.Method = "POST";
  182. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  183. request.ContentType = "application/json; charset=utf-8";
  184. byte[] buffer = encoding.GetBytes(body);
  185. request.ContentLength = buffer.Length;
  186. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  187. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  188. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  189. {
  190. return reader.ReadToEnd();
  191. }
  192. }
  193. catch (WebException ex)
  194. {
  195. throw new Exception(ex.Message);
  196. }
  197. }
  198. public string DeleteICSCheck(string keyValue)
  199. {
  200. //站点信息
  201. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  202. string msg = "";
  203. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  204. string sql = string.Empty;
  205. try
  206. {
  207. sql += string.Format(@"DELETE FROM dbo.ICSCheck WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  208. sql += string.Format(@"DELETE FROM dbo.ICSCheckDetail WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  209. SqlHelper.ExecuteNonQuery(sql);
  210. }
  211. catch (Exception ex)
  212. {
  213. throw new Exception(ex.Message);
  214. }
  215. return msg;
  216. }
  217. }
  218. }