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.

119 lines
5.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 ICSWarehouse : 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 A.ID AS Serial ,
  48. A.Code AS StorageCode ,
  49. B.Name AS StorageName ,
  50. CAST(A.IsLot AS VARCHAR) AS BatchEnable,
  51. 0 As Asset,
  52. 0 AS Proxy,
  53. 0 AS InCost,
  54. ISNULL(A.CreatedOn,A.ModifiedOn) AS MTIME,
  55. C.Code AS WorkPoint
  56. INTO #TempWarehouse
  57. FROM {1}.dbo.[CBO_Wh] A
  58. LEFT JOIN {1}.dbo.[CBO_Wh_Trl] AS B ON B.ID = A.ID AND B.SysMLFlag = 'zh-CN'
  59. LEFT JOIN {1}.dbo.Base_Organization C ON A.Org=C.ID
  60. WHERE C.Code='{0}' AND ISNULL(A.CreatedOn,A.ModifiedOn)>=@LastTime
  61. ORDER BY A.Code
  62. IF NOT EXISTS(SELECT * FROM #TempWarehouse)
  63. RETURN";
  64. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempWarehouse");
  65. sql += @"--删除数据
  66. -- DELETE ICSWarehouse WHERE WarehouseCode NOT IN (SELECT cWhCode FROM {1}.dbo.CBO_Wh)
  67. SELECT a.WarehouseCode INTO #tableICSWarehouse
  68. FROM ICSWarehouse a With(NoLock)
  69. LEFT JOIN {1}.dbo.[CBO_Wh] b With(NoLock) ON a.ID=b.ID
  70. WHERE a.WorkPoint='{0}' and b.ID IS NULL
  71. DELETE ICSWarehouse
  72. WHERE WorkPoint='{0}' and WarehouseCode IN ( SELECT WarehouseCode from #tableICSWarehouse)";
  73. Dictionary<string, string> values = new Dictionary<string, string>();
  74. values.Add("WarehouseName", "a.StorageName");
  75. values.Add("MTIME", "a.MTIME");
  76. //更新存在数据
  77. sql += ICSHelper.UpdateSQL("b", values)
  78. + @" #TempWarehouse a
  79. INNER JOIN ICSWarehouse b ON a.StorageCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  80. WHERE a.WorkPoint='" + WorkPoint + "'";
  81. values.Add("WarehouseCode", "a.StorageCode");
  82. values.Add("Enable", "1");
  83. values.Add("BatchEnable", "a.BatchEnable");
  84. values.Add("ID", "a.Serial");
  85. values.Add("Asset", "a.Asset");
  86. values.Add("Proxy", "a.Proxy");
  87. values.Add("InCost", "a.InCost");
  88. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  89. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  90. values.Add("WorkPoint", "'" + WorkPoint + "'");
  91. //插入新增数据
  92. sql += ICSHelper.InsertSQL("ICSWarehouse", values)
  93. + @" #TempWarehouse a
  94. LEFT JOIN ICSWarehouse b ON a.StorageCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  95. WHERE b.WarehouseCode IS NULL and a.WorkPoint='" + WorkPoint + @"'
  96. ";
  97. sql += " DROP TABLE #TempWarehouse " +
  98. " DROP TABLE #tableICSWarehouse";
  99. sql = string.Format(sql, WorkPoint, erpName);
  100. ICSHelper.ExecuteDate(conStr, sql);
  101. #endregion
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. log.Error(ex.ToString());
  107. }
  108. }
  109. }
  110. }