diff --git a/.vs/ICSSoft.FromERP/v14/.suo b/.vs/ICSSoft.FromERP/v14/.suo index e274849..a8549ea 100644 Binary files a/.vs/ICSSoft.FromERP/v14/.suo and b/.vs/ICSSoft.FromERP/v14/.suo differ diff --git a/ICSSoft.FromERP/ICSSoft.FromERP.csproj b/ICSSoft.FromERP/ICSSoft.FromERP.csproj index 8dcaccf..63ed365 100644 --- a/ICSSoft.FromERP/ICSSoft.FromERP.csproj +++ b/ICSSoft.FromERP/ICSSoft.FromERP.csproj @@ -131,6 +131,7 @@ + diff --git a/ICSSoft.FromERP/ICSVendorFromU8.cs b/ICSSoft.FromERP/ICSVendorFromU8.cs new file mode 100644 index 0000000..dde2c3a --- /dev/null +++ b/ICSSoft.FromERP/ICSVendorFromU8.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Quartz; + +using System.Data; + +namespace ICSSoft.FromERP +{ + /// + /// 供应商 + /// + public class ICSVendorFromU8 : 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); + + + string erpNames = ICSHelper.GetConfigString()["Workpoint_ERPDB"]; + List DBS = erpNames.Split(',').ToList(); + List ListDB = new List(); + foreach (string DB in DBS) + { + if (DB.Split('|') != null && DB.Split('|').Count() > 1) + { + WorkpointERPDBLink wd = new WorkpointERPDBLink(); + wd.Workpoint = DB.Split('|')[0]; + wd.ERPDB = DB.Split('|')[1]; + ListDB.Add(wd); + } + } + + + foreach (DataRow dr in dt.Rows) + { + string TenantId = dr["TenantId"].ToString(); + string TenantCode = dr["TenantCode"].ToString(); + string ErpId = dr["ErpID"].ToString(); //erpID + string Class = this.GetType().Name + TenantCode; + + WorkpointERPDBLink dblink = ListDB.FindLast(a => a.Workpoint == TenantCode); + if (dblink == null) + { + return; + } + string erpName = dblink.ERPDB; + + + #region SQL + string sql = @" + + + + select + a.cVenCode AS cVenCode , + NEWID() AS ID, + a.cVenName AS cVenName , + a.cVenAbbName AS cVenAbbName , + a.cVCCode AS cVCCode , + a.cMemo as cMemo, + a.dModifyDate AS MTIME + + 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 + + + + IF NOT EXISTS(SELECT * FROM #TempVendor) + RETURN"; + sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempVendor"); + + sql += @"--删除数据 + + + SELECT a.VendorCode INTO #tableICSVendor + FROM ICSVendor a With(NoLock) + LEFT JOIN {1}.dbo.Vendor B With(NoLock) ON a.VendorCode=b.cVenCode + WHERE a.TenantId='{0}' and b.cVenCode IS NULL + + DELETE ICSVendor + WHERE TenantId='{0}' and VendorCode IN ( SELECT VendorCode from #tableICSVendor) + + "; + + //Id TenantId VendorCode VendorName VendorShortName VendorDesc Memo + //Default1 Default2 Default3 Default4 Default5 + //CreationTime CreatorUserId LastModificationTime LastModifierUserId + ////LastModifierUserName CreatorUserName + + Dictionary values = new Dictionary(); + + values.Add("VendorName", "a.cVenName");//供应商名称 + values.Add("VendorShortName", "a.cVenAbbName");//供应商简称 + values.Add("Memo", "a.cMemo");//供应商分类名称 + values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'"); + values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'"); + values.Add("LastModificationTime", "a.Mtime");//操作时间 + + + + + //更新存在数据 + sql += ICSHelper.UpdateSQL("b", values) + + @" #TempVendor a + INNER JOIN ICSVendor b ON a.cVenCode=b.VendorCode and b.TenantId='{0}' "; + + values.Add("VendorCode", "a.cVenCode");//供应商代码 + values.Add("CreationTime", "a.MTime");//操作人 + values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人 + values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称 + values.Add("TenantId", "'" + TenantId + "'");//站点 + + //插入新增数据 + sql += ICSHelper.InsertSQL("ICSVendor", values) + + @" #TempVendor a + LEFT JOIN ICSVendor b ON a.cVenCode=b.VendorCode and b.TenantId='{0}' + WHERE b.VendorCode IS NULL + "; + sql += " DROP TABLE #TempVendor" + + " DROP TABLE #tableICSVendor";//删除零时表 + sql = string.Format(sql, TenantId, erpName); + ICSHelper.ExecuteDate(conStr, sql); + #endregion + } + } + catch (Exception ex) + { + log.Error(ex.ToString()); + } + } + } +}