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.
153 lines
7.2 KiB
153 lines
7.2 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 ICSSDN : 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 b.cDLCode AS DispatchCode,
|
|
CAST(a.irowno AS NVARCHAR(50)) AS DispatchRow,
|
|
ISNULL(d.cSOCode,'') AS SOCode,
|
|
CAST(ISNULL(d.iRowNo,'') AS NVARCHAR(50)) AS SORow,
|
|
b.cCusCode AS CusCode,
|
|
b.cCusName AS CusName,
|
|
CASE WHEN a.iQuantity>=0 THEN '1' ELSE '2' END AS Type,
|
|
a.cInvCode AS InvCode,
|
|
a.cWhCode AS WHCode,
|
|
CASE WHEN a.iQuantity>=0 THEN a.iQuantity ELSE -a.iQuantity END AS Quantity,
|
|
c.cComUnitCode AS ComUnitCode,
|
|
b.dDate AS VoucherDate,
|
|
CASE WHEN ISNULL(b.cVerifier, '')='' THEN '1' ELSE '2' END AS Status,
|
|
CAST(b.DLID AS NVARCHAR(50)) AS Term1,
|
|
CAST(a.AutoID AS NVARCHAR(50)) AS Term2,
|
|
b.cMaker AS MUSER,
|
|
'job' AS MUSERNAME,
|
|
ISNULL(b.dverifysystime,ISNULL(b.dmodifysystime, b.dcreatesystime)) AS MTIME,
|
|
ISNULL(b.dverifysystime,ISNULL(b.dmodifysystime, b.dcreatesystime)) AS ArriveDate,
|
|
ISNULL(a.cBatch,'') AS cBatch,
|
|
'' AS ORDERNO
|
|
,'{0}' as WorkPoint
|
|
INTO #TempSO
|
|
FROM {1}.dbo.DispatchLists a
|
|
INNER JOIN {1}.dbo.DispatchList b ON a.DLID = b.DLID
|
|
LEFT JOIN {1}.dbo.Inventory c ON a.cInvCode = c.cInvCode
|
|
LEFT JOIN {1}.dbo.SO_SODetails d ON a.iSOsID = d.iSOsID
|
|
LEFT JOIN {1}.dbo.ComputationUnit e ON c.cComUnitCode = e.cComunitCode
|
|
WHERE ISNULL(b.cVerifier, '')!='' AND ISNULL(b.cCloser, '')='' AND ISNULL(b.dverifysystime,ISNULL(b.dmodifysystime, b.dcreatesystime))>=@LastTime
|
|
|
|
|
|
IF NOT EXISTS(SELECT * FROM #TempSO)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempSO");
|
|
|
|
sql += @"--删除数据
|
|
--DELETE ICSSDN WHERE Term2 NOT IN (SELECT AutoID FROM {1}.dbo.DispatchLists) AND LEN(Term2)>0
|
|
|
|
SELECT a.Term2 INTO #tableICSSDN
|
|
FROM ICSSDN a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[DispatchLists] b With(NoLock) ON a.Term2=b.AutoID
|
|
WHERE a.WorkPoint='{0}' and b.AutoID IS NULL AND LEN(a.Term2)>0
|
|
|
|
DELETE ICSSDN
|
|
WHERE WorkPoint='{0}' and Term2 IN ( SELECT Term2 from #tableICSSDN)
|
|
";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
values.Add("SDNCode", "a.DispatchCode");
|
|
values.Add("Sequence", "a.DispatchRow");
|
|
values.Add("SOCode", "a.SOCode");
|
|
values.Add("SORow", "a.SORow");
|
|
values.Add("CusCode", "a.CusCode");
|
|
values.Add("CusName", "a.CusName");
|
|
values.Add("Type", "a.Type");
|
|
values.Add("ArriveDate", "");
|
|
|
|
values.Add("InvCode", "a.InvCode");
|
|
values.Add("WHCode", "a.WHCode");
|
|
values.Add("Quantity", "a.Quantity");
|
|
|
|
values.Add("ComUnitCode", "a.ComUnitCode");
|
|
values.Add("VoucherDate", "a.VoucherDate");
|
|
values.Add("Status", "a.Status");
|
|
values.Add("MTIME", "a.MTIME");
|
|
values.Add("ArriveDate", "a.ArriveDate");
|
|
values.Add("cBatch", "a.cBatch");
|
|
values.Add("ORDERNO", "a.ORDERNO");
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("b", values)
|
|
+ @" #TempSO a
|
|
INNER JOIN ICSSDN b ON a.Term2=b.Term2 and a.WorkPoint=b.WorkPoint
|
|
WHERE a.WorkPoint='" + WorkPoint + "' ";
|
|
|
|
values.Add("Term1", "a.Term1");
|
|
values.Add("Term2", "a.Term2");
|
|
values.Add("LotNo", "''");
|
|
values.Add("Sign", "''");
|
|
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
values.Add("MUSERNAME", "'" + ConstWorkPoint.Musername + "'");
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICSSDN", values)
|
|
+ @" #TempSO a
|
|
LEFT JOIN ICSSDN b ON a.Term2=b.Term2 and a.WorkPoint=b.WorkPoint
|
|
WHERE b.Term2 IS NULL and a.WorkPoint='" + WorkPoint + @"'
|
|
";
|
|
sql += " DROP TABLE #TempSO " +
|
|
" DROP TABLE #tableICSSDN";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|