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.

145 lines
6.4 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 ICSAssemVouchs : 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(b.ID as VARCHAR(50)) AS EATTRIBUTE ,
  48. b.cAVCode AS VouchCode ,
  49. CAST(a.autoID as VARCHAR(50)) AS Did ,
  50. CAST(a.irowno as VARCHAR(50)) AS VouchRow ,
  51. b.dAVDate AS VoucherDate ,
  52. a.cInvCode AS InvCode ,
  53. b.cAccPCode ,
  54. a.iAVQuantity AS Quantity ,
  55. 0 AS DemandQuantity,
  56. ISNULL(a.cWhCode,'') AS WHCode ,
  57. e.cComUnitCode AS ComUnitCode ,
  58. CAST(b.iverifystate as VARCHAR(50)) AS Status ,
  59. b.cMaker AS MUSER ,
  60. '' AS MUSERName ,
  61. ISNULL(b.dnmodifytime, b.dnmaketime) AS MTIME ,
  62. a.bAVType AS VouchType ,
  63. '' AS ORDERNO ,
  64. ISNULL(a.cAVBatch,'') AS cBatch,
  65. b.cDepCode AS DepCode
  66. , '{0}' as WorkPoint
  67. INTO #TempPickAssem
  68. FROM {1}.dbo.AssemVouchs a
  69. INNER JOIN {1}.dbo.AssemVouch b ON a.ID = b.ID
  70. LEFT JOIN {1}.dbo.Inventory e ON a.cInvCode = e.cInvCode
  71. WHERE ISNULL(b.cVerifyPerson,'')='' AND b.cVouchType='14'
  72. AND ISNULL(b.dnmodifytime, b.dnmaketime)>=@LastTime
  73. IF NOT EXISTS(SELECT * FROM #TempPickAssem)
  74. RETURN";
  75. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPickAssem");
  76. sql += @"--删除数据
  77. -- DELETE ICSAssemVouchs WHERE Did NOT IN (SELECT autoID FROM {1}.dbo.AssemVouchs ) AND LEN(Did)>0
  78. SELECT a.Did INTO #tableICSAssemVouchs
  79. FROM ICSAssemVouchs a With(NoLock)
  80. LEFT JOIN {1}.dbo.[AssemVouchs] b With(NoLock) ON a.Did=b.autoID
  81. WHERE a.WorkPoint='{0}' and b.autoID IS NULL AND LEN(a.Did)>0
  82. DELETE ICSAssemVouchs
  83. WHERE WorkPoint='{0}' and Did IN ( SELECT Did from #tableICSAssemVouchs)
  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("cAccPCode", "a.cAccPCode");
  89. values.Add("InvCode", "a.InvCode");
  90. values.Add("Quantity", "a.Quantity");
  91. values.Add("WHCode", "a.WHCode");
  92. values.Add("VoucherDate", "a.VoucherDate");
  93. values.Add("MTIME", "a.MTIME");
  94. values.Add("EATTRIBUTE", "a.EATTRIBUTE");
  95. values.Add("MUSER", "a.MUSER");
  96. values.Add("MUSERName", "a.MUSERName");
  97. values.Add("VouchType", "a.VouchType");
  98. values.Add("ORDERNO", "a.ORDERNO");
  99. //values.Add("WorkPoint", "a.WorkPoint");
  100. values.Add("cBatch", "a.cBatch");
  101. values.Add("DepCode", "a.DepCode");
  102. //更新存在数据
  103. sql += ICSHelper.UpdateSQL("b", values)
  104. + @" #TempPickAssem a
  105. INNER JOIN ICSAssemVouchs b ON a.Did=b.Did and a.WorkPoint=b.WorkPoint
  106. WHERE a.WorkPoint='" + WorkPoint + "' ";
  107. values.Add("ID", "NEWID()");
  108. values.Add("HasQuantity", "'0'");
  109. values.Add("Did", "a.Did");
  110. values.Add("WorkPoint", "'" + WorkPoint + "'");
  111. //插入新增数据
  112. sql += ICSHelper.InsertSQL("ICSAssemVouchs", values)
  113. + @" #TempPickAssem a
  114. LEFT JOIN ICSAssemVouchs b ON a.Did=b.Did and a.WorkPoint=b.WorkPoint
  115. WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  116. sql += " DROP TABLE #TempPickAssem " +
  117. " DROP TABLE #tableICSAssemVouchs";
  118. sql = string.Format(sql, WorkPoint, erpName);
  119. ICSHelper.ExecuteDate(conStr, sql);
  120. #endregion
  121. }
  122. }
  123. catch (Exception ex)
  124. {
  125. log.Error(ex.ToString());
  126. }
  127. }
  128. }
  129. }