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.

768 lines
38 KiB

1 year ago
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 System.Text;
using System.Data.Entity.Core;
namespace CK.SCP.GrupUniApi.Controller
{
public static class OdbcApiWmsController
{
public static void GetNewCtrlList()
{
UniApiEntities idb = EntitiesFactory.CreateUniApiInstance();
idb.Database.CommandTimeout = 60 * 20;
var tableNameList = EnumHelper.EnumToList<WmsTableName>();
List<string> _lst = new List<string>();
_lst.Add("xxwms_rc_det");
_lst.Add("xxwms_rct_det");
_lst.Add("xxwms_rt_det");
_lst.Add("xxwms_qua_det");
var wmsCtrlList = idb.xxwms_ctrl.Where(p => p.xxwms_scm == "0" && _lst.Contains(p.xxwms_table)).ToList();
// var wmsCtrlList = idb.xxwms_ctrl.Where(p => p.xxwms_wms == "0").ToList();
//ɾ��scp����ԭ�Ͽ�������
if (GlobalVar.ApiConfig.Wms)
{
ScpEntities wdb = EntitiesFactory.CreateScpInstance();
var kucunlist = wmsCtrlList.Where(p => p.xxwms_table == "xxwms_ld_det").ToList();
//�����������
if (kucunlist.Count > 0)
{
var _stockList = wdb.TS_STOCK.ToList();
wdb.TS_STOCK.RemoveRange(_stockList);
//EntitiesFactory.SaveDb(wdb);
//ȡ�������ڵ���ˮ��
xxwms_ctrl ctrl = idb.xxwms_ctrl.Where(p => p.xxwms_table == "xxwms_ld_det").OrderByDescending(p => p.xxwms_seq).FirstOrDefault();
if (ctrl != null && !string.IsNullOrEmpty(ctrl.xxwms_seq))
{
Console.WriteLine($"���� WMS �ӿ����ݣ�{ctrl.xxwms_table}:{ctrl.xxwms_table_qty}");
UpdateMaterialStocks(idb, wdb, ctrl.xxwms_seq);
EntitiesFactory.SaveDb(wdb);
}
}
}
Console.WriteLine($"����WMS �ӿ����ݣ�{wmsCtrlList.Count.ToString()}");
foreach (var wmsCtrl in wmsCtrlList)
{
if (tableNameList.All(p => p.Name != wmsCtrl.xxwms_table)) continue;
try
{
ScpEntities wdb = EntitiesFactory.CreateScpInstance();
//Console.WriteLine($"���� WMS �ӿ����ݣ�{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
WmsTableName wmsTableName;
Enum.TryParse(wmsCtrl.xxwms_table, false, out wmsTableName);
switch (wmsTableName)
{
case WmsTableName.xxwms_ld_det://ԭ�Ͽ���
if (GlobalVar.ApiConfig.Wms)
{
//Console.WriteLine($"���� WMS �ӿ����ݣ�{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
//UpdateMaterialStocks(idb, wdb, wmsCtrl.xxwms_seq);
}
else
continue;
break;
case WmsTableName.xxwms_rc_det://�����ջ���
//TODO
if (GlobalVar.ApiConfig.Wmsջ)
{
Console.WriteLine($"���� WMS �ӿ����ݣ�{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialReceive(idb, wdb, wmsCtrl.xxwms_seq, 0);//xxwms_seq:��ˮ��
}
break;
case WmsTableName.xxwms_rt_det:
//TODO
if (GlobalVar.ApiConfig.Wms˻)
{
Console.WriteLine($"���� WMS �ӿ����ݣ�{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialReturn(idb, wdb, wmsCtrl.xxwms_seq, 1);//xxwms_seq:��ˮ��
}
break;
case WmsTableName.xxwms_arv_det:
//TODO
if (GlobalVar.ApiConfig.Wms)
{
Console.WriteLine($"���� WMS �ӿ����ݣ�{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialArrive(idb, wdb, wmsCtrl.xxwms_seq);//xxwms_seq:��ˮ��
}
break;
case WmsTableName.xxwms_qua_det:
//TODO
if (GlobalVar.ApiConfig.Wms)
{
Console.WriteLine($"���� WMS �ӿ����ݣ�{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialQuality(idb, wdb, wmsCtrl.xxwms_seq);
}
break;
}
wmsCtrl.xxwms_scm = ((int)UniApiState.ɹ).ToString();
EntitiesFactory.SaveDb(wdb);
}
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);
});
}
wmsCtrl.xxwms_scm = ((int)UniApiState.ʧ).ToString();
wmsCtrl.xxwms_rmks += " SCM:" + sb.ToString();
}
catch (OptimisticConcurrencyException ex)//������ͻ�쳣
{
wmsCtrl.xxwms_scm = ((int)UniApiState.ʧ).ToString();
wmsCtrl.xxwms_rmks += " SCM:" + ex.Message;
}
catch (Exception ex)
{
wmsCtrl.xxwms_scm = ((int)UniApiState.ʧ).ToString();
wmsCtrl.xxwms_rmks += " SCM:" + ex.Message;
}
finally
{
EntitiesFactory.SaveDb(idb);
}
}
}
/// <summary>
/// ����ԭ�Ͽ���
/// </summary>
/// <param name="idb"></param>
/// <param name="wdb"></param>
/// <param name="seq"></param>
private static void UpdateMaterialStocks(UniApiEntities idb, ScpEntities wdb, string seq)
{
var wmsld_detList = idb.xxwms_ld_det.Where(p => p.xxwms_ld_seq == seq).ToList();
var scpRcvList = new List<TS_STOCK>();
foreach (var wmsld_detData in wmsld_detList)
{
var scpRcv = new TS_STOCK
{
BarCode = wmsld_detData.xxwms_ld_barcode,//��ǩ��
Site = wmsld_detData.xxwms_ld_domain,//����
PartCode = wmsld_detData.xxwms_ld_part,//������
VendId = wmsld_detData.xxwms_ld_vend,//��Ӧ�̱���
LocCode = wmsld_detData.xxwms_ld_loc,//��λ
Batch = wmsld_detData.xxwms_ld_lot,//����
VendBatch = wmsld_detData.xxwms_ld_vend_batch,//��Ӧ������
Qty = wmsld_detData.xxwms_ld_qty,//����
ReceiveDate = wmsld_detData.xxwms_ld_date,//�ջ�����
ProduceDate = wmsld_detData.xxwms_ld_time,//����ʱ��
LocUnit = wmsld_detData.xxwms_ld_um,//��λ
Remark = "",//��ע
State = (int)FormState.ر,
CreateTime = wmsld_detData.xxwms_ld_createdt == null ? DateTime.Now : (DateTime)wmsld_detData.xxwms_ld_createdt,//��������
CreateUser = wmsld_detData.xxwms_ld_createur//�����û�
};
scpRcvList.Add(scpRcv);
}
wdb.TS_STOCK.AddOrUpdate(scpRcvList.ToArray());
Console.WriteLine($"���� ԭ�Ͽ��� ���ݣ�{wmsld_detList.Count}");
}
/// <summary>
///�����ջ���
/// </summary>
/// <param name="idb"></param>
/// <param name="wdb"></param>
/// <param name="seq">��ˮ��</param>
/// <param name="billtype">0:�ջ�,1:�˻�</param>
private static void AddMaterialReceive(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
{
var qadRcvDetailList = idb.xxwms_rc_det.Where(p => p.xxwms_rc_seq == seq).ToList();
var scpRcvList = new List<TB_RECEIVE>();
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL>();
//����xxwms_rc_po_nbr�ɹ����ֶ�ȥ��
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_rc_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailListͬһxxqad_prh_receiver���м�¼
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_rc_nbr == qadRcvNbrList ).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum != null && p.RecvBillNum == qadRcvNbrList && p.Site==firstqadData.xxwms_rc_domain);
//�ж�0100�������ջ��Զ������Ƿ�Ϊ����
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_rc_domain))
{
string site = firstqadData.xxwms_rc_domain;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if(tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "�ջ��Զ�����")
{
if ("����" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.ر;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_RECEIVE
{
RecvBillNum = qadRcvNbrList,//�ջ�����
State = istate,
Remark = "",
CreateTime = firstqadData.xxwms_rc_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_rc_createdt,//��������
CreateUser = firstqadData.xxwms_rc_createur,//�����û�
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_rc_po_nbr;//�ɹ���
scpRcv.AsnBillNum = firstqadData.xxwms_rc_ps_nbr;//��������
scpRcv.Site = firstqadData.xxwms_rc_domain;//�ص�
scpRcv.VendId = firstqadData.xxwms_rc_vend;//����������
scpRcv.ShipTime = firstqadData.xxwms_rc_date_ship;//�ջ�����
//var scpAsn = wdb.TF_ASN.FirstOrDefault(p => p.BillNum == scpRcv.AsnBillNum);
var scpAsn = wdb.TB_ASN.Where(p => p.AsnBillNum== scpRcv.AsnBillNum && p.IsDeleted==false).ToList();//����������������==�ջ���������������
if (scpAsn != null && scpAsn.Count>0)
{
scpAsn.ForEach(p => {
p.State = (int)AsnState.Receive;
});
wdb.TB_ASN.AddOrUpdate(scpAsn.ToArray());
}
var scpAsnDetail = wdb.TB_ASN_DETAIL.Where(p => p.AsnBillNum == scpRcv.AsnBillNum && p.IsDeleted == false).ToList();
if (scpAsnDetail != null && scpAsnDetail.Count > 0)
{
scpAsnDetail.ForEach(p => {
p.State = (int)AsnState.Receive;
});
wdb.TB_ASN_DETAIL.AddOrUpdate(scpAsnDetail.ToArray());
}
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_rc_po_line);
var scpRcvDetail =
wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
p => p.RecvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_rc_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_rc_part &&
p.Batch == qadData.xxwms_rc_lot
);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.ر;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_RECEIVE_DETAIL
{
RecvBillNum = qadRcvNbrList,//�ջ�����
PoBillNum = qadData.xxwms_rc_po_nbr,//�ɹ���
PoLine = poLineNum,//������
PartCode = qadData.xxwms_rc_part,//������
Batch = qadData.xxwms_rc_lot,//����
VendBatch = qadData.xxwms_rc_vend_batch,//��Ӧ������
PoUnit = qadData.xxwms_rc_po_um,//�ɹ���λ
LocUnit = qadData.xxwms_rc_loc_um,//������λ
Qty = qadData.xxwms_rc_qty_total,//�ջ�����
//DockCode = ?,//�ջ���
State = istate,// (int)FormState.�ر�,
Remark = firstqadData.xxwms_rc_domain,
CreateTime = qadData.xxwms_rc_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_rc_createdt,//��������
CreateUser = qadData.xxwms_rc_createur,//�����û�
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_rc_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //������ϸReceivedQty�������� += �ջ���ϸQty�ѽ�����
// scpPoDetail.ReceivedQty += scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_rc_po_nbr);
//if (scpPo != null)
//{
// //������ϸ
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rc_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty))//��������==��������
// {
// scpPo.State = (int)PlanState.Complete;
// //var _detail = wdb.TB_ASK_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rc_po_nbr && p.PoLine == poLineNum );
// //if (_detail!=null && _detail.Count() > 0)
// //{
// // var _qty=_detail.Sum(p=>p.AskQty);
// // if(_qty== p.ReceivedQty)
// //}
// }
//}
qadData.xxwms_rc_wmsread = ((int)UniApiState.ɹ).ToString();
}
catch (Exception ex)
{
qadData.xxwms_rc_wmsread = ((int)UniApiState.ʧ).ToString();
qadData.xxwms_rc_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_rc_updateur = ScpCache.Config.SCPû;
qadData.xxwms_rc_updatedt = DateTime.Now;
}
}
wdb.TB_RECEIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_RECEIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"���� �ջ��� ���ݣ�{qadRcvDetailList.Count}");
}
#region WMS��������
private static void AddMaterialQuality(UniApiEntities idb, ScpEntities sdb, string seq)
{
var wms_qualList = idb.xxwms_qua_det.Where(p => p.xxwms_qua_seq == seq).ToList();
if (seq == "QUA_CNS_190219_13553074281")
{
string str = seq;
}
var _qualList = new List<TB_QUALITY>();
foreach (var itm in wms_qualList)
{
var scpQual = new TB_QUALITY();
scpQual.Type = itm.xxwms_qua_infotype;
scpQual.Barcode = itm.xxwms_qua_barcode;
scpQual.Loccode = itm.xxwms_qua_loccode;
scpQual.Pobillnum = itm.xxwms_qua_pobillnum;
scpQual.QualityNo = itm.xxwms_qua_nbr;
scpQual.Poline = (decimal)itm.xxwms_qua_poline;
scpQual.Inspecttype = itm.xxwms_qua_inspecttype;
scpQual.Partcode = itm.xxwms_qua_partcode;
scpQual.Batch = itm.xxwms_qua_batch;
scpQual.ReceiveQty = itm.xxwms_qua_receiveqty;
scpQual.SampleQty = itm.xxwms_qua_sampleqty;
scpQual.Inspqty = itm.xxwms_qua_inspqty;
scpQual.Passqty = itm.xxwms_qua_passqty;
scpQual.Failqty = itm.xxwms_qua_failqty;
scpQual.Crackqty = itm.xxwms_qua_crackqty;
scpQual.Inspresult = itm.xxwms_qua_inspresult;
scpQual.Failreason = itm.xxwms_qua_failreason;
scpQual.Vendid = itm.xxwms_qua_vendid;
scpQual.Vendbatch = itm.xxwms_qua_vendbatch;
scpQual.state = itm.xxwms_qua_state;
scpQual.Billtime = itm.xxwms_qua_billtime;
scpQual.Domain = itm.xxwms_qua_domain;
scpQual.Site = itm.xxwms_qua_domain;
scpQual.By1 = itm.xxwms_qua_by1;
scpQual.By2 = itm.xxwms_qua_by2;
scpQual.By3 = itm.xxwms_qua_by3;
scpQual.CreateTime = itm.xxwms_qua_createdt??DateTime.Now;
scpQual.CreateUser = itm.xxwms_qua_createur;
scpQual.UpdateTime = itm.xxwms_qua_updatedt;
scpQual.UpdateUser = itm.xxwms_qua_updateur;
scpQual.GUID = Guid.NewGuid();
_qualList.Add(scpQual);
sdb.TB_QUALITY.Add(scpQual);
}
//sdb.TB_QUALITY.Add(_qualList.ToArray());
Console.WriteLine($"�������������ݣ�{_qualList.Count}");
}
#endregion
/// <summary>
/// �����˻���
/// </summary>
private static void AddMaterialReturn(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
{
//var qadRcvDetailList = idb.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
var qadRcvDetailList = idb.xxwms_rt_det.Where(p => p.xxwms_rt_seq == seq).ToList();
var scpRcvList = new List<TB_RECEIVE>();
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL>();
//����xxqad_prh_receiver�ֶ�ȥ��
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_rt_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailListͬһxxqad_prh_receiver���м�¼
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_rt_nbr == qadRcvNbrList ).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum == qadRcvNbrList && p.Site ==firstqadData.xxwms_rt_domain);
//�ж�0100�������ջ��Զ������Ƿ�Ϊ����
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_rt_domain))
{
string site = firstqadData.xxwms_rt_domain;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "�ջ��Զ�����")
{
if ("����" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.ر;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_RECEIVE
{
RecvBillNum = qadRcvNbrList,//�˻�����
State = istate,
Remark = "",
CreateTime = firstqadData.xxwms_rt_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_rt_createdt,//��������
CreateUser = firstqadData.xxwms_rt_createur,//�����û�
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_rt_po_nbr;//�ɹ���
//scpRcv.AsnBillNum = firstqadData.xxqad_prh_psnbr;//��������
scpRcv.Site = firstqadData.xxwms_rt_domain;//�ص�
scpRcv.VendId = firstqadData.xxwms_rt_vend;//����������
scpRcv.ShipTime = firstqadData.xxwms_rt_date_ship;//�ջ�����
//var scpAsn = wdb.TF_ASN.FirstOrDefault(p => p.BillNum == scpRcv.AsnBillNum);
var scpAsn = wdb.TB_ASN.FirstOrDefault(p => p.PoBillNum == scpRcv.AsnBillNum);//����������������==�˻���������������
if (scpAsn != null)
scpAsn.State = (int)ShipState.Reject;
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_rt_po_line);
var scpRcvDetail =
wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
p => p.RecvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_rt_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_rt_part &&
p.Batch == qadData.xxwms_rt_lot);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.ر;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_RECEIVE_DETAIL
{
RecvBillNum = qadRcvNbrList,//�˻�������
PoBillNum = qadData.xxwms_rt_po_nbr,//�ɹ���
PoLine = poLineNum,//������
PartCode = qadData.xxwms_rt_part,//���Ϻ�
Batch = qadData.xxwms_rt_lot,//����
VendBatch = qadData.xxwms_rt_vend_batch,//��Ӧ������
PoUnit = qadData.xxwms_rt_po_um,//�ɹ���λ
LocUnit = qadData.xxwms_rt_loc_um,//������λ
Qty = qadData.xxwms_rt_qty_total,//�˻�����
State = istate,// (int)FormState.�ر�,
Remark = firstqadData.xxwms_rt_domain,
CreateTime = qadData.xxwms_rt_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_rt_createdt,//��������
CreateUser = qadData.xxwms_rt_createur,//�����û�
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_rt_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //������ϸRejectQty�������� += �˻���ϸQty�ѽ�����
// scpPoDetail.RejectQty -= scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_rt_po_nbr);
//if (scpPo != null)
//{
// //������ϸ
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rt_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty)) //��������==��������
// scpPo.State = (int)PlanState.Complete;
//}
qadData.xxwms_rt_wmsread = ((int)UniApiState.ɹ).ToString();
}
catch (Exception ex)
{
qadData.xxwms_rt_wmsread = ((int)UniApiState.ʧ).ToString();
qadData.xxwms_rt_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_rt_updateur = ScpCache.Config.SCPû;
qadData.xxwms_rt_updatedt = DateTime.Now;
}
}
wdb.TB_RECEIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_RECEIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"���� �˻��� ���ݣ�{qadRcvDetailList.Count}");
}
/// <summary>
///���յ�����
/// </summary>
/// <param name="idb"></param>
/// <param name="wdb"></param>
/// <param name="seq">��ˮ��</param>
private static void AddMaterialArrive(UniApiEntities idb, ScpEntities wdb, string seq)
{
//var qadRcvDetailList = idb.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
var qadRcvDetailList = idb.xxwms_arv_det.Where(p => p.xxwms_arv_seq == seq).ToList();
var scpRcvList = new List<TB_ARRIVE>();
var scpRcveDetailList = new List<TB_ARRIVE_DETAIL>();
//����xxwms_rc_po_nbr�ɹ����ֶ�ȥ��
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_arv_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailListͬһxxqad_prh_receiver���м�¼
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_arv_nbr == qadRcvNbrList).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
//var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.BillNum == qadRcvNbrList);
//var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.PoBillNum != null && p.PoBillNum == qadRcvNbrList);
var scpRcv = wdb.TB_ARRIVE.SingleOrDefault(p => p.ArrvBillNum != null && p.ArrvBillNum == qadRcvNbrList);
//�ж�0100�������ջ��Զ������Ƿ�Ϊ����
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_arv_site))
{
string site = firstqadData.xxwms_arv_site;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "�ջ��Զ�����")
{
if ("����" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.ر;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_ARRIVE
{
ArrvBillNum = qadRcvNbrList,//��������
State = istate,
Remark = "",
CreateTime = firstqadData.xxwms_arv_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_arv_createdt,//��������
CreateUser = firstqadData.xxwms_arv_createur,//�����û�
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = string.IsNullOrEmpty(firstqadData.xxwms_arv_trtype) ? 1 : int.Parse(firstqadData.xxwms_arv_trtype) //1-�ջ��� 2-�˻���
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_arv_po_nbr;//�ɹ���
scpRcv.AsnBillNum = firstqadData.xxwms_arv_ps_nbr;//��������
scpRcv.Site = firstqadData.xxwms_arv_site;//�ص�
scpRcv.VendId = firstqadData.xxwms_arv_vend;//����������
scpRcv.ShipTime = firstqadData.xxwms_arv_date_ship;//�ջ�����
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_arv_po_line);
//var scpRcvDetail =
// wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
// p => p.BillNum == qadRcvNbrList &&
// p.PoBillNum == qadData.xxqad_prh_po_nbr &&
// p.PoLineNum == poLineNum &&
// p.AsnBillNum == qadData.xxqad_prh_psnbr &&
// p.PartCode == qadData.xxqad_prh_part &&
// p.Batch == qadData.xxqad_prh_lot);
var scpRcvDetail =
wdb.TB_ARRIVE_DETAIL.SingleOrDefault(
p => p.ArrvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_arv_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_arv_part &&
p.Batch == qadData.xxwms_arv_lot);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.ر;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_ARRIVE_DETAIL
{
ArrvBillNum = qadRcvNbrList,//��������
PoBillNum = qadData.xxwms_arv_po_nbr,//�ɹ���
PoLine = poLineNum,//������
PartCode = qadData.xxwms_arv_part,//������
Batch = qadData.xxwms_arv_lot,//����
VendBatch = qadData.xxwms_arv_vend_batch,//��Ӧ������
PoUnit = qadData.xxwms_arv_po_um,//�ɹ���λ
LocUnit = qadData.xxwms_arv_loc_um,//������λ
Qty = qadData.xxwms_arv_qty_total,//�ջ�����
//DockCode = ?,//�ջ���
State = istate,// (int)FormState.�ر�,
Remark = "",
CreateTime = qadData.xxwms_arv_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_arv_createdt,//��������
CreateUser = qadData.xxwms_arv_createur,//�����û�
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = string.IsNullOrEmpty(firstqadData.xxwms_arv_trtype) ? 1 : int.Parse(firstqadData.xxwms_arv_trtype) //1-�ջ��� 2-�˻���
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_arv_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //������ϸReceivedQty�������� += �ջ���ϸQty�ѽ�����
// scpPoDetail.ReceivedQty += scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_arv_po_nbr);
//if (scpPo != null)
//{
// //������ϸ
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_arv_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty)) //��������==��������
// scpPo.State = (int)PlanState.Complete;
//}
qadData.xxwms_arv_wmsread = ((int)UniApiState.ɹ).ToString();
}
catch (Exception ex)
{
qadData.xxwms_arv_wmsread = ((int)UniApiState.ʧ).ToString();
qadData.xxwms_arv_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_arv_updateur = ScpCache.Config.SCPû;
qadData.xxwms_arv_updatedt = DateTime.Now;
}
}
wdb.TB_ARRIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_ARRIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"���� ������ ���ݣ�{qadRcvDetailList.Count}");
}
}
}