IcsFromERPJob
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.

146 lines
6.8 KiB

4 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using Quartz;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 补料单
  11. /// </summary>
  12. public class ICSReplenishapply : IJob
  13. {
  14. private static object key = new object();
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. public void Execute(IJobExecutionContext context)
  17. {
  18. try
  19. {
  20. lock (key)
  21. {
  22. log.Info("开始……………………………………………………………………");
  23. Execute();
  24. log.Info("结束……………………………………………………………………");
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. log.Error(ex.ToString());
  30. }
  31. }
  32. public void Execute()
  33. {
  34. try
  35. {
  36. string conStr = ICSHelper.GetConnectString();
  37. string Namespace = this.GetType().Namespace;
  38. //string Class = this.GetType().Name;
  39. DataTable dt = ICSHelper.GetERPDB(conStr);
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  43. string WorkPoint = dr["WorkPointCode"].ToString();
  44. string Class = this.GetType().Name + WorkPoint;
  45. erpName = string.Format(erpName, WorkPoint);
  46. #region SQL
  47. string sql = @"SELECT CAST(a.ApplyId as VARCHAR(50)) AS PODetailID ,
  48. a.DocCode AS VouchCode ,
  49. CAST(b.ApplyDId as VARCHAR(50)) AS Did ,
  50. CAST(b.SortSeq as VARCHAR(50)) AS VouchRow ,
  51. e.MoCode AS MOCode ,
  52. c.SortSeq AS MOROW ,
  53. c.InvCode AS InvCode ,
  54. d.InvCode AS SubInvCode ,
  55. a.DocDate AS VoucherDate ,
  56. CASE WHEN f.bCutMantissa='1' AND f.bKCCutMantissa='1' THEN CEILING(b.ApplyQty) ELSE b.ApplyQty END AS Quantity ,
  57. a.MDeptCode AS DepCode,
  58. '' AS WHCode ,
  59. a.CreateUser AS MUSER ,
  60. '' AS MUSERName ,
  61. ISNULL(a.RelsTime,ISNULL(a.ModifyTime, a.CreateTime)) AS MTIME ,
  62. '' AS VouchType ,
  63. '' AS ORDERNO ,
  64. '' AS cBatch
  65. INTO #TempReplenishapply
  66. FROM {1}.dbo.mom_replenishapply a
  67. INNER JOIN {1}.dbo.mom_replenishapplydtl b ON a.ApplyId=b.ApplyId
  68. INNER JOIN {1}.dbo.mom_orderdetail c ON b.MoDId=c.MoDId
  69. INNER JOIN {1}.dbo.mom_moallocate d ON b.MoAllocateId=d.AllocateId
  70. INNER JOIN {1}.dbo.mom_order e ON c.MoId=e.MoId
  71. LEFT JOIN {1}.dbo.Inventory f ON d.InvCode = f.cInvCode
  72. WHERE ISNULL (a.RelsUser,'') <> '' AND ISNULL(a.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))>=@LastTime
  73. IF NOT EXISTS(SELECT * FROM #TempReplenishapply)
  74. RETURN";
  75. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempReplenishapply");
  76. sql += @"--删除数据
  77. -- DELETE ICSReplenishapply WHERE Did NOT IN (SELECT ApplyDId FROM {1}.dbo.mom_replenishapplydtl ) AND LEN(Did)>0
  78. SELECT a.Did INTO #tableICSReplenishapply
  79. FROM ICSReplenishapply a With(NoLock)
  80. LEFT JOIN {1}.dbo.[mom_replenishapplydtl] b With(NoLock) ON a.Did=b.ApplyDId
  81. WHERE a.WorkPoint='{0}' and b.ApplyDId IS NULL AND LEN(a.Did)>0
  82. DELETE ICSReplenishapply
  83. WHERE WorkPoint='{0}' and Did IN ( SELECT Did from #tableICSReplenishapply)
  84. ";
  85. Dictionary<string, string> values = new Dictionary<string, string>();
  86. values.Add("VouchCode", "a.VouchCode");
  87. values.Add("VouchRow", "a.VouchRow");
  88. values.Add("MOCode", "a.MOCode");
  89. values.Add("MOROW", "a.MOROW");
  90. values.Add("InvCode", "a.InvCode");
  91. values.Add("SubInvCode", "a.SubInvCode");
  92. values.Add("Quantity", "a.Quantity");
  93. values.Add("WHCode", "a.WHCode");
  94. values.Add("VouchType", "a.VouchType");
  95. values.Add("VoucherDate", "a.VoucherDate");
  96. values.Add("MTIME", "a.MTIME");
  97. values.Add("PODetailID", "a.PODetailID");
  98. values.Add("MUSER", "a.MUSER");
  99. values.Add("MUSERName", "a.MUSERName");
  100. values.Add("ORDERNO", "a.ORDERNO");
  101. values.Add("cBatch", "a.cBatch");
  102. values.Add("DepCode", "a.DepCode");
  103. //更新存在数据
  104. sql += ICSHelper.UpdateSQL("b", values)
  105. + @" #TempReplenishapply a
  106. INNER JOIN ICSReplenishapply b ON a.Did=b.Did and a.WorkPoint=b.WorkPoint
  107. WHERE a.WorkPoint='" + WorkPoint + "' ";
  108. values.Add("ID", "NEWID()");
  109. values.Add("HasQuantity", "'0'");
  110. values.Add("Did", "a.Did");
  111. values.Add("WorkPoint", "'" + WorkPoint + "'");
  112. //插入新增数据
  113. sql += ICSHelper.InsertSQL("ICSReplenishapply", values)
  114. + @" #TempReplenishapply a
  115. LEFT JOIN ICSReplenishapply b ON a.Did=b.Did and a.WorkPoint=b.WorkPoint
  116. WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + @"'
  117. ";
  118. sql += " DROP TABLE #TempReplenishapply " +
  119. " DROP TABLE #tableICSReplenishapply";
  120. sql = string.Format(sql, WorkPoint, erpName);
  121. ICSHelper.ExecuteDate(conStr, sql);
  122. #endregion
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. log.Error(ex.ToString());
  128. }
  129. }
  130. }
  131. }