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.

153 lines
7.2 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 ICSSDN : 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 b.cDLCode AS DispatchCode,
  48. CAST(a.irowno AS NVARCHAR(50)) AS DispatchRow,
  49. ISNULL(d.cSOCode,'') AS SOCode,
  50. CAST(ISNULL(d.iRowNo,'') AS NVARCHAR(50)) AS SORow,
  51. b.cCusCode AS CusCode,
  52. b.cCusName AS CusName,
  53. CASE WHEN a.iQuantity>=0 THEN '1' ELSE '2' END AS Type,
  54. a.cInvCode AS InvCode,
  55. a.cWhCode AS WHCode,
  56. CASE WHEN a.iQuantity>=0 THEN a.iQuantity ELSE -a.iQuantity END AS Quantity,
  57. c.cComUnitCode AS ComUnitCode,
  58. b.dDate AS VoucherDate,
  59. CASE WHEN ISNULL(b.cVerifier, '')='' THEN '1' ELSE '2' END AS Status,
  60. CAST(b.DLID AS NVARCHAR(50)) AS Term1,
  61. CAST(a.AutoID AS NVARCHAR(50)) AS Term2,
  62. b.cMaker AS MUSER,
  63. 'job' AS MUSERNAME,
  64. ISNULL(b.dverifysystime,ISNULL(b.dmodifysystime, b.dcreatesystime)) AS MTIME,
  65. ISNULL(b.dverifysystime,ISNULL(b.dmodifysystime, b.dcreatesystime)) AS ArriveDate,
  66. ISNULL(a.cBatch,'') AS cBatch,
  67. '' AS ORDERNO
  68. ,'{0}' as WorkPoint
  69. INTO #TempSO
  70. FROM {1}.dbo.DispatchLists a
  71. INNER JOIN {1}.dbo.DispatchList b ON a.DLID = b.DLID
  72. LEFT JOIN {1}.dbo.Inventory c ON a.cInvCode = c.cInvCode
  73. LEFT JOIN {1}.dbo.SO_SODetails d ON a.iSOsID = d.iSOsID
  74. LEFT JOIN {1}.dbo.ComputationUnit e ON c.cComUnitCode = e.cComunitCode
  75. WHERE ISNULL(b.cVerifier, '')!='' AND ISNULL(b.cCloser, '')='' AND ISNULL(b.dverifysystime,ISNULL(b.dmodifysystime, b.dcreatesystime))>=@LastTime
  76. IF NOT EXISTS(SELECT * FROM #TempSO)
  77. RETURN";
  78. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempSO");
  79. sql += @"--删除数据
  80. --DELETE ICSSDN WHERE Term2 NOT IN (SELECT AutoID FROM {1}.dbo.DispatchLists) AND LEN(Term2)>0
  81. SELECT a.Term2 INTO #tableICSSDN
  82. FROM ICSSDN a With(NoLock)
  83. LEFT JOIN {1}.dbo.[DispatchLists] b With(NoLock) ON a.Term2=b.AutoID
  84. WHERE a.WorkPoint='{0}' and b.AutoID IS NULL AND LEN(a.Term2)>0
  85. DELETE ICSSDN
  86. WHERE WorkPoint='{0}' and Term2 IN ( SELECT Term2 from #tableICSSDN)
  87. ";
  88. Dictionary<string, string> values = new Dictionary<string, string>();
  89. values.Add("SDNCode", "a.DispatchCode");
  90. values.Add("Sequence", "a.DispatchRow");
  91. values.Add("SOCode", "a.SOCode");
  92. values.Add("SORow", "a.SORow");
  93. values.Add("CusCode", "a.CusCode");
  94. values.Add("CusName", "a.CusName");
  95. values.Add("Type", "a.Type");
  96. values.Add("ArriveDate", "");
  97. values.Add("InvCode", "a.InvCode");
  98. values.Add("WHCode", "a.WHCode");
  99. values.Add("Quantity", "a.Quantity");
  100. values.Add("ComUnitCode", "a.ComUnitCode");
  101. values.Add("VoucherDate", "a.VoucherDate");
  102. values.Add("Status", "a.Status");
  103. values.Add("MTIME", "a.MTIME");
  104. values.Add("ArriveDate", "a.ArriveDate");
  105. values.Add("cBatch", "a.cBatch");
  106. values.Add("ORDERNO", "a.ORDERNO");
  107. //更新存在数据
  108. sql += ICSHelper.UpdateSQL("b", values)
  109. + @" #TempSO a
  110. INNER JOIN ICSSDN b ON a.Term2=b.Term2 and a.WorkPoint=b.WorkPoint
  111. WHERE a.WorkPoint='" + WorkPoint + "' ";
  112. values.Add("Term1", "a.Term1");
  113. values.Add("Term2", "a.Term2");
  114. values.Add("LotNo", "''");
  115. values.Add("Sign", "''");
  116. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  117. values.Add("MUSERNAME", "'" + ConstWorkPoint.Musername + "'");
  118. values.Add("WorkPoint", "'" + WorkPoint + "'");
  119. //插入新增数据
  120. sql += ICSHelper.InsertSQL("ICSSDN", values)
  121. + @" #TempSO a
  122. LEFT JOIN ICSSDN b ON a.Term2=b.Term2 and a.WorkPoint=b.WorkPoint
  123. WHERE b.Term2 IS NULL and a.WorkPoint='" + WorkPoint + @"'
  124. ";
  125. sql += " DROP TABLE #TempSO " +
  126. " DROP TABLE #tableICSSDN";
  127. sql = string.Format(sql, WorkPoint, erpName);
  128. ICSHelper.ExecuteDate(conStr, sql);
  129. #endregion
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. log.Error(ex.ToString());
  135. }
  136. }
  137. }
  138. }