纽威
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.
 
 
 
 
 

3145 lines
218 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 Newtonsoft.Json;
using Quartz;
using RestSharp;
namespace ICSSoft.FromERP
{
/// <summary>
/// 委外领料单
/// </summary>
public class ICSSAPDocGet : 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"];
string HGpostUrlStr = ICSHelper.GetConfigString()["HGpostUrlStr"];
DataTable dt = ICSHelper.GetERPDB(conStr);
using (FramDataContext db = new FramDataContext(conStr))
{
try
{
foreach (DataRow dr in dt.Rows)
{
//1.wms读取sap时 SET_NOTMODIFY 传X。 sap会打上标识
//2. wms 更新失败 CLEAR_NOTMODIFY 传X。 sap会取消标识
SAPGetDocInfoZS.ZWMS_SK_WS_HEAD client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1 DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
if (DocNO != "")
{
DocInfo.DANJU = DocNO;
DocInfo.CHG_DATE = "";
}
if (Date != "")
{
DocInfo.DANJU = "";
DocInfo.CHG_DATE = Date;
}
if (DocNO == "" && Date == "")
{
DocInfo.DANJU = "";
DocInfo.CHG_DATE = DateTime.Now.Year + "-" + DateTime.Now.Month.ToString().PadLeft(2, '0') + "-" + DateTime.Now.Day.ToString().PadLeft(2, '0');
}
DocInfo.SET_NOTMODIFY = "X";
DocInfo.CLEAR_NOTMODIFY = "";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
SAPGetDocInfoZS.ZWMS_SK_WS_HEADResponse result = new SAPGetDocInfoZS.ZWMS_SK_WS_HEADResponse();
client.Timeout = 300000;
result = client.CallZWMS_SK_WS_HEAD(DocInfo);
List<SAPGetDocInfoZS.ZWMS_SK_HEAD> HeadInfoList = new List<SAPGetDocInfoZS.ZWMS_SK_HEAD>();
HeadInfoList.AddRange(result.Z_HEAD);
List<SAPGetDocInfoZS.ZWEBSERVICE_ITEM> ItemInfoList = new List<SAPGetDocInfoZS.ZWEBSERVICE_ITEM>();
ItemInfoList.AddRange(result.Z_ITEM);
List<SAPGetDocInfoZS.ZWEBS_GERNR> SubLineInfoList = new List<SAPGetDocInfoZS.ZWEBS_GERNR>();
SubLineInfoList.AddRange(result.Z_GERNR);
#region 采购免检入库(SAP单据类型:21)
var HeadInfo = HeadInfoList.Where(a => a.LEIXING == "21");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSDeliveryNotice.Where(a => a.DNCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
//string InspectJosn = "";
//InspectJosn += "{";
//InspectJosn += "\"IMP_ORDINI\":[";
//InspectJosn += "{";
//InspectJosn += "\"ORD_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"ORD_DES\":\"采购退货-采购退货单\",";
//InspectJosn += "\"ORD_TIPOOP\":\"V\"";
//InspectJosn += "}";
//InspectJosn += "],";
//InspectJosn += "\"IMP_ORDINI_RIGHE\":[";
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
//bool ToHG = false;
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
//var invline = db.ICSInventoryDetail.SingleOrDefault(a => a.INVCode == Item.MATNR.TrimStart('0') && a.WHCode == Item.LGORT && a.WorkPoint == Info.WERKS);
//var hgline = db.Sys_SRM_ItemsDetail.SingleOrDefault(a => a.F_Define1 == Item.LGORT && a.F_Define2 == invline.LocationCode && a.F_Define4 == Info.WERKS && a.F_Define3 == "HGAreaConfig");
//if (hgline != null)
//{
// ToHG = true;
//}
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSDeliveryNotice.SingleOrDefault(a => a.DNCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSDeliveryNotice();
line.ID = AppConfig.GetGuid();
line.RCVQuantity = 0;
line.DNCode = Item.DANJU;//退货单号
line.Sequence = LineNum.ToString();//退货单行号(WMS自用)
line.SAPSequence = Item.POSNR;//退货单行号(SAP)
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.VenCode = "";
line.DepCode = "";
line.DNType = "1";
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = "JOB";
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.POID = Item.EBELN;//订单号
line.PODetailID = Item.EBELP;//订单行号
line.DNID = Item.RSNUM;//预留/相关需求的编号
line.DNDetailID = Item.RSPOS;//预留 / 相关需求的项目编号
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "2";
line.EATTRIBUTE1 = Info.LEIXING;
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
//新增字段
line.InspectionType = "免检";//检验类型
line.InvoDescribe = Item.MAKTX;//物料描述
line.Unity = Item.MEINS;//单位
line.StockIndicator = Item.SOBKZ;//特殊库存标识
line.DepositArea = Item.LGORT;//存放区域
if (isNew == true)
{
db.ICSDeliveryNotice.InsertOnSubmit(line);
}
db.SubmitChanges();
//InspectJosn += "{";
//InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
//InspectJosn += "\"RIG_SUB1\": \"\",";
//InspectJosn += "\"RIG_SUB2\": \"\",";
//InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
//InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
//InspectJosn += "},";
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSDeliveryNotice.SingleOrDefault(a => a.DNCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSDeliveryNotice();
line.ID = AppConfig.GetGuid();
line.RCVQuantity = 0;
line.DNCode = Item.DANJU;//退货单号
line.Sequence = LineNum.ToString();//退货单行号(WMS自用)
line.SAPSequence = Item.POSNR;//退货单行号(SAP)
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.VenCode = "";
line.DepCode = "";
line.DNType = "2";
line.WorkPoint = Info.WERKS;//站点
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.POID = Item.EBELN;//订单号
line.PODetailID = Item.EBELP;//订单行号
line.DNID = Item.RSNUM;//预留/相关需求的编号
line.DNDetailID = Item.RSPOS;//预留 / 相关需求的项目编号
line.Quantity = 1;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "2";
line.EATTRIBUTE1 = Info.LEIXING;
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
if (isNew == true)
{
db.ICSDeliveryNotice.InsertOnSubmit(line);
}
db.SubmitChanges();
//InspectJosn += "{";
//InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
//InspectJosn += "\"RIG_SUB1\": \"\",";
//InspectJosn += "\"RIG_SUB2\": \"\",";
//InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
//InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
//InspectJosn += "},";
LineNum += 10;
}
}
}
//InspectJosn = InspectJosn.TrimEnd(',');
//InspectJosn += "]";
//InspectJosn += "}";
//if (ToHG == true)
//{
// string HGID = AppConfig.GetGuid();
// #region 调用货柜接口前日志
// var hgline = new ICSWMS_HGLog();
// hgline.ID = HGID;
// hgline.InputJSON = InspectJosn;
// hgline.MTIME = DateTime.Now;
// hgline.ReturnResult = "";
// hgline.MUSER = "JOB";
// hgline.MUSERNAME = "JOB";
// hgline.WorkPoint = Info.WERKS;
// db.ICSWMS_HGLog.InsertOnSubmit(hgline);
// db.SubmitChanges();
// #endregion
// string resultstr = RestFulGet(InspectJosn, HGpostUrlStr);
// #region 调用货柜接口后日志
// hgline = db.ICSWMS_HGLog.SingleOrDefault(a => a.ID == HGID);
// hgline.ReturnResult = resultstr;
// db.SubmitChanges();
// #endregion
// if (resultstr.Contains("Error"))
// {
// ICSHGResult hgresult = JsonConvert.DeserializeObject<ICSHGResult>(resultstr.TrimStart('[').TrimEnd(']'));
// throw new Exception("货柜单据传输接口(采购退货)调用报错,主要报错信息:" + hgresult.PrimaryError + ",次要报错信息:" + hgresult.SecondaryError + "");
// }
//}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 委外领料单同步(单据类型:05)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "05");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSOApply.Where(a => a.ApplyCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
//string InspectJosn = "";
//InspectJosn += "{";
//InspectJosn += "\"IMP_ORDINI\":[";
//InspectJosn += "{";
//InspectJosn += "\"ORD_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"ORD_DES\":\"委外发料-委外领料申请单\",";
//InspectJosn += "\"ORD_TIPOOP\":\"P\"";
//InspectJosn += "\"ORD_CLIENTE\":\"" + Info.WERKS + "\"";
//InspectJosn += "}";
//InspectJosn += "],";
//InspectJosn += "\"IMP_ORDINI_RIGHE\":[";
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
//bool ToHG = false;
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
//var invline = db.ICSInventoryDetail.SingleOrDefault(a => a.INVCode == Item.MATNR.TrimStart('0') && a.WHCode == Item.LGORT && a.WorkPoint == Info.WERKS);
//var hgline = db.Sys_SRM_ItemsDetail.SingleOrDefault(a => a.F_Define1 == Item.LGORT && a.F_Define2 == invline.LocationCode && a.F_Define4 == Info.WERKS && a.F_Define3 == "HGAreaConfig");
//if (hgline != null)
//{
// ToHG = true;
//}
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSOApply.SingleOrDefault(a => a.ApplyCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSOApply();
line.ID = AppConfig.GetGuid();
line.IssueQuantity = 0;
line.ApplyCode = Item.DANJU;//委外领料单号
line.Sequence = LineNum.ToString();//委外领料单行号(WMS自用)
line.SAPSequence = Item.POSNR;//委外领料单行号(SAP)
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.Type = "领料";
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.SourceCode = Item.EBELN;//采购凭证号
line.SourceSequence = Item.EBELP;//采购凭证的项目编号
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "2";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
line.EATTRIBUTE = Info.LEIXING;
line.VenCode = Info.TEST2;//供应商编码
line.VenName = Info.TEST3;//供应商名称
if (isNew == true)
{
db.ICSOApply.InsertOnSubmit(line);
}
db.SubmitChanges();
//InspectJosn += "{";
//InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
//InspectJosn += "\"RIG_SUB1\": \"\",";
//InspectJosn += "\"RIG_SUB2\": \"\",";
//InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
//InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
//InspectJosn += "},";
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSOApply.SingleOrDefault(a => a.ApplyCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSOApply();
line.ID = AppConfig.GetGuid();
line.IssueQuantity = 0;
line.ApplyCode = Item.DANJU;//委外领料单号
line.Sequence = LineNum.ToString();//委外领料单行号(WMS自用)
line.SAPSequence = Item.POSNR;//委外领料单行号(SAP)
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.Type = "领料";
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.SourceCode = Item.EBELN;//采购凭证号
line.SourceSequence = Item.EBELP;//采购凭证的项目编号
line.Quantity = 1;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "2";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
line.EATTRIBUTE = Info.LEIXING;
line.VenCode = Info.TEST2;//供应商编码
line.VenName = Info.TEST3;//供应商名称
if (isNew == true)
{
db.ICSOApply.InsertOnSubmit(line);
}
db.SubmitChanges();
//InspectJosn += "{";
//InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
//InspectJosn += "\"RIG_SUB1\": \"\",";
//InspectJosn += "\"RIG_SUB2\": \"\",";
//InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
//InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
//InspectJosn += "},";
LineNum += 10;
}
}
}
//InspectJosn = InspectJosn.TrimEnd(',');
//InspectJosn += "]";
//InspectJosn += "}";
//if (ToHG == true)
//{
// string HGID = AppConfig.GetGuid();
// #region 调用货柜接口前日志
// var hgline = new ICSWMS_HGLog();
// hgline.ID = HGID;
// hgline.InputJSON = InspectJosn;
// hgline.MTIME = DateTime.Now;
// hgline.ReturnResult = "";
// hgline.MUSER = "JOB";
// hgline.MUSERNAME = "JOB";
// hgline.WorkPoint = Info.WERKS;
// db.ICSWMS_HGLog.InsertOnSubmit(hgline);
// db.SubmitChanges();
// #endregion
// string resultstr = RestFulGet(InspectJosn, HGpostUrlStr);
// #region 调用货柜接口后日志
// hgline = db.ICSWMS_HGLog.SingleOrDefault(a => a.ID == HGID);
// hgline.ReturnResult = resultstr;
// db.SubmitChanges();
// #endregion
// if (resultstr.Contains("Error"))
// {
// ICSHGResult hgresult = JsonConvert.DeserializeObject<ICSHGResult>(resultstr.TrimStart('[').TrimEnd(']'));
// throw new Exception("货柜单据传输接口(委外领料)调用报错,主要报错信息:" + hgresult.PrimaryError + ",次要报错信息:" + hgresult.SecondaryError + "");
// }
//}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 生产领料单同步(单据类型:01 03 17 20)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "01" || a.LEIXING == "03" || a.LEIXING == "17" || a.LEIXING == "20");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSMOApply.Where(a => a.ApplyCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
//string InspectJosn = "";
//InspectJosn += "{";
//InspectJosn += "\"IMP_ORDINI\":[";
//InspectJosn += "{";
//InspectJosn += "\"ORD_ORDINE\":\"" + Info.DANJU + "\",";
//InspectJosn += "\"ORD_DES\":\"生产发料-领料申请单\",";
//InspectJosn += "\"ORD_TIPOOP\":\"P\",";
//InspectJosn += "\"ORD_CLIENTE\":\"" + Info.WERKS + "\"";
//InspectJosn += "}";
//InspectJosn += "],";
//InspectJosn += "\"IMP_ORDINI_RIGHE\":[";
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
//bool ToHG = false;
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int Count = 0;
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
//var invline = db.ICSInventoryDetail.SingleOrDefault(a => a.INVCode == Item.MATNR.TrimStart('0') && a.WHCode == Item.LGORT && a.WorkPoint == Info.WERKS);
//var hgline = db.Sys_SRM_ItemsDetail.SingleOrDefault(a => a.F_Define1 == Item.LGORT && a.F_Define2 == invline.LocationCode && a.F_Define4 == Info.WERKS && a.F_Define3 == "HGAreaConfig");
//if (hgline != null)
//{
// ToHG = true;
//}
if (Item.SERNP != "ZS01")
{
Count++;
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSMOApply.SingleOrDefault(a => a.ApplyCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSMOApply();
line.ID = AppConfig.GetGuid();
line.IssueQuantity = 0;
line.ApplyID = AppConfig.GetGuid();
line.ApplyDetailID = AppConfig.GetGuid();
line.ApplyCode = Item.DANJU;//领料单号
line.SAPSequence = Item.POSNR;//领料单行号(SAP)
line.Sequence = LineNum.ToString();//领料单行号(WMS自用)
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.Type = "1";
line.WorkPoint = Info.WERKS;//站点(工厂)
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.SourceCode = Item.EBELN;//采购凭证号
line.SourceSequence = Item.EBELP;//采购凭证的项目编号
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "2";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
line.EATTRIBUTE = Info.LEIXING;//单据类型
//订单号
line.OrderNumber = Info.AUFNR;
//套数
line.Sets = Info.TAOSHU;
//物料号 父项生产订单物料
line.OrderInvCode = Info.MATNR_FAT;
//物料描述 父项 生产订单主物料
line.OrderInvDescribe = Info.MAKTX_FAT;
//出入库 1.出库 2.入库 3.转移 4.盘点
line.BillType = Info.CHURU;
//备注
line.Remarks = Info.BEIZHU;
//工位
line.Desks = Info.P_GW;
//调度工号
line.DispatchNumber = Info.P_DD;
//调度姓名
line.DispatcherName = Info.P_DDNAME;
//收料人工号
line.ReceiverNumber = Info.P_SL;
//收料人姓名
line.ReceiverName = Info.P_SLNAME;
//紧急程度
line.Urgency = Info.P_JJ;
//需求日期
line.NeedDate = Info.ZXQRQ;
//需求时间
line.NeedTime = Info.ZXQSJ.ToString("HH:mm:ss");
//备注项
line.RemarksTerm = Info.ZBEIZ;
//工艺文本码
line.TextNumber = Info.KTSCH;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSMOApply.InsertOnSubmit(line);
}
db.SubmitChanges();
//if (Count == ItemInfo.Count())
//{
// InspectJosn += "{";
// InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
// InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
// InspectJosn += "\"RIG_SUB1\": \"\",";
// InspectJosn += "\"RIG_SUB2\": \"\",";
// InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
// InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
// InspectJosn += "}";
//}
//else
//{
// InspectJosn += "{";
// InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
// InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
// InspectJosn += "\"RIG_SUB1\": \"\",";
// InspectJosn += "\"RIG_SUB2\": \"\",";
// InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
// InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
// InspectJosn += "},";
//}
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
Count++;
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSMOApply.SingleOrDefault(a => a.ApplyCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSMOApply();
line.ID = AppConfig.GetGuid();
line.IssueQuantity = 0;
line.ApplyID = AppConfig.GetGuid();
line.ApplyDetailID = AppConfig.GetGuid();
line.ApplyCode = Item.DANJU;//领料单号
line.SAPSequence = Item.POSNR;//领料单行号(SAP)
line.Sequence = LineNum.ToString();//领料单行号(WMS自用)
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.Type = "1";
line.WorkPoint = Info.WERKS;//站点(工厂)
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.SourceCode = Item.EBELN;//采购凭证号
line.SourceSequence = Item.EBELP;//采购凭证的项目编号
line.Quantity = 1;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "2";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
line.EATTRIBUTE = Info.LEIXING;//单据类型
//订单号
line.OrderNumber = Info.AUFNR;
//套数
line.Sets = Info.TAOSHU;
//物料号 父项生产订单物料
line.OrderInvCode = Info.MATNR_FAT;
//物料描述 父项 生产订单主物料
line.OrderInvDescribe = Info.MAKTX_FAT;
//出入库 1.出库 2.入库 3.转移 4.盘点
line.BillType = Info.CHURU;
//备注
line.Remarks = Info.BEIZHU;
//工位
line.Desks = Info.P_GW;
//调度工号
line.DispatchNumber = Info.P_DD;
//调度姓名
line.DispatcherName = Info.P_DDNAME;
//收料人工号
line.ReceiverNumber = Info.P_SL;
//收料人姓名
line.ReceiverName = Info.P_SLNAME;
//紧急程度
line.Urgency = Info.P_JJ;
//需求日期
line.NeedDate = Info.ZXQRQ;
//需求时间
line.NeedTime = Info.ZXQSJ.ToString("HH:mm:ss");
//备注项
line.RemarksTerm = Info.ZBEIZ;
//工艺文本码
line.TextNumber = Info.KTSCH;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSMOApply.InsertOnSubmit(line);
}
db.SubmitChanges();
//if (Count == ItemInfo.Count())
//{
// InspectJosn += "{";
// InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
// InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
// InspectJosn += "\"RIG_SUB1\": \"\",";
// InspectJosn += "\"RIG_SUB2\": \"\",";
// InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
// InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
// InspectJosn += "}";
//}
//else
//{
// InspectJosn += "{";
// InspectJosn += "\"RIG_ORDINE\":\"" + Info.DANJU + "\",";
// InspectJosn += "\"RIG_ARTICOLO\": \"" + Item.MATNR.TrimStart('0') + "\",";
// InspectJosn += "\"RIG_SUB1\": \"\",";
// InspectJosn += "\"RIG_SUB2\": \"\",";
// InspectJosn += "\"RIG_QTAR\": " + Item.LINGYSL + ",";
// InspectJosn += "\"RIG_HOSTINF\": \"" + LineNum + "\"";
// InspectJosn += "},";
//}
LineNum += 10;
}
}
}
//InspectJosn += "]";
//InspectJosn += "}";
//if (ToHG == true)
//{
// string HGID = AppConfig.GetGuid();
// #region 调用货柜接口前日志
// var hgline = new ICSWMS_HGLog();
// hgline.ID = HGID;
// hgline.InputJSON = InspectJosn;
// hgline.MTIME = DateTime.Now;
// hgline.ReturnResult = "";
// hgline.MUSER = "JOB";
// hgline.MUSERNAME = "JOB";
// hgline.WorkPoint = Info.WERKS;
// db.ICSWMS_HGLog.InsertOnSubmit(hgline);
// db.SubmitChanges();
// #endregion
// string resultstr = RestFulGet(InspectJosn, HGpostUrlStr);
// #region 调用货柜接口后日志
// hgline = db.ICSWMS_HGLog.SingleOrDefault(a => a.ID == HGID);
// hgline.ReturnResult = resultstr;
// db.SubmitChanges();
// #endregion
// if (resultstr.Contains("Error"))
// {
// ICSHGResult hgresult = JsonConvert.DeserializeObject<ICSHGResult>(resultstr.TrimStart('[').TrimEnd(']'));
// throw new Exception("货柜单据传输接口(生产领料)调用报错,主要报错信息:" + hgresult.PrimaryError + ",次要报错信息:" + hgresult.SecondaryError + "");
// }
//}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 生产退料单同步(单据类型:02 04 06 18 19)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "02" || a.LEIXING == "04" || a.LEIXING == "06" || a.LEIXING == "18" || a.LEIXING == "19");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSMOApplyNeg.Where(a => a.ApplyNegCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
bool headisNew = false;
int LineNum = 10;
var headline = db.ICSMOApplyNeg.SingleOrDefault(a => a.ApplyNegCode == Info.DANJU && a.WorkPoint == Info.WERKS);
if (headline == null)
{
headisNew = true;
headline = new ICSMOApplyNeg();
headline.ID = AppConfig.GetGuid();
headline.ApplyNegCode = Info.DANJU;
}
//headline.WHCode = ""; 仓库字段放到子表中
headline.Status = "1";
headline.Type = "2";
headline.Memo = "";
headline.CreatePerson = Info.XINGMING;
headline.CreateDateTime = Convert.ToDateTime(Info.DATE_C);
headline.MUSER = "JOB";
headline.MUSERName = "JOB";
headline.MTIME = DateTime.Now;
headline.WorkPoint = Info.WERKS;
headline.EATTRIBUTE1 = Info.LEIXING;
if (headisNew == true)
{
db.ICSMOApplyNeg.InsertOnSubmit(headline);
}
db.SubmitChanges();
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSMOApplyNegDetail.SingleOrDefault(a => a.ApplyNegCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSMOApplyNegDetail();
line.ID = AppConfig.GetGuid();
line.IssueNegQuantity = 0;
line.ApplyNegCode = Item.DANJU;//退料单号
line.Sequence = LineNum.ToString();//退料单行号(WMS自用)
line.SAPSequence = Item.POSNR;//ASP行号
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
line.SourceDetailID = "";
}
line.Quantity = Item.LINGYSL;//领用数量
line.SourceDetailID = Item.LGORT;//仓库
line.WHCode = Item.LGORT;//仓库
line.Amount = 0;
line.ExtensionID = ExtensionID;
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.WorkPoint = Info.WERKS;//站点
LineNum += 10;
if (isNew == true)
{
db.ICSMOApplyNegDetail.InsertOnSubmit(line);
}
db.SubmitChanges();
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSMOApplyNegDetail.SingleOrDefault(a => a.ApplyNegCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSMOApplyNegDetail();
line.ID = AppConfig.GetGuid();
line.IssueNegQuantity = 0;
line.ApplyNegCode = Item.DANJU;//退料单号
line.Sequence = LineNum.ToString();//退料单行号(WMS自用)
line.SAPSequence = Item.POSNR;//ASP行号
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
line.SourceDetailID = "";
}
line.Quantity = 1;//领用数量
line.SourceDetailID = Item.LGORT;//仓库
line.WHCode = Item.LGORT;//仓库
line.Amount = 0;
line.ExtensionID = ExtensionID;
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.WorkPoint = Info.WERKS;//站点
LineNum += 10;
if (isNew == true)
{
db.ICSMOApplyNegDetail.InsertOnSubmit(line);
}
db.SubmitChanges();
}
}
}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 成品入库单同步(单据类型:15)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "15");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSManufactureReceive.Where(a => a.RCVCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSManufactureReceive.SingleOrDefault(a => a.RCVCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSManufactureReceive();
line.ID = AppConfig.GetGuid();
line.RCVQuantity = 0;
line.RCVCode = Item.DANJU;//委外领料单号
line.Sequence = LineNum.ToString();//委外领料单行号
line.SAPSequence = Item.POSNR;
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.Type = "1";
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.SourceCode = Item.EBELN;//采购凭证号
line.SourceSequence = Item.EBELP;//采购凭证的项目编号
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
if (Info.TEST1 == "N")//Info.TEST1=N为SAP未过账入库单 Info.TEST1=Y为SAP已过账入库单
{
line.Status = "1";
}
else
{
line.Status = "3";
}
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
line.EATTRIBUTE = Info.LEIXING;
//物料描述
line.InvDescribe = Item.MAKTX;
//订单号
line.OrderNumber = Info.AUFNR;
//物料号 父项生产订单主物料
line.OrderInvCode = Info.MATNR_FAT;
//物料描述 父项生产订单主物料
line.OrderInvDescribe = Info.MAKTX_FAT;
//出入库
line.BillType = Info.CHURU;
//备注
line.Remarks = Info.BEIZHU;
//基本计量单位
line.Unit = Item.MEINS;
//接受特殊库存标识
line.StockIndicator = Item.SOBKZ;
//备注项
line.RemarksTerm = Info.ZBEIZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSManufactureReceive.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSManufactureReceive.SingleOrDefault(a => a.RCVCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSManufactureReceive();
line.ID = AppConfig.GetGuid();
line.RCVQuantity = 0;
line.RCVCode = Item.DANJU;//委外领料单号
line.Sequence = LineNum.ToString();//委外领料单行号
line.SAPSequence = Item.POSNR;
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.Type = "1";
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.SourceCode = Item.EBELN;//采购凭证号
line.SourceSequence = Item.EBELP;//采购凭证的项目编号
line.Quantity = 1;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
if (Info.TEST1 == "N")//Info.TEST1=N为SAP未过账入库单 Info.TEST1=Y为SAP已过账入库单
{
line.Status = "1";
}
else
{
line.Status = "3";
}
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
line.EATTRIBUTE = Info.LEIXING;
//物料描述
line.InvDescribe = Item.MAKTX;
//订单号
line.OrderNumber = Info.AUFNR;
//物料号 父项生产订单主物料
line.OrderInvCode = Info.MATNR_FAT;
//物料描述 父项生产订单主物料
line.OrderInvDescribe = Info.MAKTX_FAT;
//出入库
line.BillType = Info.CHURU;
//备注
line.Remarks = Info.BEIZHU;
//基本计量单位
line.Unit = Item.MEINS;
//接受特殊库存标识
line.StockIndicator = Item.SOBKZ;
//备注项
line.RemarksTerm = Info.ZBEIZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSManufactureReceive.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
}
}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 调拨单同步(单据类型:07 08 11)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "07" || a.LEIXING == "08" || a.LEIXING == "11");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSTransfer.Where(a => a.TransferNO == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSTransfer.SingleOrDefault(a => a.TransferNO == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSTransfer();
line.ID = AppConfig.GetGuid();
line.TransferQuantity = 0;
line.TransferNO = Item.DANJU;//调拨单号
line.SAPSequence = Item.POSNR;
line.Sequence = LineNum.ToString(); //调拨单行号
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.FromWarehouseCode = Item.LGORT;
line.FromLocationCode = "";
line.ToWarehouseCode = Item.LGORT_JS;
line.ToLocationCode = "";
line.Status = "2";
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.Type = "1";
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.ExtensionID = ExtensionID;
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.WorkPoint = Info.WERKS;//站点
line.EATTRIBUTE1 = Item.WERKS_JS;//接收站点
//单据类型
line.OrderType = Info.LEIXING;
//类型描述
line.TypeDescribe = Info.MIAOSHU;
//备注
line.Remarks = Info.BEIZHU;
//人员号
line.PersonNumber = Info.PERNR;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//接收物料号
line.ReceiveInvCode = Item.MATNR_JS.TrimStart('0');
//接受物料描述
line.ReceiveInvDescribe = Item.MAKTX_JS;
//接受库存标识
line.ReceiveStock = Item.SOBKZ_JS;
//接受销售订单
line.ReceiveSales = Item.VBELN_JS;
//接受行号
line.ReceiveSequence = Item.POSNR_JS;
//备注2
line.Remark2 = Item.BEIZHU2;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSTransfer.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var line = db.ICSTransfer.SingleOrDefault(a => a.TransferNO == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSTransfer();
line.ID = AppConfig.GetGuid();
line.TransferQuantity = 0;
line.TransferNO = Item.DANJU;//调拨单号
line.SAPSequence = Item.POSNR;
line.Sequence = LineNum.ToString(); //调拨单行号
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.FromWarehouseCode = Item.LGORT;
line.FromLocationCode = "";
line.ToWarehouseCode = Item.LGORT_JS;
line.ToLocationCode = "";
line.Status = "2";
line.Quantity = 1;//领用数量
line.Amount = 0;
line.Type = "1";
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.ExtensionID = ExtensionID;
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.WorkPoint = Info.WERKS;//站点
line.EATTRIBUTE1 = Item.WERKS_JS;//接收站点
//单据类型
line.OrderType = Info.LEIXING;
//类型描述
line.TypeDescribe = Info.MIAOSHU;
//备注
line.Remarks = Info.BEIZHU;
//人员号
line.PersonNumber = Info.PERNR;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//接收物料号
line.ReceiveInvCode = Item.MATNR_JS.TrimStart('0');
//接受物料描述
line.ReceiveInvDescribe = Item.MAKTX_JS;
//接受库存标识
line.ReceiveStock = Item.SOBKZ_JS;
//接受销售订单
line.ReceiveSales = Item.VBELN_JS;
//接受行号
line.ReceiveSequence = Item.POSNR_JS;
//备注2
line.Remark2 = Item.BEIZHU2;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSTransfer.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
}
}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 形态转换单同步(物料)(单据类型:13)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "13");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSMTDOC.Where(a => a.MTDOCCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var linebefore = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.MTDOCType == "1" && a.WorkPoint == Info.WERKS);
if (linebefore == null)
{
isNew = true;
linebefore = new Frame.Data.Entity.ICSMTDOC();
linebefore.ID = AppConfig.GetGuid();
linebefore.MTDOCQuantity = 0;
linebefore.MTDOCCode = Item.DANJU;//形态转换单号
linebefore.SAPSequence = Item.POSNR;
linebefore.Sequence = LineNum.ToString();//形态转换单行号
linebefore.MTDOCType = "1";//转换前
}
linebefore.DepCode = Info.KOSTL;
linebefore.WHCode = Item.LGORT;
linebefore.Quantity = Item.LINGYSL;//领用数量
linebefore.Amount = 0;
linebefore.Memo = "";
linebefore.Status = "2";
linebefore.INVCode = Item.MATNR.TrimStart('0');//转换前物料编码
linebefore.SOCode = "";
linebefore.SOSequence = "";
linebefore.CreatePerson = Info.XINGMING;
linebefore.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
linebefore.ExtensionID = ExtensionID;
linebefore.MUSER = "JOB";
linebefore.MUSERName = "JOB";
linebefore.MTIME = DateTime.Now;
linebefore.WorkPoint = Info.WERKS;//站点
linebefore.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(linebefore);
}
db.SubmitChanges();
var lineafter = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.MTDOCType == "2" && a.WorkPoint == Info.WERKS);
if (lineafter == null)
{
isNew = true;
lineafter = new Frame.Data.Entity.ICSMTDOC();
lineafter.ID = AppConfig.GetGuid();
lineafter.MTDOCQuantity = 0;
lineafter.MTDOCCode = Item.DANJU;//形态转换单号
lineafter.Sequence = LineNum.ToString();//形态转换单行号
lineafter.SAPSequence = Item.POSNR;
lineafter.MTDOCType = "2";//转换后
}
lineafter.DepCode = Info.KOSTL;
lineafter.WHCode = Item.LGORT;
lineafter.Quantity = Item.LINGYSL;//领用数量
lineafter.Amount = 0;
lineafter.Memo = "";
lineafter.Status = "2";
lineafter.INVCode = Item.MATNR_JS.TrimStart('0');//转换后物料编码
lineafter.SOCode = "";
lineafter.SOSequence = "";
lineafter.CreatePerson = Info.XINGMING;
lineafter.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
lineafter.ExtensionID = ExtensionID;
lineafter.MUSER = "JOB";
lineafter.MUSERName = "JOB";
lineafter.MTIME = DateTime.Now;
lineafter.WorkPoint = Info.WERKS;//站点
lineafter.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(lineafter);
}
db.SubmitChanges();
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
var linebefore = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.MTDOCType == "1" && a.WorkPoint == Info.WERKS);
if (linebefore == null)
{
isNew = true;
linebefore = new Frame.Data.Entity.ICSMTDOC();
linebefore.ID = AppConfig.GetGuid();
linebefore.MTDOCQuantity = 0;
linebefore.MTDOCCode = Item.DANJU;//形态转换单号
linebefore.SAPSequence = Item.POSNR;
linebefore.Sequence = LineNum.ToString();//形态转换单行号
linebefore.MTDOCType = "1";//转换前
}
linebefore.DepCode = Info.KOSTL;
linebefore.WHCode = Item.LGORT;
linebefore.Quantity = 1;//领用数量
linebefore.Amount = 0;
linebefore.Memo = "";
linebefore.Status = "2";
linebefore.INVCode = Item.MATNR.TrimStart('0');//转换前物料编码
linebefore.SOCode = "";
linebefore.SOSequence = "";
linebefore.CreatePerson = Info.XINGMING;
linebefore.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
linebefore.ExtensionID = ExtensionID;
linebefore.MUSER = "JOB";
linebefore.MUSERName = "JOB";
linebefore.MTIME = DateTime.Now;
linebefore.WorkPoint = Info.WERKS;//站点
linebefore.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(linebefore);
}
db.SubmitChanges();
var lineafter = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.MTDOCType == "2" && a.WorkPoint == Info.WERKS);
if (lineafter == null)
{
isNew = true;
lineafter = new Frame.Data.Entity.ICSMTDOC();
lineafter.ID = AppConfig.GetGuid();
lineafter.MTDOCQuantity = 0;
lineafter.MTDOCCode = Item.DANJU;//形态转换单号
lineafter.Sequence = LineNum.ToString();//形态转换单行号
lineafter.SAPSequence = Item.POSNR;
lineafter.MTDOCType = "2";//转换后
}
lineafter.DepCode = Info.KOSTL;
lineafter.WHCode = Item.LGORT;
lineafter.Quantity = Item.LINGYSL;//领用数量
lineafter.Amount = 0;
lineafter.Memo = "";
lineafter.Status = "2";
lineafter.INVCode = Item.MATNR_JS.TrimStart('0');//转换后物料编码
lineafter.SOCode = "";
lineafter.SOSequence = "";
lineafter.CreatePerson = Info.XINGMING;
lineafter.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
lineafter.ExtensionID = ExtensionID;
lineafter.MUSER = "JOB";
lineafter.MUSERName = "JOB";
lineafter.MTIME = DateTime.Now;
lineafter.WorkPoint = Info.WERKS;//站点
lineafter.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(lineafter);
}
db.SubmitChanges();
LineNum += 10;
}
}
}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 形态转换单同步(按单)(单据类型:12)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "12");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSMTDOC.Where(a => a.MTDOCCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
if (Item.SERNP != "ZS01")
{
string ExtensionBefore = "";
string ExtensionAfter = "";
bool isNew = false;
string Colspan;
string ColspanAfter;
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
ColspanAfter = Item.VBELN_JS + "~~~" + Item.POSNR_JS + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
ColspanAfter = "~~~~~~~~~~~~~";
}
Colspan = Item.VBELN_VA + "~" + Item.SERNP + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionBefore = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionBefore;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionBefore = Extensionline.ID;
}
var ExtensionlineAfter = db.ICSExtension.SingleOrDefault(a => a.Colspan == ColspanAfter && a.WorkPoint == Info.WERKS);
if (ExtensionlineAfter == null)
{
ExtensionAfter = AppConfig.GetGuid();
ExtensionlineAfter = new ICSExtension();
ExtensionlineAfter.ID = ExtensionAfter;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_JS;
Extensionline.ProjectCode = Item.VBELN_JS;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
ExtensionlineAfter.cFree1 = "";
ExtensionlineAfter.cFree2 = "";
ExtensionlineAfter.cFree3 = "";
ExtensionlineAfter.cFree4 = "";
ExtensionlineAfter.cFree5 = "";
ExtensionlineAfter.cFree6 = "";
ExtensionlineAfter.cFree7 = "";
ExtensionlineAfter.cFree8 = "";
ExtensionlineAfter.cFree9 = "";
ExtensionlineAfter.cFree10 = "";
ExtensionlineAfter.Colspan = ColspanAfter;
ExtensionlineAfter.MTIME = DateTime.Now;
ExtensionlineAfter.MUSER = "JOB";
ExtensionlineAfter.MUSERName = "JOB";
ExtensionlineAfter.WorkPoint = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionAfter = ExtensionlineAfter.ID;
}
var linebefore = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionBefore && a.MTDOCType == "1" && a.WorkPoint == Info.WERKS);
if (linebefore == null)
{
isNew = true;
linebefore = new Frame.Data.Entity.ICSMTDOC();
linebefore.ID = AppConfig.GetGuid();
linebefore.MTDOCQuantity = 0;
linebefore.MTDOCCode = Item.DANJU;//形态转换单号
linebefore.SAPSequence = Item.POSNR;
linebefore.Sequence = LineNum.ToString(); //形态转换单行号
linebefore.MTDOCType = "1";//转换前
}
linebefore.DepCode = Info.KOSTL;
linebefore.WHCode = Item.LGORT;
linebefore.Quantity = Item.LINGYSL;//领用数量
linebefore.Amount = 0;
linebefore.Memo = Item.SOBKZ_JS;
linebefore.Status = "2";
linebefore.INVCode = Item.MATNR.TrimStart('0');//转换前物料编码
linebefore.SOCode = "";
linebefore.SOSequence = "";
linebefore.CreatePerson = Info.XINGMING;
linebefore.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
linebefore.ExtensionID = ExtensionBefore;
linebefore.MUSER = "JOB";
linebefore.MUSERName = "JOB";
linebefore.MTIME = DateTime.Now;
linebefore.WorkPoint = Info.WERKS;//站点
linebefore.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(linebefore);
}
db.SubmitChanges();
var lineafter = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionAfter && a.MTDOCType == "2" && a.WorkPoint == Info.WERKS);
if (lineafter == null)
{
isNew = true;
lineafter = new Frame.Data.Entity.ICSMTDOC();
lineafter.ID = AppConfig.GetGuid();
lineafter.MTDOCQuantity = 0;
lineafter.MTDOCCode = Item.DANJU;//形态转换单号
lineafter.SAPSequence = Item.POSNR;
lineafter.Sequence = LineNum.ToString(); //形态转换单行号
lineafter.MTDOCType = "2";//转换后
}
lineafter.DepCode = Info.KOSTL;
lineafter.WHCode = Item.LGORT;
lineafter.Quantity = Item.LINGYSL;//领用数量
lineafter.Amount = 0;
lineafter.Memo = Item.SOBKZ_JS;
lineafter.Status = "2";
lineafter.INVCode = Item.MATNR.TrimStart('0');//转换后物料编码
lineafter.SOCode = "";
lineafter.SOSequence = "";
lineafter.CreatePerson = Info.XINGMING;
lineafter.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
lineafter.ExtensionID = ExtensionAfter;
lineafter.MUSER = "JOB";
lineafter.MUSERName = "JOB";
lineafter.MTIME = DateTime.Now;
lineafter.WorkPoint = Info.WERKS;//站点
lineafter.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(lineafter);
}
db.SubmitChanges();
LineNum += 10;
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionBefore = "";
string ExtensionAfter = "";
bool isNew = false;
string Colspan;
string ColspanAfter;
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
ColspanAfter = Item.VBELN_JS + "~" + SubInfo.GERNR + "~~" + Item.POSNR_JS + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
ColspanAfter = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionBefore = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionBefore;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionBefore = Extensionline.ID;
}
var ExtensionlineAfter = db.ICSExtension.SingleOrDefault(a => a.Colspan == ColspanAfter && a.WorkPoint == Info.WERKS);
if (ExtensionlineAfter == null)
{
ExtensionAfter = AppConfig.GetGuid();
ExtensionlineAfter = new ICSExtension();
ExtensionlineAfter.ID = ExtensionAfter;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_JS;
Extensionline.ProjectCode = Item.VBELN_JS;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
ExtensionlineAfter.cFree1 = "";
ExtensionlineAfter.cFree2 = "";
ExtensionlineAfter.cFree3 = "";
ExtensionlineAfter.cFree4 = "";
ExtensionlineAfter.cFree5 = "";
ExtensionlineAfter.cFree6 = "";
ExtensionlineAfter.cFree7 = "";
ExtensionlineAfter.cFree8 = "";
ExtensionlineAfter.cFree9 = "";
ExtensionlineAfter.cFree10 = "";
ExtensionlineAfter.Colspan = ColspanAfter;
ExtensionlineAfter.MTIME = DateTime.Now;
ExtensionlineAfter.MUSER = "JOB";
ExtensionlineAfter.MUSERName = "JOB";
ExtensionlineAfter.WorkPoint = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionAfter = ExtensionlineAfter.ID;
}
var linebefore = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionBefore && a.MTDOCType == "1" && a.WorkPoint == Info.WERKS);
if (linebefore == null)
{
isNew = true;
linebefore = new Frame.Data.Entity.ICSMTDOC();
linebefore.ID = AppConfig.GetGuid();
linebefore.MTDOCQuantity = 0;
linebefore.MTDOCCode = Item.DANJU;//形态转换单号
linebefore.SAPSequence = Item.POSNR;
linebefore.Sequence = LineNum.ToString(); //形态转换单行号
linebefore.MTDOCType = "1";//转换前
}
linebefore.DepCode = Info.KOSTL;
linebefore.WHCode = Item.LGORT;
linebefore.Quantity = 1;//领用数量
linebefore.Amount = 0;
linebefore.Memo = Item.SOBKZ_JS;
linebefore.Status = "2";
linebefore.INVCode = Item.MATNR.TrimStart('0');//转换前物料编码
linebefore.SOCode = "";
linebefore.SOSequence = "";
linebefore.CreatePerson = Info.XINGMING;
linebefore.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
linebefore.ExtensionID = ExtensionBefore;
linebefore.MUSER = "JOB";
linebefore.MUSERName = "JOB";
linebefore.MTIME = DateTime.Now;
linebefore.WorkPoint = Info.WERKS;//站点
linebefore.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(linebefore);
}
db.SubmitChanges();
var lineafter = db.ICSMTDOC.SingleOrDefault(a => a.MTDOCCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionAfter && a.MTDOCType == "2" && a.WorkPoint == Info.WERKS);
if (lineafter == null)
{
isNew = true;
lineafter = new Frame.Data.Entity.ICSMTDOC();
lineafter.ID = AppConfig.GetGuid();
lineafter.MTDOCQuantity = 0;
lineafter.MTDOCCode = Item.DANJU;//形态转换单号
lineafter.SAPSequence = Item.POSNR;
lineafter.Sequence = LineNum.ToString(); //形态转换单行号
lineafter.MTDOCType = "2";//转换后
}
lineafter.DepCode = Info.KOSTL;
lineafter.WHCode = Item.LGORT;
lineafter.Quantity = 1;//领用数量
lineafter.Amount = 0;
lineafter.Memo = Item.SOBKZ_JS;
lineafter.Status = "2";
lineafter.INVCode = Item.MATNR.TrimStart('0');//转换后物料编码
lineafter.SOCode = "";
lineafter.SOSequence = "";
lineafter.CreatePerson = Info.XINGMING;
lineafter.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
lineafter.ExtensionID = ExtensionAfter;
lineafter.MUSER = "JOB";
lineafter.MUSERName = "JOB";
lineafter.MTIME = DateTime.Now;
lineafter.WorkPoint = Info.WERKS;//站点
lineafter.EATTRIBUTE1 = Info.LEIXING;//单据类型 12:按单转移 13:按物料转移
if (isNew == true)
{
db.ICSMTDOC.InsertOnSubmit(lineafter);
}
db.SubmitChanges();
LineNum += 10;
}
}
}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
#region 成本中心发料/退料单维护同步(即其他出入库单 单据类型:09:其他出库单 10:其他入库单)
HeadInfo = HeadInfoList.Where(a => a.LEIXING == "09" || a.LEIXING == "10");
foreach (SAPGetDocInfoZS.ZWMS_SK_HEAD Info in HeadInfo)
{
try
{
//var chkline = db.ICSOtherOut.Where(a => a.OutCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline.Count() != 0)
//{
// continue;
//}
//var chkline2 = db.ICSOtherIn.Where(a => a.InCode == Info.DANJU && a.WorkPoint == Info.WERKS);
//if (chkline2.Count() != 0)
//{
// continue;
//}
if (db.Connection.State == ConnectionState.Open)
{
db.Connection.Close();
}
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
var ItemInfo = ItemInfoList.Where(a => a.DANJU == Info.DANJU);
int LineNum = 10;
foreach (SAPGetDocInfoZS.ZWEBSERVICE_ITEM Item in ItemInfo)
{
if (Item.SERNP != "ZS01")
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~~~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = "";
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
if (Info.LEIXING == "09")
{
var line = db.ICSOtherOut.SingleOrDefault(a => a.OutCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSOtherOut();
line.ID = AppConfig.GetGuid();
line.OutQuantity = 0;
line.OutCode = Item.DANJU;//其他出库单号
line.SAPSequence = Item.POSNR;
line.Sequence = LineNum.ToString();//其他出库单行号
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "1";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
//单据类型
line.OrderType = Info.LEIXING;
//类型描述
line.TypeDescribe = Info.MIAOSHU;
//成本中心
line.CostCenter = Info.KOSTL;
//备注
line.Remarks = Info.BEIZHU;
//人员号
line.PersonNumber = Info.PERNR;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSOtherOut.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
else
{
var line = db.ICSOtherIn.SingleOrDefault(a => a.InCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSOtherIn();
line.ID = AppConfig.GetGuid();
line.InQuantity = 0;
line.InCode = Item.DANJU;//其他出库单号
line.Sequence = LineNum.ToString();//其他出库单行号
line.SAPSequence = Item.POSNR;
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "1";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
//单据类型
line.OrderType = Info.LEIXING;
//类型描述
line.TypeDescribe = Info.MIAOSHU;
//成本中心
line.CostCenter = Info.KOSTL;
//备注
line.Remarks = Info.BEIZHU;
//人员号
line.PersonNumber = Info.PERNR;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSOtherIn.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
}
else
{
var SubLineInfo = SubLineInfoList.Where(a => a.DANJU == Item.DANJU);
foreach (SAPGetDocInfoZS.ZWEBS_GERNR SubInfo in SubLineInfo)
{
string ExtensionID = "";
bool isNew = false;
string Colspan = "";
if (Item.SOBKZ == "E")
{
Colspan = Item.VBELN_VA + "~" + SubInfo.GERNR + "~~" + Item.POSNR_VA + "~~~~~~~~~~";
}
else
{
Colspan = "~" + SubInfo.GERNR + "~~~~~~~~~~~~";
}
var Extensionline = db.ICSExtension.SingleOrDefault(a => a.Colspan == Colspan && a.WorkPoint == Info.WERKS);
if (Extensionline == null)
{
ExtensionID = AppConfig.GetGuid();
Extensionline = new ICSExtension();
Extensionline.ID = ExtensionID;
if (Item.SOBKZ == "E")
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = Item.POSNR_VA;
Extensionline.ProjectCode = Item.VBELN_VA;
}
else
{
Extensionline.BatchCode = SubInfo.GERNR;
Extensionline.Version = "";
Extensionline.Brand = "";
Extensionline.ProjectCode = "";
}
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 = Info.WERKS;
db.ICSExtension.InsertOnSubmit(Extensionline);
db.SubmitChanges();
}
else
{
ExtensionID = Extensionline.ID;
}
if (Info.LEIXING == "09")
{
var line = db.ICSOtherOut.SingleOrDefault(a => a.OutCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSOtherOut();
line.ID = AppConfig.GetGuid();
line.OutQuantity = 0;
line.OutCode = Item.DANJU;//其他出库单号
line.SAPSequence = Item.POSNR;
line.Sequence = LineNum.ToString();//其他出库单行号
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "1";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
//单据类型
line.OrderType = Info.LEIXING;
//类型描述
line.TypeDescribe = Info.MIAOSHU;
//成本中心
line.CostCenter = Info.KOSTL;
//备注
line.Remarks = Info.BEIZHU;
//人员号
line.PersonNumber = Info.PERNR;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSOtherOut.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
else
{
var line = db.ICSOtherIn.SingleOrDefault(a => a.InCode == Item.DANJU && a.SAPSequence == Item.POSNR && a.ExtensionID == ExtensionID && a.WorkPoint == Info.WERKS);
if (line == null)
{
isNew = true;
line = new Frame.Data.Entity.ICSOtherIn();
line.ID = AppConfig.GetGuid();
line.InQuantity = 0;
line.InCode = Item.DANJU;//其他出库单号
line.Sequence = LineNum.ToString();//其他出库单行号
line.SAPSequence = Item.POSNR;
line.InvCode = Item.MATNR.TrimStart('0');//物料编码
}
line.WorkPoint = Info.WERKS;//站点
line.CreatePerson = Info.XINGMING;
line.CreateDateTime = Convert.ToDateTime(Info.DATE_C);//检验时间
line.Quantity = Item.LINGYSL;//领用数量
line.Amount = 0;
line.WHCode = Item.LGORT;//仓库
line.Status = "1";
line.MUSER = "JOB";
line.MUSERName = "JOB";
line.MTIME = DateTime.Now;
line.ExtensionID = ExtensionID;
//单据类型
line.OrderType = Info.LEIXING;
//类型描述
line.TypeDescribe = Info.MIAOSHU;
//成本中心
line.CostCenter = Info.KOSTL;
//备注
line.Remarks = Info.BEIZHU;
//人员号
line.PersonNumber = Info.PERNR;
//物料描述
line.InvDescribe = Item.MAKTX;
//基本计量单位
line.Unit = Item.MEINS;
//特殊库存标识
line.StockIndicator = Item.SOBKZ;
//序列号参数
line.IsSerialNumber = Item.SERNP;
if (isNew == true)
{
db.ICSOtherIn.InsertOnSubmit(line);
}
db.SubmitChanges();
LineNum += 10;
}
}
}
}
db.Transaction.Commit();
db.Connection.Close();
}
catch (Exception ex)
{
db.Transaction.Rollback();
db.Connection.Close();
#region 调用SAP接口反写修改NOTMODIFY栏位,取消单据在SAP的锁定状态
string ErrorDanJU = Info.DANJU;
client = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD();
DocInfo = new SAPGetDocInfoZS.ZWMS_SK_WS_HEAD1();
DocInfo.DANJU = ErrorDanJU;
DocInfo.CHG_DATE = "";
DocInfo.SET_NOTMODIFY = "";
DocInfo.CLEAR_NOTMODIFY = "X";
DocInfo.WERKS = dr["WorkPointCode"].ToString();
DocInfo.Z_HEAD = new SAPGetDocInfoZS.ZWMS_SK_HEAD[1];
DocInfo.Z_ITEM = new SAPGetDocInfoZS.ZWEBSERVICE_ITEM[1];
DocInfo.Z_GERNR = new SAPGetDocInfoZS.ZWEBS_GERNR[1];
client.Timeout = 300000;
client.CallZWMS_SK_WS_HEAD(DocInfo);
#endregion
log.Error(ex.ToString());
}
}
#endregion
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public static string RestFulGet(string jsonParam, string url)
{
try
{
var userName = "ADVANCED";
var password = "SYSTEM08";
var client = new RestClient(url);
client.Authenticator = new HttpBasicAuthenticator(userName, password);
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", jsonParam, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
return response.Content;
}
catch (Exception ex)
{
throw new Exception("货柜传输检验批接口调用失败," + ex.Message);
}
}
public class ICSHGResult
{
public string PrimaryError { get; set; }
public string SecondaryError { get; set; }
public List<string> MasterRow { get; set; }
public List<string> SlaveRow { get; set; }
}
}
}