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.
144 lines
6.5 KiB
144 lines
6.5 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 ICSSO : 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
|
|
a.ID as SOID,
|
|
a.iSOsID as iSOsID,
|
|
b.cSOCode as cSOCode,
|
|
a.iRowNo as iRowNo,
|
|
b.dDate as dDate,
|
|
b.cCusCode as cCusCode,
|
|
b.cCusName as cCusName,
|
|
b.cDepCode as cDepCode,
|
|
b.cPersonCode as cPersonCode,
|
|
b.cCusOAddress as cCusOAddress,
|
|
b.cCrmPersonCode as cCrmPersonCode,
|
|
b.cDefine10 as contract,
|
|
a.cInvCode as cInvCode,
|
|
a.iQuantity as iQuantity,
|
|
ISNULL(b.dmodifysystime, b.dcreatesystime) as MTime,
|
|
'job' as MUserCode,
|
|
e.cCIGUID as Free1,
|
|
a.cCusInvCode as cCusInvCode,
|
|
a.cCusInvName as cCusInvName
|
|
,'{0}' as WorkPoint
|
|
INTO #Temp_SO
|
|
FROM {1}.dbo.SO_SODetails a
|
|
INNER JOIN {1}.dbo.SO_SOMain b ON a.ID = b.ID
|
|
LEFT JOIN {1}.dbo.Inventory c ON a.cInvCode = c.cInvCode
|
|
LEFT JOIN {1}.dbo.ComputationUnit d ON c.cComUnitCode = d.cComunitCode
|
|
LEFT JOIN {1}.dbo.CusInvContrapose e ON b.cCusCode=e.cCusCode and a.cInvCode=e.cInvCode AND a.cCusInvCode=e.cCusInvCode
|
|
WHERE ISNULL(b.dmodifysystime, b.dcreatesystime)>=@LastTime
|
|
|
|
IF NOT EXISTS(SELECT * FROM #Temp_SO)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#Temp_SO");
|
|
|
|
sql += @"--删除数据
|
|
-- DELETE ICS_SO WHERE iSOsID NOT IN (SELECT iSOsID FROM {1}.dbo.SO_SODetails) AND LEN(iSOsID)>0
|
|
|
|
SELECT a.iSOsID INTO #tableICS_SO
|
|
FROM ICS_SO a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[SO_SODetails] b With(NoLock) ON a.iSOsID=b.iSOsID
|
|
WHERE a.WorkPoint='{0}' and b.iSOsID IS NULL AND LEN(a.iSOsID)>0
|
|
|
|
DELETE ICS_SO
|
|
WHERE WorkPoint='{0}' and iSOsID IN ( SELECT iSOsID from #tableICS_SO)
|
|
";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
values.Add("cSOCode", "a.cSOCode");
|
|
values.Add("iRowNo", "a.iRowNo");
|
|
values.Add("dDate", "a.dDate");
|
|
values.Add("cCusCode", "a.cCusCode");
|
|
values.Add("cCusName", "a.cCusName");
|
|
values.Add("cDepCode", "a.cDepCode");
|
|
values.Add("cPersonCode", "a.cPersonCode");
|
|
values.Add("cCusOAddress", "a.cCusOAddress");
|
|
values.Add("cCrmPersonCode", "a.cCrmPersonCode");
|
|
values.Add("contract", "a.contract");
|
|
values.Add("cInvCode", "a.cInvCode");
|
|
values.Add("iQuantity", "a.iQuantity");
|
|
values.Add("MTime", "a.MTIME");
|
|
values.Add("cCusInvCode", "a.cCusInvCode");
|
|
values.Add("cCusInvName", "a.cCusInvName");
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("b", values)
|
|
+ @" #Temp_SO a
|
|
INNER JOIN ICS_SO b ON a.iSOsID=b.iSOsID and a.WorkPoint=b.WorkPoint
|
|
WHERE a.WorkPoint='" + WorkPoint + "' ";
|
|
values.Add("SOID", "a.SOID");
|
|
values.Add("iSOsID", "a.iSOsID ");
|
|
values.Add("Free1", "a.Free1 ");
|
|
values.Add("MUserCode", "'" + ConstWorkPoint.Muser + "'");
|
|
values.Add("MUserName", "'" + ConstWorkPoint.Musername + "'");
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICS_SO", values)
|
|
+ @" #Temp_SO a
|
|
LEFT JOIN ICS_SO b ON a.iSOsID=b.iSOsID and a.WorkPoint=b.WorkPoint
|
|
WHERE b.iSOsID IS NULL and a.WorkPoint='" + WorkPoint + @"'
|
|
";
|
|
sql += " DROP TABLE #Temp_SO" +
|
|
" DROP TABLE #tableICS_SO";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|