|
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Quartz;
using System.Data;
namespace ICSSoft.FromERP { /// <summary>
/// 供应商
/// </summary>
public class ICSVendor : IJob { private static object key = new object(); private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public void Execute(IJobExecutionContext context) { try { lock (key) { log.Info("开始……………………………………………………………………"); Execute(); log.Info("结束……………………………………………………………………"); } } catch (Exception ex) { log.Error(ex.ToString()); } }
public void Execute() { try {
//string conERPStr = ICSHelper.GetERPConnectString();
string conStr = ICSHelper.GetConnectString(); string Namespace = this.GetType().Namespace; //string Class = this.GetType().Name;
DataTable dt = ICSHelper.GetERPDB(conStr); foreach (DataRow dr in dt.Rows) { string erpName = ICSHelper.GetConfigString()["ERPDB"]; string WorkPoint = dr["WorkPointCode"].ToString(); string Class = this.GetType().Name + WorkPoint; erpName = string.Format(erpName, WorkPoint);
#region SQL
string sql = @"select
A40.Code AS cVenCode , NEWID() AS ID, A41.Name AS cVenName , A40.ShortName AS cVenAbbName , A44.Code AS cVCCode , A45.Name AS cVCName , '' AS cVenAddress , '' AS cVenRegCode , '' AS cVenBank , '' AS cVenAccount , '' AS dVenDevDate , '' AS cVenLPerson , '' AS cVenPhone , '' AS cVenEmail , '' AS cVenPerson , '' AS cVenHand , 1 AS iVenDisRate , '' AS iVenCreLine , '' AS iVenCreDate , '' AS cVenPayCond , '' AS cPayName , A47.Name AS cVenExch_name , '' AS Free1 , A40.ModifiedOn AS MTIME ,A42.Code as WorkPoint INTO #TempVendor from {1}.dbo.CBO_Supplier A40 LEFT JOIN {1}.dbo.CBO_Supplier_Trl A41 ON ( A40.ID = A41.ID AND A41.SysMLFlag = 'zh-CN') LEFT JOIN {1}.dbo.[Base_Organization] AS A42 ON ( A40.[Org] = A42.[ID] ) LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS A43 ON ( A42.[ID] = A43.[ID] AND A43.SysMLFlag = 'zh-CN') LEFT JOIN {1}.dbo.[CBO_SupplierCategory] AS A44 ON (A44.[ID] = A40.[Category]) LEFT JOIN {1}.dbo.[CBO_SupplierCategory_Trl] AS A45 ON (A45.[ID] = A44.[ID] AND A45.SysMLFlag = 'zh-CN') LEFT JOIN {1}.dbo.[Base_Currency] AS A46 ON (A46.[ID] = A40.[CheckCurrency] ) LEFT JOIN {1}.dbo.[Base_Currency_Trl] AS A47 ON (A47.[ID] = A46.[ID] AND A47.SysMLFlag = 'zh-CN') where A40.ModifiedOn>=@LastTime AND A42.Code='{0}' ORDER BY A40.Code
IF NOT EXISTS(SELECT * FROM #TempVendor) RETURN";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempVendor");
sql += @"--删除数据
-- DELETE ICSVendor WHERE VenCode NOT IN (SELECT cVenCode FROM {1}.dbo.Vendor)
SELECT a.VenCode INTO #tableICSVendor FROM ICSVendor a With(NoLock) LEFT JOIN {1}.dbo.[CBO_Supplier] b With(NoLock) ON a.VenCode=b.Code WHERE a.WorkPoint='{0}' and b.Code IS NULL
DELETE ICSVendor WHERE WorkPoint='{0}' and VenCode IN ( SELECT VenCode from #tableICSVendor)
";
Dictionary<string, string> values = new Dictionary<string, string>(); values.Add("ID", "a.ID");//供应商名称
values.Add("VenName", "a.cVenName");//供应商名称
values.Add("VenAbbName", "a.cVenAbbName");//供应商简称
values.Add("VCCode", "a.cVCCode");//供应商分类代码
values.Add("VCName", "a.cVCName");//供应商分类名称
values.Add("VenAddress", "a.cVenAddress");//地址
values.Add("VenRegCode", "a.cVenRegCode");//纳税人登记号
values.Add("VenBank", "a.cVenBank");//开会银行
values.Add("VenAccount", "a.cVenAccount");//银行账号
values.Add("VenDevDate", "a.dVenDevDate");//发展日期
values.Add("VenLPerson", "a.cVenLPerson");//法人
values.Add("VenPhone", "a.cVenPhone");//电话
values.Add("VenEmail", "a.cVenEmail");//邮件
values.Add("VenPerson", "a.cVenPerson");//联系人
values.Add("VenHand", "a.cVenHand");//手机
values.Add("VenDisRate", "a.iVenDisRate");//扣率
values.Add("VenCreLine", "a.iVenCreLine");//信用额度
values.Add("VenCreDate", "a.iVenCreDate");//信用期限
values.Add("VenPayCond", "a.cVenPayCond");//付款条件编码
values.Add("PayName", "a.cPayName");//付款条件名称
values.Add("VenExch_name", "a.cVenExch_name");//币种
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'"); values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'"); values.Add("MTIME", "a.MTIME"); //values.Add("PODetailID", "");//自由项
//更新存在数据
sql += ICSHelper.UpdateSQL("b", values) + @" #TempVendor a
INNER JOIN ICSVendor b ON a.cVenCode=b.VenCode and a.WorkPoint=b.WorkPoint WHERE a.WorkPoint='" + WorkPoint + "' ";
values.Add("VenCode", "a.cVenCode");//供应商代码
values.Add("WorkPoint", "'" + WorkPoint + "'");//站点
//插入新增数据
sql += ICSHelper.InsertSQL("ICSVendor", values) + @" #TempVendor a
LEFT JOIN ICSVendor b ON a.cVenCode=b.VenCode and a.WorkPoint=b.WorkPoint WHERE b.VenCode IS NULL and a.WorkPoint='" + WorkPoint + @"' ";
sql += " DROP TABLE #TempVendor" + " DROP TABLE #tableICSVendor";//删除零时表
sql = string.Format(sql, WorkPoint, erpName); ICSHelper.ExecuteDate(conStr, sql); #endregion
} } catch (Exception ex) { log.Error(ex.ToString()); } } } }
|