|
|
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using Quartz;
namespace ICSSoft.FromERP { /// <summary>
/// 拆卸单
/// </summary>
public class ICSAssemVouchs : 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(b.ID as VARCHAR(50)) AS EATTRIBUTE ,
b.cAVCode AS VouchCode , CAST(a.autoID as VARCHAR(50)) AS Did , CAST(a.irowno as VARCHAR(50)) AS VouchRow , b.dAVDate AS VoucherDate , a.cInvCode AS InvCode , b.cAccPCode , a.iAVQuantity AS Quantity , 0 AS DemandQuantity, ISNULL(a.cWhCode,'') AS WHCode , e.cComUnitCode AS ComUnitCode , CAST(b.iverifystate as VARCHAR(50)) AS Status , b.cMaker AS MUSER , '' AS MUSERName , ISNULL(b.dnmodifytime, b.dnmaketime) AS MTIME , a.bAVType AS VouchType , '' AS ORDERNO , ISNULL(a.cAVBatch,'') AS cBatch, b.cDepCode AS DepCode , '{0}' as WorkPoint INTO #TempPickAssem FROM {1}.dbo.AssemVouchs a INNER JOIN {1}.dbo.AssemVouch b ON a.ID = b.ID LEFT JOIN {1}.dbo.Inventory e ON a.cInvCode = e.cInvCode WHERE ISNULL(b.cVerifyPerson,'')='' AND b.cVouchType='14' AND ISNULL(b.dnmodifytime, b.dnmaketime)>=@LastTime
IF NOT EXISTS(SELECT * FROM #TempPickAssem) RETURN";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPickAssem");
sql += @"--删除数据
-- DELETE ICSAssemVouchs WHERE Did NOT IN (SELECT autoID FROM {1}.dbo.AssemVouchs ) AND LEN(Did)>0
SELECT a.Did INTO #tableICSAssemVouchs FROM ICSAssemVouchs a With(NoLock) LEFT JOIN {1}.dbo.[AssemVouchs] b With(NoLock) ON a.Did=b.autoID WHERE a.WorkPoint='{0}' and b.autoID IS NULL AND LEN(a.Did)>0
DELETE ICSAssemVouchs WHERE WorkPoint='{0}' and Did IN ( SELECT Did from #tableICSAssemVouchs)
";
Dictionary<string, string> values = new Dictionary<string, string>(); values.Add("VouchCode", "a.VouchCode"); values.Add("VouchRow", "a.VouchRow"); values.Add("cAccPCode", "a.cAccPCode"); values.Add("InvCode", "a.InvCode"); values.Add("Quantity", "a.Quantity"); values.Add("WHCode", "a.WHCode"); values.Add("VoucherDate", "a.VoucherDate"); values.Add("MTIME", "a.MTIME"); values.Add("EATTRIBUTE", "a.EATTRIBUTE");
values.Add("MUSER", "a.MUSER"); values.Add("MUSERName", "a.MUSERName");
values.Add("VouchType", "a.VouchType"); values.Add("ORDERNO", "a.ORDERNO"); //values.Add("WorkPoint", "a.WorkPoint");
values.Add("cBatch", "a.cBatch"); values.Add("DepCode", "a.DepCode"); //更新存在数据
sql += ICSHelper.UpdateSQL("b", values) + @" #TempPickAssem a
INNER JOIN ICSAssemVouchs b ON a.Did=b.Did and a.WorkPoint=b.WorkPoint WHERE a.WorkPoint='" + WorkPoint + "' ";
values.Add("ID", "NEWID()"); values.Add("HasQuantity", "'0'"); values.Add("Did", "a.Did"); values.Add("WorkPoint", "'" + WorkPoint + "'");
//插入新增数据
sql += ICSHelper.InsertSQL("ICSAssemVouchs", values) + @" #TempPickAssem a
LEFT JOIN ICSAssemVouchs b ON a.Did=b.Did and a.WorkPoint=b.WorkPoint WHERE b.ID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
sql += " DROP TABLE #TempPickAssem " + " DROP TABLE #tableICSAssemVouchs"; sql = string.Format(sql, WorkPoint, erpName); ICSHelper.ExecuteDate(conStr, sql); #endregion
} } catch (Exception ex) { log.Error(ex.ToString()); } } } }
|