|
|
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using Quartz;
namespace ICSSoft.FromERP { /// <summary>
/// 其他出库
/// </summary>
public class ICSOtherOut : 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(A2.ID AS NVARCHAR(50)) AS OutDetailID, CAST(A1.ID AS NVARCHAR(50)) AS OutID, '' as TransferID, '' as TransferDetailID, A1.DocNo AS OutCode, A1.BusinessDate AS VoucherDate, A3.Code AS cWhCode, CAST(A2.DocLineNo AS NVARCHAR(50)) AS Sequence, A2.ItemInfo_ItemCode AS InvCode, A2.StoreUOMQty AS iQuantity, 0 as Amount, '1' AS Status, A1.CreatedBy as CreatePerson, A1.CreatedOn as CreateDateTime, ISNULL(A2.LotInfo_LotCode,'') AS cBatch, '出' AS TransType, ISNULL(A2.ModifiedOn ,A2.CreatedOn) AS MTIME, isnull(A5.Code,'') ProjectCode, '' version ,'' brand, '' as cFree1, '' as cFree2, '' as cFree3, '' as cFree4, '' as cFree5, '' as cFree6, '' as cFree7, '' as cFree8, '' as cFree9, '' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan ,A4.Code as WorkPoint INTO #TempPick FROM {0}.dbo.InvDoc_MiscShip A1 LEFT JOIN {0}.dbo.InvDoc_MiscShipL A2 ON A2.MiscShip=A1.ID LEFT JOIN {0}.dbo.CBO_Wh A3 ON A2.Wh=A3.ID LEFT JOIN {0}.dbo.Base_Organization A4 ON A1.Org=a4.ID LEFT JOIN {0}.dbo.CBO_Project A5 ON A2.Project=A5.ID WHERE A1.Status<2 AND ISNULL(A2.ModifiedOn ,A2.CreatedOn)>=@LastTime
update #TempPick 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 #TempPick IF NOT EXISTS(SELECT * FROM #TempPick) RETURN";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPick"); 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 ICSOtherOut WHERE OutDetailID NOT IN ( SELECT AutoID FROM {1}.dbo.rdrecords09)
SELECT a.OutDetailID INTO #tableICSOtherOut FROM ICSOtherOut a With(NoLock) LEFT JOIN {1}.dbo.[InvDoc_MiscShipL] b With(NoLock) ON a.OutDetailID= b.ID WHERE a.WorkPoint='{0}' and b.ID IS NULL
DELETE ICSOtherOut WHERE WorkPoint='{0}' and OutDetailID IN ( SELECT OutDetailID from #tableICSOtherOut)
";
Dictionary<string, string> values = new Dictionary<string, string>();
values.Add("OutCode", "a.OutCode"); values.Add("WHCode", "a.cWhCode"); values.Add("Sequence", "a.Sequence"); values.Add("InvCode", "a.InvCode"); values.Add("Quantity", "a.iQuantity"); values.Add("Amount", "a.Amount"); values.Add("Status", "a.Status"); values.Add("CreatePerson", "a.CreatePerson "); values.Add("CreateDateTime", "a.CreateDateTime"); values.Add("OutID", "a.OutID"); values.Add("OutDetailID", "a.OutDetailID"); values.Add("TransferID", "a.TransferID"); values.Add("TransferDetailID", "a.TransferDetailID"); 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("ICSOtherOut", values) + @" #TempPick a
INNER JOIN ICSOtherOut b ON a.OutDetailID=b.OutDetailID 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("OutQuantity", "0"); //values.Add("ErpAutoID", "a.ErpAutoID");
//values.Add("ErpID", "a.ErpID");
//values.Add("iFQuantity", "a.iFQuantity");
//插入新增数据
sql += ICSHelper.InsertSQL("ICSOtherOut", values) + @" #TempPick a
LEFT JOIN ICSOtherOut b ON a.OutDetailID=b.OutDetailID and a.WorkPoint=b.WorkPoint inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint WHERE b.OutID IS NULL and a.WorkPoint='" + WorkPoint + @"' ";
sql += "DROP TABLE #TempPick"; sql += " DROP TABLE #TempExtension " + " DROP TABLE #tableICSOtherOut"; sql = string.Format(sql, WorkPoint, erpName); ICSHelper.ExecuteDate(conStr, sql); #endregion
} } catch (Exception ex) { log.Error(ex.ToString()); } } } }
|