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.

285 lines
12 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. using System.Reflection.Emit;
  18. namespace NFine.Application.WMS
  19. {
  20. /// <summary>
  21. /// 委外到货单
  22. /// </summary>
  23. public class ICSODeliveryNoticeApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable Invmes = new DataTable();
  26. /// <summary>
  27. /// 委外到货单 删除
  28. /// </summary>
  29. /// <param name="keyValue"></param>
  30. /// <returns></returns>
  31. /// <exception cref="Exception"></exception>
  32. public string DeleteICSODeliveryNoticeApplyNeg(string keyValue)
  33. {
  34. //站点信息
  35. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  36. string msg = "";
  37. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  38. string sql = string.Empty;
  39. sql += string.Format(@"DELETE FROM dbo.ICSODeliveryNotice WHERE ODNCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  40. //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  41. try
  42. {
  43. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  44. {
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. throw new Exception(ex.Message);
  50. }
  51. return msg;
  52. }
  53. /// <summary>
  54. /// 委外到货单 查询
  55. /// </summary>
  56. /// <param name="jqgridparam"></param>
  57. /// <returns></returns>
  58. public DataTable GetODeliveryNoticeApplyNeg(ref Pagination jqgridparam)
  59. {
  60. DataTable dt = new DataTable();
  61. List<DbParameter> parameter = new List<DbParameter>();
  62. string sql = @"select a.ODNCode,a.CreatePerson from ICSODeliveryNotice a
  63. group by a.ODNCode,a.CreatePerson";
  64. sql = string.Format(sql);
  65. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  66. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  67. }
  68. /// <summary>
  69. /// 委外到货单 明细查询
  70. /// </summary>
  71. /// <param name="jqgridparam"></param>
  72. /// <returns></returns>
  73. public DataTable GetODeliveryNoticeApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  74. {
  75. DataTable dt = new DataTable();
  76. object Figure = GetDecimalDigits();
  77. List<DbParameter> parameter = new List<DbParameter>();
  78. string sql = @"SELECT a.ID,a.ODNCode,a.Sequence,a.VenCode,d.VenName,a.DepCode,g.DepName,a.InvCode,a.Quantity,a.ODNType,a.RCVQuantity,a.Amount,a.UnitPrice,a.Currency,a.OOID,c.OOCode,a.OASNCode
  79. ,a.WHCode,e.WarehouseName as WHName,a.Status,a.CreatePerson,a.CreateDateTime
  80. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  81. ,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,
  82. a.EATTRIBUTE9,a.EATTRIBUTE10
  83. from ICSODeliveryNotice a
  84. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  85. left join ICSOutsourcingOrder c on a.OOID = c.ID and a.WorkPoint = c.WorkPoint
  86. left join ICSVendor d on a.VenCode = d.VenCode and a.WorkPoint = d.WorkPoint
  87. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  88. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  89. left join ICSDepartment g on a.DepCode = g.DepCode and a.WorkPoint = g.WorkPoint
  90. where a.ODNCode = '" + ApplyNegCode + "' ";
  91. sql = string.Format(sql, Figure);
  92. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  93. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  94. }
  95. public object GetDecimalDigits()
  96. {
  97. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  98. try
  99. {
  100. string sql = string.Empty;
  101. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  102. object Figure = SqlHelper.ExecuteScalar(sql);
  103. return Figure;
  104. }
  105. catch (Exception ex)
  106. {
  107. throw new Exception(ex.Message.ToString());
  108. }
  109. }
  110. public void ClearTemp()
  111. {
  112. Invmes.Rows.Clear();
  113. }
  114. /// <summary>
  115. /// 新增
  116. /// </summary>
  117. /// <param name="ICSASN"></param>
  118. /// <returns></returns>
  119. public string SaveICSODeliveryNoticeApplyNeg(string ICSASN)
  120. {
  121. string msg = "";
  122. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "ODeliveryNotice/Create";
  123. string result = HttpPost(APIURL, ICSASN);
  124. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  125. string MessAge = Obj["Message"].ToString();
  126. string Success = Obj["Success"].ToString();
  127. if (Success.ToUpper() == "FALSE")
  128. {
  129. msg = MessAge;
  130. }
  131. return msg;
  132. }
  133. /// <summary>
  134. /// 修改
  135. /// </summary>
  136. /// <param name="ICSASN"></param>
  137. /// <returns></returns>
  138. public string UpdateICSODeliveryNoticeApplyNeg(string ICSASN)
  139. {
  140. string msg = "";
  141. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "ODeliveryNotice/Update";
  142. string result = HttpPost(APIURL, ICSASN);
  143. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  144. string MessAge = Obj["Message"].ToString();
  145. string Success = Obj["Success"].ToString();
  146. if (Success.ToUpper() == "FALSE")
  147. {
  148. msg = MessAge;
  149. }
  150. return msg;
  151. }
  152. /// <summary>
  153. /// 获取单号
  154. /// </summary>
  155. /// <param name="WorkPoint"></param>
  156. /// <returns></returns>
  157. public string GetCode(string WorkPoint)
  158. {
  159. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  160. string OOCode = string.Empty;
  161. if (!string.IsNullOrEmpty(WorkPoint))
  162. {
  163. OOCode = GetSerialCode(WorkPoint, "ICSODeliveryNotice", "ODNCode", "OD", 8);
  164. }
  165. if (!string.IsNullOrWhiteSpace(OOCode))
  166. {
  167. string sqlISHave = @"SELECT ODNCode FROM ICSODeliveryNotice a
  168. WHERE a.ODNCode = '{0}'";
  169. sqlISHave = string.Format(sqlISHave, OOCode);
  170. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  171. if (dtIsHave.Rows.Count > 0)
  172. {
  173. throw new Exception("单号已存在!");
  174. }
  175. }
  176. return OOCode;
  177. }
  178. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  179. {
  180. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  181. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  182. return SqlHelper.ExecuteScalar(sql).ToString();
  183. }
  184. public void UpdateODeliveryNoticeOrderApplyNegTemp(string json)
  185. {
  186. var data = json.ToJObject();
  187. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  188. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  189. if (info != null && info.Length > 0)
  190. {
  191. info[0]["ZJID"] = data["ZJID"];
  192. info[0]["InvName"] = data["InvName"];
  193. }
  194. else
  195. {
  196. DataRow newrow = Invmes.NewRow();
  197. newrow["ZJID"] = data["ZJID"];
  198. Invmes.Rows.Add(newrow);
  199. }
  200. }
  201. public DataTable GetICSODeliveryNoticeReturnTemporary(string ODNCode)
  202. {
  203. string sql = @"SELECT a.ID,a.ODNCode,a.Sequence,a.VenCode,d.VenName,a.DepCode,g.DepName,a.InvCode,a.Quantity,a.ODNType,a.RCVQuantity,a.Amount,a.UnitPrice,a.Currency,a.OOID,c.OOCode,a.OASNCode
  204. ,a.WHCode,e.WarehouseName as WHName,a.Status,a.CreatePerson,a.CreateDateTime
  205. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  206. ,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,
  207. a.EATTRIBUTE9,a.EATTRIBUTE10
  208. from ICSODeliveryNotice a
  209. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  210. left join ICSOutsourcingOrder c on a.OOID = c.ID and a.WorkPoint = c.WorkPoint
  211. left join ICSVendor d on a.VenCode = d.VenCode and a.WorkPoint = d.WorkPoint
  212. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  213. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  214. left join ICSDepartment g on a.DepCode = g.DepCode and a.WorkPoint = g.WorkPoint
  215. where a.ODNCode ='" + ODNCode + "' ";
  216. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  217. DataTable dtCloned = table.Clone();
  218. foreach (DataColumn col in dtCloned.Columns)
  219. {
  220. col.DataType = typeof(string);
  221. }
  222. foreach (DataRow row in table.Rows)
  223. {
  224. DataRow newrow = dtCloned.NewRow();
  225. foreach (DataColumn column in dtCloned.Columns)
  226. {
  227. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  228. }
  229. dtCloned.Rows.Add(newrow);
  230. }
  231. if (Invmes.Rows.Count > 0)
  232. {
  233. dtCloned.Merge(Invmes, false);
  234. }
  235. return dtCloned;
  236. }
  237. /// <summary>
  238. /// 接口api解析
  239. /// </summary>
  240. /// <param name="url"></param>
  241. /// <param name="body"></param>
  242. /// <returns></returns>
  243. /// <exception cref="Exception"></exception>
  244. public static string HttpPost(string url, string body)
  245. {
  246. try
  247. {
  248. Encoding encoding = Encoding.UTF8;
  249. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  250. request.Method = "POST";
  251. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  252. request.ContentType = "application/json; charset=utf-8";
  253. byte[] buffer = encoding.GetBytes(body);
  254. request.ContentLength = buffer.Length;
  255. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  256. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  257. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  258. {
  259. return reader.ReadToEnd();
  260. }
  261. }
  262. catch (WebException ex)
  263. {
  264. throw new Exception(ex.Message);
  265. }
  266. }
  267. }
  268. }