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.
180 lines
9.7 KiB
180 lines
9.7 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 ICSBrrow : 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.cCODE as BrrowCode,
|
|
a.cdepcode as DepCode,
|
|
b.cwhcode as WHCode ,
|
|
b.cinvcode as InvCode,
|
|
b.iquantity as Quantity,
|
|
Row_Number() OVER (PARTITION BY cCODE ORDER BY b.cinvcode desc) as Sequence,
|
|
a.iStatus as Status,
|
|
a.cMaker as CreatePerson ,
|
|
a.dmDate as CreateDateTime,
|
|
a.ID as BrrowID,
|
|
b.AutoID as BrrowDetailID,
|
|
ISNULL(a.dCloseDate ,ISNULL(a.dmDate ,a.dVeriDate)) AS MTIME,
|
|
'' ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
|
|
(case WHEN inv.bFree1=1 THEN b.cFree1 ELSE '' END) as cFree1,
|
|
(case WHEN inv.bFree2=1 THEN b.cFree2 ELSE '' END) as cFree2,
|
|
(case WHEN inv.bFree3=1 THEN b.cFree3 ELSE '' END) as cFree3,
|
|
(case WHEN inv.bFree4=1 THEN b.cFree4 ELSE '' END) as cFree4,
|
|
(case WHEN inv.bFree5=1 THEN b.cFree5 ELSE '' END) as cFree5,
|
|
(case WHEN inv.bFree6=1 THEN b.cFree6 ELSE '' END) as cFree6,
|
|
(case WHEN inv.bFree7=1 THEN b.cFree7 ELSE '' END) as cFree7,
|
|
(case WHEN inv.bFree8=1 THEN b.cFree8 ELSE '' END) as cFree8,
|
|
(case WHEN inv.bFree9=1 THEN b.cFree9 ELSE '' END) as cFree9,
|
|
(case WHEN inv.bFree10=1 THEN b.cFree10 ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
|
|
, '{0}' as WorkPoint
|
|
INTO #Brrow
|
|
from {1}.dbo.HY_DZ_BorrowOut a
|
|
inner join {1}.dbo.HY_DZ_BorrowOuts b on a.ID =b.ID
|
|
LEFT JOIN {1}.dbo.Inventory inv ON b.cInvCode = inv.cInvCode
|
|
WHERE ISNULL(a.cHandler, '')<>'' AND a.dVeriDate >=@LastTime
|
|
update #Brrow 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 #Brrow
|
|
IF NOT EXISTS(SELECT * FROM #Brrow)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#Brrow");
|
|
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 += @"--删除数据
|
|
-- DELETE ICSBrrow WHERE BrrowDetailID NOT IN ( SELECT AutoID FROM {1}.dbo.HY_DZ_BorrowOuts)
|
|
SELECT a.BrrowDetailID INTO #tableICSBrrow
|
|
FROM ICSBrrow a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[HY_DZ_BorrowOuts] b With(NoLock) ON a.BrrowDetailID=b.AutoID
|
|
WHERE a.WorkPoint='{0}' and b.AutoID IS NULL
|
|
|
|
DELETE ICSBrrow
|
|
WHERE WorkPoint='{0}' and BrrowDetailID IN ( SELECT BrrowDetailID from #tableICSBrrow)
|
|
|
|
";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
|
|
values.Add("BrrowCode", "a.BrrowCode");
|
|
values.Add("DepCode", "a.DepCode");
|
|
values.Add("WHCode", "a.WHCode");
|
|
values.Add("InvCode", "a.InvCode");
|
|
values.Add("Quantity", "a.Quantity");
|
|
values.Add("Amount", "0");
|
|
values.Add("Sequence", "a.Sequence");
|
|
values.Add("Status", "a.Status ");
|
|
values.Add("CreatePerson", "a.CreatePerson");
|
|
values.Add("CreateDateTime", "a.CreateDateTime");
|
|
values.Add("BrrowID", "a.BrrowID");
|
|
values.Add("BrrowDetailID", "a.BrrowDetailID");
|
|
values.Add("ExtensionID", "c.ID");
|
|
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
values.Add("MTIME", "a.MTIME");
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("ICSBrrow", values)
|
|
+ @" #Brrow a
|
|
INNER JOIN ICSBrrow b ON a.BrrowDetailID=b.BrrowDetailID 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("ID", "NEWID()");
|
|
values.Add("BrrowQuantity", "0");
|
|
//values.Add("ErpAutoID", "a.ErpAutoID");
|
|
//values.Add("ErpID", "a.ErpID");
|
|
//values.Add("iFQuantity", "a.iFQuantity");
|
|
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICSBrrow", values)
|
|
+ @" #Brrow a
|
|
LEFT JOIN ICSBrrow b ON a.BrrowDetailID=b.BrrowDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE b.BrrowDetailID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
|
|
|
|
sql += "DROP TABLE #Brrow ";
|
|
sql += " DROP TABLE #TempExtension " +
|
|
" DROP TABLE #tableICSBrrow ";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|