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

117 lines
5.0 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Quartz;
namespace ICSSoft.FromERP
{
/// <summary>
/// 仓库
/// </summary>
public class ICSWarehouse : 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 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 NEWID() AS Serial ,
cWhCode AS StorageCode ,
cWhName AS StorageName ,
bWhAsset As Asset,
bProxyWh AS Proxy,
bInCost AS InCost,
dModifyDate AS MTIME,
'{0}' as WorkPoint
INTO #TempWarehouse
FROM {1}.dbo.Warehouse
WHERE dWhEndDate IS NULL AND dModifyDate>=@LastTime
ORDER BY cWhCode
IF NOT EXISTS(SELECT * FROM #TempWarehouse)
RETURN";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempWarehouse");
sql += @"--删除数据
-- DELETE ICSWarehouse WHERE WarehouseCode NOT IN (SELECT cWhCode FROM {1}.dbo.Warehouse)
SELECT a.WarehouseCode INTO #tableICSWarehouse
FROM ICSWarehouse a With(NoLock)
LEFT JOIN {1}.dbo.[Warehouse] b With(NoLock) ON a.WarehouseCode=b.cWhCode
WHERE a.WorkPoint='{0}' and b.cWhCode IS NULL
DELETE ICSWarehouse
WHERE WorkPoint='{0}' and WarehouseCode IN ( SELECT WarehouseCode from #tableICSWarehouse)
";
Dictionary<string, string> values = new Dictionary<string, string>();
values.Add("WarehouseName", "a.StorageName");
values.Add("MTIME", "a.MTIME");
//更新存在数据
sql += ICSHelper.UpdateSQL("b", values)
+ @" #TempWarehouse a
INNER JOIN ICSWarehouse b ON a.StorageCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
WHERE a.WorkPoint='" + WorkPoint + "'";
values.Add("WarehouseCode", "a.StorageCode");
values.Add("Enable", "1");
values.Add("BatchEnable", "0");
values.Add("ID", "a.Serial");
values.Add("Asset", "a.Asset");
values.Add("Proxy", "a.Proxy");
values.Add("InCost", "a.InCost");
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
values.Add("WorkPoint", "'" + WorkPoint + "'");
//插入新增数据
sql += ICSHelper.InsertSQL("ICSWarehouse", values)
+ @" #TempWarehouse a
LEFT JOIN ICSWarehouse b ON a.StorageCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
WHERE b.WarehouseCode IS NULL and a.WorkPoint='" + WorkPoint + @"'
";
sql += " DROP TABLE #TempWarehouse " +
" DROP TABLE #tableICSWarehouse";
sql = string.Format(sql, WorkPoint, erpName);
ICSHelper.ExecuteDate(conStr, sql);
#endregion
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}