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.

149 lines
6.6 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 ICSICSMOIssue : 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
  48. a.cCode,as IssueCode,
  49. b.irowno as Sequence,
  50. c.MoCode as SourceCode,
  51. d.SortSeq as SourceSequence,
  52. b.cInvCode as InvCode,
  53. b.iQuantity as Quantity
  54. b.iNum as Amount,
  55. a.cWhCode as WHCode,
  56. a.bredvouch as Type,
  57. a.iverifystate as Status,
  58. a.cMaker as CreatePerson,
  59. a.dnmaketime as CreateDateTime,
  60. a.id as IssueID,
  61. b.AutoID as IssueDetailID ,
  62. ISNULL(a.dnmodifytime, a.dnmaketime) AS MTIME
  63. , '{0}' as WorkPoint
  64. INTO #TempRd
  65. from rdrecord11 a
  66. inner join {1}.dbo.rdrecords11 b on a.ID=b.ID
  67. left join {1}.dbo.mom_order c on a.iproorderid=c.MoId
  68. left JOIN {1}.dbo.mom_orderdetail d ON c.MoId=d.MoId
  69. and ISNULL(a.cHandler , '')<>'' AND ISNULL(a.dnmodifytime, a.dnmaketime)>=@LastTime
  70. IF NOT EXISTS(SELECT * FROM #TempRd)
  71. RETURN";
  72. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempRd");
  73. sql += @"--删除数据
  74. --DELETE ICSMOIssue where ISNULL(IssueDetailID,'') NOT IN ( SELECT autoID FROM {1}.dbo.rdrecords11 )
  75. SELECT ISNULL(a.IssueDetailID,'') IssueDetailID INTO #tableICSMOIssue
  76. FROM ICSMOIssue a With(NoLock)
  77. LEFT JOIN {1}.dbo.[rdrecords11] b With(NoLock) ON ISNULL(a.IssueDetailID,'')=b.autoID
  78. WHERE a.WorkPoint='{0}' and b.autoID IS NULL
  79. DELETE ICSMOIssue
  80. WHERE WorkPoint='{0}' and ISNULL(a.IssueDetailID,'') IN ( SELECT IssueDetailID from #tableICSMOIssue)
  81. ";
  82. sql += "\r\n";
  83. Dictionary<string, string> values = new Dictionary<string, string>();
  84. values.Add("TransferNO", "a.TransferNO");
  85. values.Add("Sequence", "a.Sequence");
  86. values.Add("FromWarehouseCode", "a.FromWarehouseCode");
  87. values.Add("FromLocationCode", "a.FromLocationCode");
  88. values.Add("ToWarehouseCode", "a.ToWarehouseCode");
  89. values.Add("Status", "a.Status");
  90. values.Add("InvCode", "a.InvCode");
  91. values.Add("Quantity", "a.Quantity");
  92. values.Add("Amount", "a.Amount");
  93. values.Add("Type", "a.Type");
  94. values.Add("Memo", "a.Memo");
  95. values.Add("CreateDateTime", "a.CreateDateTime");
  96. values.Add("CreatePerson", "a.CreatePerson");
  97. values.Add("TransferID", "a.TransferID");
  98. values.Add("TransferDetailID", "a.TransferDetailID");
  99. values.Add("ExtensionID", "''");
  100. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  101. values.Add("MUSERNAME", "'" + ConstWorkPoint.Musername + "'");
  102. values.Add("WorkPoint", "'" + WorkPoint + "'");
  103. values.Add("MTIME", "a.MTIME");
  104. //更新存在数据
  105. sql += "\r\n";
  106. sql += ICSHelper.UpdateSQL("b", values)
  107. + @" #TempRd a
  108. INNER JOIN ICSMOIssue b ON a.IssueDetailID=b.IssueDetailID and a.WorkPoint=b.WorkPoint
  109. WHERE a.WorkPoint='" + WorkPoint + "' ";
  110. //values.Add("EATTRIBUTE3", "a.EATTRIBUTE3");
  111. values.Add("ID", "newid()");
  112. values.Add("TransferQuantity", "0");
  113. //插入新增数据
  114. sql += "\r\n";
  115. sql += ICSHelper.InsertSQL("ICSMOIssue", values)
  116. + @" #TempRd a
  117. LEFT JOIN ICSMOIssue b ON a.IssueDetailID=b.IssueDetailID and a.WorkPoint=b.WorkPoint
  118. WHERE b.IssueDetailID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  119. sql += " DROP TABLE #TempRd " +
  120. " DROP TABLE #tableICSMOIssue";
  121. sql = string.Format(sql, WorkPoint, erpName);
  122. ICSHelper.ExecuteDate(conStr, sql);
  123. #endregion
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. log.Error(ex.ToString());
  129. }
  130. }
  131. }
  132. }