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

244 lines
9.9 KiB

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
  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 CheckCode, 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.CheckCode='" + CheckCode + "' 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 GetPai(string WHCodeID, string Qu)
  120. {
  121. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  122. string sql = @" select '' as PaiValue,'' as PaiName union all
  123. SELECT Row as PaiValue,Row+'排' as PaiName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}'
  124. ";
  125. sql = string.Format(sql, WHCodeID, WorkPoint, Qu);
  126. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  127. return dt;
  128. }
  129. public DataTable GetHuoJia(string WHCodeID, string Qu,string Pai)
  130. {
  131. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  132. string sql = @" select '' as HuoJiaValue,'' as HuoJiaName union all
  133. SELECT GoodsShelf as HuoJiaValue,GoodsShelf +'' as HuoJiaName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}'
  134. ";
  135. sql = string.Format(sql, WHCodeID, WorkPoint, Qu,Pai);
  136. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  137. return dt;
  138. }
  139. public DataTable GetCeng(string WHCodeID, string Qu, string Pai,string HuoJia)
  140. {
  141. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  142. string sql = @" select '' as CengValue,'' as CengName union all
  143. 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}'
  144. ";
  145. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai,HuoJia);
  146. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  147. return dt;
  148. }
  149. public DataTable GetGe(string WHCodeID, string Qu, string Pai, string HuoJia,string Ceng)
  150. {
  151. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  152. string sql = @" select '' as GeValue,'' as GeName union all
  153. 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}'
  154. ";
  155. sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai, HuoJia,Ceng);
  156. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  157. return dt;
  158. }
  159. public string AddICSCheck(string Parameter)
  160. {
  161. string msg = "";
  162. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/Create";
  163. string result = HttpPost(APIURL, Parameter);
  164. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  165. string MessAge = Obj["Message"].ToString();
  166. string Success = Obj["Success"].ToString();
  167. if (Success.ToUpper() == "FALSE")
  168. {
  169. msg = MessAge;
  170. }
  171. return msg;
  172. }
  173. //接口api解析
  174. public static string HttpPost(string url, string body)
  175. {
  176. try
  177. {
  178. Encoding encoding = Encoding.UTF8;
  179. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  180. request.Method = "POST";
  181. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  182. request.ContentType = "application/json; charset=utf-8";
  183. byte[] buffer = encoding.GetBytes(body);
  184. request.ContentLength = buffer.Length;
  185. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  186. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  187. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  188. {
  189. return reader.ReadToEnd();
  190. }
  191. }
  192. catch (WebException ex)
  193. {
  194. throw new Exception(ex.Message);
  195. }
  196. }
  197. public string DeleteICSCheck(string keyValue)
  198. {
  199. //站点信息
  200. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  201. string msg = "";
  202. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  203. string sql = string.Empty;
  204. try
  205. {
  206. sql += string.Format(@"DELETE FROM dbo.ICSCheck WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  207. sql += string.Format(@"DELETE FROM dbo.ICSCheckDetail WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  208. SqlHelper.ExecuteNonQuery(sql);
  209. }
  210. catch (Exception ex)
  211. {
  212. throw new Exception(ex.Message);
  213. }
  214. return msg;
  215. }
  216. }
  217. }