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.
1383 lines
74 KiB
1383 lines
74 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity.Migrations;
|
|
using System.Linq;
|
|
using CK.SCP.Models;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Models.UniApiEntity;
|
|
using CK.SCP.Utils;
|
|
using CK.SCP.Controller;
|
|
using System.Text;
|
|
using System.Data.Entity.Core;
|
|
using System.Text.RegularExpressions;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using System.ComponentModel;
|
|
using CK.SCP.Common;
|
|
using System.Configuration;
|
|
|
|
namespace CK.SCP.GrupUniApi.Controller
|
|
{
|
|
|
|
public class TP_TB_PO_PLAN
|
|
{
|
|
|
|
public string Domain { get; set; }
|
|
public Nullable<System.DateTime> EndTime { get; set; }
|
|
public string PoBillNum { get; set; }
|
|
public string Site { get; set; }
|
|
public string VendId { get; set; }
|
|
public string ProjectId { get; set; }
|
|
|
|
}
|
|
public static class OdbcApiQadController
|
|
{
|
|
public static void GetNewCtrlList()
|
|
{
|
|
List<string> _lst = new List<string>();
|
|
_lst.Add("xxqad_pt_mstr");
|
|
_lst.Add("xxqad_vd_mstr");
|
|
_lst.Add("xxqad_vp_mstr");
|
|
_lst.Add("xxqad_pod_det");
|
|
_lst.Add("xxqad_prh_det");
|
|
_lst.Add("xxqad_pprice_det");
|
|
_lst.Add("xxqad_ppod_det");
|
|
UniApiEntities idb = EntitiesFactory.CreateUniApiInstance();
|
|
idb.Database.CommandTimeout = 60 * 20;
|
|
var tableNameList = EnumHelper.EnumToList<QadTableName>();
|
|
// var qadCtrlList = idb.xxqad_ctrl.Where(p => p.xxqad_domain == ScpCache.Config.QADÓò && p.xxqad_scm == "0").ToList();
|
|
var qadCtrlList = idb.xxqad_ctrl.Where(p => p.xxqad_scm == "0" && _lst.Contains(p.xxqad_table)).ToList();
|
|
foreach (var qadCtrl in qadCtrlList)
|
|
{
|
|
if (tableNameList.All(p => p.Name != qadCtrl.xxqad_table)) continue;
|
|
try
|
|
{
|
|
ScpEntities wdb = EntitiesFactory.CreateScpInstance();
|
|
var authdb = EntitiesFactory.CreateAppBoxInstance();
|
|
QadTableName qadTableName;
|
|
Enum.TryParse(qadCtrl.xxqad_table, false, out qadTableName);
|
|
switch (qadTableName)
|
|
{
|
|
case QadTableName.xxqad_pt_mstr: //ÎïÁÏ
|
|
if (GlobalVar.ApiConfig.QadÁã¼þ)
|
|
{
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
UpdateParts(idb, wdb, qadCtrl.xxqad_seq);
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
}
|
|
else
|
|
continue;
|
|
break;
|
|
case QadTableName.xxqad_vd_mstr: //¹©Ó¦ÉÌ
|
|
if (GlobalVar.ApiConfig.Qad¹©Ó¦ÉÌ)
|
|
{
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
|
|
var qadDataList = idb.xxqad_vd_mstr.Where(p => p.xxqad_vd_seq == qadCtrl.xxqad_seq).ToList();
|
|
UpdateVender(qadDataList, wdb, authdb, qadCtrl.xxqad_seq);
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
UpdateVenderExtend(qadDataList, wdb, authdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
}
|
|
else
|
|
continue;
|
|
break;
|
|
case QadTableName.xxqad_vp_mstr: //¹©Ó¦ÉÌÎïÁÏ
|
|
if (GlobalVar.ApiConfig.Qad¹©Ó¦ÉÌÁã¼þ)
|
|
{
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
UpdateVendParts(idb, wdb, qadCtrl.xxqad_seq);
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
}
|
|
else
|
|
continue;
|
|
break;
|
|
case QadTableName.xxqad_pod_det: //²É¹º¶©µ¥
|
|
if (GlobalVar.ApiConfig.Qad²É¹º¶©µ¥)
|
|
{
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
// UpdatePurchaseOrders(idb, wdb, qadCtrl.xxqad_seq);
|
|
UpdatePurchaseOrders(idb, wdb, qadCtrl.xxqad_seq,"1");
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
}
|
|
else
|
|
continue;
|
|
break;
|
|
case QadTableName.xxqad_prh_det:
|
|
if (GlobalVar.ApiConfig.QadÊÕ»õµ¥)
|
|
{
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
AddReceive(idb, wdb, qadCtrl.xxqad_seq, 0);
|
|
AddReject(idb, wdb, qadCtrl.xxqad_seq, 1);
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
}
|
|
else
|
|
continue;
|
|
break;
|
|
case QadTableName.xxqad_pprice_det: //²É¹º¼Û¸ñ
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
UpdatePrice(idb, wdb, qadCtrl.xxqad_seq);
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
|
|
break;
|
|
case QadTableName.xxqad_ppod_det: //²É¹º¼Û¸ñ
|
|
Console.WriteLine($"·¢ÏÖ QAD ½Ó¿ÚÊý¾Ý£º{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
|
UpdatePPod(idb, wdb, qadCtrl.xxqad_seq);
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
EntitiesFactory.SaveDb(authdb);
|
|
|
|
break;
|
|
|
|
}
|
|
//qadCtrl.xxqad_scm = ((int)UniApiState.³É¹¦).ToString();
|
|
//EntitiesFactory.SaveDb(wdb);
|
|
//EntitiesFactory.SaveDb(authdb);
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//²¶»ñʵÌåÑéÖ¤Òì³£
|
|
{
|
|
var sb = new StringBuilder();
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
{
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
{
|
|
sb.AppendFormat("±í£º{0}£¬×ֶΣº{1}£¬ÐÅÏ¢£º{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
});
|
|
}
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadCtrl.xxqad_rmks += " SCM:" + sb.ToString();
|
|
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//²¢·¢³åÍ»Òì³£
|
|
{
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadCtrl.xxqad_rmks += " SCM:" + ex.Message+ex.InnerException.Message;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadCtrl.xxqad_scm = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadCtrl.xxqad_rmks += " SCM:" + ex.Message + ex.InnerException.Message;
|
|
|
|
}
|
|
finally
|
|
{
|
|
EntitiesFactory.SaveDb(idb);
|
|
}
|
|
}
|
|
|
|
UpdatePlanToAsk();
|
|
}
|
|
|
|
|
|
private static void UpdatePlanToAsk()
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
try
|
|
{
|
|
var _ls = db.Database.SqlQuery<TP_TB_PO_PLAN>(
|
|
"SELECT\n" +
|
|
" [Domain]\n" +
|
|
" ,[EndTime]\n" +
|
|
" ,[PoBillNum]\n" +
|
|
" ,[Site]\n" +
|
|
" ,[VendId]\n" +
|
|
|
|
"FROM [V_TB_PO_PLAN]\n" +
|
|
"where ISPLAN = 'P' and ASKBillNum is null\n" +
|
|
"GROUP BY EndTime, PoBillNum,VendId,[Site],[Domain]"
|
|
).ToList();
|
|
Console.WriteLine($"·¢ÏÖMRP½Ó¿ÚÊý¾Ý£º"+_ls.Count().ToString());
|
|
List<string> _vendList = new List<string>();
|
|
var _detail = db.Database.SqlQuery<V_TB_PO_PLAN>("select * from v_tb_po_plan where ISPLAN = 'p' and askbillnum is null").ToList();
|
|
var _first= _detail.FirstOrDefault();
|
|
foreach (var itm in _ls)
|
|
{
|
|
TB_ASK _ask = new TB_ASK();
|
|
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakePLAN_ASKCode();
|
|
_ask.VendId = itm.VendId;
|
|
_ask.State = (int)AskState.Release;
|
|
_ask.PoBillNum = itm.PoBillNum;
|
|
_ask.ModType = (int)BillModType.Contract;
|
|
_ask.Site = itm.Domain;
|
|
_ask.Remark = string.Empty;
|
|
|
|
_ask.BeginTime = DateTime.Now;
|
|
_ask.Buyer = "MRP";
|
|
_ask.BuyerPhone = string.Empty;
|
|
_ask.ErpBillNum = itm.ProjectId;
|
|
_ask.EndTime = itm.EndTime;
|
|
_ask.CreateTime = DateTime.Now;
|
|
_ask.CreateUser = "MRP";
|
|
_ask.GUID = Guid.NewGuid();
|
|
_ask.ReceivedPort = string.Empty;
|
|
_ask.IsDeleted = false;
|
|
db.TB_ASK.Add(_ask);
|
|
_vendList.Add(_ask.VendId);
|
|
var _askDetail = _detail.Where(p => p.EndTime == itm.EndTime && p.PoBillNum == itm.PoBillNum && p.VendId == itm.VendId && p.Domain==itm.Domain).ToList();
|
|
List<long> _lst = new List<long>();
|
|
foreach (var detail in _askDetail)
|
|
{
|
|
TB_ASK_DETAIL _t_ASK_Detail = new TB_ASK_DETAIL();
|
|
_t_ASK_Detail.PoLine = detail.PoLine;
|
|
_t_ASK_Detail.Currency = string.Empty;
|
|
_t_ASK_Detail.AskBillNum = _ask.AskBillNum;
|
|
_t_ASK_Detail.PoBillNum = _ask.PoBillNum;
|
|
_t_ASK_Detail.PoUnit = detail.PoUnit;
|
|
_t_ASK_Detail.CreateTime = DateTime.Now;
|
|
_t_ASK_Detail.CreateUser = _ask.CreateUser;
|
|
_t_ASK_Detail.PartCode = detail.PartCode;
|
|
_t_ASK_Detail.BeginTime = _ask.BeginTime;
|
|
_t_ASK_Detail.EndTime = _ask.EndTime;
|
|
_t_ASK_Detail.TempQty = 0;
|
|
_t_ASK_Detail.AskQty = detail.PlanQty;
|
|
_t_ASK_Detail.IsDeleted = false;
|
|
_t_ASK_Detail.LocUnit = detail.PoUnit;
|
|
_t_ASK_Detail.UnConv = 1;
|
|
_t_ASK_Detail.DockCode = string.Empty;
|
|
_t_ASK_Detail.State = _ask.State;
|
|
_t_ASK_Detail.Price = 0;
|
|
_t_ASK_Detail.GUID = Guid.NewGuid();
|
|
_t_ASK_Detail.Remark = _ask.Site;
|
|
_lst.Add(detail.UID);
|
|
db.TB_ASK_DETAIL.Add(_t_ASK_Detail);
|
|
}
|
|
var _planList=db.TB_PO_PLAN.Where(p => _lst.Contains(p.UID)).ToList();
|
|
_planList.ForEach(p => {
|
|
p.Extend2 = "F";
|
|
});
|
|
db.TB_PO_PLAN.AddOrUpdate(_planList.ToArray());
|
|
EntitiesFactory.SaveDb(db);
|
|
}
|
|
BackgroundWorker _sendMail = new BackgroundWorker();
|
|
_sendMail.DoWork += (sender, e) => {
|
|
foreach (var itm in _vendList)
|
|
{
|
|
SendMail(itm,"п´°åÉú³É³É¹¦","ÇëÈ¥SCPϵͳ²é¿´Ð¿´°å",_first.Site);
|
|
}
|
|
};
|
|
_sendMail.RunWorkerCompleted += (sender,e) => {
|
|
Console.WriteLine($"ÓʼþÒÑ·¢ËÍ!");
|
|
};
|
|
Console.WriteLine($"Íê³ÉMRP½Ó¿ÚÊý¾Ý£º" + _ls.Count().ToString());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine($"¸üÐÂMRP³ö´í£º{e.Message}");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void SendMail(string p_VendId, string p_Content, string p_title, string p_site)
|
|
{
|
|
try
|
|
{
|
|
using (AppBoxContext db = EntitiesFactory.CreateAppBoxInstance())
|
|
{
|
|
StringBuilder _buffer = new StringBuilder();
|
|
_buffer.Append("SELECT b.Email ");
|
|
_buffer.Append(" FROM VenderUsers AS a INNER JOIN ");
|
|
_buffer.Append(" Users AS b ON a.UserId = b.ID INNER JOIN ");
|
|
_buffer.Append(" FactoryUsers AS c ON a.UserId = c.UserID INNER JOIN ");
|
|
_buffer.Append(" TA_FACTORY AS d ON c.FACTORY_ID = d.ID INNER JOIN ");
|
|
_buffer.Append(" Users AS f ON c.UserID = f.ID INNER JOIN ");
|
|
_buffer.Append(" RoleUsers AS g ON a.UserId = g.UserID INNER JOIN ");
|
|
_buffer.Append(" Roles AS h ON g.RoleID = h.ID ");
|
|
_buffer.AppendFormat(" WHERE(h.Name = '¹©Ó¦ÉÌ' and a.VenderId='{0}' and d.FactoryId='{1}' ) ", p_VendId, p_site);
|
|
var _userList = db.Database.SqlQuery<string>(_buffer.ToString()).ToList();
|
|
if (_userList != null && _userList.Count > 0)
|
|
{
|
|
foreach (var itm in _userList)
|
|
{
|
|
string mails = "";
|
|
mails += itm + ",";
|
|
if (mails != "")
|
|
{
|
|
mails = mails.Substring(0, mails.Length - 1);
|
|
}
|
|
string mailbody = "";
|
|
mailbody += "×𾴵Ĺ©Ó¦ÉÌ<br>";
|
|
mailbody += "ÄãºÃ£¡<br><br>";
|
|
mailbody += "<b>" + p_Content + "</b> ,Çëµ½¹©Ó¦ÉÌÐͬÍøÕ¾" + ConfigurationManager.AppSettings["ResetPassWord"] + "´ò¿ª²é¿´£¡<br>";
|
|
mailbody += "<br><br><br><br>ÈÕÆÚ£º" + DateTime.Now;
|
|
MyWebSmtpMail webmail = new MyWebSmtpMail();
|
|
webmail.Send(mails, mailbody, p_title);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(MyWebSmtpMail), "MailManager", e.Message);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///½ÓÊÕÊÕ»õµ¥
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq">Á÷Ë®ºÅ</param>
|
|
/// <param name="billtype">0:ÊÕ»õ,1:ÍË»õ</param>
|
|
private static void AddReceive(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
|
|
{
|
|
|
|
string _rec = "SELECT * FROM [xxqad_prh_det] WHERE xxqad_prh_uid IN\n" +
|
|
"(\n" +
|
|
"SELECT\n" +
|
|
" MAX(xxqad_prh_uid)\n" +
|
|
" FROM [xxqad_prh_det] where xxqad_prh_seq='{0}' and xxqad_prh_qty_rcvd>=0\n" +
|
|
" GROUP BY\n" +
|
|
" [xxqad_prh_receiver]\n" +
|
|
" ,[xxqad_prh_po_nbr]\n" +
|
|
" ,[xxqad_prh_po_line]\n" +
|
|
" ,[xxqad_prh_part]\n" +
|
|
" ,[xxqad_prh_domain]\n" +
|
|
")";
|
|
var qadRcvDetailList = idb.Database.SqlQuery<xxqad_prh_det>(string.Format(_rec, seq)).ToList();
|
|
var scpRcvList = new List<TB_RECEIVE_QAD>();
|
|
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL_QAD>();
|
|
//¸ù¾Ýxxwms_rc_po_nbr²É¹ºµ¥×Ö¶ÎÈ¥ÖØ
|
|
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxqad_prh_receiver.ToUpper()).DistinctBy(p => p).ToList();
|
|
int j = 0;
|
|
foreach (var qadReceiveNbr in qadReceiveNbrList)
|
|
{
|
|
|
|
//qadRcvDetailListͬһxxqad_prh_receiverËùÓмǼ
|
|
var qadDataList = qadRcvDetailList.Where(p => p.xxqad_prh_receiver == qadReceiveNbr).ToList();
|
|
if (qadDataList.Count == 0)
|
|
{
|
|
continue;
|
|
}
|
|
var firstqadData = qadDataList[0];
|
|
var scpRcv = wdb.TB_RECEIVE_QAD.SingleOrDefault(p => p.ErpRecvBillNum != null && p.ErpRecvBillNum == qadReceiveNbr && p.Site == firstqadData.xxqad_prh_domain);
|
|
//ÅжÏ0100¹¤³§µÄÊÕ»õ×Ô¶¯ÉóºËÊÇ·ñΪÔÊÐí
|
|
if (scpRcv == null)
|
|
{
|
|
scpRcv = new TB_RECEIVE_QAD
|
|
{
|
|
ErpRecvBillNum = qadReceiveNbr,//ÊÕ»õµ¥ºÅ
|
|
State = (int)FormState.¿ª·Å,
|
|
Remark = "",
|
|
CreateTime = firstqadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_prh_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = firstqadData.xxqad_prh_createur,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BillType = billtype,
|
|
Site= firstqadData.xxqad_prh_domain,
|
|
SubSite = firstqadData.xxqad_prh_site,
|
|
};
|
|
}
|
|
scpRcv.PoBillNum = firstqadData.xxqad_prh_po_nbr;//²É¹ºµ¥
|
|
//·¢»õµ¥ºÅ
|
|
// scpRcv.Site = firstqadData.xxqad_prh_domain;//µØµã
|
|
//scpRcv.SubSite = firstqadData.xxqad_prh_site;
|
|
scpRcv.VendId = firstqadData.xxqad_prh_vend;//¹©»õÉÌÃû³Æ
|
|
scpRcv.ShipTime = firstqadData.xxqad_prh_date_ship;//ÊÕ»õÈÕÆÚ
|
|
scpRcv.RecvBillNum = firstqadData.xxqad_prh_psnbr;
|
|
|
|
if (scpRcvList.Count(p =>
|
|
p.ErpRecvBillNum == scpRcv.ErpRecvBillNum &&
|
|
p.Site == scpRcv.Site
|
|
) == 0)
|
|
{
|
|
scpRcvList.Add(scpRcv);
|
|
}
|
|
int i = 0;
|
|
scpRcv.Tax = firstqadData.xxqad_prh_taxc;
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var poLineNum = Convert.ToInt32(qadData.xxqad_prh_po_line);
|
|
var scpRcvDetail =
|
|
wdb.TB_RECEIVE_DETAIL_QAD.FirstOrDefault(
|
|
p => p.ErpRecvBillNum == qadReceiveNbr &&
|
|
p.PoBillNum == qadData.xxqad_prh_po_nbr &&
|
|
p.PoLine == poLineNum &&
|
|
p.PartCode == qadData.xxqad_prh_part &&
|
|
p.Site==qadData.xxqad_prh_domain
|
|
&& p.Qty>=0
|
|
);
|
|
if (scpRcvDetail == null)
|
|
{
|
|
scpRcvDetail = new TB_RECEIVE_DETAIL_QAD
|
|
{
|
|
ErpRecvBillNum = qadReceiveNbr,
|
|
RecvBillNum = qadData.xxqad_prh_psnbr,//ÊÕ»õµ¥ºÅ
|
|
PoBillNum = qadData.xxqad_prh_po_nbr,//²É¹ºµ¥
|
|
PoLine = poLineNum,//¶©µ¥ÐÐ
|
|
PartCode = qadData.xxqad_prh_part,//Áã¼þºÅ
|
|
Batch = qadData.xxqad_prh_vend_batch,//Åú´Î
|
|
VendBatch = qadData.xxqad_prh_vend_batch,//¹©Ó¦ÉÌÅúºÅ
|
|
PoUnit = qadData.xxqad_prh_po_um,//²É¹ºµ¥Î»
|
|
LocUnit = qadData.xxqad_prh_loc_um,//»ù±¾µ¥Î»
|
|
Qty = qadData.xxqad_prh_qty_rcvd,//ÊÕ»õ×ÜÁ¿
|
|
CurAmt = qadData.xxqad_prh_curr_amt != null ? qadData.xxqad_prh_curr_amt.Value : 0,
|
|
DockCode = qadData.xxqad_prh_loc,//ÊÕ»õ¿Ú
|
|
State = (int)FormState.¿ª·Å,// (int)FormState.¹Ø±Õ,
|
|
CreateTime = qadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)qadData.xxqad_prh_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = qadData.xxqad_prh_createur,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BillType = billtype,
|
|
PurCost = qadData.xxqad_prh_pur_cost,
|
|
StdCost = qadData.xxqad_prh_std_cost != null ? qadData.xxqad_prh_std_cost.Value : 0,
|
|
Rate = qadData.xxqad_prh_curr_rate != null ? qadData.xxqad_prh_curr_rate.Value : 1,
|
|
Site = qadData.xxqad_prh_domain,
|
|
Tax = firstqadData.xxqad_prh_taxc,
|
|
SubSite = qadData.xxqad_prh_site,
|
|
};
|
|
}
|
|
|
|
scpRcvDetail.RecvBillNum = !string.IsNullOrEmpty(qadData.xxqad_prh_psnbr) ? qadData.xxqad_prh_psnbr : string.Empty;
|
|
|
|
scpRcvDetail.CurAmt = qadData.xxqad_prh_curr_amt != null ? qadData.xxqad_prh_curr_amt.Value : 0;
|
|
scpRcvDetail.PurCost = qadData.xxqad_prh_pur_cost;
|
|
scpRcvDetail.StdCost = qadData.xxqad_prh_std_cost != null ? qadData.xxqad_prh_std_cost.Value : 0;
|
|
scpRcvDetail.Rate = qadData.xxqad_prh_curr_rate != null ? qadData.xxqad_prh_curr_rate.Value : 1;
|
|
//scpRcvDetail.Site = qadData.xxqad_prh_domain;
|
|
//scpRcvDetail.SubSite = qadData.xxqad_prh_site;
|
|
scpRcvDetail.Tax = firstqadData.xxqad_prh_taxc;
|
|
if (scpRcveDetailList.Count(p =>
|
|
p.RecvBillNum == scpRcvDetail.RecvBillNum &&
|
|
p.ErpRecvBillNum == scpRcvDetail.ErpRecvBillNum &&
|
|
p.PoBillNum == scpRcvDetail.PoBillNum &&
|
|
p.PoLine == scpRcvDetail.PoLine &&
|
|
p.PartCode == scpRcvDetail.PartCode&&
|
|
p.Site==scpRcvDetail.Site
|
|
) == 0)
|
|
{
|
|
scpRcveDetailList.Add(scpRcvDetail);
|
|
}
|
|
i++;
|
|
qadData.xxqad_prh_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_prh_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_prh_rmks += " SCM:" + ex.Message+i.ToString()+","+j.ToString();
|
|
}
|
|
qadData.xxqad_prh_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_prh_updatedt = DateTime.Now;
|
|
}
|
|
}
|
|
wdb.TB_RECEIVE_QAD.AddOrUpdate(scpRcvList.ToArray());
|
|
wdb.TB_RECEIVE_DETAIL_QAD.AddOrUpdate(scpRcveDetailList.ToArray());
|
|
Console.WriteLine($"¸üРÊÕ»õµ¥ Êý¾Ý£º{qadRcvDetailList.Count}");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void AddReject(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
|
|
{
|
|
string _rec = "SELECT * FROM [xxqad_prh_det] WHERE xxqad_prh_uid IN\n" +
|
|
"(\n" +
|
|
"SELECT\n" +
|
|
" MAX(xxqad_prh_uid)\n" +
|
|
" FROM [xxqad_prh_det] where xxqad_prh_seq='{0}' and xxqad_prh_qty_rcvd<0 \n" +
|
|
" GROUP BY\n" +
|
|
" [xxqad_prh_receiver]\n" +
|
|
" ,[xxqad_prh_po_nbr]\n" +
|
|
" ,[xxqad_prh_po_line]\n" +
|
|
" ,[xxqad_prh_part]\n" +
|
|
" ,[xxqad_prh_domain]\n" +
|
|
")";
|
|
var qadRcvDetailList = idb.Database.SqlQuery<xxqad_prh_det>(string.Format(_rec, seq)).ToList();
|
|
var scpRcvList = new List<TB_RECEIVE_QAD>();
|
|
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL_QAD>();
|
|
//¸ù¾Ýxxwms_rc_po_nbr²É¹ºµ¥×Ö¶ÎÈ¥ÖØ
|
|
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxqad_prh_receiver.ToUpper()).DistinctBy(p => p).ToList();
|
|
|
|
foreach (var qadReceiveNbr in qadReceiveNbrList)
|
|
{
|
|
|
|
//qadRcvDetailListͬһxxqad_prh_receiverËùÓмǼ
|
|
var qadDataList = qadRcvDetailList.Where(p => p.xxqad_prh_receiver == qadReceiveNbr).ToList();
|
|
if (qadDataList.Count == 0)
|
|
{
|
|
continue;
|
|
}
|
|
var firstqadData = qadDataList[0];
|
|
var scpRcv = wdb.TB_RECEIVE_QAD.FirstOrDefault(p => p.ErpRecvBillNum != null && p.ErpRecvBillNum == qadReceiveNbr && p.Site == firstqadData.xxqad_prh_domain);
|
|
|
|
|
|
//ÅжÏ0100¹¤³§µÄÊÕ»õ×Ô¶¯ÉóºËÊÇ·ñΪÔÊÐí
|
|
if (scpRcv == null)
|
|
{
|
|
scpRcv = new TB_RECEIVE_QAD
|
|
{
|
|
ErpRecvBillNum = qadReceiveNbr,//ÊÕ»õµ¥ºÅ
|
|
State = (int)FormState.¿ª·Å,
|
|
Remark = "",
|
|
CreateTime = firstqadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_prh_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = firstqadData.xxqad_prh_createur,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BillType = billtype,
|
|
Site= firstqadData.xxqad_prh_domain,
|
|
SubSite = firstqadData.xxqad_prh_site,
|
|
};
|
|
}
|
|
scpRcv.PoBillNum = firstqadData.xxqad_prh_po_nbr;//²É¹ºµ¥ //·¢»õµ¥ºÅ
|
|
//scpRcv.Site = firstqadData.xxqad_prh_domain;//µØµã
|
|
//scpRcv.SubSite = firstqadData.xxqad_prh_site;//µØµã
|
|
scpRcv.VendId = firstqadData.xxqad_prh_vend;//¹©»õÉÌÃû³Æ
|
|
scpRcv.ShipTime = firstqadData.xxqad_prh_date_ship;//ÊÕ»õÈÕÆÚ
|
|
scpRcv.RecvBillNum = firstqadData.xxqad_prh_psnbr;
|
|
scpRcvList.Add(scpRcv);
|
|
scpRcv.Tax = firstqadData.xxqad_prh_taxc;
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var poLineNum = Convert.ToInt32(qadData.xxqad_prh_po_line);
|
|
var scpRcvDetail =
|
|
wdb.TB_RECEIVE_DETAIL_QAD.SingleOrDefault(
|
|
p => p.ErpRecvBillNum == qadReceiveNbr &&
|
|
p.PoBillNum == qadData.xxqad_prh_po_nbr &&
|
|
p.PoLine == poLineNum &&
|
|
p.PartCode == qadData.xxqad_prh_part
|
|
&& p.Site==qadData.xxqad_prh_domain
|
|
|
|
);
|
|
if (scpRcvDetail == null)
|
|
{
|
|
|
|
scpRcvDetail = new TB_RECEIVE_DETAIL_QAD
|
|
{
|
|
ErpRecvBillNum = qadReceiveNbr,
|
|
RecvBillNum = qadData.xxqad_prh_psnbr,//ÊÕ»õµ¥ºÅ
|
|
PoBillNum = qadData.xxqad_prh_po_nbr,//²É¹ºµ¥
|
|
PoLine = poLineNum,//¶©µ¥ÐÐ
|
|
PartCode = qadData.xxqad_prh_part,//Áã¼þºÅ
|
|
Batch = qadData.xxqad_prh_vend_batch,//Åú´Î
|
|
VendBatch = qadData.xxqad_prh_vend_batch,//¹©Ó¦ÉÌÅúºÅ
|
|
PoUnit = qadData.xxqad_prh_po_um,//²É¹ºµ¥Î»
|
|
LocUnit = qadData.xxqad_prh_loc_um,//»ù±¾µ¥Î»
|
|
Qty = qadData.xxqad_prh_qty_rcvd,//ÊÕ»õ×ÜÁ¿
|
|
CurAmt = qadData.xxqad_prh_curr_amt != null ? qadData.xxqad_prh_curr_amt.Value : 0,
|
|
DockCode = qadData.xxqad_prh_loc,//ÊÕ»õ¿Ú
|
|
State = (int)FormState.¿ª·Å,// (int)FormState.¹Ø±Õ,
|
|
CreateTime = qadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)qadData.xxqad_prh_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = qadData.xxqad_prh_createur,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BillType = billtype,
|
|
PurCost = qadData.xxqad_prh_pur_cost,
|
|
StdCost = qadData.xxqad_prh_std_cost != null ? qadData.xxqad_prh_std_cost.Value : 0,
|
|
Rate = qadData.xxqad_prh_curr_rate != null ? qadData.xxqad_prh_curr_rate.Value : 1,
|
|
Site = qadData.xxqad_prh_domain,
|
|
SubSite=qadData.xxqad_prh_site,
|
|
Tax = firstqadData.xxqad_prh_taxc
|
|
};
|
|
|
|
}
|
|
scpRcvDetail.RecvBillNum = !string.IsNullOrEmpty(qadData.xxqad_prh_psnbr) ? qadData.xxqad_prh_psnbr : string.Empty;
|
|
scpRcvDetail.PurCost = qadData.xxqad_prh_pur_cost;
|
|
scpRcvDetail.StdCost = qadData.xxqad_prh_std_cost != null ? qadData.xxqad_prh_std_cost.Value : 0;
|
|
scpRcvDetail.Rate = qadData.xxqad_prh_curr_rate != null ? qadData.xxqad_prh_curr_rate.Value : 1;
|
|
scpRcvDetail.CurAmt = qadData.xxqad_prh_curr_amt != null ? qadData.xxqad_prh_curr_amt.Value : 0;
|
|
//scpRcvDetail.Site = qadData.xxqad_prh_domain;
|
|
//scpRcvDetail.SubSite = qadData.xxqad_prh_domain;
|
|
|
|
scpRcveDetailList.Add(scpRcvDetail);
|
|
qadData.xxqad_prh_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_prh_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_prh_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_prh_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_prh_updatedt = DateTime.Now;
|
|
}
|
|
}
|
|
wdb.TB_RECEIVE_QAD.AddOrUpdate(scpRcvList.ToArray());
|
|
wdb.TB_RECEIVE_DETAIL_QAD.AddOrUpdate(scpRcveDetailList.ToArray());
|
|
Console.WriteLine($"¸üРÍË»õµ¥ Êý¾Ý£º{qadRcvDetailList.Count}");
|
|
}
|
|
/// <summary>
|
|
/// ¸üвɹº¶©µ¥
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq"></param>
|
|
private static void UpdatePPod(UniApiEntities idb, ScpEntities wdb, string seq)
|
|
{
|
|
string _sql = "select * from\n" +
|
|
"(SELECT [xxqad_ppod_uid]\n" +
|
|
" ,[xxqad_ppod_seq]\n" +
|
|
" ,[xxqad_ppod_nbr]\n" +
|
|
" ,[xxqad_ppod_line]\n" +
|
|
" ,case\n" +
|
|
" LEN(replace([xxqad_ppod_rev],'-',''))\n" +
|
|
" when 8 then replace([xxqad_ppod_rev],'-','')+'000'\n" +
|
|
" when 11 then replace([xxqad_ppod_rev],'-','') end as xxqad_ppod_rev\n" +
|
|
" ,[xxqad_ppod_site]\n" +
|
|
" ,[xxqad_ppod_domain]\n" +
|
|
" ,[xxqad_ppod_part]\n" +
|
|
" ,[xxqad_ppod_desc]\n" +
|
|
" ,[xxqad_ppod_type]\n" +
|
|
" ,[xxqad_ppod_wolot]\n" +
|
|
" ,[xxqad_ppod_pricum]\n" +
|
|
" ,[xxqad_ppod_reccum]\n" +
|
|
" ,[xxqad_ppod_qty_ord]\n" +
|
|
" ,[xxqad_ppod_qty_std]\n" +
|
|
" ,[xxqad_ppod_due_date]\n" +
|
|
" ,[xxqad_ppod_loc_um]\n" +
|
|
" ,[xxqad_ppod_um]\n" +
|
|
" ,[xxqad_ppod_um_conv]\n" +
|
|
" ,[xxqad_ppod_vend]\n" +
|
|
" ,[xxqad_ppod_buyer]\n" +
|
|
" ,[xxqad_ppod_buyer_phone]\n" +
|
|
" ,[xxqad_ppod_status]\n" +
|
|
" ,[xxqad_ppod_qadread]\n" +
|
|
" ,[xxqad_ppod_wmsread]\n" +
|
|
" ,[xxqad_ppod_scmread]\n" +
|
|
" ,[xxqad_ppod_mesread]\n" +
|
|
" ,[xxqad_ppod_rmks]\n" +
|
|
" ,[xxqad_ppod_createdt]\n" +
|
|
" ,[xxqad_ppod_createur]\n" +
|
|
" ,[xxqad_ppod_updatedt]\n" +
|
|
" ,[xxqad_ppod_prj]\n" + //ÆäËûµØÇø×¢ÊÍ´ËÏî
|
|
" ,[xxqad_ppod_plan]\n" + //ÆäËûµØÇø×¢ÊÍ´ËÏî
|
|
" ,[xxqad_ppod_updateur] from xxqad_ppod_det\n" +
|
|
" where xxqad_ppod_seq = '{0}' and xxqad_ppod_scmread = '0'\n" +
|
|
" ) as a\n" +
|
|
"inner join\n" +
|
|
"(\n" +
|
|
"SELECT\n" +
|
|
" xxqad_ppod_seq\n" +
|
|
" ,[xxqad_ppod_nbr]\n" +
|
|
" ,[xxqad_ppod_line]\n" +
|
|
" ,[xxqad_ppod_domain]\n" +
|
|
" ,[xxqad_ppod_part]\n" +
|
|
" ,[xxqad_ppod_due_date]\n" +
|
|
" ,[xxqad_ppod_vend]\n" +
|
|
" ,max(\n" +
|
|
" case\n" +
|
|
" LEN(replace([xxqad_ppod_rev],'-',''))\n" +
|
|
" when 8 then replace([xxqad_ppod_rev],'-','')+'000'\n" +
|
|
" when 11 then replace([xxqad_ppod_rev],'-','') end\n" +
|
|
" ) as xxqad_ppod_rev\n" +
|
|
" FROM [xxqad_ppod_det]\n" +
|
|
" where xxqad_ppod_seq = '{0}' and xxqad_ppod_scmread = '0'\n" +
|
|
" group by\n" +
|
|
" xxqad_ppod_seq\n" +
|
|
" ,[xxqad_ppod_nbr]\n" +
|
|
" ,[xxqad_ppod_line]\n" +
|
|
" ,[xxqad_ppod_domain]\n" +
|
|
" ,[xxqad_ppod_part]\n" +
|
|
" ,[xxqad_ppod_due_date]\n" +
|
|
" ,[xxqad_ppod_vend]) as b\n" +
|
|
" on\n" +
|
|
" a.xxqad_ppod_seq=b.xxqad_ppod_seq\n" +
|
|
" and a.xxqad_ppod_domain=b.xxqad_ppod_domain\n" +
|
|
" and a.xxqad_ppod_due_date=b.xxqad_ppod_due_date\n" +
|
|
" and a.xxqad_ppod_line=b.xxqad_ppod_line\n" +
|
|
" and a.xxqad_ppod_nbr=b.xxqad_ppod_nbr\n" +
|
|
" and a.xxqad_ppod_vend=b.xxqad_ppod_vend\n" +
|
|
" and a.xxqad_ppod_part=b.xxqad_ppod_part\n" +
|
|
" and a.xxqad_ppod_rev=b.xxqad_ppod_rev";
|
|
_sql = string.Format(_sql, seq);
|
|
var _ppodList=idb.Database.SqlQuery<xxqad_ppod_det>(_sql).ToList();
|
|
|
|
List<TB_PO_PLAN> _list = new List<TB_PO_PLAN>();
|
|
|
|
try
|
|
{
|
|
|
|
foreach (var itm in _ppodList)
|
|
{
|
|
|
|
var _plan=wdb.TB_PO_PLAN.Where(p => p.PoBillNum == itm.xxqad_ppod_nbr && p.PartCode == itm.xxqad_ppod_part && p.EndTime == itm.xxqad_ppod_due_date && p.Domain == itm.xxqad_ppod_domain && p.Site == itm.xxqad_ppod_site && p.Version == itm.xxqad_ppod_rev).FirstOrDefault();
|
|
if(_plan!=null)
|
|
{
|
|
_plan.PlanQty = itm.xxqad_ppod_qty_ord.Value;
|
|
continue;
|
|
|
|
}
|
|
_plan = new TB_PO_PLAN();
|
|
_plan.PoBillNum = itm.xxqad_ppod_nbr;
|
|
_plan.VendId = itm.xxqad_ppod_vend;
|
|
_plan.IsDeleted = false;//²Ù×÷Ô±
|
|
_plan.CreateTime = itm.xxqad_ppod_createdt == null ? DateTime.Now : itm.xxqad_ppod_createdt.Value;
|
|
_plan.CreateUser = itm.xxqad_ppod_createur;
|
|
_plan.Domain = itm.xxqad_ppod_domain;
|
|
_plan.Site = itm.xxqad_ppod_site;
|
|
_plan.PlanType = (int)PoPlanType.New;
|
|
_plan.ErpBillNum = itm.xxqad_ppod_nbr;
|
|
_plan.BeginTime = itm.xxqad_ppod_createdt == null ? DateTime.Now : itm.xxqad_ppod_createdt.Value;
|
|
_plan.EndTime = itm.xxqad_ppod_due_date;
|
|
_plan.Buyer = itm.xxqad_ppod_buyer;
|
|
_plan.BuyerPhone = itm.xxqad_ppod_buyer_phone;
|
|
_plan.PoLine = itm.xxqad_ppod_line;
|
|
_plan.PoUnit = itm.xxqad_ppod_um;
|
|
_plan.CreateTime = itm.xxqad_ppod_createdt == null ? DateTime.Now : itm.xxqad_ppod_createdt.Value;
|
|
_plan.CreateUser = itm.xxqad_ppod_createur;
|
|
_plan.PartCode = itm.xxqad_ppod_part;
|
|
_plan.EndTime = itm.xxqad_ppod_due_date;
|
|
_plan.PlanQty = itm.xxqad_ppod_qty_ord.Value;
|
|
_plan.IsDeleted = false;
|
|
_plan.LocUnit = itm.xxqad_ppod_um;
|
|
_plan.UnConv = itm.xxqad_ppod_um_conv;
|
|
_plan.State = (int)AskState.New;
|
|
_plan.GUID = Guid.NewGuid();
|
|
_plan.Version = itm.xxqad_ppod_rev;
|
|
_plan.Extend1 = itm.xxqad_ppod_prj;
|
|
_plan.Extend2 = itm.xxqad_ppod_plan;
|
|
_list.Add(_plan);
|
|
}
|
|
|
|
List<TB_PO_PLAN> _ls = new List<TB_PO_PLAN>();
|
|
foreach (var itm in _list)
|
|
{
|
|
var _count=_ls.Count(p => p.PoBillNum == itm.PoBillNum && p.PartCode == itm.PartCode && p.EndTime == itm.EndTime && p.Domain == p.Domain && p.Site == itm.Site && p.Version == itm.Version);
|
|
if (_count == 0)
|
|
{
|
|
_ls.Add(itm);
|
|
}
|
|
}
|
|
wdb.TB_PO_PLAN.AddOrUpdate(_ls.ToArray());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
|
|
Console.WriteLine($"¸üп´°åÊý¾Ý£º{_ppodList.Count}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// ¸üвɹº¶©µ¥
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq"></param>
|
|
private static void UpdatePurchaseOrders(UniApiEntities idb, ScpEntities wdb, string seq)
|
|
{
|
|
var _ls=wdb.TB_FACTORY.Select(p => p.FactoryId).ToList();
|
|
// var qadPoDetailList = idb.xxqad_pod_det.Where(p => p.xxqad_pod_seq == seq).ToList(); ÔÀ´µÄ xxqad_pod_modtype 1Ϊ´ó¶©µ¥
|
|
var qadPoDetailList = idb.xxqad_pod_det.Where(p => p.xxqad_pod_seq == seq && p.xxqad_pod_scmread == "0").ToList();
|
|
|
|
var wmsPoList = new List<TB_PO>();
|
|
var wmsPoDetailList = new List<TB_PO_DETAIL>();
|
|
|
|
var qadPoNbrList = qadPoDetailList.Select(p => p.xxqad_pod_nbr.ToUpper()).DistinctBy(p => p);
|
|
|
|
foreach (var qadPoNbr in qadPoNbrList)
|
|
{
|
|
var qadDataList = qadPoDetailList.Where(p => p.xxqad_pod_nbr == qadPoNbr).ToList();
|
|
if (qadDataList.Count == 0)
|
|
{
|
|
continue;
|
|
}
|
|
var firstqadData = qadDataList[0];
|
|
//var wmsPo = wdb.TF_PO.SingleOrDefault(p => p.ErpBillNum == qadPoNbr);
|
|
var wmsPo = wdb.TB_PO.SingleOrDefault(p => p.ErpBillNum == qadPoNbr );
|
|
if (wmsPo == null)
|
|
{
|
|
int temp;
|
|
string strPoBillNum = SCP_BILLCODE_CONTROLLER.MakePOCode();
|
|
wmsPo = new TB_PO
|
|
{
|
|
PoBillNum = qadPoNbr,//¶©µ¥ºÅ
|
|
ErpBillNum = firstqadData.xxqad_pod_prj,//ERP¶©µ¥ºÅ
|
|
VendId = firstqadData.xxqad_pod_vend.ToUpper(),//¹©Ó¦É̱àºÅ
|
|
ModType = Int32.TryParse(firstqadData.xxqad_pod_modtype, out temp) ? temp : (int?)null, //µ¥¾ÝÀàÐÍ(1:Èճ̵¥,2:ÀëÉ¢¶©µ¥)
|
|
Contacter = firstqadData.xxqad_pod_attn,//ÁªÏµÈË
|
|
Site = firstqadData.xxqad_pod_domain,//µØµã
|
|
State = (int)FormState.¿ª·Å,//״̬
|
|
CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = firstqadData.xxqad_pod_createur,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BeginTime = firstqadData.xxqad_pod_createdt==null ? DateTime.Now: (DateTime)firstqadData.xxqad_pod_createdt,//´´½¨ÈÕÆÚ
|
|
EndTime = firstqadData.xxqad_pod_due_date//ÊÕ»õ½áÊøʱ¼ä
|
|
};
|
|
wmsPoList.Add(wmsPo);
|
|
}
|
|
wmsPo.Contacter = firstqadData.xxqad_pod_attn;
|
|
wmsPo.Buyer = firstqadData.xxqad_pod_buyer;
|
|
wmsPo.BuyerPhone = firstqadData.xxqad_pod_buyer_phone;
|
|
wmsPo.UpdateTime = firstqadData.xxqad_pod_updatedt;//¸üÐÂÈÕÆÚ
|
|
wmsPo.UpdateUser = firstqadData.xxqad_pod_updateur;//¸üÐÂÓû§
|
|
wmsPo.SubSite = firstqadData.xxqad_pod_site;
|
|
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var lineNum = Convert.ToInt32(qadData.xxqad_pod_line);
|
|
|
|
var wmsPoDetail =
|
|
wdb.TB_PO_DETAIL.SingleOrDefault(
|
|
p => p.PoBillNum == qadPoNbr && p.PoLine == lineNum && p.Remark==qadData.xxqad_pod_domain);
|
|
if (wmsPoDetail == null)
|
|
{
|
|
wmsPoDetail = new TB_PO_DETAIL
|
|
{
|
|
PoBillNum = qadPoNbr,//¶©µ¥ºÅ
|
|
PoLine = lineNum,//¶©µ¥ÐÐ
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid()
|
|
};
|
|
wmsPoDetailList.Add(wmsPoDetail);
|
|
}
|
|
wmsPoDetail.PartCode = qadData.xxqad_pod_part.ToUpper();//Áã¼þºÅ-ÎïÁϺÅ
|
|
wmsPoDetail.PlanQty = qadData.xxqad_pod_qty_ord;//¶©»õÊýÁ¿-²É¹ºÁ¿
|
|
wmsPoDetail.BeginTime = firstqadData.xxqad_pod_createdt;//ÊÕ»õ¿ªÊ¼Ê±¼ä
|
|
wmsPoDetail.EndTime = qadData.xxqad_pod_due_date;//ÊÕ»õ½áÊøʱ¼ä
|
|
wmsPoDetail.PoUnit = qadData.xxqad_pod_um;//²É¹ºµ¥Î»
|
|
wmsPoDetail.LocUnit = qadData.xxqad_pod_loc_um.ToUpper();//´æ´¢µ¥Î»
|
|
wmsPoDetail.DockCode = qadData.xxqad_pod_loc;
|
|
wmsPoDetail.Price = ScpCache.Config.ÏîÄ¿Ãû³Æ == ProjectName.ÖØÇì±±ÆûÄ£ËÜ.ToString()? 0: qadData.xxqad_pod_price;
|
|
wmsPoDetail.Currency = qadData.xxqad_pod_curr;//±ÒÖÖ
|
|
wmsPoDetail.PackQty = qadData.xxqad_pod_qty_std;//±ê°üÊýÁ¿
|
|
wmsPoDetail.UnConv = qadData.xxqad_pod_um_conv;//ת»»ÂÊ
|
|
wmsPoDetail.DockCode = qadData.xxqad_pod_loc;
|
|
wmsPoDetail.State = Convert.ToInt32(qadData.xxqad_pod_status);//״̬
|
|
wmsPoDetail.Site = qadData.xxqad_pod_domain;//±¸×¢
|
|
wmsPoDetail.SubSite = qadData.xxqad_pod_site;
|
|
wmsPoDetail.CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt;//´´½¨ÈÕÆÚ
|
|
wmsPoDetail.CreateUser = firstqadData.xxqad_pod_createur;//´´½¨Óû§
|
|
wmsPoDetail.UpdateTime = firstqadData.xxqad_pod_updatedt;//¸üÐÂÈÕÆÚ
|
|
wmsPoDetail.UpdateUser = firstqadData.xxqad_pod_updateur;//¸üÐÂÓû§
|
|
//if (wmsPoDetail.BillQty != 0 && wmsPoDetail.BillQty <= wmsPoDetail.ReceivedQty)
|
|
// wmsPoDetail.State = (int)FormState.¹Ø±Õ;
|
|
|
|
if (wmsPoDetail.PlanQty != 0 && wmsPoDetail.PlanQty <= wmsPoDetail.ReceivedQty)
|
|
wmsPoDetail.State = (int)FormState.¹Ø±Õ;
|
|
|
|
qadData.xxqad_pod_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_pod_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_pod_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_pod_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_pod_updatedt = DateTime.Now;
|
|
|
|
}
|
|
wmsPo.State = qadDataList.All(p => p.xxqad_pod_status == ((int)FormState.¹Ø±Õ).ToString())
|
|
? (int)FormState.¹Ø±Õ
|
|
: (int)FormState.¿ª·Å;
|
|
}
|
|
wdb.TB_PO.AddOrUpdate(wmsPoList.ToArray());
|
|
wdb.TB_PO_DETAIL.AddOrUpdate(wmsPoDetailList.ToArray());
|
|
Console.WriteLine($"¸üР²É¹º¶©µ¥ Êý¾Ý£º{qadPoDetailList.Count}");
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UpdatePurchaseOrders(UniApiEntities idb, ScpEntities wdb, string seq,string p_flag)
|
|
{
|
|
var _ls = wdb.TB_FACTORY.Select(p => p.FactoryId).ToList();
|
|
var wmsPoList = new List<TB_PO>();
|
|
var wmsPoDetailList = new List<TB_PO_DETAIL>();
|
|
var _askList = new List<TB_ASK>();
|
|
var _askDetailList = new List<TB_ASK_DETAIL>();
|
|
var qadPoDetailList = idb.xxqad_pod_det.Where(p => p.xxqad_pod_seq == seq && p.xxqad_pod_scmread == "0" ).ToList();
|
|
List<xxqad_pod_det> _lst = new List<xxqad_pod_det>();
|
|
foreach (var itm in qadPoDetailList)
|
|
{
|
|
var _cnt=_lst.Where(p => p.xxqad_pod_nbr == itm.xxqad_pod_nbr && p.xxqad_pod_domain == itm.xxqad_pod_domain).Count();
|
|
if(_cnt==0)
|
|
{
|
|
_lst.Add(itm);
|
|
}
|
|
}
|
|
foreach (var po in _lst)
|
|
{
|
|
var firstqadData = po;
|
|
var qadDataList = qadPoDetailList.Where(p => p.xxqad_pod_nbr == po.xxqad_pod_nbr && p.xxqad_pod_domain==po.xxqad_pod_domain).ToList();
|
|
var wmsPo = wdb.TB_PO.SingleOrDefault(p => p.PoBillNum== po.xxqad_pod_nbr && p.Site==po.xxqad_pod_domain);
|
|
if (wmsPo == null)
|
|
{
|
|
int temp;
|
|
wmsPo = new TB_PO
|
|
{
|
|
PoBillNum = po.xxqad_pod_nbr,//¶©µ¥ºÅ
|
|
ErpBillNum = po.xxqad_pod_prj,//ERP¶©µ¥ºÅ
|
|
VendId = firstqadData.xxqad_pod_vend.ToUpper(),//¹©Ó¦É̱àºÅ
|
|
ModType = Int32.TryParse(firstqadData.xxqad_pod_modtype, out temp) ? temp : (int?)null, //µ¥¾ÝÀàÐÍ(1:Èճ̵¥,2:ÀëÉ¢¶©µ¥)
|
|
Contacter = firstqadData.xxqad_pod_attn,//ÁªÏµÈË
|
|
Site = firstqadData.xxqad_pod_domain,//µØµã
|
|
SubSite=firstqadData.xxqad_pod_site,
|
|
State = (int)FormState.¿ª·Å,//״̬
|
|
CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = firstqadData.xxqad_pod_createur,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BeginTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt,//´´½¨ÈÕÆÚ
|
|
EndTime = firstqadData.xxqad_pod_due_date//ÊÕ»õ½áÊøʱ¼ä
|
|
};
|
|
wmsPoList.Add(wmsPo);
|
|
}
|
|
wmsPo.Contacter = firstqadData.xxqad_pod_attn;
|
|
wmsPo.Buyer = firstqadData.xxqad_pod_buyer;
|
|
wmsPo.BuyerPhone = firstqadData.xxqad_pod_buyer_phone;
|
|
wmsPo.UpdateTime = firstqadData.xxqad_pod_updatedt;//¸üÐÂÈÕÆÚ
|
|
wmsPo.UpdateUser = firstqadData.xxqad_pod_updateur;//¸üÐÂÓû§
|
|
wmsPo.State = qadDataList.All(p => p.xxqad_pod_status == ((int)FormState.¹Ø±Õ).ToString())
|
|
? (int)FormState.¹Ø±Õ
|
|
: (int)FormState.¿ª·Å;
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var lineNum = Convert.ToInt32(qadData.xxqad_pod_line);
|
|
var wmsPoDetail =
|
|
wdb.TB_PO_DETAIL.SingleOrDefault(
|
|
p => p.PoBillNum == qadData.xxqad_pod_nbr && p.PoLine == lineNum && p.Site== qadData.xxqad_pod_domain);
|
|
if (wmsPoDetail == null)
|
|
{
|
|
wmsPoDetail = new TB_PO_DETAIL
|
|
{
|
|
PoBillNum = qadData.xxqad_pod_nbr,//¶©µ¥ºÅ
|
|
PoLine = lineNum,//¶©µ¥ÐÐ
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid()
|
|
};
|
|
wmsPoDetailList.Add(wmsPoDetail);
|
|
}
|
|
wmsPoDetail.PartCode = qadData.xxqad_pod_part.ToUpper();//Áã¼þºÅ-ÎïÁϺÅ
|
|
wmsPoDetail.PlanQty = qadData.xxqad_pod_qty_ord;//¶©»õÊýÁ¿-²É¹ºÁ¿
|
|
wmsPoDetail.BeginTime = firstqadData.xxqad_pod_createdt;//ÊÕ»õ¿ªÊ¼Ê±¼ä
|
|
wmsPoDetail.EndTime = qadData.xxqad_pod_due_date;//ÊÕ»õ½áÊøʱ¼ä
|
|
wmsPoDetail.PoUnit = qadData.xxqad_pod_um;//²É¹ºµ¥Î»
|
|
wmsPoDetail.LocUnit = qadData.xxqad_pod_loc_um.ToUpper();//´æ´¢µ¥Î»
|
|
wmsPoDetail.DockCode = qadData.xxqad_pod_loc;
|
|
wmsPoDetail.Price = ScpCache.Config.ÏîÄ¿Ãû³Æ == ProjectName.ÖØÇì±±ÆûÄ£ËÜ.ToString()
|
|
? 0
|
|
: qadData.xxqad_pod_price;
|
|
wmsPoDetail.Currency = qadData.xxqad_pod_curr;//±ÒÖÖ
|
|
wmsPoDetail.PackQty = qadData.xxqad_pod_qty_std;//±ê°üÊýÁ¿
|
|
wmsPoDetail.UnConv = qadData.xxqad_pod_um_conv;//ת»»ÂÊ
|
|
wmsPoDetail.DockCode = qadData.xxqad_pod_loc;
|
|
wmsPoDetail.State = Convert.ToInt32(qadData.xxqad_pod_status);//״̬
|
|
wmsPoDetail.Site = qadData.xxqad_pod_domain;//±¸×¢
|
|
wmsPoDetail.SubSite = qadData.xxqad_pod_site;
|
|
wmsPoDetail.CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt;//´´½¨ÈÕÆÚ
|
|
wmsPoDetail.CreateUser = firstqadData.xxqad_pod_buyer;//´´½¨Óû§
|
|
wmsPoDetail.UpdateTime = firstqadData.xxqad_pod_updatedt;//¸üÐÂÈÕÆÚ
|
|
wmsPoDetail.UpdateUser = firstqadData.xxqad_pod_updateur;//¸üÐÂÓû§
|
|
if (wmsPoDetail.PlanQty != 0 && wmsPoDetail.PlanQty <= wmsPoDetail.ReceivedQty)
|
|
wmsPoDetail.State = (int)FormState.¹Ø±Õ;
|
|
qadData.xxqad_pod_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_pod_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_pod_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_pod_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_pod_updatedt = DateTime.Now;
|
|
}
|
|
if(firstqadData.xxqad_pod_modtype=="2")
|
|
{
|
|
if(firstqadData.xxqad_pod_domain=="CNH")
|
|
{
|
|
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var _first = db.TA_CONFIG.Where(p => p.ParamName == "×Ô¶¯Éú³É¿´°å" && p.ParamValue == "ÔÊÐí").FirstOrDefault();
|
|
if (_first != null)
|
|
{
|
|
try
|
|
{
|
|
var _task = wdb.TB_ASK.FirstOrDefault(p => p.ErpBillNum == po.xxqad_pod_nbr && p.Site == po.xxqad_pod_domain);
|
|
|
|
if (_task == null)
|
|
{
|
|
_task = new TB_ASK()
|
|
{
|
|
AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode(),
|
|
PoBillNum = po.xxqad_pod_nbr,//¶©µ¥ºÅ
|
|
ErpBillNum = po.xxqad_pod_prj,//ERP¶©µ¥ºÅ
|
|
VendId = firstqadData.xxqad_pod_vend.ToUpper(),//¹©Ó¦É̱àºÅ
|
|
Buyer = firstqadData.xxqad_pod_attn,//ÁªÏµÈË
|
|
Site = firstqadData.xxqad_pod_domain,//µØµã
|
|
SubSite=firstqadData.xxqad_pod_site,
|
|
State = (int)AskState.New,//״̬
|
|
CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = firstqadData.xxqad_pod_buyer,//´´½¨Óû§
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
BeginTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt,//´´½¨ÈÕÆÚ
|
|
EndTime = firstqadData.xxqad_pod_due_date,//ÊÕ»õ½áÊøʱ¼ä
|
|
ModType = (int)BillModType.Non_Contract,
|
|
};
|
|
_askList.Add(_task);
|
|
}
|
|
if (_task.State == 0)
|
|
{
|
|
_task.Buyer = firstqadData.xxqad_pod_buyer;
|
|
_task.BuyerPhone = firstqadData.xxqad_pod_buyer_phone;
|
|
_task.UpdateTime = firstqadData.xxqad_pod_updatedt;//¸üÐÂÈÕÆÚ
|
|
_task.UpdateUser = firstqadData.xxqad_pod_updateur;//¸üÐÂÓû§
|
|
_task.State = (int)AskState.New;
|
|
}
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var lineNum = Convert.ToInt32(qadData.xxqad_pod_line);
|
|
var _taskDetail =
|
|
wdb.TB_ASK_DETAIL.SingleOrDefault(
|
|
p => p.PoBillNum == qadData.xxqad_pod_nbr && p.PoLine == lineNum && p.Remark == qadData.xxqad_pod_domain);
|
|
if (_taskDetail == null)
|
|
{
|
|
_taskDetail = new TB_ASK_DETAIL
|
|
{
|
|
AskBillNum = _task.AskBillNum,
|
|
PoBillNum = qadData.xxqad_pod_nbr,//¶©µ¥ºÅ
|
|
PoLine = lineNum,//¶©µ¥ÐÐ
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid()
|
|
};
|
|
_askDetailList.Add(_taskDetail);
|
|
}
|
|
if (_task.State == 0)
|
|
{
|
|
_taskDetail.PartCode = qadData.xxqad_pod_part.ToUpper();//Áã¼þºÅ-ÎïÁϺÅ
|
|
_taskDetail.AskQty = qadData.xxqad_pod_qty_ord;//¶©»õÊýÁ¿-²É¹ºÁ¿
|
|
_taskDetail.BeginTime = firstqadData.xxqad_pod_createdt;//ÊÕ»õ¿ªÊ¼Ê±¼ä
|
|
_taskDetail.EndTime = qadData.xxqad_pod_due_date;//ÊÕ»õ½áÊøʱ¼ä
|
|
_taskDetail.PoUnit = qadData.xxqad_pod_um;//²É¹ºµ¥Î»
|
|
_taskDetail.LocUnit = qadData.xxqad_pod_loc_um.ToUpper();//´æ´¢µ¥Î»
|
|
_taskDetail.DockCode = qadData.xxqad_pod_loc;
|
|
_taskDetail.Price = qadData.xxqad_pod_price;
|
|
_taskDetail.Currency = qadData.xxqad_pod_curr;//±ÒÖÖ
|
|
_taskDetail.PackQty = qadData.xxqad_pod_qty_std;//±ê°üÊýÁ¿
|
|
_taskDetail.UnConv = qadData.xxqad_pod_um_conv;//ת»»ÂÊ
|
|
_taskDetail.DockCode = qadData.xxqad_pod_loc;
|
|
_taskDetail.State = Convert.ToInt32(qadData.xxqad_pod_status);//״̬
|
|
_taskDetail.SubSite = qadData.xxqad_pod_site;//±¸×¢
|
|
_taskDetail.Site = qadData.xxqad_pod_domain;
|
|
_taskDetail.CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt;//´´½¨ÈÕÆÚ
|
|
_taskDetail.CreateUser = firstqadData.xxqad_pod_buyer;//´´½¨Óû§
|
|
_taskDetail.UpdateTime = firstqadData.xxqad_pod_updatedt;//¸üÐÂÈÕÆÚ
|
|
_taskDetail.UpdateUser = firstqadData.xxqad_pod_updateur;//¸üÐÂÓû§
|
|
_taskDetail.State = _task.State;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_pod_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_pod_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_pod_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_pod_updatedt = DateTime.Now;
|
|
}
|
|
db.TB_ASK.AddOrUpdate(_askList.ToArray());
|
|
db.TB_ASK_DETAIL.AddOrUpdate(_askDetailList.ToArray());
|
|
if (db.SaveChanges() != 1)
|
|
{ }
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine($"¸üдíÎó£º{e.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
wdb.TB_PO.AddOrUpdate(wmsPoList.ToArray());
|
|
wdb.TB_PO_DETAIL.AddOrUpdate(wmsPoDetailList.ToArray());
|
|
Console.WriteLine($"¸üР²É¹º¶©µ¥ Êý¾Ý£º{qadPoDetailList.Count}");
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// ¸üвɹº¶©µ¥
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq"></param>
|
|
private static void UpdatePrice(UniApiEntities idb, ScpEntities scpdb, string seq)
|
|
{
|
|
var _list = idb.xxqad_pprice_det.Where(p => p.xxqad_pprice_seq == seq && p.xxqad_pprice_scmread == "0").ToList();
|
|
var PriceList = new List<TB_PRICE>();
|
|
foreach (var itm in _list)
|
|
{
|
|
var _price= new TB_PRICE
|
|
{
|
|
VendId = itm.xxqad_pprice_list,
|
|
Unit = itm.xxqad_pprice_um,
|
|
PartCode = itm.xxqad_pprice_part,
|
|
Site = itm.xxqad_pprice_domain,
|
|
Remarks = itm.xxqad_pprice_rmks,
|
|
StartTime = itm.xxqad_pprice_start,
|
|
EndTime = itm.xxqad_pprice_end,
|
|
Curr = itm.xxqad_pprice_curr
|
|
};
|
|
_price.Amt = itm.xxqad_pprice_amt;
|
|
PriceList.Add(_price);
|
|
}
|
|
scpdb.TB_PRICE.AddOrUpdate(PriceList.ToArray());
|
|
Console.WriteLine($"¸üвɹº¼Û¸ñÊý¾Ý£º{PriceList.Count}");
|
|
}
|
|
/// <summary>
|
|
/// ¸üй©Ó¦ÉÌÁã¼þ
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq"></param>
|
|
private static void UpdateVendParts(UniApiEntities idb, ScpEntities wdb, string seq)
|
|
{
|
|
var qadDataList = idb.xxqad_vp_mstr.Where(p => p.xxqad_vp_seq == seq ).ToList();
|
|
var wmsDataList = new List<TA_VEND_PART>();
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(qadData.xxqad_vp_vend_part))
|
|
qadData.xxqad_vp_vend_part = qadData.xxqad_vp_part;
|
|
var wmsData =
|
|
wdb.TA_VEND_PART.SingleOrDefault(
|
|
p => p.VendId == qadData.xxqad_vp_addr.ToUpper()
|
|
&& p.PartCode == qadData.xxqad_vp_part.ToUpper()
|
|
&& p.Site==qadData.xxqad_vp_domain
|
|
) ??
|
|
new TA_VEND_PART
|
|
{
|
|
VendId = qadData.xxqad_vp_addr.ToUpper(),//¹©Ó¦É̱àºÅ
|
|
PartCode = qadData.xxqad_vp_part.ToUpper(),//¶ÔÓ¦ÎïÁϺÅ
|
|
VendPartCode = qadData.xxqad_vp_vend_part.ToUpper(),//¹©Ó¦ÉÌÎïÁϺÅ
|
|
VendPackQty = qadData.xxqad_vp_comment,//¹©Ó¦ÉÌÎïÁϺÅ
|
|
//PoUnit = qadData.,//²É¹ºµ¥Î»
|
|
State = 1,//״̬£¨0£ºÊ§Ð§ 1:ÓÐЧ£©
|
|
Remark = "",
|
|
CreateTime = qadData.xxqad_vp_createdt == null ? DateTime.Now : (DateTime)qadData.xxqad_vp_createdt,//´´½¨ÈÕÆÚ
|
|
CreateUser = qadData.xxqad_vp_createur,//´´½¨Óû§
|
|
UpdateTime = qadData.xxqad_vp_updatedt,//¸üÐÂÈÕÆÚ
|
|
UpdateUser = qadData.xxqad_vp_updateur,//¸üÐÂÓû§
|
|
TransportationTime=qadData.xxqad_vp_vend_lead,
|
|
IsDeleted = false,
|
|
GUID = new Guid()
|
|
};
|
|
wmsData.Site = string.IsNullOrEmpty(wmsData.Site) ? qadData.xxqad_vp_domain : wmsData.Site;
|
|
wmsData.VendPartCode = qadData.xxqad_vp_vend_part?.ToUpper() ?? qadData.xxqad_vp_part.ToUpper();
|
|
wmsData.VendPackQty = qadData.xxqad_vp_comment;
|
|
wmsData.TransportationTime = qadData.xxqad_vp_vend_lead;
|
|
wmsDataList.Add(wmsData);
|
|
qadData.xxqad_vp_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_vp_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_vp_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_vp_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_vp_updatedt = DateTime.Now;
|
|
}
|
|
wdb.TA_VEND_PART.AddOrUpdate(wmsDataList.ToArray());
|
|
Console.WriteLine($"¸üР¹©Ó¦ÉÌÁã¼þ Êý¾Ý£º{wmsDataList.Count}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// ¸üй©Ó¦ÉÌ
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq"></param>
|
|
private static void UpdateVender(List<Models.UniApiEntity.xxqad_vd_mstr> qadDataList, ScpEntities wdb,AppBoxContext authdb, string seq)
|
|
{
|
|
|
|
var wmsDataList = new List<TA_VENDER>();
|
|
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var wmsData = wdb.TA_VENDER.SingleOrDefault(p => p.VendId == qadData.xxqad_vd_addr.ToUpper() && p.Site==qadData.xxqad_vd_domain) ??
|
|
new TA_VENDER { VendId = qadData.xxqad_vd_addr.ToUpper(), VendAbbCode = "0", State = 1 };
|
|
wmsData.VendName = string.IsNullOrEmpty(qadData.xxqad_vd_name)?qadData.xxqad_vd_addr:qadData.xxqad_vd_name;
|
|
wmsData.VendType = qadData.xxqad_vd_type.ToUpper().ToString();
|
|
wmsData.Country = qadData.xxqad_vd_country;
|
|
wmsData.City = qadData.xxqad_vd_city;
|
|
wmsData.Currency = qadData.xxqad_vd_curr.ToUpper();
|
|
wmsData.Address = qadData.xxqad_vd_line1 + qadData.xxqad_vd_line2 + qadData.xxqad_vd_line3;
|
|
wmsData.ZipCode = qadData.xxqad_vd_pst_id;
|
|
wmsData.Contacter = qadData.xxqad_vd_attn;
|
|
wmsData.Phone = qadData.xxqad_vd_phone;
|
|
wmsData.Fax = qadData.xxqad_vd_fax;
|
|
wmsData.Site = string.IsNullOrEmpty(wmsData.Site)? qadData.xxqad_vd_domain:wmsData.Site;
|
|
wmsData.Tax = qadData.xxqad_vd_tax;//Ë°ÂÊ
|
|
wmsDataList.Add(wmsData);
|
|
qadData.xxqad_vd_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
var vendname=string.Format("{0}@{1}", qadData.xxqad_vd_addr.ToUpper(), qadData.xxqad_vd_domain.ToUpper());
|
|
var _first=authdb.Users.Where(p => p.Name == vendname).FirstOrDefault();
|
|
var _vend=authdb.Roles.Where(p => p.Name == "¹©Ó¦ÉÌ").FirstOrDefault();
|
|
var _factory = authdb.TA_FACTORY.Where(p => p.ErpDomain == qadData.xxqad_vd_domain.ToUpper()).FirstOrDefault();
|
|
if (_first==null && _vend!=null && _factory!=null)
|
|
{
|
|
User _entity = new User();
|
|
_entity.Name = vendname;
|
|
_entity.Remark = qadData.xxqad_vd_domain.ToUpper();
|
|
_entity.Password = PasswordUtil.CreateDbPassword("555555");
|
|
_entity.ChineseName = wmsData.VendName;
|
|
_entity.Email = wmsData.VendId + "@163.com";
|
|
_entity.Gender = "ÄÐ";
|
|
_entity.Enabled = true;
|
|
_entity.Roles = new List<Role>();
|
|
|
|
Role t = authdb.Set<Role>().Local.Where(x => x.ID == _vend.ID).FirstOrDefault();
|
|
if (t == null)
|
|
{
|
|
t = new Role { ID =_vend.ID };
|
|
authdb.Set<Role>().Attach(t);
|
|
}
|
|
_entity.Roles.Add(t);
|
|
_entity.TA_FACTORY = new List<TA_FACTORY>();
|
|
TA_FACTORY f = authdb.Set<TA_FACTORY>().Local.Where(x => x.ID == _factory.ID).FirstOrDefault();
|
|
if (f == null)
|
|
{
|
|
f = new TA_FACTORY { ID = _factory.ID };
|
|
authdb.Set<TA_FACTORY>().Attach(f);
|
|
}
|
|
_entity.TA_FACTORY.Add(f);
|
|
authdb.Users.Add(_entity);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_vd_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_vd_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_vd_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_vd_updatedt = DateTime.Now;
|
|
}
|
|
if (wmsDataList.Count == 0)
|
|
{
|
|
Console.WriteLine("¸üР¹©Ó¦ÉÌ Êý¾Ý:"+ seq+"ÎÞÊý¾Ý");
|
|
return;
|
|
}
|
|
|
|
wdb.TA_VENDER.AddOrUpdate(p=>new {p.VendId,p.Site } ,wmsDataList.ToArray());
|
|
Console.WriteLine($"¸üР¹©Ó¦ÉÌ Êý¾Ý£º{qadDataList.Count}");
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UpdateVenderExtend(List<Models.UniApiEntity.xxqad_vd_mstr> qadDataList, ScpEntities wdb, AppBoxContext authdb)
|
|
{
|
|
|
|
var _ls= new List<VenderUsers>();
|
|
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var vendname = string.Format("{0}@{1}", qadData.xxqad_vd_addr.ToUpper(), qadData.xxqad_vd_domain.ToUpper());
|
|
var _first= authdb.Users.Where(p => p.Name == vendname).FirstOrDefault();
|
|
if (_first != null)
|
|
{
|
|
|
|
var _ef= authdb.VenderUsers.FirstOrDefault(p => p.VenderId == qadData.xxqad_vd_addr && p.UserId == _first.ID)??new VenderUsers()
|
|
{
|
|
UserId=_first.ID,
|
|
VenderId=qadData.xxqad_vd_addr.ToUpper()
|
|
};
|
|
_ls.Add(_ef);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
authdb.VenderUsers.AddOrUpdate(_ls.ToArray());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// ¸üÐÂÁã¼þ
|
|
/// </summary>
|
|
/// <param name="idb"></param>
|
|
/// <param name="wdb"></param>
|
|
/// <param name="seq"></param>
|
|
private static void UpdateParts(UniApiEntities idb, ScpEntities wdb, string seq)
|
|
{
|
|
var qadDataList = idb.xxqad_pt_mstr.Where(p => p.xxqad_pt_seq == seq ).ToList();
|
|
var wmsDataList = new List<TA_PART>();
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var wmsData = wdb.TA_PART.SingleOrDefault(p => p.ErpPartCode == qadData.xxqad_pt_part.ToUpper() && p.Site==qadData.xxqad_pt_domain) ??
|
|
new TA_PART
|
|
{
|
|
PartCode = qadData.xxqad_pt_part.ToUpper(),
|
|
ErpPartCode = qadData.xxqad_pt_part.ToUpper(),
|
|
};
|
|
wmsData.PartDesc1 = qadData.xxqad_pt_desc1;
|
|
wmsData.PartDesc2 = qadData.xxqad_pt_desc2;
|
|
wmsData.ProjectId = qadData.xxqad_pt_group.ToUpper();
|
|
wmsData.Unit = !string.IsNullOrEmpty(qadData.xxqad_pt_um)? qadData.xxqad_pt_um.ToUpper():"EA";
|
|
wmsData.PartGroup = qadData.xxqad_pt_dsgn_grp.ToUpper();
|
|
wmsData.State = qadData.xxqad_pt_status.ToUpper();
|
|
wmsData.Site = qadData.xxqad_pt_domain;
|
|
|
|
wmsDataList.Add(wmsData);
|
|
qadData.xxqad_pt_scmread = ((int)UniApiState.³É¹¦).ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
qadData.xxqad_pt_scmread = ((int)UniApiState.ʧ°Ü).ToString();
|
|
qadData.xxqad_pt_rmks += " SCM:" + ex.Message;
|
|
}
|
|
qadData.xxqad_pt_updateur = ScpCache.Config.SCP̞;
|
|
qadData.xxqad_pt_updatedt = DateTime.Now;
|
|
}
|
|
wdb.TA_PART.AddOrUpdate(p =>new { p.PartCode, p.Site }, wmsDataList.ToArray());
|
|
Console.WriteLine($"¸üРÁã¼þÐÅÏ¢ Êý¾Ý£º{qadDataList.Count}");
|
|
}
|
|
|
|
}
|
|
}
|
|
|