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

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