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

162 lines
8.2 KiB

2 years ago
2 years ago
2 years ago
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 ICSVendor : 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
  49. A40.Code AS cVenCode ,
  50. NEWID() AS ID,
  51. A41.Name AS cVenName ,
  52. A40.ShortName AS cVenAbbName ,
  53. A44.Code AS cVCCode ,
  54. A45.Name AS cVCName ,
  55. '' AS cVenAddress ,
  56. '' AS cVenRegCode ,
  57. '' AS cVenBank ,
  58. '' AS cVenAccount ,
  59. '' AS dVenDevDate ,
  60. '' AS cVenLPerson ,
  61. '' AS cVenPhone ,
  62. '' AS cVenEmail ,
  63. '' AS cVenPerson ,
  64. '' AS cVenHand ,
  65. 1 AS iVenDisRate ,
  66. '' AS iVenCreLine ,
  67. '' AS iVenCreDate ,
  68. '' AS cVenPayCond ,
  69. '' AS cPayName ,
  70. A47.Name AS cVenExch_name ,
  71. '' AS Free1 ,
  72. A40.ModifiedOn AS MTIME
  73. ,A42.Code as WorkPoint
  74. INTO #TempVendor
  75. from {1}.dbo.CBO_Supplier A40
  76. LEFT JOIN {1}.dbo.CBO_Supplier_Trl A41 ON ( A40.ID = A41.ID AND A41.SysMLFlag = 'zh-CN')
  77. LEFT JOIN {1}.dbo.[Base_Organization] AS A42 ON ( A40.[Org] = A42.[ID] )
  78. LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS A43 ON ( A42.[ID] = A43.[ID] AND A43.SysMLFlag = 'zh-CN')
  79. LEFT JOIN {1}.dbo.[CBO_SupplierCategory] AS A44 ON (A44.[ID] = A40.[Category])
  80. LEFT JOIN {1}.dbo.[CBO_SupplierCategory_Trl] AS A45 ON (A45.[ID] = A44.[ID] AND A45.SysMLFlag = 'zh-CN')
  81. LEFT JOIN {1}.dbo.[Base_Currency] AS A46 ON (A46.[ID] = A40.[CheckCurrency] )
  82. LEFT JOIN {1}.dbo.[Base_Currency_Trl] AS A47 ON (A47.[ID] = A46.[ID] AND A47.SysMLFlag = 'zh-CN')
  83. where A40.ModifiedOn>=@LastTime AND A42.Code='{0}'
  84. ORDER BY A40.Code
  85. IF NOT EXISTS(SELECT * FROM #TempVendor)
  86. RETURN";
  87. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempVendor");
  88. sql += @"--删除数据
  89. -- DELETE ICSVendor WHERE VenCode NOT IN (SELECT cVenCode FROM {1}.dbo.Vendor)
  90. SELECT a.VenCode INTO #tableICSVendor
  91. FROM ICSVendor a With(NoLock)
  92. LEFT JOIN {1}.dbo.[CBO_Supplier] b With(NoLock) ON a.VenCode=b.Code
  93. WHERE a.WorkPoint='{0}' and b.Code IS NULL
  94. DELETE ICSVendor
  95. WHERE WorkPoint='{0}' and VenCode IN ( SELECT VenCode from #tableICSVendor)
  96. ";
  97. Dictionary<string, string> values = new Dictionary<string, string>();
  98. values.Add("ID", "a.ID");//供应商名称
  99. values.Add("VenName", "a.cVenName");//供应商名称
  100. values.Add("VenAbbName", "a.cVenAbbName");//供应商简称
  101. values.Add("VCCode", "a.cVCCode");//供应商分类代码
  102. values.Add("VCName", "a.cVCName");//供应商分类名称
  103. values.Add("VenAddress", "a.cVenAddress");//地址
  104. values.Add("VenRegCode", "a.cVenRegCode");//纳税人登记号
  105. values.Add("VenBank", "a.cVenBank");//开会银行
  106. values.Add("VenAccount", "a.cVenAccount");//银行账号
  107. values.Add("VenDevDate", "a.dVenDevDate");//发展日期
  108. values.Add("VenLPerson", "a.cVenLPerson");//法人
  109. values.Add("VenPhone", "a.cVenPhone");//电话
  110. values.Add("VenEmail", "a.cVenEmail");//邮件
  111. values.Add("VenPerson", "a.cVenPerson");//联系人
  112. values.Add("VenHand", "a.cVenHand");//手机
  113. values.Add("VenDisRate", "a.iVenDisRate");//扣率
  114. values.Add("VenCreLine", "a.iVenCreLine");//信用额度
  115. values.Add("VenCreDate", "a.iVenCreDate");//信用期限
  116. values.Add("VenPayCond", "a.cVenPayCond");//付款条件编码
  117. values.Add("PayName", "a.cPayName");//付款条件名称
  118. values.Add("VenExch_name", "a.cVenExch_name");//币种
  119. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  120. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  121. values.Add("MTIME", "a.MTIME");
  122. //values.Add("PODetailID", "");//自由项
  123. //更新存在数据
  124. sql += ICSHelper.UpdateSQL("b", values)
  125. + @" #TempVendor a
  126. INNER JOIN ICSVendor b ON a.cVenCode=b.VenCode and a.WorkPoint=b.WorkPoint
  127. WHERE a.WorkPoint='" + WorkPoint + "' ";
  128. values.Add("VenCode", "a.cVenCode");//供应商代码
  129. values.Add("WorkPoint", "'" + WorkPoint + "'");//站点
  130. //插入新增数据
  131. sql += ICSHelper.InsertSQL("ICSVendor", values)
  132. + @" #TempVendor a
  133. LEFT JOIN ICSVendor b ON a.cVenCode=b.VenCode and a.WorkPoint=b.WorkPoint
  134. WHERE b.VenCode IS NULL and a.WorkPoint='" + WorkPoint + @"'
  135. ";
  136. sql += " DROP TABLE #TempVendor" +
  137. " DROP TABLE #tableICSVendor";//删除零时表
  138. sql = string.Format(sql, WorkPoint, erpName);
  139. ICSHelper.ExecuteDate(conStr, sql);
  140. #endregion
  141. }
  142. }
  143. catch (Exception ex)
  144. {
  145. log.Error(ex.ToString());
  146. }
  147. }
  148. }
  149. }