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.

323 lines
15 KiB

3 weeks ago
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using NFine.Domain._03_Entity.SRM;
  6. using NFine.Repository;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Data.Common;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace NFine.Application.WMS
  18. {
  19. public class ICSDeliveryNoticeApp : RepositoryFactory<ICSVendor>
  20. {
  21. public static DataTable Invmes = new DataTable();
  22. /// <summary>
  23. /// 采购到货查询
  24. /// </summary>
  25. /// <param name="jqgridparam"></param>
  26. /// <returns></returns>
  27. public DataTable GetDeliveryNoticeApplyNeg(ref Pagination jqgridparam)
  28. {
  29. DataTable dt = new DataTable();
  30. List<DbParameter> parameter = new List<DbParameter>();
  31. string sql = @"select a.ID,a.DNCode,a.Sequence,a.VenCode,a.DepCode,a.WHCode,a.DNType,a.InvCode,a.Quantity
  32. ,a.Amount,a.RCVQuantity,a.UnitPrice,a.Currency,a.Status,a.CreatePerson,a.CreateDateTime,a.POID,a.PODetailID,a.DNID,a.DNDetailID,
  33. a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,a.EATTRIBUTE1,a.ASNCode,b.InvName
  34. ,f.Colspan ,f.ProjectCode ,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4
  35. ,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10 ,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  36. a.EATTRIBUTE9,a.EATTRIBUTE10
  37. from ICSDeliveryNotice a
  38. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  39. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  40. where isnull(a.POID,'0') != '0'";
  41. sql = string.Format(sql);
  42. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  43. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  44. }
  45. /// <summary>
  46. /// 删除
  47. /// </summary>
  48. /// <param name="keyValue">传入ID</param>
  49. /// <returns></returns>
  50. public string DeleteICSDeliveryNotice(string keyValue)
  51. {
  52. //删除前校验
  53. //站点信息
  54. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  55. string msg = "";
  56. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  57. string sql = string.Empty;
  58. sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'"
  59. , keyValue.TrimEnd(','), WorkPoint);
  60. try
  61. {
  62. SqlHelper.ExecuteNonQuery(sql);
  63. }
  64. catch (Exception ex)
  65. {
  66. throw new Exception(ex.Message);
  67. }
  68. return msg;
  69. }
  70. /// <summary>
  71. /// 无源头采购到货查询
  72. /// </summary>
  73. /// <param name="jqgridparam"></param>
  74. /// <returns></returns>
  75. public DataTable GetEDeliveryNoticeApplyNeg(ref Pagination jqgridparam)
  76. {
  77. DataTable dt = new DataTable();
  78. List<DbParameter> parameter = new List<DbParameter>();
  79. string sql = @"select a.ID,a.DNCode,a.Sequence,a.VenCode,a.DepCode,a.WHCode,a.DNType,a.InvCode,a.Quantity,c.VenName,e.DepName,g.WarehouseName as WHName
  80. ,a.Amount,a.RCVQuantity,a.UnitPrice,a.Currency,a.Status,a.CreatePerson,a.CreateDateTime,a.POID,a.PODetailID,a.DNID,a.DNDetailID,
  81. a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,a.EATTRIBUTE1,a.ASNCode,b.InvName
  82. ,f.Colspan ,f.ProjectCode ,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4
  83. ,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  84. a.EATTRIBUTE9,a.EATTRIBUTE10
  85. from ICSDeliveryNotice a
  86. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  87. left join ICSVendor c on c.VenCode=a.VenCode and c.WorkPoint=a.WorkPoint
  88. left join ICSDepartment e on e.DepCode=a.DepCode and e.WorkPoint=a.WorkPoint
  89. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  90. left join ICSWarehouse g on a.WHCode = g.WarehouseCode and a.WorkPoint=g.WorkPoint
  91. where isnull(a.POID,'0') = '0'";
  92. sql = string.Format(sql);
  93. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  94. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  95. }
  96. /// <summary>
  97. /// 采购删除
  98. /// </summary>
  99. /// <param name="keyValue"></param>
  100. /// <returns></returns>
  101. /// <exception cref="Exception"></exception>
  102. public string DeleteDeliveryNoticeApplyNeg(string keyValue)
  103. {
  104. //站点信息
  105. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  106. string msg = "";
  107. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  108. string sql = string.Empty;
  109. sql += string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE Id IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  110. //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  111. try
  112. {
  113. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  114. {
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. throw new Exception(ex.Message);
  120. }
  121. return msg;
  122. }
  123. /// <summary>
  124. /// 获取部门
  125. /// </summary>
  126. /// <param name="InvCode"></param>
  127. /// <returns></returns>
  128. public DataTable GetSelectICSVenCode()
  129. {
  130. string sql = string.Empty;
  131. DataTable dt = null;
  132. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  133. sql = @"
  134. select a.VenCode,a.VenName from dbo.ICSVendor a";
  135. sql = string.Format(sql, WorkPoint);
  136. dt = SqlHelper.GetDataTableBySql(sql);
  137. return dt;
  138. }
  139. /// <summary>
  140. /// 选择表格—采购订单行选择
  141. /// </summary>
  142. /// <param name="ID"></param>
  143. /// <param name="jqgridparam"></param>
  144. /// <returns></returns>
  145. public DataTable GetPurOrder(string POCode, ref Pagination jqgridparam)
  146. {
  147. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  148. List<DbParameter> parameter = new List<DbParameter>();
  149. DataTable table = new DataTable();
  150. string wherestr = "";
  151. if (!string.IsNullOrEmpty(POCode))
  152. {
  153. wherestr += " and a.POCode like '%" + POCode + "%'";
  154. }
  155. string sql = @"select a.ID,a.POCode,a.Sequence,a.InvCode,a.Quantity,a.Amount,a.InQuantity,a.ExtensionID,a.MUSER
  156. ,a.MUSERName,a.MTIME,b.InvName
  157. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  158. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  159. from ICSPurchaseOrder a
  160. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  161. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  162. where a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  163. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  164. }
  165. public void ClearTemp()
  166. {
  167. Invmes.Rows.Clear();
  168. }
  169. public DataTable GetICSDeliveryNoticeReturnTemporary(string ID)
  170. {
  171. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  172. string wherestr = "";
  173. //if (!string.IsNullOrEmpty(ID))
  174. //{
  175. // wherestr += "and a.DNCode = " + DNCode + " and a.Sequence = " + Sequence;
  176. //}
  177. string sql = @"select a.ID,a.DNCode,a.Sequence,a.VenCode,a.DepCode,a.WHCode,a.DNType,a.InvCode,a.Quantity,c.WarehouseCode,c.WarehouseName
  178. ,a.Amount,a.RCVQuantity,a.UnitPrice,a.Currency,a.Status,a.CreatePerson,a.CreateDateTime,a.POID,a.PODetailID,a.DNID,a.DNDetailID,
  179. a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,a.ASNCode,b.InvName
  180. ,f.Colspan ,f.ProjectCode ,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4
  181. ,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10 ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  182. a.EATTRIBUTE9,a.EATTRIBUTE10
  183. from ICSDeliveryNotice a
  184. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  185. left join ICSWarehouse c on a.WHCode = c.WarehouseCode and a.WorkPoint=c.WorkPoint
  186. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  187. where a.ID in (" + ID + ") ";
  188. // where a.WorkPoint = '" + WorkPoint + "' " + wherestr;
  189. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  190. DataTable dtCloned = table.Clone();
  191. foreach (DataColumn col in dtCloned.Columns)
  192. {
  193. col.DataType = typeof(string);
  194. }
  195. foreach (DataRow row in table.Rows)
  196. {
  197. DataRow newrow = dtCloned.NewRow();
  198. foreach (DataColumn column in dtCloned.Columns)
  199. {
  200. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  201. }
  202. dtCloned.Rows.Add(newrow);
  203. }
  204. if (Invmes.Rows.Count > 0)
  205. {
  206. dtCloned.Merge(Invmes, false);
  207. }
  208. return dtCloned;
  209. }
  210. /// <summary>
  211. /// 新增
  212. /// </summary>
  213. /// <param name="ICSASN"></param>
  214. /// <returns></returns>
  215. public string SaveICSDeliveryNoticeAppApplyNeg(string ICSASN)
  216. {
  217. string msg = "";
  218. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "EDeliveryNotice/Create";
  219. string result = HttpPost(APIURL, ICSASN);
  220. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  221. string MessAge = Obj["Message"].ToString();
  222. string Success = Obj["Success"].ToString();
  223. if (Success.ToUpper() == "FALSE")
  224. {
  225. msg = MessAge;
  226. }
  227. return msg;
  228. }
  229. /// <summary>
  230. /// 修改
  231. /// </summary>
  232. /// <param name="ICSASN"></param>
  233. /// <returns></returns>
  234. public string UpdateICSDeliveryNoticeApplyNeg(string ICSASN)
  235. {
  236. string msg = "";
  237. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "EDeliveryNotice/Update";
  238. string result = HttpPost(APIURL, ICSASN);
  239. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  240. string MessAge = Obj["Message"].ToString();
  241. string Success = Obj["Success"].ToString();
  242. if (Success.ToUpper() == "FALSE")
  243. {
  244. msg = MessAge;
  245. }
  246. return msg;
  247. }
  248. /// <summary>
  249. /// 获取单号
  250. /// </summary>
  251. /// <param name="WorkPoint"></param>
  252. /// <returns></returns>
  253. public string GetDNCode(string WorkPoint)
  254. {
  255. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  256. string DNCode = string.Empty;
  257. if (!string.IsNullOrEmpty(WorkPoint))
  258. {
  259. DNCode = GetSerialCode(WorkPoint, "ICSDeliveryNotice", "DNCode", "", 9);
  260. }
  261. if (!string.IsNullOrWhiteSpace(DNCode))
  262. {
  263. string sqlISHave = @"SELECT ApplyCode FROM ICSMOApply a
  264. WHERE a.ApplyCode = '{0}'";
  265. sqlISHave = string.Format(sqlISHave, DNCode);
  266. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  267. if (dtIsHave.Rows.Count > 0)
  268. {
  269. throw new Exception("单号已存在!");
  270. }
  271. }
  272. return DNCode;
  273. }
  274. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  275. {
  276. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  277. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  278. return SqlHelper.ExecuteScalar(sql).ToString();
  279. }
  280. /// <summary>
  281. /// 接口api解析
  282. /// </summary>
  283. /// <param name="url"></param>
  284. /// <param name="body"></param>
  285. /// <returns></returns>
  286. /// <exception cref="Exception"></exception>
  287. public static string HttpPost(string url, string body)
  288. {
  289. try
  290. {
  291. Encoding encoding = Encoding.UTF8;
  292. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  293. request.Method = "POST";
  294. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  295. request.ContentType = "application/json; charset=utf-8";
  296. byte[] buffer = encoding.GetBytes(body);
  297. request.ContentLength = buffer.Length;
  298. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  299. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  300. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  301. {
  302. return reader.ReadToEnd();
  303. }
  304. }
  305. catch (WebException ex)
  306. {
  307. throw new Exception(ex.Message);
  308. }
  309. }
  310. }
  311. }