using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace ICSSoft.FromERP
{
///
/// 装配工单(产品途程)
///
public class IcsAutoSyncItemRoute : 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 conERPStr = ICSHelper.GetERPConnectString();
string conStr = ICSHelper.GetConnectString();
string Namespace = this.GetType().Namespace;
//string Class = this.GetType().Name;
// List itemCodeList = new List() { "A2001", "A2002", "KA10", "A2003" };
DataTable dt = ICSHelper.GetERPDB(conStr);
Dictionary dis = new Dictionary() {
{ "A2001", "ZP01_Route" },
{ "A2002", "ZP02_Route" },
{ "KA10", "ZP03_Route" },
{ "A2003", "ZP04_Route" },
};
foreach (DataRow dr in dt.Rows)
{
string erpName = ICSHelper.GetConfigString()["ERPDB"];
string TenantId = dr["TenantId"].ToString();
string TenantCode = dr["TenantCode"].ToString();
foreach (var item in dis)
{
string sql1 = @" select a.ItemCode,a.Id from IcsInventory a with(nolock)
where a.ItemCode like '" + item.Key + "%' and not exists (select ItemCode from IcsItem2Route with(nolock) where ItemCode=a.ItemCode) and TenantId='" + TenantId + "' ";
var itemDt = ICSHelper.ExecuteTable(conStr, sql1);
if (itemDt != null && itemDt.Rows.Count > 0)
{
string sql2 = "";
foreach (DataRow dr2 in itemDt.Rows)
{
//工艺路线表头
sql2 += @"
insert into IcsItem2Route (ItemId,RouteId,ItemCode,RouteCode,IsRef,TenantId,CreationTime,CreatorUserId,CreatorUserName)
select top 1 "+ dr2["Id"].ToInt64() + ",Id,'"+ dr2["ItemCode"].ToStringExt() + "',RouteCode,'Y','"+ TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsRoute where RouteCode='"+ item.Value + "' and TenantId='" + TenantId + "' ";
//工艺路线明细
sql2 += @"
insert into IcsItemRoute2Op (ItemId,RouteId,OpId,ItemCode,RouteCode,OpCode,OpSeq,OpControl,OpControlSeq,ParallelOp,OpDesc
,OptionalOp,IdMergeRule,OpLevel,TenantId,CreationTime,CreatorUserId,CreatorUserName)
select " + dr2["Id"].ToInt64() + ",RouteId,OpId,'" + dr2["ItemCode"].ToStringExt() + "',RouteCode,OpCode,OpSeq,OPControl ,OpControlSeq,'N',OpDesc,null,0,'A','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsRoute2Op with(nolock) where RouteCode='" + item.Value + "' and TenantId='" + TenantId + "' ";
}
ICSHelper.ExecuteDate(conStr, sql2);
}
}
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}