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.
196 lines
11 KiB
196 lines
11 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 ICSOutsourcingReceive : 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 CAST(a.Autoid AS NVARCHAR(50)) AS RCVDetailID,
|
|
b.cCode AS cCode,
|
|
CAST(a.irowno AS NVARCHAR(50)) AS irowno,
|
|
CAST(f.irowno AS NVARCHAR(50)) as SourceSequence,
|
|
isnull(a.iNum,0) as Amount,
|
|
b.cSource as SourceCode,
|
|
'1' as Status,
|
|
b.cMaker as CreatePerson,
|
|
b.dnmaketime as CreateDateTime,
|
|
b.ID as RCVID,
|
|
b.cVenCode AS cVenCode,
|
|
d.cVenName AS cVenName,
|
|
b.cDepCode AS cDepCode,
|
|
c.cDepName AS cDepName,
|
|
b.cWhCode AS cWhCode,
|
|
a.cInvCode AS cInvCode,
|
|
a.iQuantity AS iQuantity,
|
|
ISNULL(b.dnmodifytime, b.dnmaketime) AS MTIME,
|
|
CAST(b.ID AS NVARCHAR(50)) AS ErpID,
|
|
b.cOrderCode AS POCode,
|
|
CAST(e.ivouchrowno AS NVARCHAR(50)) AS iPOsID,
|
|
b.cBusType AS Free1,
|
|
isnull(a.cItemCode,'') as ProjectCode,isnull(a.cbatch,'') cBatch,'' version ,'' brand,
|
|
(case WHEN inv.bFree1=1 THEN a.cFree1 ELSE '' END) as cFree1,
|
|
(case WHEN inv.bFree2=1 THEN a.cFree2 ELSE '' END) as cFree2,
|
|
(case WHEN inv.bFree3=1 THEN a.cFree3 ELSE '' END) as cFree3,
|
|
(case WHEN inv.bFree4=1 THEN a.cFree4 ELSE '' END) as cFree4,
|
|
(case WHEN inv.bFree5=1 THEN a.cFree5 ELSE '' END) as cFree5,
|
|
(case WHEN inv.bFree6=1 THEN a.cFree6 ELSE '' END) as cFree6,
|
|
(case WHEN inv.bFree7=1 THEN a.cFree7 ELSE '' END) as cFree7,
|
|
(case WHEN inv.bFree8=1 THEN a.cFree8 ELSE '' END) as cFree8,
|
|
(case WHEN inv.bFree9=1 THEN a.cFree9 ELSE '' END) as cFree9,
|
|
(case WHEN inv.bFree10=1 THEN a.cFree10 ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
|
|
, '{0}' as WorkPoint
|
|
INTO #TempPOArrive
|
|
FROM {1}.dbo.RdRecords01 a
|
|
INNER JOIN {1}.dbo.RdRecord01 b ON a.ID = b.ID
|
|
LEFT JOIN {1}.dbo.Department c ON b.cDepCode = c.cDepCode
|
|
LEFT JOIN {1}.dbo.Vendor d ON b.cVenCode = d.cVenCode
|
|
LEFT JOIN {1}.dbo.Inventory inv ON a.cInvCode = inv.cInvCode
|
|
LEFT JOIN {1}.dbo.PO_Podetails e ON a.iPOsID = e.ID
|
|
LEFT JOIN {1}.dbo.PU_ArrivalVouchs f on a.iArrsId=f.Autoid
|
|
WHERE ISNULL(b.dnmodifytime, b.dnmaketime)>=@LastTime AND b.cBusType IN ('委外加工') AND a.iQuantity<0 AND ISNULL(b.cHandler, '')=''
|
|
update #TempPOArrive set Colspan=isNULL(ProjectCode,'')+'~'+isNULL(cBatch,'')+'~'+isNULL(Version,'')+'~'+isNULL(Brand,'')+'~'+isNULL(cFree1,'')+'~'+isnull(cFree2,'')+'~'+isnull(cFree3,'')+'~'+isnull(cFree4,'')+'~'+isnull(cFree5,'')+'~'+isnull(cFree6,'')+'~'+isnull(cFree7,'')+'~'+isnull(cFree8,'')+'~'+isnull(cFree9,'')+'~'+isnull(cFree10,'')
|
|
select distinct
|
|
Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
|
|
INTO #TempExtension
|
|
from #TempPOArrive
|
|
IF NOT EXISTS(SELECT * FROM #TempPOArrive)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPOArrive");
|
|
Dictionary<string, string> value = new Dictionary<string, string>();
|
|
value.Add("ID", "NEWID()");
|
|
value.Add("BatchCode", "a.cBatch");
|
|
value.Add("version", "a.version");
|
|
value.Add("brand", "a.brand");
|
|
value.Add("ProjectCode", "a.ProjectCode");
|
|
value.Add("cFree1", "a.cFree1");
|
|
value.Add("cFree2", "a.cFree2");
|
|
value.Add("cFree3", "a.cFree3");
|
|
value.Add("cFree4", "a.cFree4");
|
|
value.Add("cFree5", "a.cFree5");
|
|
value.Add("cFree6", "a.cFree6");
|
|
value.Add("cFree7", "a.cFree7");
|
|
value.Add("cFree8", "a.cFree8");
|
|
value.Add("cFree9", "a.cFree9");
|
|
value.Add("cFree10", "a.cFree10");
|
|
value.Add("Colspan", "a.Colspan");
|
|
value.Add("MTIME", "GETDATE()");
|
|
value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
|
|
value.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
|
|
//插入新增数据->ICSExtension表
|
|
sql += ICSHelper.InsertSQL("ICSExtension", value)
|
|
+ @"#TempExtension a
|
|
LEFT JOIN ICSExtension b ON a.ProjectCode+'~'+a.cBatch+'~'+a.Version+'~'+a.Brand+'~'+a.cFree1+'~'+a.cFree2+'~'+a.cFree3+'~'+a.cFree4+'~'+a.cFree5+'~'+a.cFree6+'~'+a.cFree7+'~'+a.cFree8+'~'+a.cFree9+'~'+a.cFree10=b.Colspan and a.WorkPoint=b.WorkPoint
|
|
WHERE b.Colspan IS NULL";
|
|
sql += "\r\n";
|
|
sql += @"--删除数据
|
|
--DELETE ICSOutsourcingReceive WHERE RCVDetailID NOT IN (SELECT Autoid FROM {1}.dbo.RdRecords01) AND LEN(RCVDetailID)>0
|
|
|
|
SELECT a.RCVDetailID INTO #tableICSOutsourcingReceive
|
|
FROM ICSOutsourcingReceive a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[RdRecords01] b With(NoLock) ON a.RCVDetailID=b.AutoID
|
|
WHERE a.WorkPoint='{0}' and b.AutoID IS NULL AND LEN(a.RCVDetailID)>0
|
|
|
|
DELETE ICSOutsourcingReceive
|
|
WHERE WorkPoint='{0}' and RCVDetailID IN ( SELECT RCVDetailID from #tableICSOutsourcingReceive)
|
|
|
|
";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
values.Add("RCVCode", "a.cCode");//入库单号
|
|
values.Add("Sequence", "a.irowno");//入库单行号
|
|
values.Add("SourceCode", "a.SourceCode");//来源单号
|
|
values.Add("SourceSequence", "a.SourceSequence");//来源单号行号
|
|
values.Add("InvCode", "a.cInvCode");//物料编码
|
|
values.Add("Quantity", "ABS(a.iQuantity)");//入库数量
|
|
values.Add("Amount", "a.Amount");//辅助数量
|
|
values.Add("WHCode", "a.cWhCode");//仓库代码
|
|
values.Add("ExtensionID", "c.ID");
|
|
values.Add("RCVDetailID", "a.RCVDetailID");
|
|
values.Add("RCVID", "a.RCVID");
|
|
values.Add("CreateDateTime", "a.CreateDateTime");
|
|
values.Add("CreatePerson", "a.CreatePerson");
|
|
values.Add("Status", "a.Status");//状态
|
|
values.Add("MTIME", "a.MTIME");
|
|
values.Add("Type", "2");//类型
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("b", values)
|
|
+ @" #TempPOArrive a
|
|
INNER JOIN ICSOutsourcingReceive b ON a.RCVDetailID=b.RCVDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE a.WorkPoint='" + WorkPoint + "' ";
|
|
|
|
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
values.Add("ID", "NewID()");
|
|
values.Add("RCVQuantity", "'0'");
|
|
sql += "\r\n";
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICSOutsourcingReceive", values)
|
|
+ @" #TempPOArrive a
|
|
LEFT JOIN ICSOutsourcingReceive b ON a.RCVDetailID=b.RCVDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE b.RCVID IS NULL and a.WorkPoint='" + WorkPoint + @"'
|
|
";
|
|
sql += "DROP TABLE #TempPOArrive";
|
|
sql += " DROP TABLE #TempExtension " +
|
|
" DROP TABLE #tableICSOutsourcingReceive";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|