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.
171 lines
8.7 KiB
171 lines
8.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using Quartz;
|
|
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 委外到货(退货单)
|
|
/// </summary>
|
|
public class ICSDispatchDoc : 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 WHCode = ICSHelper.GetConfigString()["WHCode"];
|
|
string Date = ICSHelper.GetConfigString()["Date"];
|
|
string DocNO = ICSHelper.GetConfigString()["DocNo"];
|
|
|
|
DataTable dt = ICSHelper.GetERPDB(conStr);
|
|
using (FramDataContext db = new FramDataContext(conStr))
|
|
{
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
#region 销售发退货单同步
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
SAPDispatchGetVPN.ZWMS_SK_DO_READ client = new SAPDispatchGetVPN.ZWMS_SK_DO_READ();
|
|
SAPDispatchGetVPN.ZWMS_SK_DO_READ1 Info = new SAPDispatchGetVPN.ZWMS_SK_DO_READ1();
|
|
Info.VBELN = "0000000";
|
|
Info.CHG_DATE = Date;
|
|
Info.T_HEAD = new SAPDispatchGetVPN.ZWMS_DO_HEAD[1];
|
|
Info.T_ITEM = new SAPDispatchGetVPN.ZWMS_DO_ITEM[1];
|
|
Info.T_GERNR = new SAPDispatchGetVPN.ZWMS_DO_GERNR[1];
|
|
|
|
SAPDispatchGetVPN.ZWMS_SK_DO_READResponse result = new SAPDispatchGetVPN.ZWMS_SK_DO_READResponse();
|
|
result = client.CallZWMS_SK_DO_READ(Info);
|
|
List<SAPDispatchGetVPN.ZWMS_DO_ITEM> ItemInfoList = new List<SAPDispatchGetVPN.ZWMS_DO_ITEM>();
|
|
ItemInfoList.AddRange(result.T_ITEM);
|
|
foreach (SAPDispatchGetVPN.ZWMS_DO_HEAD HeadInfo in result.T_HEAD)
|
|
{
|
|
var ItemInfo = ItemInfoList.Where(a => a.VBELN == HeadInfo.VBELN);
|
|
foreach (SAPDispatchGetVPN.ZWMS_DO_ITEM Item in ItemInfo)
|
|
{
|
|
string ExtensionID = "";
|
|
bool isNew = false;
|
|
string Colspan = Item.KDAUF + "~" + Item.SERAIL + "~~" + Item.KDPOS + "~~~~~~~~~~";
|
|
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan);
|
|
if (Extensionline == null)
|
|
{
|
|
ExtensionID = AppConfig.GetGuid();
|
|
Extensionline = new ICSExtension();
|
|
Extensionline.ID = ExtensionID;
|
|
Extensionline.BatchCode = Item.SERAIL;
|
|
Extensionline.Version = "";
|
|
Extensionline.Brand = Item.KDPOS;
|
|
Extensionline.ProjectCode = Item.KDAUF;
|
|
Extensionline.cFree1 = "";
|
|
Extensionline.cFree2 = "";
|
|
Extensionline.cFree3 = "";
|
|
Extensionline.cFree4 = "";
|
|
Extensionline.cFree5 = "";
|
|
Extensionline.cFree6 = "";
|
|
Extensionline.cFree7 = "";
|
|
Extensionline.cFree8 = "";
|
|
Extensionline.cFree9 = "";
|
|
Extensionline.cFree10 = "";
|
|
Extensionline.Colspan = Colspan;
|
|
Extensionline.MTIME = DateTime.Now;
|
|
Extensionline.MUSER = "JOB";
|
|
Extensionline.MUSERName = "JOB";
|
|
Extensionline.WorkPoint = Item.WERKS;
|
|
|
|
db.ICSExtension.InsertOnSubmit(Extensionline);
|
|
db.SubmitChanges();
|
|
}
|
|
else
|
|
{
|
|
ExtensionID = Extensionline.ID;
|
|
}
|
|
|
|
var rcvline = db.ICSSDN.SingleOrDefault(a => a.SDNCode == Item.VBELN && a.Sequence == Item.POSNR && a.WorkPoint == Item.WERKS);
|
|
if (rcvline == null)
|
|
{
|
|
isNew = true;
|
|
rcvline = new Frame.Data.Entity.ICSSDN();
|
|
rcvline.ID = AppConfig.GetGuid();
|
|
rcvline.SDNQuantity = 0;
|
|
rcvline.SDNCode = Item.VBELN;//销售出/退货单
|
|
rcvline.Sequence = Item.POSNR;//行号
|
|
rcvline.InvCode = Item.MATNR;//物料编码
|
|
rcvline.SOCode = Item.KDAUF;//销售订单
|
|
rcvline.SOSequence = Item.KDPOS;//销售订单行号
|
|
}
|
|
rcvline.CusCode = HeadInfo.KUNNR;//送达方
|
|
rcvline.CusName = HeadInfo.NAME1;//送达方名称
|
|
rcvline.ArriveDate = Convert.ToDateTime(HeadInfo.LFDAT);//交货日期
|
|
rcvline.WHCode = Item.LGORT;//仓库
|
|
if (HeadInfo.LFART == "LF" || HeadInfo.LFART == "ZLF" || HeadInfo.LFART == "ZYB1")
|
|
{
|
|
rcvline.Type = "1";
|
|
}
|
|
else
|
|
{
|
|
rcvline.Type = "2";
|
|
}
|
|
rcvline.Quantity = Item.LFIMG;//数量
|
|
rcvline.Amount = 0;
|
|
rcvline.CreatePerson = "JOB";
|
|
rcvline.CreateDateTime = DateTime.Now;
|
|
rcvline.Status = "1";
|
|
rcvline.ExtensionID = ExtensionID;
|
|
rcvline.MUSER = "JOB";
|
|
rcvline.MUSERName = "JOB";
|
|
rcvline.MTIME = DateTime.Now;
|
|
rcvline.WorkPoint = Item.WERKS;//站点
|
|
if (isNew == true)
|
|
{
|
|
db.ICSSDN.InsertOnSubmit(rcvline);
|
|
}
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|