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

144 lines
6.5 KiB

  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 ICSSO : 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
  48. a.ID as SOID,
  49. a.iSOsID as iSOsID,
  50. b.cSOCode as cSOCode,
  51. a.iRowNo as iRowNo,
  52. b.dDate as dDate,
  53. b.cCusCode as cCusCode,
  54. b.cCusName as cCusName,
  55. b.cDepCode as cDepCode,
  56. b.cPersonCode as cPersonCode,
  57. b.cCusOAddress as cCusOAddress,
  58. b.cCrmPersonCode as cCrmPersonCode,
  59. b.cDefine10 as contract,
  60. a.cInvCode as cInvCode,
  61. a.iQuantity as iQuantity,
  62. ISNULL(b.dmodifysystime, b.dcreatesystime) as MTime,
  63. 'job' as MUserCode,
  64. e.cCIGUID as Free1,
  65. a.cCusInvCode as cCusInvCode,
  66. a.cCusInvName as cCusInvName
  67. ,'{0}' as WorkPoint
  68. INTO #Temp_SO
  69. FROM {1}.dbo.SO_SODetails a
  70. INNER JOIN {1}.dbo.SO_SOMain b ON a.ID = b.ID
  71. LEFT JOIN {1}.dbo.Inventory c ON a.cInvCode = c.cInvCode
  72. LEFT JOIN {1}.dbo.ComputationUnit d ON c.cComUnitCode = d.cComunitCode
  73. LEFT JOIN {1}.dbo.CusInvContrapose e ON b.cCusCode=e.cCusCode and a.cInvCode=e.cInvCode AND a.cCusInvCode=e.cCusInvCode
  74. WHERE ISNULL(b.dmodifysystime, b.dcreatesystime)>=@LastTime
  75. IF NOT EXISTS(SELECT * FROM #Temp_SO)
  76. RETURN";
  77. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#Temp_SO");
  78. sql += @"--删除数据
  79. -- DELETE ICS_SO WHERE iSOsID NOT IN (SELECT iSOsID FROM {1}.dbo.SO_SODetails) AND LEN(iSOsID)>0
  80. SELECT a.iSOsID INTO #tableICS_SO
  81. FROM ICS_SO a With(NoLock)
  82. LEFT JOIN {1}.dbo.[SO_SODetails] b With(NoLock) ON a.iSOsID=b.iSOsID
  83. WHERE a.WorkPoint='{0}' and b.iSOsID IS NULL AND LEN(a.iSOsID)>0
  84. DELETE ICS_SO
  85. WHERE WorkPoint='{0}' and iSOsID IN ( SELECT iSOsID from #tableICS_SO)
  86. ";
  87. Dictionary<string, string> values = new Dictionary<string, string>();
  88. values.Add("cSOCode", "a.cSOCode");
  89. values.Add("iRowNo", "a.iRowNo");
  90. values.Add("dDate", "a.dDate");
  91. values.Add("cCusCode", "a.cCusCode");
  92. values.Add("cCusName", "a.cCusName");
  93. values.Add("cDepCode", "a.cDepCode");
  94. values.Add("cPersonCode", "a.cPersonCode");
  95. values.Add("cCusOAddress", "a.cCusOAddress");
  96. values.Add("cCrmPersonCode", "a.cCrmPersonCode");
  97. values.Add("contract", "a.contract");
  98. values.Add("cInvCode", "a.cInvCode");
  99. values.Add("iQuantity", "a.iQuantity");
  100. values.Add("MTime", "a.MTIME");
  101. values.Add("cCusInvCode", "a.cCusInvCode");
  102. values.Add("cCusInvName", "a.cCusInvName");
  103. //更新存在数据
  104. sql += ICSHelper.UpdateSQL("b", values)
  105. + @" #Temp_SO a
  106. INNER JOIN ICS_SO b ON a.iSOsID=b.iSOsID and a.WorkPoint=b.WorkPoint
  107. WHERE a.WorkPoint='" + WorkPoint + "' ";
  108. values.Add("SOID", "a.SOID");
  109. values.Add("iSOsID", "a.iSOsID ");
  110. values.Add("Free1", "a.Free1 ");
  111. values.Add("MUserCode", "'" + ConstWorkPoint.Muser + "'");
  112. values.Add("MUserName", "'" + ConstWorkPoint.Musername + "'");
  113. values.Add("WorkPoint", "'" + WorkPoint + "'");
  114. //插入新增数据
  115. sql += ICSHelper.InsertSQL("ICS_SO", values)
  116. + @" #Temp_SO a
  117. LEFT JOIN ICS_SO b ON a.iSOsID=b.iSOsID and a.WorkPoint=b.WorkPoint
  118. WHERE b.iSOsID IS NULL and a.WorkPoint='" + WorkPoint + @"'
  119. ";
  120. sql += " DROP TABLE #Temp_SO" +
  121. " DROP TABLE #tableICS_SO";
  122. sql = string.Format(sql, WorkPoint, erpName);
  123. ICSHelper.ExecuteDate(conStr, sql);
  124. #endregion
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. log.Error(ex.ToString());
  130. }
  131. }
  132. }
  133. }