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

366 lines
17 KiB

3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 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 ID, CheckCode, SelectLevel, Status, Quantity, Amount, MUSER, MUSERName, MTIME, WorkPoint
  26. FROM
  27. dbo.ICSCheck";
  28. sql += " WHERE 1=1";
  29. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  30. #endregion
  31. if (!string.IsNullOrWhiteSpace(queryJson))
  32. {
  33. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  34. {
  35. sql += " and a.CheckCode like '%" + queryParam["POCode"].ToString() + "%' ";
  36. }
  37. }
  38. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  39. {
  40. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  41. }
  42. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  43. {
  44. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  45. }
  46. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  47. }
  48. public DataTable GetSubGridJson(string ID, string Sequence, ref Pagination jqgridparam)
  49. {
  50. DataTable dt = new DataTable();
  51. //var queryParam = queryJson.ToJObject();
  52. List<DbParameter> parameter = new List<DbParameter>();
  53. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  54. string sql = @" SELECT distinct a.ID, b.InvCode,
  55. b.InvName ,
  56. b.InvStd ,
  57. a.LotNo,
  58. a.Quantity,
  59. d.WarehouseCode,
  60. d.LocationCode,
  61. a.PrimaryQuantity,
  62. a.PrimaryAmount,
  63. a.ReplayQuantity,
  64. a.ReplayAmount,
  65. a.CheckQuantity,
  66. a.CheckAmount
  67. FROM ICSCheckDetail a
  68. left join ICSInventoryLot c on a.LotNo=c.LotNO and a.WorkPoint=c.WorkPoint
  69. left join ICSInventory b on c.InvCode=b.InvCode AND c.WorkPoint=b.WorkPoint
  70. left join ICSWareHouseLotInfo d on c.LotNO=d.LotNO AND c.WorkPoint=d.WorkPoint
  71. WHERE a.CheckID='" + ID + "' and a.WorkPoint in ('" + WorkPoint + "')";
  72. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  73. }
  74. public string DeleteICSCheckDetail(string ID)
  75. {
  76. //站点信息
  77. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  78. string msg = "";
  79. string sql = string.Empty;
  80. try
  81. {
  82. sql = string.Format(@"DELETE FROM ICSCheckDetail WHERE ID ='{0}' and WorkPoint ='{1}'", ID, WorkPoint);
  83. SqlHelper.ExecuteNonQuery(sql);
  84. }
  85. catch (Exception ex)
  86. {
  87. throw new Exception(ex.Message);
  88. }
  89. return msg;
  90. }
  91. /// <summary>
  92. /// 获取仓库
  93. /// </summary>
  94. /// <returns></returns>
  95. public DataTable GetWHCode()
  96. {
  97. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  98. string sql = @" select '' as ID,'' as WarehouseName union all
  99. SELECT ID+'|'+WarehouseCode,WarehouseName FROM ICSWarehouse WITH (NOLOCK) WHERE WorkPoint = '{0}' ";
  100. sql = string.Format(sql, WorkPoint);
  101. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  102. //if (role != "admin")
  103. //{
  104. // sql += " and b.WorkPoint='" + WorkPoint + "'";
  105. //}
  106. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  107. return dt;
  108. }
  109. public DataTable GetQU(string WHCodeID)
  110. {
  111. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  112. string sql = @" select '' as QUValue,'' as QUName union all
  113. SELECT Region as QUValue,Region+'区' as QUName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}'
  114. ";
  115. sql = string.Format(sql, WHCodeID, WorkPoint);
  116. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  117. return dt;
  118. }
  119. //public DataTable GetQU(string WHCodeID)
  120. //{
  121. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  122. // string sql = @"SELECT Region as QUValue,Region+'区' as QUName FROM ICSLocation WHERE WHID = '{0}' AND WorkPoint='{1}'";
  123. // sql = string.Format(sql, WHCodeID, WorkPoint);
  124. // DataTable dt = Repository().FindTableBySql(sql);
  125. // return dt;
  126. //}
  127. public DataTable GetPai(string WHCodeID, string Qu)
  128. {
  129. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  130. string sql = @" select '' as PaiValue,'' as PaiName union all
  131. SELECT Row as PaiValue,Row+'排' as PaiName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}'
  132. ";
  133. sql = string.Format(sql, WHCodeID, WorkPoint, Qu);
  134. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  135. return dt;
  136. }
  137. public DataTable GetHuoJia(string WHCodeID, string Qu, string Pai)
  138. {
  139. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  140. string sql = @" select '' as HuoJiaValue,'' as HuoJiaName union all
  141. SELECT GoodsShelf as HuoJiaValue,GoodsShelf +'' as HuoJiaName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}'
  142. ";
  143. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai);
  144. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  145. return dt;
  146. }
  147. public DataTable GetCeng(string WHCodeID, string Qu, string Pai, string HuoJia)
  148. {
  149. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  150. string sql = @" select '' as CengValue,'' as CengName union all
  151. 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}'
  152. ";
  153. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai, HuoJia);
  154. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  155. return dt;
  156. }
  157. public DataTable GetGe(string WHCodeID, string Qu, string Pai, string HuoJia, string Ceng)
  158. {
  159. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  160. string sql = @" select '' as GeValue,'' as GeName union all
  161. 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}'
  162. ";
  163. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai, HuoJia, Ceng);
  164. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  165. return dt;
  166. }
  167. public string AddICSCheck(string Parameter)
  168. {
  169. string msg = "";
  170. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/Create";
  171. string result = HttpPost(APIURL, Parameter);
  172. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  173. string MessAge = Obj["Message"].ToString();
  174. string Success = Obj["Success"].ToString();
  175. if (Success.ToUpper() == "FALSE")
  176. {
  177. msg = MessAge;
  178. }
  179. return msg;
  180. }
  181. //接口api解析
  182. public static string HttpPost(string url, string body)
  183. {
  184. try
  185. {
  186. Encoding encoding = Encoding.UTF8;
  187. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  188. request.Method = "POST";
  189. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  190. request.ContentType = "application/json; charset=utf-8";
  191. byte[] buffer = encoding.GetBytes(body);
  192. request.ContentLength = buffer.Length;
  193. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  194. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  195. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  196. {
  197. return reader.ReadToEnd();
  198. }
  199. }
  200. catch (WebException ex)
  201. {
  202. throw new Exception(ex.Message);
  203. }
  204. }
  205. public string DeleteICSCheck(string keyValue)
  206. {
  207. //站点信息
  208. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  209. string msg = "";
  210. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  211. string sql = string.Empty;
  212. try
  213. {
  214. sql += string.Format(@" IF EXISTS(SELECT CheckID FROM ICSCheckDetail WHERE CheckID in ({0}) )
  215. BEGIN
  216. RAISERROR(',',16,1);
  217. RETURN
  218. END
  219. DELETE FROM dbo.ICSCheck WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  220. sql += string.Format(@"DELETE FROM dbo.ICSCheckDetail WHERE CheckID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  221. SqlHelper.ExecuteNonQuery(sql);
  222. }
  223. catch (Exception ex)
  224. {
  225. msg = ex.Message;
  226. }
  227. return msg;
  228. }
  229. public DataTable GetGridJsonWarehouse(string queryJson, ref Pagination jqgridparam)
  230. {
  231. DataTable dt = new DataTable();
  232. var queryParam = queryJson.ToJObject();
  233. List<DbParameter> parameter = new List<DbParameter>();
  234. #region [SQL]
  235. string sql = @"select distinct ID, WarehouseCode as SelectLevel ,WarehouseCode,WarehouseName from ICSWarehouse";
  236. sql += " WHERE 1=1";
  237. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  238. #endregion
  239. if (!string.IsNullOrWhiteSpace(queryJson))
  240. {
  241. if (!string.IsNullOrWhiteSpace(queryParam["WarehouseCode"].ToString()))
  242. {
  243. sql += " and WarehouseCode like '%" + queryParam["WarehouseCode"].ToString() + "%' ";
  244. }
  245. }
  246. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  247. {
  248. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  249. }
  250. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  251. {
  252. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  253. }
  254. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  255. }
  256. public DataTable GetSubGridJsonRegion(string ID, ref Pagination jqgridparam)
  257. {
  258. DataTable dt = new DataTable();
  259. //var queryParam = queryJson.ToJObject();
  260. List<DbParameter> parameter = new List<DbParameter>();
  261. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  262. string sql = @" select distinct b.WarehouseCode+'-'+a.Region as SelectLevel, a.WHID, b.WarehouseCode,a.Region from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
  263. WHERE a.WHID='" + ID + "' and a.WorkPoint in ('" + WorkPoint + "')";
  264. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  265. }
  266. public DataTable GetSubGridJsonRow(string WHID, string Region, ref Pagination jqgridparam)
  267. {
  268. DataTable dt = new DataTable();
  269. //var queryParam = queryJson.ToJObject();
  270. List<DbParameter> parameter = new List<DbParameter>();
  271. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  272. string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row
  273. from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
  274. WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and isnull(a.Row,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
  275. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  276. }
  277. public DataTable GetSubGridJsonGoodsShelf(string WHID, string Region, string Row, ref Pagination jqgridparam)
  278. {
  279. DataTable dt = new DataTable();
  280. //var queryParam = queryJson.ToJObject();
  281. List<DbParameter> parameter = new List<DbParameter>();
  282. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  283. string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'')+'-'+isnull(a.GoodsShelf,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row,a.GoodsShelf
  284. from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
  285. WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and a.Row='" + Row + "' and isnull(a.GoodsShelf,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
  286. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  287. }
  288. public DataTable GetSubGridJsonTier(string WHID, string Region, string Row, string GoodsShelf, ref Pagination jqgridparam)
  289. {
  290. DataTable dt = new DataTable();
  291. //var queryParam = queryJson.ToJObject();
  292. List<DbParameter> parameter = new List<DbParameter>();
  293. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  294. string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'')+'-'+isnull(a.GoodsShelf,'') +'-'+isnull(a.Tier,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row,a.GoodsShelf ,a.Tier
  295. from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
  296. WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and a.Row='" + Row + "' and a.GoodsShelf='" + GoodsShelf + "' and isnull(a.Tier,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
  297. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  298. }
  299. public DataTable GetSubGridJsonGrid(string WHID, string Region, string Row, string GoodsShelf, string Tier, ref Pagination jqgridparam)
  300. {
  301. DataTable dt = new DataTable();
  302. //var queryParam = queryJson.ToJObject();
  303. List<DbParameter> parameter = new List<DbParameter>();
  304. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  305. string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'')+'-'+isnull(a.GoodsShelf,'') +'-'+isnull(a.Tier,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row ,a.GoodsShelf ,a.Tier,a.Grid
  306. from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
  307. WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and a.Row='" + Row + "' and a.Tier='" + Tier + "' and a.GoodsShelf='" + GoodsShelf + "' and isnull(a.Grid,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
  308. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  309. }
  310. }
  311. }