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.

429 lines
21 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 System.Collections;
  19. using NFine.Application.Models;
  20. namespace NFine.Application.WMS
  21. {
  22. /// <summary>
  23. /// 发料申请
  24. /// </summary>
  25. public class ICSMOReplenishmentApp : RepositoryFactory<ICSVendor>
  26. {
  27. public static DataTable Invmes = new DataTable();
  28. /// <summary>
  29. /// 委外发料申请删除
  30. /// </summary>
  31. /// <param name="keyValue"></param>
  32. /// <returns></returns>
  33. /// <exception cref="Exception"></exception>
  34. public string DeleteMOReplenishmentApplyNeg(string keyValue)
  35. {
  36. //站点信息
  37. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  38. string msg = "";
  39. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  40. string sql = string.Empty;
  41. sql += string.Format(@"DELETE FROM dbo.ICSMOReplenishment WHERE ReplenishmentCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  42. //sql += string.Format(@"DELETE FROM dbo.ICSMMOReplenishmentNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  43. try
  44. {
  45. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  46. {
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. throw new Exception(ex.Message);
  52. }
  53. return msg;
  54. }
  55. /// <summary>
  56. /// 委外申请单号查询
  57. /// </summary>
  58. /// <param name="jqgridparam"></param>
  59. /// <returns></returns>
  60. public DataTable GetMOReplenishmentApplyNeg(ref Pagination jqgridparam)
  61. {
  62. DataTable dt = new DataTable();
  63. List<DbParameter> parameter = new List<DbParameter>();
  64. string sql = @"select a.ReplenishmentCode, a.MUSERName,a.MTIME,a.WHCode,b.WarehouseName,a.Type,a.Status from ICSMOReplenishment a
  65. left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint=b.WorkPoint
  66. group by a.ReplenishmentCode, a.MUSERName,a.MTIME,a.WHCode,b.WarehouseName,a.Type,a.Status";
  67. sql = string.Format(sql);
  68. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  69. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  70. }
  71. /// <summary>
  72. /// 委外订单明细查询
  73. /// </summary>
  74. /// <param name="jqgridparam"></param>
  75. /// <returns></returns>
  76. public DataTable GetMOReplenishmentApplyNegDetail(string ReplenishmentCode, ref Pagination jqgridparam)
  77. {
  78. DataTable dt = new DataTable();
  79. //object Figure = GetDecimalDigits();
  80. List<DbParameter> parameter = new List<DbParameter>();
  81. string sql = @"SELECT a.ID,a.ReplenishmentCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity,a.WHCode,e.WarehouseName as WHName,a.Type,a.Status,a.CreatePerson,a.CreateDateTime
  82. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName
  83. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  84. ,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,
  85. a.EATTRIBUTE9,a.EATTRIBUTE10
  86. from ICSMOReplenishment a
  87. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  88. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  89. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  90. where a.ReplenishmentCode = '" + ReplenishmentCode + "' ";
  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 SaveICSMOReplenishmentApplyNeg(string keyValue, string deleteIDs)
  120. {
  121. string returnValue = string.Empty;
  122. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  123. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  124. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  125. var Dates = DateTime.Now;
  126. string Colspan = string.Empty;
  127. string IDD = string.Empty;
  128. var sql = string.Empty;
  129. try
  130. {
  131. var modelList = JsonConvert.DeserializeObject<List<ICSMOReplenishmentEdit>>(keyValue);
  132. if (!string.IsNullOrEmpty(deleteIDs))
  133. {
  134. var deleteentityList = deleteIDs.Split(',');
  135. foreach (var item in deleteentityList)
  136. {
  137. if (!string.IsNullOrEmpty(item))
  138. {
  139. var deleteEntity = MsSqlData.Get<ICSMOReplenishment>(item);
  140. sql += string.Format(@"DELETE FROM dbo.ICSMOReplenishment WHERE ID IN ({0}) and WorkPoint ='{1}'", item, WorkPoint);
  141. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  142. {
  143. }
  144. }
  145. }
  146. }
  147. foreach (var model in modelList)
  148. {
  149. if (string.IsNullOrEmpty(model.ID))
  150. {
  151. //新增
  152. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSMOReplenishment where ReplenishmentCode ='" + model.ReplenishmentCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  153. if (count > 0)
  154. {
  155. throw new Exception("当前代码已经存在");
  156. }
  157. //检验自由项
  158. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  159. + "~" + model.Brand + "~" + model.cFree1
  160. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  161. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  162. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  163. sql = @"select ID,Colspan from ICSExtension a
  164. where Colspan='{0}' and WorkPoint='{1}'";
  165. sql = string.Format(sql, Colspan, model.WorkPoint);
  166. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  167. if (dttt.Rows.Count == 0)
  168. {
  169. IDD = Guid.NewGuid().ToString();
  170. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  171. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  172. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  173. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  174. {
  175. throw new Exception("自由项添加失败");
  176. }
  177. }
  178. else
  179. {
  180. IDD = dttt.Rows[0]["ID"].ToString();
  181. }
  182. var entity = new ICSMOReplenishment();
  183. ConvertExt.Mapping<ICSMOReplenishmentEdit, ICSMOReplenishment>(model, entity);
  184. entity.ID = Guid.NewGuid().ToString();
  185. entity.Status = "1";
  186. entity.CreatePerson = MUSER;
  187. entity.CreateDateTime = Dates;
  188. entity.ReplenishmentID = "";
  189. entity.ReplenishmentDetailID = "";
  190. entity.MUSER = MUSER;
  191. entity.MUSERName = MUSERNAME;
  192. entity.MTIME = Dates;
  193. entity.WorkPoint = WorkPoint;
  194. entity.ExtensionID = IDD;
  195. var result = MsSqlData.Insert<ICSMOReplenishment>(entity);
  196. if (!result)
  197. {
  198. returnValue = "新增失败";
  199. }
  200. }
  201. else
  202. {
  203. //修改
  204. var entity = MsSqlData.Get<ICSMOReplenishment>(model.ID);
  205. if (entity == null)
  206. {
  207. //新增
  208. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSMOReplenishment where ReplenishmentCode='" + model.ReplenishmentCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  209. if (count > 0)
  210. {
  211. throw new Exception("当前代码已经存在");
  212. }
  213. //检验自由项
  214. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  215. + "~" + model.Brand + "~" + model.cFree1
  216. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  217. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  218. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  219. sql = @"select ID,Colspan from ICSExtension a
  220. where Colspan='{0}' and WorkPoint='{1}'";
  221. sql = string.Format(sql, Colspan, model.WorkPoint);
  222. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  223. if (dttt.Rows.Count == 0)
  224. {
  225. IDD = Guid.NewGuid().ToString();
  226. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  227. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  228. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  229. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  230. {
  231. throw new Exception("自由项添加失败");
  232. }
  233. }
  234. else
  235. {
  236. IDD = dttt.Rows[0]["ID"].ToString();
  237. }
  238. entity = new ICSMOReplenishment();
  239. ConvertExt.Mapping<ICSMOReplenishmentEdit, ICSMOReplenishment>(model, entity);
  240. entity.ID = Guid.NewGuid().ToString();
  241. entity.Status = "1";
  242. entity.CreatePerson = MUSER;
  243. entity.CreateDateTime = Dates;
  244. entity.MUSER = MUSER;
  245. entity.MUSERName = MUSERNAME;
  246. entity.ReplenishmentID = "";
  247. entity.ReplenishmentDetailID = "";
  248. entity.MTIME = Dates;
  249. entity.WorkPoint = WorkPoint;
  250. entity.ExtensionID = IDD;
  251. var result = MsSqlData.Insert<ICSMOReplenishment>(entity);
  252. if (!result)
  253. {
  254. returnValue = "新增失败";
  255. }
  256. }
  257. else
  258. {
  259. //检验自由项
  260. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  261. + "~" + model.Brand + "~" + model.cFree1
  262. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  263. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  264. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  265. sql = @"select ID,Colspan from ICSExtension a
  266. where Colspan='{0}' and WorkPoint='{1}'";
  267. sql = string.Format(sql, Colspan, model.WorkPoint);
  268. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  269. if (dtt.Rows.Count == 0)
  270. {
  271. IDD = Guid.NewGuid().ToString();
  272. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  273. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  274. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  275. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  276. {
  277. throw new Exception("自由项添加失败");
  278. }
  279. }
  280. else
  281. {
  282. IDD = dtt.Rows[0]["ID"].ToString();
  283. }
  284. ConvertExt.Mapping<ICSMOReplenishmentEdit, ICSMOReplenishment>(model, entity);
  285. entity.MUSER = MUSER;
  286. entity.MUSERName = MUSERNAME;
  287. entity.ReplenishmentID = "";
  288. entity.ReplenishmentDetailID = "";
  289. entity.MTIME = Dates;
  290. entity.ExtensionID = IDD;
  291. var result = MsSqlData.Update<ICSMOReplenishment>(entity);
  292. if (!result)
  293. {
  294. returnValue = "修改失败";
  295. }
  296. }
  297. }
  298. }
  299. }
  300. catch (Exception ex)
  301. {
  302. returnValue = ex.Message;
  303. }
  304. return returnValue;
  305. }
  306. ///// <summary>
  307. ///// 修改
  308. ///// </summary>
  309. ///// <param name="ICSASN"></param>
  310. ///// <returns></returns>
  311. //public string UpdateICSMOReplenishmentApplyNeg(string ICSASN)
  312. //{
  313. // string msg = "";
  314. // string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOReplenishment/Update";
  315. // string result = HttpPost(APIURL, ICSASN);
  316. // JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  317. // string MessAge = Obj["Message"].ToString();
  318. // string Success = Obj["Success"].ToString();
  319. // if (Success.ToUpper() == "FALSE")
  320. // {
  321. // msg = MessAge;
  322. // }
  323. // return msg;
  324. //}
  325. /// <summary>
  326. /// 创建自增单号
  327. /// </summary>
  328. /// <param name="WorkPoint"></param>
  329. /// <returns></returns>
  330. public string GetOOCode(string WorkPoint)
  331. {
  332. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  333. string OOCode = string.Empty;
  334. if (!string.IsNullOrEmpty(WorkPoint))
  335. {
  336. OOCode = GetSerialCode(WorkPoint, "ICSMOReplenishment", "ReplenishmentCode", "00", 8);
  337. }
  338. if (!string.IsNullOrWhiteSpace(OOCode))
  339. {
  340. string sqlISHave = @"SELECT ReplenishmentCode FROM ICSMOReplenishment a
  341. WHERE a.ReplenishmentCode = '{0}'";
  342. sqlISHave = string.Format(sqlISHave, OOCode);
  343. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  344. if (dtIsHave.Rows.Count > 0)
  345. {
  346. throw new Exception("单号已存在!");
  347. }
  348. }
  349. return OOCode;
  350. }
  351. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  352. {
  353. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  354. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  355. return SqlHelper.ExecuteScalar(sql).ToString();
  356. }
  357. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  358. {
  359. var data = json.ToJObject();
  360. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  361. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  362. if (info != null && info.Length > 0)
  363. {
  364. info[0]["ZJID"] = data["ZJID"];
  365. info[0]["InvName"] = data["InvName"];
  366. }
  367. else
  368. {
  369. DataRow newrow = Invmes.NewRow();
  370. newrow["ZJID"] = data["ZJID"];
  371. Invmes.Rows.Add(newrow);
  372. }
  373. }
  374. public DataTable GetICSMOReplenishmentReturnTemporary(string ReplenishmentCode)
  375. {
  376. string sql = @"SELECT a.ID,a.ReplenishmentCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity
  377. ,a.WHCode,a.Type,a.Status,a.CreatePerson,a.CreateDateTime,b.InvName
  378. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
  379. from ICSMOReplenishment a
  380. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  381. where a.ReplenishmentCode ='" + ReplenishmentCode + "' ";
  382. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  383. DataTable dtCloned = table.Clone();
  384. foreach (DataColumn col in dtCloned.Columns)
  385. {
  386. col.DataType = typeof(string);
  387. }
  388. foreach (DataRow row in table.Rows)
  389. {
  390. DataRow newrow = dtCloned.NewRow();
  391. foreach (DataColumn column in dtCloned.Columns)
  392. {
  393. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  394. }
  395. dtCloned.Rows.Add(newrow);
  396. }
  397. if (Invmes.Rows.Count > 0)
  398. {
  399. dtCloned.Merge(Invmes, false);
  400. }
  401. return dtCloned;
  402. }
  403. }
  404. }