纽威
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.

148 lines
7.9 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Quartz;
  6. using System.Data;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 物料
  11. /// </summary>
  12. public class ICSInventory : 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 conERPStr = ICSHelper.GetERPConnectString();
  37. string conStr = ICSHelper.GetConnectString();
  38. string Namespace = this.GetType().Namespace;
  39. //string Class = this.GetType().Name;
  40. DataTable dt = ICSHelper.GetERPDB(conStr);
  41. foreach (DataRow dr in dt.Rows)
  42. {
  43. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  44. string WorkPoint = dr["WorkPointCode"].ToString();
  45. string Class = this.GetType().Name + WorkPoint;
  46. erpName = string.Format(erpName, WorkPoint);
  47. #region SQL
  48. string sql = @"select A.ID AS ID,
  49. A.Code AS INVCODE,
  50. dbo.GetReplaceStr(A.Name) AS INVNAME,
  51. dbo.GetReplaceStr(A.SPECS) AS INVSTD,
  52. B.Description AS INVDESC,
  53. D.Name AS InvUnit,
  54. G.Code as ClassCode,
  55. H.Name as ClassName,
  56. 1 as InvRate,
  57. 1 as EffectiveDays,
  58. ISNULL(CONVERT(NVARCHAR(50),A.ModifiedOn,21),'') as MTIME,
  59. K.Code as WorkPoint
  60. INTO #TempINV
  61. from {1}.dbo.[CBO_ItemMaster] AS A
  62. LEFT JOIN {1}.dbo.[CBO_ItemMaster_Trl] AS B ON ( A.[ID] = B.[ID] AND B.SysMLFlag='zh-CN')
  63. LEFT JOIN {1}.dbo.[Base_UOM] AS C ON ( A.[CostUOM] = C.[ID] )
  64. LEFT JOIN {1}.dbo.[Base_UOM_Trl] AS D ON ( C.[ID] = D.[ID] AND D.SysMLFlag='zh-CN')
  65. LEFT JOIN {1}.dbo.[Base_UOM] AS E ON ( A.[InventoryUOM] = E.[ID] )
  66. LEFT JOIN {1}.dbo.[Base_UOM_Trl] AS F ON ( E.[ID] = F.[ID] AND F.SysMLFlag='zh-CN')
  67. LEFT JOIN {1}.dbo.[CBO_Category] AS G ON ( A.[MainItemCategory] = G.[ID] )
  68. LEFT JOIN {1}.dbo.[CBO_Category_Trl] AS H ON ( G.[ID] = H.[ID] AND H.SysMLFlag='zh-CN')
  69. LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A.[Org] = I.[ID] )
  70. LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN')
  71. LEFT JOIN {1}.dbo.Base_Organization K ON A.Org=K.ID
  72. LEFT JOIN {1}.dbo.CBO_InventoryInfo L on A.id=L.ItemMaster
  73. LEFT JOIN {1}.dbo.CBO_Wh M on L.warehouse=M.id and A.org=M.org
  74. LEFT JOIN {1}.dbo.Base_DefineValue N ON N.Code=A.DescFlexField_PrivateDescSeg5 AND N.ValueSetDef='1002204070000769'
  75. LEFT JOIN {1}.dbo.Base_DefineValue_Trl O ON O.ID=N.ID
  76. LEFT JOIN {1}.dbo.CBO_Category_Trl P ON P.ID=A.MainItemCategory
  77. LEFT JOIN {1}.dbo.CBO_MfgInfo Q ON Q.ItemMaster=A.ID
  78. where A.ModifiedOn>=@LastTime AND K.Code='{0}'
  79. ORDER BY A.Code
  80. IF NOT EXISTS(SELECT * FROM #TempINV)
  81. RETURN";
  82. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempINV");
  83. sql += @"--删除数据
  84. -- DELETE ICSINVENTORY WHERE InvCode NOT IN (SELECT cInvCode FROM {1}.dbo.[CBO_ItemMaster])
  85. SELECT a.INVCODE INTO #tableICSINVENTORY
  86. FROM ICSINVENTORY a With(NoLock)
  87. LEFT JOIN {1}.dbo.[CBO_ItemMaster] b With(NoLock) ON a.ID=b.ID
  88. WHERE a.WorkPoint='{0}' and b.ID IS NULL
  89. DELETE ICSINVENTORY
  90. WHERE WorkPoint='{0}' and INVCODE IN ( SELECT INVCODE from #tableICSINVENTORY) ";
  91. Dictionary<string, string> values = new Dictionary<string, string>();
  92. values.Add("INVCODE", "a.INVCODE");//物料编号
  93. values.Add("InvName", "a.INVNAME");//物料名称
  94. values.Add("INVDESC", "a.INVDESC");//物料描述
  95. values.Add("InvStd", "a.INVSTD");//规格型号
  96. values.Add("InvUnit", "a.InvUnit");//主计量单位
  97. values.Add("ClassCode", "a.ClassCode");//大类编码
  98. values.Add("ClassName", "a.ClassName");//大类编码
  99. values.Add("InvRate", "a.InvRate");
  100. values.Add("InvVersion", "''");
  101. values.Add("InvBrand", "''");
  102. values.Add("InvIQC", "0");//大类编码
  103. values.Add("InvFQC", "0");//大类编码
  104. values.Add("EffectiveEnable", "0");//大类名称
  105. values.Add("EffectiveDays", "a.EffectiveDays");//大类名称
  106. values.Add("BatchEnable", "0");//大类名称
  107. values.Add("LotEnable", "0");//大类名称
  108. values.Add("PrintEnable", "0");//大类名称
  109. values.Add("MTIME", "a.MTIME");//操作时间
  110. //更新存在数据
  111. sql += ICSHelper.UpdateSQL("b", values)
  112. + @" #TempINV a
  113. INNER JOIN ICSINVENTORY b ON a.INVCODE=b.INVCODE and a.WorkPoint=b.WorkPoint
  114. WHERE a.WorkPoint='" + WorkPoint + "' ";
  115. values.Add("ID", "a.ID");//唯一标识
  116. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");//操作人
  117. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
  118. values.Add("WorkPoint", "'" + WorkPoint + "'");//站点
  119. //插入新增数据
  120. sql += ICSHelper.InsertSQL("ICSINVENTORY", values)
  121. + @" #TempINV a
  122. LEFT JOIN ICSINVENTORY b ON a.INVCODE=b.INVCODE and a.WorkPoint=b.WorkPoint
  123. WHERE b.INVCODE IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  124. sql += " DROP TABLE #TempINV " +
  125. " DROP TABLE #tableICSINVENTORY ";
  126. sql = string.Format(sql, WorkPoint, erpName);
  127. ICSHelper.ExecuteDate(conStr, sql);
  128. #endregion
  129. }
  130. }
  131. catch (Exception ex)
  132. {
  133. log.Error(ex.ToString());
  134. }
  135. }
  136. }
  137. }