IcsFromERPJob
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.

100 lines
4.2 KiB

using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace ICSSoft.FromERP
{
/// <summary>
/// 装配工单(工单途程)
/// </summary>
public class IcsAutoSyncMoRoute : 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<string> itemCodeList = new List<string>() { "A2001", "A2002", "KA10", "A2003" };
DataTable dt = ICSHelper.GetERPDB(conStr);
Dictionary<string, string> dis = new Dictionary<string, string>() {
{ "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.MoCode,a.MoSeq, a.Id from IcsMo a with(nolock)
where a.ItemCode like '" + item.Key+ "%' and not exists (select MoCode from IcsMo2Route with(nolock) where MoCode=a.MoCode) 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 IcsMo2Route (MoId,RouteId,MoCode,MoSeq, RouteCode,IsMRoute, TenantId,CreationTime,CreatorUserId,CreatorUserName)
select top 1 " + dr2["Id"].ToInt64() + ",Id,'"+ dr2["MoCode"].ToString() + "',"+ dr2["MoSeq"].ToInt64() + ",RouteCode,'Y','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsRoute where RouteCode='" + item.Value + "' and TenantId='" + TenantId + "' ";
//工艺路线明细
sql2 += @"
insert into IcsMoRoute2Op (MoId,RouteId,OpId,MoCode,MoSeq, RouteCode,OpCode,OpSeq,OpControl ,OpLevel ,OpControlSeq,ParallelOp
,TenantId,CreationTime,CreatorUserId,CreatorUserName)
select " + dr2["Id"].ToInt64() + ",RouteId,OpId,'" + dr2["MoCode"].ToString() + "'," + dr2["MoSeq"].ToInt64() + ",RouteCode,OpCode,OpSeq,OPControl,'A',OpControlSeq,'N','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsRoute2Op where RouteCode='" + item.Value + "' and TenantId='" + TenantId + "' ";
sql2 += @" update icsmo set MoRoute='" + item.Value + "' where Id=" + dr2["Id"].ToInt64() + " and TenantId='" + TenantId + "' ";
}
ICSHelper.ExecuteDate(conStr, sql2);
}
}
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}