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

147 lines
7.9 KiB

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