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.

217 lines
8.8 KiB

3 weeks ago
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using NFine.Data.Extensions;
  4. using NFine.Domain._03_Entity.SRM;
  5. using NFine.Repository;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.IO;
  14. using System.Net;
  15. using NFine.Code;
  16. using System.Data.Common;
  17. namespace NFine.Application.WMS
  18. {
  19. public class ICSOOPickApp : 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 GetOOPickApplyNeg(ref Pagination jqgridparam)
  28. {
  29. DataTable dt = new DataTable();
  30. List<DbParameter> parameter = new List<DbParameter>();
  31. string sql = @"select a.ID
  32. ,a.OODetailID
  33. ,b.OOCode
  34. ,a.PickID
  35. ,a.ParentPickID
  36. ,a.ParentQuantity
  37. ,a.ParentAmount
  38. ,a.Sequence
  39. ,a.InvCode
  40. ,a.Quantity
  41. ,a.Amount
  42. ,a.IssueQuantity
  43. ,a.WHCode
  44. ,a.SupplyType
  45. ,a.ExtensionID
  46. ,a.MUSER
  47. ,a.MUSERName
  48. ,a.MTIME
  49. ,a.WorkPoint from ICSOOPick a
  50. left join ICSOutsourcingOrder b on a.OODetailID = b.ID";
  51. sql = string.Format(sql);
  52. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  53. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  54. }
  55. /// <summary>
  56. /// 委外备料删除
  57. /// </summary>
  58. /// <param name="keyValue"></param>
  59. /// <returns></returns>
  60. /// <exception cref="Exception"></exception>
  61. public string DeleteOOPickApplyNeg(string keyValue)
  62. {
  63. //站点信息
  64. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  65. string msg = "";
  66. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  67. string sql = string.Empty;
  68. sql += string.Format(@"DELETE FROM dbo.ICSOOPick WHERE Id IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  69. //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  70. try
  71. {
  72. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  73. {
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. throw new Exception(ex.Message);
  79. }
  80. return msg;
  81. }
  82. /// <summary>
  83. /// 选择表格—委外订单行选择
  84. /// </summary>
  85. /// <param name="ID"></param>
  86. /// <param name="jqgridparam"></param>
  87. /// <returns></returns>
  88. public DataTable GetINV(string OOCode, ref Pagination jqgridparam)
  89. {
  90. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  91. List<DbParameter> parameter = new List<DbParameter>();
  92. DataTable table = new DataTable();
  93. string wherestr = "";
  94. if (!string.IsNullOrEmpty(OOCode))
  95. {
  96. wherestr += " and a.OOCode like '%" + OOCode + "%'";
  97. }
  98. string sql = @"select a.ID,a.OOCode,a.Sequence,a.InvCode,a.Quantity,b.InvName,a.Status,a.InQuantity,e.VenName,g.DepName,isnull(p.Quantity,0) as PickQuantity,a.UnitPrice,a.Currency
  99. from ICSOutsourcingOrder a
  100. join ICSInventory b on a.InvCode = b.InvCode
  101. left join ICSVendor e on a.VenCode = e.VenCode and a.WorkPoint = e.WorkPoint
  102. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  103. left join ICSDepartment g on a.DepCode = g.DepCode and a.WorkPoint = g.WorkPoint
  104. left join ICSOOPick p on a.OOCode = p.OODetailID and a.WorkPoint = p.WorkPoint
  105. where a.Status != 3 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  106. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  107. }
  108. public void ClearTemp()
  109. {
  110. Invmes.Rows.Clear();
  111. }
  112. public DataTable GetICSOOPickReturnTemporary(string ID)
  113. {
  114. string sql = @"select a.ID,a.OODetailID as OOID,a.Sequence,a.InvCode,a.Quantity,a.WHCode,a.MUSERName,a.MTIME,b.OOCode
  115. ,b.Quantity as OOQuantity,b.Sequence as OOSequence,c.InvName
  116. from ICSOOPick a
  117. join ICSOutsourcingOrder b on a.OODetailID = b.ID
  118. join ICSInventory c on a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint
  119. where a.ID in (" + ID + ") ";
  120. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  121. DataTable dtCloned = table.Clone();
  122. foreach (DataColumn col in dtCloned.Columns)
  123. {
  124. col.DataType = typeof(string);
  125. }
  126. foreach (DataRow row in table.Rows)
  127. {
  128. DataRow newrow = dtCloned.NewRow();
  129. foreach (DataColumn column in dtCloned.Columns)
  130. {
  131. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  132. }
  133. dtCloned.Rows.Add(newrow);
  134. }
  135. if (Invmes.Rows.Count > 0)
  136. {
  137. dtCloned.Merge(Invmes, false);
  138. }
  139. return dtCloned;
  140. }
  141. /// <summary>
  142. /// 新增
  143. /// </summary>
  144. /// <param name="ICSASN"></param>
  145. /// <returns></returns>
  146. public string SaveICSOOPickAppApplyNeg(string ICSASN)
  147. {
  148. string msg = "";
  149. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OOPick/Create";
  150. string result = HttpPost(APIURL, ICSASN);
  151. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  152. string MessAge = Obj["Message"].ToString();
  153. string Success = Obj["Success"].ToString();
  154. if (Success.ToUpper() == "FALSE")
  155. {
  156. msg = MessAge;
  157. }
  158. return msg;
  159. }
  160. /// <summary>
  161. /// 修改
  162. /// </summary>
  163. /// <param name="ICSASN"></param>
  164. /// <returns></returns>
  165. public string UpdateICSOOPickApplyNeg(string ICSASN)
  166. {
  167. string msg = "";
  168. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OOPick/Update";
  169. string result = HttpPost(APIURL, ICSASN);
  170. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  171. string MessAge = Obj["Message"].ToString();
  172. string Success = Obj["Success"].ToString();
  173. if (Success.ToUpper() == "FALSE")
  174. {
  175. msg = MessAge;
  176. }
  177. return msg;
  178. }
  179. /// <summary>
  180. /// 接口api解析
  181. /// </summary>
  182. /// <param name="url"></param>
  183. /// <param name="body"></param>
  184. /// <returns></returns>
  185. /// <exception cref="Exception"></exception>
  186. public static string HttpPost(string url, string body)
  187. {
  188. try
  189. {
  190. Encoding encoding = Encoding.UTF8;
  191. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  192. request.Method = "POST";
  193. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  194. request.ContentType = "application/json; charset=utf-8";
  195. byte[] buffer = encoding.GetBytes(body);
  196. request.ContentLength = buffer.Length;
  197. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  198. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  199. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  200. {
  201. return reader.ReadToEnd();
  202. }
  203. }
  204. catch (WebException ex)
  205. {
  206. throw new Exception(ex.Message);
  207. }
  208. }
  209. }
  210. }