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
10 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. using NFine.Application.Entity;
  18. using NFine.Application.Models;
  19. using NFine.Application.WMS;
  20. using System.Web.UI.WebControls;
  21. using System.Net.NetworkInformation;
  22. using System.Collections;
  23. using System.Xml;
  24. using NFine.Domain._03_Entity.WMS;
  25. namespace NFine.Application.HGWMS
  26. {
  27. public class ICSTransferApp : RepositoryFactory<ICSVendor>
  28. {
  29. public static DataTable Invmes = new DataTable();
  30. /// <summary>
  31. /// 获取仓库库位信息
  32. /// </summary>
  33. /// <param name="queryJson"></param>
  34. /// <param name="jqgridparam"></param>
  35. /// <returns></returns>
  36. public DataTable GetLocationCode(string queryJson, ref Pagination jqgridparam)
  37. {
  38. //站点信息
  39. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  40. DataTable dt = new DataTable();
  41. List<DbParameter> parameter = new List<DbParameter>();
  42. var queryParam = queryJson.ToJObject();
  43. object Figure = GetDecimalDigits();
  44. #region [SQL]
  45. string sql = $@" SELECT a.WarehouseCode,a.WarehouseName,b.LocationCode,b.LocationName,b.ID
  46. FROM ICSWarehouse a
  47. LEFT JOIN ICSLocation b ON a.ID=b.WHID
  48. WHERE 1=1 ";
  49. sql = string.Format(sql, Figure);
  50. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  51. #endregion
  52. if (!string.IsNullOrWhiteSpace(queryJson))
  53. {
  54. if (!string.IsNullOrWhiteSpace(queryParam["WarehouseCode"].ToString()))
  55. {
  56. sql += " and a.WarehouseCode like '%" + queryParam["WarehouseCode"].ToString() + "%' ";
  57. }
  58. if (!string.IsNullOrWhiteSpace(queryParam["LocationCode"].ToString()))
  59. {
  60. sql += " and b.LocationCode like '%" + queryParam["LocationCode"].ToString() + "%' ";
  61. }
  62. }
  63. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  64. {
  65. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  66. }
  67. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  68. }
  69. public object GetDecimalDigits()
  70. {
  71. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  72. try
  73. {
  74. string sql = string.Empty;
  75. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  76. object Figure = SqlHelper.ExecuteScalar(sql);
  77. return Figure;
  78. }
  79. catch (Exception ex)
  80. {
  81. throw new Exception(ex.Message.ToString());
  82. }
  83. }
  84. /// <summary>
  85. /// 订单备料明细查询
  86. /// </summary>
  87. /// <param name="jqgridparam"></param>
  88. /// <returns></returns>
  89. public DataTable GetMOIssueApplyNegDetail(string RCVCode, ref Pagination jqgridparam)
  90. {
  91. DataTable dt = new DataTable();
  92. //object Figure = GetDecimalDigits();
  93. List<DbParameter> parameter = new List<DbParameter>();
  94. string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.SourceSequence,a.SourceCode,a.InvCode,a.Quantity,a.Amount,a.RCVQuantity,a.WHCode,e.WarehouseName as WHName,a.Type
  95. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName,a.CreateDateTime,a.CreatePerson
  96. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  97. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  98. ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10
  99. from ICSManufactureReceive a
  100. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  101. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  102. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  103. where a.RCVCode = '" + RCVCode + "' ";
  104. //sql = string.Format(sql, Figure);
  105. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  106. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  107. }
  108. public void ClearTemp()
  109. {
  110. Invmes.Rows.Clear();
  111. }
  112. public string ICSMOIssueSendBackAuditRollback(string keyValue)
  113. {
  114. return "";
  115. }
  116. /// <summary>
  117. /// 创建一步调拨单
  118. /// </summary>
  119. /// <param name="keyValue"></param>
  120. /// <returns></returns>
  121. public string AddICSTransfer(string keyValue)
  122. {
  123. string returnValue = string.Empty;
  124. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  125. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  126. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  127. var sql = string.Empty;
  128. try
  129. {
  130. var key = keyValue.ToJObject();
  131. //验证是否同一个供应商
  132. sql = $@"SELECT DISTINCT WarehouseCode FROM ICSWareHouseLotInfo where LotNo in ({key["Lots"]}) AND WorkPoint ='{WorkPoint}' ";
  133. var dt1 = SqlHelper.CmdExecuteDataTable(sql);
  134. if (dt1.Rows.Count>1|| dt1.Rows.Count<=0)
  135. {
  136. throw new Exception("创建调拨单的条码必须是同一个供应商的物料,操作失败");
  137. }
  138. TransferINHead addICSTransfer = new TransferINHead();
  139. List<TransferINBody> transferINBodies = new List<TransferINBody>();
  140. //查询单据信息
  141. sql = $@"SELECT Sum(Quantity) Quantity,WarehouseCode OutWhCode,LocationCode OutBinCode,InvCode from ICSWareHouseLotInfo WHERE LotNo in ({key["Lots"]}) AND WorkPoint='{WorkPoint}' GROUP BY WarehouseCode,LocationCode,InvCode ";
  142. var dt = SqlHelper.CmdExecuteDataTable(sql);
  143. if (dt.Rows.Count <= 1)
  144. {
  145. throw new Exception("条码信息有误请确认,操作失败");
  146. }
  147. addICSTransfer.DocDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  148. addICSTransfer.OrgCode = WorkPoint;
  149. for (int i=0;i< dt.Rows.Count; i++)
  150. {
  151. TransferINBody transferINBody =
  152. new TransferINBody
  153. {
  154. Quantity = (dt.Rows[i]["Quantity"]).ToDecimal(),
  155. InvCode = dt.Rows[i]["InvCode"].ToString(),
  156. OutWhCode = dt.Rows[i]["OutWhCode"].ToString(),
  157. OutBinCode = dt.Rows[i]["OutBinCode"].ToString(),
  158. //SupplierCode = dt.Rows[0]["VenCode"].ToString(),
  159. INWhCode = key["WarehouseCode"].ToString(),
  160. INBinCode = key["LocationCode"].ToString(),
  161. Sequence = i + 1
  162. };
  163. transferINBodies.Add(transferINBody);
  164. }
  165. addICSTransfer.details = transferINBodies;
  166. #region 调用ERP接口
  167. if (!addICSTransfer.IsEmpty())
  168. {
  169. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "U9OneStepTransferDocIn/Create";
  170. var erpinput = JsonConvert.SerializeObject(addICSTransfer);
  171. string result1 = HttpPost(APIURL, erpinput);
  172. JObject Obj = (JObject)JsonConvert.DeserializeObject(result1);//或者JObject jo = JObject.Parse(jsonText);
  173. string MessAge = Obj["Message"].ToString();
  174. string Success = Obj["Success"].ToString();
  175. if (Success.ToUpper() == "FALSE")
  176. {
  177. throw new Exception(MessAge);
  178. }
  179. }
  180. #endregion
  181. return "";
  182. }
  183. catch (Exception ex)
  184. {
  185. return ex.Message;
  186. }
  187. }
  188. //接口api解析
  189. public static string HttpPost(string url, string body)
  190. {
  191. try
  192. {
  193. Encoding encoding = Encoding.UTF8;
  194. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  195. request.Method = "POST";
  196. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  197. request.ContentType = "application/json; charset=utf-8";
  198. byte[] buffer = encoding.GetBytes(body);
  199. request.ContentLength = buffer.Length;
  200. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  201. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  202. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  203. {
  204. return reader.ReadToEnd();
  205. }
  206. }
  207. catch (WebException ex)
  208. {
  209. throw new Exception(ex.Message);
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// api/Rd1011/Approve 调用产成品入库单、材料出库单审核
  215. /// </summary>
  216. public class ApproveInput
  217. {
  218. public string ID { get; set; }//ID
  219. public string User { get; set; }//用户
  220. public string Type { get; set; }//类型(入库,倒冲)
  221. public string WorkPoint { get; set; }//站点
  222. public bool UpdateStock { get; set; }//是否更新现存量
  223. public DateTime MTime { get; set; }//时间
  224. public bool UpdateTodoQuantity { get; set; }//更新待出入数量
  225. }
  226. }