using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using System.Data;
namespace ICSSoft.FromERP
{
///
/// 供应商
///
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
a.cVenCode AS cVenCode ,
NEWID() AS ID,
a.cVenName AS cVenName ,
a.cVenAbbName AS cVenAbbName ,
a.cVCCode AS cVCCode ,
b.cVCName AS cVCName ,
a.cVenAddress AS cVenAddress ,
a.cVenRegCode AS cVenRegCode ,
a.cVenBank AS cVenBank ,
a.cVenAccount AS cVenAccount ,
a.dVenDevDate AS dVenDevDate ,
a.cVenLPerson AS cVenLPerson ,
a.cVenPhone AS cVenPhone ,
a.cVenEmail AS cVenEmail ,
a.cVenPerson AS cVenPerson ,
a.cVenHand AS cVenHand ,
a.iVenDisRate AS iVenDisRate ,
a.iVenCreLine AS iVenCreLine ,
a.iVenCreDate AS iVenCreDate ,
a.cVenPayCond AS cVenPayCond ,
c.cPayName AS cPayName ,
a.cVenExch_name AS cVenExch_name ,
CONVERT(NVARCHAR(50),a.dModifyDate,21) AS Free1 ,
a.dModifyDate AS MTIME
,'{0}' as WorkPoint
INTO #TempVendor
from {1}.dbo.Vendor a
LEFT JOIN {1}.dbo.VendorClass b ON a.cVCCode = b.cVCCode
LEFT JOIN {1}.dbo.PayCondition c ON a.cVenPayCond = c.cPayCode
where a.dModifyDate>=@LastTime
ORDER BY a.cVenCode
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.[Vendor] b With(NoLock) ON a.VenCode=b.cVenCode
WHERE a.WorkPoint='{0}' and b.cVenCode IS NULL
DELETE ICSVendor
WHERE WorkPoint='{0}' and VenCode IN ( SELECT VenCode from #tableICSVendor)
";
Dictionary values = new Dictionary();
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());
}
}
}
}