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

365 lines
17 KiB

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