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.
 
 
 
 
 

9436 lines
441 KiB

using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CK.SCP.Models;
using CK.SCP.Models.Enums;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Models.ScpEntity.ExcelImportEntity;
using CK.SCP.Utils;
using System.Data.Entity.Core;
using CK.SCP.Models.ScpEntity.ExcelExportEnttity;
using System.Text.RegularExpressions;
using System.Threading;
using System.Data;
using Newtonsoft.Json;
using CK.SCP.Models.UniApiEntity;
namespace CK.SCP.Controller
{
public class SCP_PO_CONTROLLER
{
public static void Get_V_TB_PO_List(V_TB_PO p_entity, Action<ResultObject<IQueryable<V_TB_PO>>> p_action)
{
ResultObject<IQueryable<V_TB_PO>> _ret = new ResultObject<IQueryable<V_TB_PO>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PO> q = db.V_TB_PO;
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
}
if (!string.IsNullOrEmpty(p_entity.ErpBillNum))
{
q = q.Where(p => p.ErpBillNum == p_entity.ErpBillNum);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (p_entity.ModType != null)
{
q = q.Where(p => p.ModType == p_entity.ModType);
}
if (!string.IsNullOrEmpty(p_entity.Contacter))
{
q = q.Where(p => p.Contacter.Contains(p_entity.Contacter));
}
if (!string.IsNullOrEmpty(p_entity.Site))
{
q = q.Where(p => p.Site.Contains(p_entity.Site));
}
if (!string.IsNullOrEmpty(p_entity.Buyer))
{
q = q.Where(p => p.Buyer.Contains(p_entity.Buyer));
}
if (!string.IsNullOrEmpty(p_entity.BuyerPhone))
{
q = q.Where(p => p.BuyerPhone.Contains(p_entity.BuyerPhone));
}
if (p_entity.State != null)
{
q = q.Where(p => p.State == p_entity.State);
}
if (!string.IsNullOrEmpty(p_entity.Remark))
{
q = q.Where(p => p.Remark.Contains(p_entity.Remark));
}
if (!string.IsNullOrEmpty(p_entity.CreateUser))
{
q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser));
}
if (!string.IsNullOrEmpty(p_entity.UpdateUser))
{
q = q.Where(p => p.UpdateUser.Contains(p_entity.UpdateUser));
}
if (!string.IsNullOrEmpty(p_entity.UpdateInfo))
{
q = q.Where(p => p.UpdateInfo.Contains(p_entity.UpdateInfo));
}
q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
if (!string.IsNullOrEmpty(p_entity.VendName))
{
q = q.Where(p => p.VendName.Contains(p_entity.VendName));
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p.BeginTime >= p_entity.BeginTime);
}
if (p_entity.BeginTime_End != null)
{
q = q.Where(p => p.BeginTime <= p_entity.BeginTime_End);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.EndTime >= p_entity.EndTime);
}
if (p_entity.EndTime_End != null)
{
q = q.Where(p => p.EndTime <= p_entity.EndTime_End);
}
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
{
q = q.Where(p => p_entity.UserInVendIds.Contains(p.VendId));
}
if (!string.IsNullOrEmpty(p_entity.SubSite))
{
q = q.Where(p => p.SubSite.Contains(p_entity.SubSite));
}
if (!string.IsNullOrEmpty(p_entity.Extend1))
{
q = q.Where(p => p.Extend1.Contains(p_entity.Extend1));
}
if (!string.IsNullOrEmpty(p_entity.Extend2))
{
q = q.Where(p => p.Extend2.Contains(p_entity.Extend2));
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
if (p_entity.MaxpoList != null && p_entity.MaxpoList.Count > 0)
{
q = q.Where(p => p_entity.MaxpoList.Contains(p.PoBillNum));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
var _po = db.TB_PO_DETAIL.Where(p => p.PartCode == p_entity.PartCode );
if (_po.Count() > 0)
{
List<string> _list = new List<string>();
_po.ToList().ForEach(itm =>
{
_list.Add(itm.PoBillNum);
});
if (_list.Count() > 0)
{
q = q.Where(p => _list.Contains(p.PoBillNum));
}
}
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_List", e.Message);
throw e;
}
}
public static List<V_TB_PO_DETAIL> LOAD_ASK_DETAIL_SUM(List<V_TB_PO_DETAIL> p_list)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
if (p_list.Count > 0)
{
var _detail = p_list[0];
var _ask = db.TB_ASK_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Sum(itm => itm.AskQty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
p_list.ForEach(p =>
{
_ask.ToList().ForEach(itm =>
{
if (p.PoBillNum == itm.PoBillNum && p.PoLine == itm.PoLine && p.PartCode == itm.PartCode)
{
p.TempQty = itm.AskSum;
}
});
});
}
}
return p_list;
}
public static ResultObject<bool> Save_TB_MAXPO_DETAIL_QTY(List<TB_MAXPO_DETAIL> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_entitys)
{
var _entity = db.TB_MAXPO_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
if(itm.OrderQtykg <_entity.OrderQtykg- _entity.AsnQty)
{
_ret.MessageList.Add("零件号"+_entity.PartCode+"剩余可消耗订货量不足!");
}
if( itm.OrderQtykg == 0)
{
_ret.MessageList.Add("订货量不能修改为0!");
}
else
{
_entity.SurplusQty = itm.OrderQtykg - _entity.OrderQtykg + _entity.SurplusQty;
_entity.AsnQty=itm.OrderQtykg - _entity.OrderQtykg + _entity.AsnQty;
_entity.OrderQtykg = itm.OrderQtykg;
_entity.OrderQtyd = itm.OrderQtykg / 1000;
db.TB_MAXPO_DETAIL.AddOrUpdate(p => p.UID, _entity);
TS_UNI_API maxuni = new TS_UNI_API();
maxuni.BillNum = _entity.PoBillNum;
maxuni.InterfaceType = "MaxPobillnum";
maxuni.TableName = "TS_UNI_API";
maxuni.BillType = 701;
maxuni.SubBillType = 0;
maxuni.PartCode = _entity.PartCode;
maxuni.VendId = _entity.VendId;//供应商编号
if (string.IsNullOrEmpty(_entity.Texture))
{
maxuni.Batch = "";
}
else
{
maxuni.Batch = _entity.Texture;//材质
}
maxuni.Qty = _entity.OrderNumber;
maxuni.State = 1;
maxuni.CreateOper = _entity.CreateUser;//创建者
maxuni.CreateTime =DateTime.Now;
maxuni.PutTime = DateTime.Now;
maxuni.Extend1 = _entity.PartNumber;
maxuni.PackQty = _entity.MinordQty;
maxuni.Price = _entity.OrderQtyd;
maxuni.VendBatch = _entity.ContractMonth;//合同月
maxuni.Currency = _entity.Model;
maxuni.Buyer = _entity.TechStandard;
maxuni.BuyerPhone =_entity.Finprspec;//规格
maxuni.Tax = 0;
maxuni.PoUnit = _entity.forecastone;//预测1
maxuni.LocUnit = _entity.forecasttwo;//预测2
maxuni.Attn =_entity.forecastthree;//预测3
maxuni.Receiver = _entity.forecastfour;//预测4
maxuni.ModType = _entity.forecastfive;//预测5
maxuni.SubSite = _entity.forecastsix;//预测6
maxuni.Site = _entity.Site;
maxuni.Extend2 = _entity.Matermanu;
maxuni.TaxAmt = _entity.Singlecon;//单件消耗
maxuni.ValidDate = DateTime.Now;
maxuni.ErpLineNum = _entity.PoLine;
maxuni.Domain = _entity.Site;
maxuni.Extend3 = "U";
db.TS_UNI_API.AddOrUpdate(maxuni);
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL_LIER", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL_LIER", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL_LIER", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_DETAIL_LIER", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static List<V_TB_PO_DETAIL> LOAD_PO_DETAIL_SUM(List<V_TB_PO_DETAIL> p_list)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
if (p_list.Count > 0)
{
//var _detail = p_list[0];
foreach (V_TB_PO_DETAIL _detail in p_list)
{
var _ask = db.TB_ASK_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Sum(itm => itm.AskQty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
var rec = db.TB_RECEIVE_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && p.State == (int)ReceiveState.Check && p.BillType == 0)
.GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { ReceiveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
var reject = db.TB_RECEIVE_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && p.State == (int)RejectState.Check && p.BillType == 1).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { RejectSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
var asn = db.TB_ASN_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && (p.State == (int)AsnState.Ship || p.State == (int)AsnState.Receive))
.GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode })
.Select(p => new { AsSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
var arrive = db.TB_ARRIVE_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == (int)ArriveBillType.Receive).GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode });
_detail.PartDesc1 = _detail.PartDesc1 + _detail.PartDesc2;
rec.ToList().ForEach(itm =>
{
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
{
_detail.ReceivedQty = itm.ReceiveSum;
}
});
reject.ToList().ForEach(itm =>
{
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
{
_detail.RejectQty = itm.RejectSum.ToString();
}
});
asn.ToList().ForEach(itm =>
{
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
{
_detail.ShippedQty = itm.AsSum;
}
});
_ask.ToList().ForEach(itm =>
{
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
{
_detail.TempQty = itm.AskSum;
}
});
arrive.ToList().ForEach(itm =>
{
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
{
_detail.ArriveQty = itm.ArriveSum.ToString();
}
});
}
}
}
return p_list;
}
public static ResultObject<bool> Save_TB_PO_STATE(List<string> p_list, PoState p_state)
{
ResultObject<bool> _ret = new ResultObject<bool>();
//try
//{
// using (ScpEntities db = EntitiesFactory.CreateScpInstance())
// {
// if (db.TB_ASN.Where(p => p_list.Contains(p.PoBillNum)).Count() == 0)
// {
// if(p_state==PoState.Reject)
// {
// var _askDetailList = db.TB_ASK_DETAIL.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// db.TB_ASK_DETAIL.RemoveRange(_askDetailList);//移除要货看板明细
// var _ls = db.TB_ASK.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// db.TB_ASK.RemoveRange(_ls.ToArray());//移除要货看板
// var _lsPending = db.TB_PENING_ITEMS.Where(p => p_list.Contains(p.ITEM_NO)).ToList();
// db.TB_PENING_ITEMS.RemoveRange(_lsPending.ToArray());//移除代办
// var _list = db.TB_PO.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// int count = _ls.Count(p => p.State == (int)AskState.New || p.State == (int)AskState.Release);
// if (_list.Count > 0 && _list.Count == count)
// {
// _list.ForEach(p =>
// {
// p.State = (int)PoState.Reject;
// p.IsDeleted = true;
// var _poList = db.TB_PO_DETAIL.Where(itm => itm.PoBillNum == p.PoBillNum).ToList();
// _poList.ForEach(itm =>
// {
// itm.State = (int)PoState.Reject;
// itm.IsDeleted = true;
// });
// db.TB_PO_DETAIL.AddOrUpdate(itm => itm.UID, _poList.ToArray());
// }
// );
// db.TB_PO.AddOrUpdate(p => p.PoBillNum, _list.ToArray());
// }
// else
// {
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
// _ret.Message = "选择的记录,有不是新建或发布状态记录!";
// }
// }
// if (p_state == PoState.Complete)
// {
// var _list = db.TB_PO.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// _list.ForEach(p =>
// {
// p.State = (int)PoState.Complete;
// p.IsDeleted = true;
// var _poList = db.TB_PO_DETAIL.Where(itm => itm.PoBillNum == p.PoBillNum).ToList();
// _poList.ForEach(itm =>
// {
// itm.State = (int)PoState.Complete;
// });
// db.TB_PO_DETAIL.AddOrUpdate(itm => itm.UID, _poList.ToArray());
// }
// );
// db.TB_PO.AddOrUpdate(p => p.PoBillNum, _list.ToArray());
// }
// if (p_state == PoState.CompleteForce)
// {
// var _list = db.TB_PO.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// _list.ForEach(p =>
// {
// p.State = (int)PoState.CompleteForce;
// p.IsDeleted = true;
// var _poList = db.TB_PO_DETAIL.Where(itm => itm.PoBillNum == p.PoBillNum).ToList();
// _poList.ForEach(itm =>
// {
// itm.State = (int)PoState.CompleteForce;
// });
// db.TB_PO_DETAIL.AddOrUpdate(itm => itm.UID, _poList.ToArray());
// }
// );
// db.TB_PO.AddOrUpdate(p => p.PoBillNum, _list.ToArray());
// }
// if (p_state == PoState.Release)
// {
// var _list = db.TB_PO.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// int count = _list.Count(p => p.State == (int)AskState.New);
// if (_list.Count > 0 && _list.Count == count)
// {
// _list.ForEach(p =>
// {
// p.State = (int)PoState.Release;
// var _poList = db.TB_PO_DETAIL.Where(itm => itm.PoBillNum == p.PoBillNum).ToList();
// _poList.ForEach(itm =>
// {
// itm.State = (int)PoState.Release;
// });
// db.TB_PO_DETAIL.AddOrUpdate(itm => itm.UID, _poList.ToArray());
// }
// );
// db.TB_PO.AddOrUpdate(p => p.PoBillNum, _list.ToArray());
// }
// else
// {
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
// _ret.Message = "选择的记录,有不是新建状态记录!";
// }
// }
// if (p_state == PoState.New)
// {
// var _AskDetailList = db.TB_ASK_DETAIL.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// if (_AskDetailList.Count > 0)
// {
// db.TB_ASK_DETAIL.RemoveRange(_AskDetailList);//移除要货看板明细
// }
// var _ls = db.TB_ASK.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// if (_ls.Count > 0)
// {
// #region 供应商要货代办作废
// var _pList = _ls.Select(p => p.AskBillNum).ToList();
// var _pendingList = db.TB_PENING_ITEMS.Where(itm => _pList.Contains(itm.ITEM_NO)).ToList();
// if (_pendingList.Count > 0)
// {
// db.TB_PENING_ITEMS.RemoveRange(_pendingList);
// }
// #endregion
// db.TB_ASK.RemoveRange(_ls.ToArray());//移除要货看板
// }
// var _list = db.TB_PO.Where(p => p_list.Contains(p.PoBillNum)).ToList();
// int count = _list.Count(p => p.State == (int)AskState.Release);
// if (_list.Count > 0 && _list.Count == count)
// {
// _list.ForEach(p =>
// {
// p.State = (int)PoState.New;
// p.IsDeleted = false;
// var _poList = db.TB_PO_DETAIL.Where(itm => itm.PoBillNum == p.PoBillNum).ToList();
// _poList.ForEach(itm =>
// {
// itm.State = (int)PoState.New;
// });
// db.TB_PO_DETAIL.AddOrUpdate(itm => itm.UID, _poList.ToArray());
// });
// db.TB_PO.AddOrUpdate(p => p.PoBillNum, _list.ToArray());
// }
// else
// {
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
// _ret.Message = "选择的记录,有不是发布状态记录!";
// }
// }
// if (db.SaveChanges() != -1)
// {
// _ret.State = ReturnStatus.Succeed;
// _ret.Result = true;
// }
// else
// {
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
// _ret.Message = "数据更新失败!";
// }
// }
// else
// {
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
// _ret.Message = "该订单已经存在发货单,不能取消发布!";
// }
// }
//}
//catch (Exception e)
//{
// _ret.State = ReturnStatus.Failed;
// LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_PO), "Save_TB_PO", e.Message);
// _ret.Result = false;
// _ret.ErrorList.Add(e);
// throw e;
//}
return _ret;
}
public static List<V_TB_PO_DETAIL> GetPoDetailList(List<String> p_lst)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.V_TB_PO_DETAIL.Where(p => p_lst.Contains(p.PoBillNum)).ToList();
}
}
public static List<TB_MAXPO_CONSUME> GetMaxpoConsume(string maxpobillnum)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.TB_MAXPO_CONSUME.Where(p => p.PoBillNum == maxpobillnum).ToList();
}
}
public static List<V_TB_MAXPO_DETAIL> GetMaxPoDetailList(List<String> p_lst)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.V_TB_MAXPO_DETAIL.Where(p => p_lst.Contains(p.PoBillNum)).ToList();
}
}
public static ResultObject<bool> Save_TB_PO(List<TB_PO> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_entitys)
{
db.TB_PO.AddOrUpdate(p => p.PoBillNum, itm);
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_TB_PO", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_TB_PO", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_TB_PO", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_TB_PO", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
private static List<string> CheckExcelPackQty(ScpEntities db, SCP_PO_EXCEL p_excel)
{
List<string> ErrorList = new List<string>();
var _ls = db.TA_VEND_PART.Where(p => p.PartCode == p_excel. && p.VendId == p_excel.).ToList();
if (_ls.Count != 0)
{
if (_ls[0].VendPackQty != 0)
{
if (Convert.ToDecimal(p_excel.) % _ls[0].VendPackQty > 0)
{
ErrorList.Add(string.Format("分组【{2}】零件号【{0}】行号【{1}】不是整箱!标包数为【{3}】", p_excel., p_excel., p_excel., _ls[0].VendPackQty));
}
}
}
return ErrorList;
}
private static List<string> CheckExcel(ScpEntities db, SCP_PO_EXCEL p_excel)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.QAD订单号))
{
int count = db.TB_PO.Count(p => p.PoBillNum == p_excel.QAD订单号);
if (count == 0)
{
ErrorList.Add(string.Format("订单编号{0}不存在!", p_excel.QAD订单号));
}
}
else
{
ErrorList.Add(string.Format("订单编号为空!"));
}
var _list = db.TB_PO_DETAIL.Where(p => p.PoBillNum == p_excel.QAD订单号 && p.PartCode == p_excel.).ToList();
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.QAD订单号) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("分组【{1}】零件号【{0}】有填写为空!", p_excel., p_excel.));
}
if (_list.Count == 0)
{
ErrorList.Add(string.Format("分组【{2}】零件号【{0}】行号【{1}】不存在!", p_excel., p_excel., p_excel.));
}
else
{
p_excel. = _list[0].PoLine.ToString();
p_excel. = _list[0].Price.ToString();
p_excel. = _list[0].PoUnit.ToString();
p_excel. = _list[0].Currency.ToString();
}
return ErrorList;
}
private static List<string> CheckExce2(ScpEntities db, string lt)
{
List<string> ErrorList = new List<string>();
// 刨除作废的单子
var _asn = db.TB_ASN_DETAIL.Count(p => (p.PoBillNum ==lt) && (p.State != (int)AsnState.Reject ));
if (_asn> 0)
{
ErrorList.Add(string.Format("订单【{0}】已经生成发货单了,不能作废", lt));
}
return ErrorList;
}
private static List<string> CheckExce3(ScpEntities db, string lt)
{
List<string> ErrorList = new List<string>();
var _asn = db.TB_ASK.SingleOrDefault(p => p.AskBillNum == lt);
if (_asn.State > 0)
{
ErrorList.Add(string.Format("看板【{0}】不是新建状态,不能删除", lt));
}
return ErrorList;
}
public static ResultObject<bool> Save_EXCEL_PO_MOD(List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, BillModType p_modtype, string subsite, string p_chineseName, string p_buyerPhone)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
string _polist = "";
int _num = 1;
var OrderList = _lst.GroupBy(p => p.).ToList();
OrderList.ForEach((p) =>
{
var list = p.ToList();
if (list.Count > 0)
{
#region 日程单
if (p_modtype == BillModType.Contract)
{
var _entity = list.FirstOrDefault();
var _po = db.TB_PO.SingleOrDefault(t => t.PoBillNum == _entity./* && t.State == state*/ && t.Site == site && t.SubSite == subsite && t.VendId == _entity..ToUpper()) ??
new TB_PO { GUID = Guid.NewGuid(), PoBillNum = _entity..ToUpper(), State = (int)PoState.Open, Site = site, SubSite = subsite, VendId = _entity..ToUpper() };
_po.ErpBillNum = _entity..ToUpper();
_po.ModType = (int)p_modtype;
_po.Contacter = p_chineseName;// _entity.联系人;
_po.Buyer = p_chineseName;// _entity.联系人;
_po.BuyerPhone = p_buyerPhone;
_po.Site = site;
_po.Remark = _entity.;
_po.IsDeleted = false;
_po.CreateTime = DateTime.Parse(_entity.);
_po.CreateUser = p_creator;
_po.BeginTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now : DateTime.Parse(_entity.);
_po.EndTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now.AddYears(30) : DateTime.Parse(_entity.);
db.TB_PO.AddOrUpdate(_po);
list.ForEach((itm) =>
{
int _poline = Int32.Parse(itm.);
var _PO_Detail = db.TB_PO_DETAIL.FirstOrDefault(t => t.PartCode == itm. && t.PoLine == _poline && t.PoBillNum == itm. /*&& t.State == state*/ && t.Site == site && t.SubSite == subsite) ??
new TB_PO_DETAIL { GUID = Guid.NewGuid(), PartCode = itm..ToUpper(), PoLine = _poline, PoBillNum = itm..ToUpper(), State = (int)PoState.Open, Site = site, SubSite = subsite };
_PO_Detail.Currency = "CNY";
_PO_Detail.PoUnit = itm.;
_PO_Detail.CreateTime = DateTime.Parse(itm.);
_PO_Detail.CreateUser = p_creator;
_PO_Detail.BeginTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now : DateTime.Parse(_entity.);
_PO_Detail.EndTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now.AddYears(30) : DateTime.Parse(_entity.);
_PO_Detail.PlanQty = decimal.Parse(itm.);
_PO_Detail.IsDeleted = false;
_PO_Detail.LocUnit = itm.;
_PO_Detail.PoUnit = itm.;
_PO_Detail.UnConv = 1;
_PO_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.);
db.TB_PO_DETAIL.AddOrUpdate(_PO_Detail);
});
_polist = _polist + _po.PoBillNum + ",";
}
#endregion
#region 离散单
if (p_modtype == BillModType.Non_Contract)
{
var _entity = list.FirstOrDefault();
TB_PO _po = new TB_PO();
_po.GUID = Guid.NewGuid();
_po.PoBillNum = SCP_BILLCODE_CONTROLLER.MakePoNum(_num);
_po.State = (int)PoState.Open;
_po.Site = site;
_po.SubSite = subsite;
_po.VendId = _entity..ToUpper();
_po.ErpBillNum = _po.PoBillNum;
_po.ModType = (int)p_modtype;
_po.Contacter = p_chineseName;// _entity.联系人;
_po.Buyer = p_chineseName;// _entity.联系人;
_po.BuyerPhone = p_buyerPhone;
_po.Site = site;
_po.Remark = _entity.;
_po.IsDeleted = false;
_po.CreateTime = DateTime.Parse(_entity.);
_po.CreateUser = p_creator;
_po.BeginTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now : DateTime.Parse(_entity.);
_po.EndTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now.AddYears(30) : DateTime.Parse(_entity.);
db.TB_PO.AddOrUpdate(_po);
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(_num);
_ask.GUID = Guid.NewGuid();
_ask.PoBillNum = _po.PoBillNum;
_ask.VendId = _entity..ToUpper();
_ask.IsDeleted = false;
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = p_creator;
_ask.Site = site;
_ask.ReceivedPort = "";//交货口
_ask.State = (int)AskState.New;
// _ask.State = (int)AskState.Release;
_ask.Remark = _entity.;
_ask.ModType = (int)p_modtype;
_ask.ErpBillNum = _po.PoBillNum;
_ask.BeginTime = p_time;
_ask.EndTime = DateTime.Parse(_entity.);
_ask.Buyer = p_chineseName;
_ask.BuyerPhone = p_buyerPhone;
_ask.SubSite = subsite;
db.TB_ASK.Add(_ask);
int _number = 1;
list.ForEach((itm) =>
{
TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL();
_PO_Detail.GUID = Guid.NewGuid();
_PO_Detail.PartCode = itm..Trim().ToUpper();
_PO_Detail.PoLine = _number;
_PO_Detail.PoBillNum = _po.PoBillNum;
_PO_Detail.State = (int)PoState.Open;
_PO_Detail.Site = site;
_PO_Detail.SubSite = subsite;
_PO_Detail.Currency = "CNY";
_PO_Detail.PoUnit = itm.;
_PO_Detail.CreateTime = DateTime.Parse(itm.);
_PO_Detail.CreateUser = p_creator;
_PO_Detail.BeginTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now : DateTime.Parse(_entity.);
_PO_Detail.EndTime = string.IsNullOrEmpty(_entity.) ? DateTime.Now.AddYears(30) : DateTime.Parse(_entity.);
_PO_Detail.PlanQty = decimal.Parse(itm.);
_PO_Detail.IsDeleted = false;
_PO_Detail.LocUnit = itm.;
_PO_Detail.PoUnit = itm.;
_PO_Detail.UnConv = 1;
_PO_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.);
_PO_Detail.TempQty = decimal.Parse(itm.);
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.Remark = itm.;
_tDetail.PoBillNum = _po.PoBillNum;
_tDetail.AskBillNum = _ask.AskBillNum;
_tDetail.PoLine = _number;
_tDetail.PoUnit = itm.;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = p_creator;
_tDetail.PartCode = itm..Trim().ToUpper();
_tDetail.ReceivedPort = "";
_tDetail.BeginTime = p_time;
_tDetail.EndTime = Convert.ToDateTime(itm.);
_tDetail.TempQty = 0;
_tDetail.AskQty = Decimal.Parse(itm.);
_tDetail.IsDeleted = false;
_tDetail.LocUnit = itm.;
_tDetail.UnConv = 1;
_tDetail.State = (int)PoState.Open;
_tDetail.SubSite = subsite;
_tDetail.Site = site;
_tDetail.Price = Decimal.Parse(itm.);
_tDetail.GUID = Guid.NewGuid();
_tDetail.Currency = itm.;
db.TB_ASK_DETAIL.Add(_tDetail);
db.TB_PO_DETAIL.AddOrUpdate(_PO_Detail);
_number++;
});
_polist = _polist + _po.PoBillNum + "</br>";
}
#endregion
}
else
{
_ret.MessageList.Add("订单导入有误!");
return;
}
_num++;
Thread.Sleep(10);
}
);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
_ret.Message = _polist;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_EXCEL_PO_MOD1(List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, string subsite, string p_chineseName, string p_buyerPhone, string CreateTime, string EN, string EndTime, string PartCode, string PoBillNum, string Remark, string Time, string VendId, string PoUnit)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int _num = 1;
var _lst = p_order_list;
string _polist = "";
var OrderList = _lst.GroupBy(p => PoBillNum).ToList();
OrderList.ForEach((p) =>
{
var list = p.ToList();
if (list.Count > 0)
{
TB_PO _po = new TB_PO();
_po.GUID = Guid.NewGuid();
_po.PoBillNum = SCP_BILLCODE_CONTROLLER.MakePoNum(_num);
_po.State = (int)PoState.Open;
_po.Site = site;
_po.SubSite = subsite;
_po.VendId = VendId;
_po.ErpBillNum = _po.PoBillNum;
_po.ModType = 2;
_po.Contacter = p_chineseName;// _entity.联系人;
_po.Buyer = p_chineseName;// _entity.联系人;
_po.BuyerPhone = p_buyerPhone;
_po.Site = site;
_po.Remark = Remark;
_po.IsDeleted = false;
_po.CreateTime = DateTime.Parse(CreateTime);
_po.CreateUser = p_creator;
_po.BeginTime = DateTime.Parse(EndTime);
_po.EndTime = DateTime.Parse(Time);
db.TB_PO.AddOrUpdate(_po);
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(_num);
_ask.GUID = Guid.NewGuid();
_ask.PoBillNum = _po.PoBillNum;
_ask.VendId = VendId;
_ask.IsDeleted = false;
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = p_creator;
_ask.Site = site;
_ask.ReceivedPort = "";//交货口
_ask.State = (int)AskState.Release;
_ask.Remark = Remark;
_ask.ModType = 2;
_ask.ErpBillNum = _po.PoBillNum;
_ask.BeginTime = p_time;
_ask.EndTime = DateTime.Parse(EndTime);
_ask.Buyer = p_chineseName;
_ask.BuyerPhone = p_buyerPhone;
_ask.SubSite = subsite;
db.TB_ASK.Add(_ask);
int _number = 1;
list.ForEach((itm) =>
{
TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL();
_PO_Detail.GUID = Guid.NewGuid();
_PO_Detail.PartCode = PartCode;
_PO_Detail.PoLine = _number;
_PO_Detail.PoBillNum = _po.PoBillNum;
_PO_Detail.State = (int)PoState.Open;
_PO_Detail.Site = site;
_PO_Detail.SubSite = subsite;
_PO_Detail.Currency = "CNY";
_PO_Detail.PoUnit = PoUnit;
_PO_Detail.CreateTime = DateTime.Parse(CreateTime);
_PO_Detail.CreateUser = p_creator;
_PO_Detail.BeginTime = string.IsNullOrEmpty(CreateTime) ? DateTime.Now : DateTime.Parse(CreateTime);
_PO_Detail.EndTime = string.IsNullOrEmpty(EndTime) ? DateTime.Now.AddYears(30) : DateTime.Parse(EndTime);
_PO_Detail.PlanQty = decimal.Parse(EN);
_PO_Detail.IsDeleted = false;
_PO_Detail.LocUnit = PoUnit;
_PO_Detail.PoUnit = PoUnit;
_PO_Detail.UnConv = 1;
//_PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价);
_PO_Detail.TempQty = decimal.Parse(EN);
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.Remark = Remark;
_tDetail.PoBillNum = _po.PoBillNum;
_tDetail.AskBillNum = _ask.AskBillNum;
_tDetail.PoLine = _number;
_tDetail.PoUnit = PoUnit;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = p_creator;
_tDetail.PartCode = PartCode;
_tDetail.ReceivedPort = "";
_tDetail.BeginTime = p_time;
_tDetail.EndTime = Convert.ToDateTime(EndTime);
_tDetail.TempQty = 0;
_tDetail.AskQty = Decimal.Parse(EN);
_tDetail.IsDeleted = false;
_tDetail.LocUnit = PoUnit;
_tDetail.UnConv = 1;
_tDetail.State = (int)PoState.Open;
_tDetail.SubSite = subsite;
_tDetail.Site = site;
//_tDetail.Price = Decimal.Parse(itm.单价);
_tDetail.GUID = Guid.NewGuid();
_tDetail.Currency = "CNY";
db.TB_ASK_DETAIL.Add(_tDetail);
db.TB_PO_DETAIL.AddOrUpdate(_PO_Detail);
//_number++;
});
}
else
{
_ret.MessageList.Add("订单信息输入有误");
return;
}
}
);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
_ret.Message = _polist;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Check_EXCEL_PO_MOD(List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, BillModType p_modtype, string site, string subsite)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
p_order_list.ForEach(p =>
{
var _count1 = _lst.Count(itm => itm. == p. && itm. == p.);
var _count2 = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count1 > 1 && p_modtype == BillModType.Contract)
{
lineError.Add(string.Format("导入订单编号【{0}】行号【{1}】有重复", p., p.));
ErrorList = lineError;
}
if (_count2 > 1)
{
lineError.Add(string.Format("导入订单编号【{0}】零件编码【{1}】有重复", p., p.));
ErrorList = lineError;
}
});
p_order_list.ForEach
(p =>
{
var _ls = CheckExcelMode_Po(db, p, p_modtype, site, subsite);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 订单导入检查
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Po(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel, BillModType p_modtype, string site = null, string subsite = null)
{
List<string> ErrorList = new List<string>();
decimal _result = 0;
if (!decimal.TryParse(p_excel., out _result))
{
ErrorList.Add(string.Format("订单编号【{0}】零件编号【{1}】数量填写有问题", p_excel., p_excel.));
}
var _checkpart = db.TA_PART.FirstOrDefault(p => p.PartCode == p_excel.);
if (_checkpart != null)
{
if (_checkpart.State.ToUpper() != "SP")
{
p_excel. = _checkpart.Unit;
}
else
{
ErrorList.Add(string.Format("订单编号为【{0}】的零件编号【{1}】零件表零件停用,无法导入!", p_excel., p_excel.));
}
}
else
{
ErrorList.Add(string.Format("订单编号为【{0}】的零件编号【{1}】零件表里无数据,无法导入!", p_excel., p_excel.));
}
DateTime _d = DateTime.Now;
#region 日程单验证
if (p_modtype == BillModType.Contract)
{
if (string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("分组【{1}】零件名称【{0}】有填写为空!", p_excel., p_excel.));
}
else
{
if (!string.IsNullOrEmpty(p_excel.))
{
DateTime year = DateTime.Parse(p_excel.);
if (year.Year > 2049)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的零件截止日期必须大于等于2049年!", p_excel., p_excel., p_excel.));
}
}
if (!string.IsNullOrEmpty(p_excel.))
{
DateTime year = DateTime.Parse(p_excel.);
if (year.Year > 2049)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单截止日期必须大于等于2049年!", p_excel., p_excel., p_excel.));
}
}
string _ponumber = p_excel..ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1);
if (p_excel..ToUpper() != _ponumber.ToUpper())
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】零件号【{2}】的订单编号不正确,请更换订单编号!", p_excel., p_excel., p_excel.));
}
int _polinr = Int32.Parse(p_excel.);
var _partlist = db.TB_PO_DETAIL.Where(p => p.PoBillNum == p_excel. && p.PartCode == p_excel. && p.PoLine != _polinr).ToList();
if (_partlist.Count > 0)
{
ErrorList.Add(string.Format("订单编号【{0}】零件号【{1}】已经存在(系统:行号-【{2}】),请更换零件号!", p_excel., p_excel., _partlist[0].PoLine));
}
int linecount = db.TB_PO_DETAIL.Count(p => p.PoBillNum == p_excel. && p.PoLine == _polinr && p.PartCode != p_excel.);
if (linecount > 0)
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】已经存在,请更换行号!", p_excel., p_excel.));
}
var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel. && p.Site == site && p.VendId == p_excel. && p.StartTime <= DateTime.Now && DateTime.Now <= p.EndTime && p.Extend3 != "D").ToList();
if (checkcount.Count == 0)
{
ErrorList.Add(string.Format("零件名称【{0}】供应编码【{1}】价格表没有维护信息!", p_excel., p_excel.));
}
else
{
p_excel. = checkcount[0].Amt.ToString();
p_excel. = checkcount[0].Unit;
p_excel. = checkcount[0].Curr;
}
if (p_excel. != "0")
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的要货数量应该为零!", p_excel., p_excel., p_excel.));
}
if (DateTime.TryParse(p_excel., out _d) && DateTime.TryParse(p_excel., out _d))
{
if (DateTime.Parse(p_excel.) < DateTime.Parse(p_excel.))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】要求到货日期不能小于订单创建时间日期!", p_excel., p_excel., p_excel.));
}
}
else
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单创建日期或要求到货日期要求为文本格式!", p_excel., p_excel., p_excel.));
}
if (!Regex.IsMatch(p_excel., "^[0-9]{1,2}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】税率最大应为2位整数!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.))
{
if (p_excel..ToUpper() == "S")
{
if (string.IsNullOrEmpty(p_excel.) || !Regex.IsMatch(p_excel., "^[0-9]{1,8}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】加工单最大8位整数!", p_excel., p_excel., p_excel.));
}
if (string.IsNullOrEmpty(p_excel.) || !Regex.IsMatch(p_excel., "^[0-9]{1,6}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】工序最大6位整数!", p_excel., p_excel., p_excel.));
}
}
else
{
ErrorList.Add(string.Format("{0}订单类型必须填写为S为转包订单,不填写为正常订单", p_excel.));
}
//注释结束
}
if (!string.IsNullOrEmpty(p_excel.) && p_excel..Length > 8)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】库位最大8位字符!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && !Regex.IsMatch(p_excel., "^[0-9]{1,4}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】固定天数最大4位整数!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && !Regex.IsMatch(p_excel., "^[0-9]{1,3}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】日程天数最大3位整数!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && !Regex.IsMatch(p_excel., "^[0-9]{1,3}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】日程周数最大3位整数!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && !Regex.IsMatch(p_excel., "^[0-9]{1,3}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】日程月数最大3位整数!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && p_excel..Length > 2)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】发货样式最大2位字符!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && p_excel..Length > 2)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】发货时间样式最大2位字符!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && !Regex.IsMatch(p_excel., "^[0-9]{1,3}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】运输周期最大3位整数!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.) && p_excel..Length > 8)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】库位最大8位字符!", p_excel., p_excel., p_excel.));
}
}
}
#endregion
#region 离散单验证
if (p_modtype == BillModType.Non_Contract)
{
if (/*string.IsNullOrEmpty(p_excel.订单编号) ||string.IsNullOrEmpty(p_excel.行号) ||*/ string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.)/* || string.IsNullOrEmpty(p_excel.税率)*/)
{
ErrorList.Add(string.Format("分组【{1}】零件名称【{0}】有填写为空!", p_excel., p_excel.));
}
else
{
var ls = db.TA_VENDER.SingleOrDefault(p => p.VendId == p_excel.);
if (ls == null)
{
ErrorList.Add(string.Format("订单编号【{1}】零件名称【{0}】的供应商编号不存在", p_excel., p_excel.));
}
decimal a = decimal.Parse(p_excel.);
if (a <= 0)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的数量不能小于等于0", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.))
{
DateTime year = DateTime.Parse(p_excel.);
if (year.Year > 2049)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的零件截止日期必须大于等于2049年!", p_excel., p_excel., p_excel.));
}
}
if (!string.IsNullOrEmpty(p_excel.))
{
DateTime year = DateTime.Parse(p_excel.);
if (year.Year > 2049)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单截止日期必须大于等于2049年!", p_excel., p_excel., p_excel.));
}
}
//var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件号 && p.Site == site&& p.VendId == p_excel.供应商编号 && p.StartTime <= DateTime.Now && DateTime.Now <= p.EndTime).ToList();
//if (checkcount.Count == 0)
//{
// ErrorList.Add(string.Format("零件名称【{0}】供应编码【{1}】价格表没有维护信息!", p_excel.零件号, p_excel.供应商编号));
//}
//else
//{
// p_excel.单价 = checkcount[0].Amt.ToString();
// p_excel.单位 = checkcount[0].Unit;
// p_excel.币种 = checkcount[0].Curr;
//}
//if (!Regex.IsMatch(p_excel.税率, "^[0-9]{1,2}$"))
//{
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】税率最大2位整数!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
//}
if (DateTime.TryParse(p_excel., out _d) && DateTime.TryParse(p_excel., out _d))
{
if (DateTime.Parse(p_excel.) < DateTime.Parse(p_excel.))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】要求到货日期不能小于订单创建时间日期!", p_excel., p_excel., p_excel.));
}
}
else
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单创建日期或要求到货日期要求为文本格式!", p_excel., p_excel., p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.))
{
if (p_excel..ToUpper() != "S" && p_excel..ToUpper() != "M")
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单类型只能为M或S!", p_excel., p_excel., p_excel.));
}
//注释结束
if (p_excel..ToUpper() == "S")
{
if (string.IsNullOrEmpty(p_excel.) || !Regex.IsMatch(p_excel., "^[0-9]{1,8}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】加工单最大8位整数!", p_excel., p_excel., p_excel.));
}
if (string.IsNullOrEmpty(p_excel.) || !Regex.IsMatch(p_excel., "^[0-9]{1,6}$"))
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】工序最大6位整数!", p_excel., p_excel., p_excel.));
}
}
}
if (!string.IsNullOrEmpty(p_excel.) && p_excel..Length > 8)
{
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】库位最大8位字符!", p_excel., p_excel., p_excel.));
}
}
}
#endregion
return ErrorList;
}
private static List<string> CheckExcelMode(ScpEntities db, SCP_PO_DETAIL_EXPORT_MODEL p_excel)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.))
{
int count = db.TB_PO.Count(p => p.PoBillNum == p_excel.);
if (count == 0)
{
ErrorList.Add(string.Format("订单编号{0}不存在!", p_excel.));
}
}
else
{
ErrorList.Add(string.Format("订单编号为空!"));
}
decimal _result = 0;
if (!decimal.TryParse(p_excel., out _result))
{
ErrorList.Add(string.Format("订单编号{0}零件编号{1}数量填写有问题", p_excel., p_excel.));
}
var _count = db.TB_PO_DETAIL.Count(p => p.PoBillNum == p_excel. && p.PartCode == p_excel. && p.PoLine.ToString() == p_excel.);
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("分组【{1}】零件名称【{0}】有填写为空!", p_excel., p_excel.));
}
//else
//{
// if (!Regex.IsMatch(p_excel.计划员电话, @"^1[1,9]\d{9}$"))
// {
// ErrorList.Add(string.Format("订单编号{0}零件编号{1}计划员手机号填写有问题", p_excel.订单编号, p_excel.零件编码));
// }
//}
if (_count == 0)
{
ErrorList.Add(string.Format("分组【{2}】零件名称【{0}】行号【{1}】不存在!", p_excel., p_excel., p_excel.));
}
return ErrorList;
}
/// <summary>
/// 供应商零件导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_VenderPart(ScpEntities db, SCP_VENDER_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.))
{
int count = db.TA_VENDER.Count(p => p.VendId == p_excel. && p.Site == site);
if (count <= 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
}
else
{
ErrorList.Add(string.Format("供应商代码为空!"));
}
if (!string.IsNullOrEmpty(p_excel.))
{
int count = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Site == site);
if (count <= 0)
{
ErrorList.Add(string.Format("零件编号{0}不存在!", p_excel.));
}
}
else
{
ErrorList.Add(string.Format("零件号为空!"));
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.) || string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("供应商代码【{0}】零件编号【{1}】有填写为空!", p_excel., p_excel.));
}
return ErrorList;
}
/// <summary>
/// 供应商零件导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_VenderPart1(ScpEntities db, SCP_VENDER_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
//if (!string.IsNullOrEmpty(p_excel.零件号))
//{
// //int count = db.TA_PART.Count(p => p.PartCode == p_excel.零件号);
// //if (count <= 0)
// //{
// // ErrorList.Add(string.Format("零件编号【{0}】不存在!", p_excel.零件号));
// //}
// int count1 = db.TA_Appliance.Count(p => p.PartCode == p_excel.零件号 && p.Appliancenumber==p_excel.器具型号/*&&p.Model==p_excel.车型*/);
// if (count1 > 0)
// {
// ErrorList.Add(string.Format("零件编号【{0}】已存在!", p_excel.零件号));
// }
//}
if (
string.IsNullOrEmpty(p_excel.)||
string.IsNullOrEmpty(p_excel.)||
string.IsNullOrEmpty(p_excel.)||
string.IsNullOrEmpty(p_excel.)
)
{
ErrorList.Add(string.Format("零件号码【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 供应商零件导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_CousmterPart1(ScpEntities db, SCP_VENDER_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.))
{
int count = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (count <= 0)
{
ErrorList.Add(string.Format("零件号【{0}】不存在!", p_excel.));
}
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.)
)
{
ErrorList.Add(string.Format("零件号【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 本特勒收货信息导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Receiving(ScpEntities db, SCP_VENDER_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if(p_excel.!="白班"&& p_excel. != "夜班")
{
ErrorList.Add(string.Format("班次【{0}】填写不对,班次只能为白班或者夜班!", p_excel.));
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.)
)
{
ErrorList.Add(string.Format("班次【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
private static List<string> CheckExcelMode_PurchasingGroup(ScpEntities db, SCP_VENDER_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.)
)
{
ErrorList.Add(string.Format("采购组【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
private static List<string> CheckExcelMode_Sort(ScpEntities db, SCP_VENDER_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.Code39条码) ||
string.IsNullOrEmpty(p_excel.)
)
{
ErrorList.Add(string.Format("品番【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
private static List<string> CheckExcelMode_Box(ScpEntities db, SCP_VENDER_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (
string.IsNullOrEmpty(p_excel.)
)
{
ErrorList.Add(string.Format("箱种【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
private static List<string> CheckExcel_Model(ScpEntities db, SCP_VENDER_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
var ModelCount = db.TA_CarModel.Count(p=>p.Model==p_excel.);
if (ModelCount > 0)
{
ErrorList.Add(string.Format("车型【{0}】已经存在,请不要重复导入!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 供应商导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Vender(ScpEntities db, SCP_VENDER_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("供应商编号【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 价格导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <param name="site"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Price(ScpEntities db, SCP_PRICE_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.))
{
int count = db.TA_VENDER.Count(p => p.VendId == p_excel. && p.Site == site);
if (count <= 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
}
else
{
ErrorList.Add(string.Format("供应商代码为空!"));
}
if (!string.IsNullOrEmpty(p_excel.))
{
int count = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Site == site);
if (count <= 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
}
else
{
ErrorList.Add(string.Format("供应商代码为空!"));
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("零件编号【{0}】有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 零件导入验证
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Part(ScpEntities db, SCP_PART_EXPORT p_excel, string site)
{
List<string> ErrorList = new List<string>();
//if (!string.IsNullOrEmpty(p_excel.零件编号))
//{
// int count = db.TA_PART.Count(p => p.PartCode == p_excel.零件编号&&p.Site== site);
// if (count > 0)
// {
// ErrorList.Add(string.Format("零件编号{0}已经存在!", p_excel.零件编号));
// }
//}
//else
//{
// ErrorList.Add(string.Format("零件编号为空!"));
//}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("零件编号{0}有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 订单导入检查
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Po(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.)) {
var _count = db.TA_Appliance.Count(p => p.PartNumber == p_excel.&&p.VendID==p_excel.);
if (_count == 0)
{
ErrorList.Add(string.Format("零件号码{0}与供应商{1}没有对应的基础信息!", p_excel.,p_excel.));
}
}
var _count1 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count1 == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在!", p_excel.));
}
if (_count1 > 0)
{
if (!string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("普通采购订单不涉及组件物料号,请到委外采购订单菜单导入"));
}
var _part = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part.PartCode.ToString()!= p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}填写不正确请注意大小写!", p_excel.));
}
var _Unit = db.TA_PART.Count(p => p.PartCode == p_excel.&&p.Unit==p_excel.);
if (_Unit==0)
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确!", p_excel.));
}
if(_part.Unit.ToString()!= p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确,请注意大小写!", p_excel.));
}
var _checkpart = db.TA_PART.FirstOrDefault(p => p.PartCode == p_excel.);
if (decimal.Parse(_checkpart.Remark) <= 0)
{
ErrorList.Add(string.Format("物料号码{0}没有价格!", p_excel.));
}
}
var _count2 = db.TA_VENDER.Count(p => p.VendId == p_excel.);
if (_count2 == 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
if (_count2 > 0)
{
var _countvend = db.TA_VENDER.SingleOrDefault(p => p.VendId == p_excel.);
if (_countvend.VendId != p_excel.)
{
ErrorList.Add(string.Format("供应商编号{0}不正确!", p_excel.));
}
}
var _count7 = db.TA_PurchasGroup.Count(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel.);
if (_count7 == 0)
{
ErrorList.Add(string.Format("采购组{0}不存在!", p_excel.));
}
if (_count7 > 0)
{
var _count9 = db.TA_PurchasGroup.SingleOrDefault(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel. && p.ChineseName == p_excel.);
if (_count9.PurchasingGroup.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("采购组{0}填写错误,请注意大小写!", p_excel.));
}
}
var _count8 = db.TA_StorageLocation.Count(p => p.StLocation == p_excel.);
if (_count8 == 0)
{
ErrorList.Add(string.Format("存储地点{0}不存在!", p_excel.));
}
if (_count8 > 0)
{
var _count10 = db.TA_StorageLocation.SingleOrDefault(p => p.StLocation == p_excel.);
if (_count10.StLocation.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("存储地点{0}填写错误,请注意大小写!", p_excel.));
}
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("分组【{0}】物料号码有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 期货订单导入检查
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_QH_Po(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel)
{
List<string> ErrorList = new List<string>();
if (!string.IsNullOrEmpty(p_excel.))
{
var _count = db.TA_Appliance.Count(p => p.PartNumber == p_excel. && p.VendID == p_excel.);
if (_count == 0)
{
ErrorList.Add(string.Format("零件号码{0}与供应商{1}没有对应的基础信息!", p_excel., p_excel.));
}
}
var _count1 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count1 == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在!", p_excel.));
}
if (!string.IsNullOrEmpty(p_excel.))
{
if (p_excel. != "Y")
{
ErrorList.Add(string.Format("物料号码{0}期货订单必须填Y!", p_excel.));
}
}
if (_count1 > 0)
{
var _part = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part.PartCode.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}填写不正确请注意大小写!", p_excel.));
}
var _Unit = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Unit == p_excel.);
if (_Unit == 0)
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确!", p_excel.));
}
if (_part.Unit.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确,请注意大小写!", p_excel.));
}
var _checkpart = db.TA_PART.FirstOrDefault(p => p.PartCode == p_excel.);
if (decimal.Parse(_checkpart.Remark) <= 0)
{
ErrorList.Add(string.Format("物料号码{0}没有价格!", p_excel.));
}
}
var _count2 = db.TA_VENDER.Count(p => p.VendId == p_excel.);
if (_count2 == 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
if (_count2 > 0)
{
var _countvend = db.TA_VENDER.SingleOrDefault(p => p.VendId == p_excel.);
if (_countvend.VendId != p_excel.)
{
ErrorList.Add(string.Format("供应商编号{0}不正确!", p_excel.));
}
}
var maxpocount = db.TB_MAXPO_DETAIL.Count(p=>p.PartCode==p_excel.&&p.VendId == p_excel.);
if (maxpocount ==0)
{
ErrorList.Add(string.Format("物料号码{0}供应商编号{1}没有对应的大订单!",p_excel., p_excel.));
}
var _count7 = db.TA_PurchasGroup.Count(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel.);
if (_count7 == 0)
{
ErrorList.Add(string.Format("采购组{0}不存在!", p_excel.));
}
if (_count7 > 0)
{
var _count9 = db.TA_PurchasGroup.SingleOrDefault(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel. && p.ChineseName == p_excel.);
if (_count9.PurchasingGroup.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("采购组{0}填写错误,请注意大小写!", p_excel.));
}
}
var _count8 = db.TA_StorageLocation.Count(p => p.StLocation == p_excel.);
if (_count8 == 0)
{
ErrorList.Add(string.Format("存储地点{0}不存在!", p_excel.));
}
if (_count8 > 0)
{
var _count10 = db.TA_StorageLocation.SingleOrDefault(p => p.StLocation == p_excel.);
if (_count10.StLocation.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("存储地点{0}填写错误,请注意大小写!", p_excel.));
}
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("分组【{0}】物料号码有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 富维订单导入检查
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Po1(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel , bool _wmsweb)
{
List<string> ErrorList = new List<string>();
var _count = db.TA_Appliance.Count(p => p.PartNumber == p_excel. && p.VendID == p_excel.);
if (_count == 0)
{
ErrorList.Add(string.Format("零件号码{0}与供应商{1}没有对应的基础信息!", p_excel., p_excel.));
}
if (_wmsweb)
{
BomList1.JsonService bomVersionRe = new BomList1.JsonService();
var _ReturnRelust = bomVersionRe.GetBomVersion(p_excel., p_excel.);
if (p_excel.BOM版本 != _ReturnRelust)
{
ErrorList.Add(string.Format("物料号码{0}的BOM版本号填写错误", p_excel.));
}
}
else
{
BomList.JsonService bomVersionRe = new BomList.JsonService();
var _ReturnRelust = bomVersionRe.GetBomVersion(p_excel., p_excel.);
if (p_excel.BOM版本 != _ReturnRelust)
{
ErrorList.Add(string.Format("物料号码{0}的BOM版本号填写错误", p_excel.));
}
}
var price = db.TB_NetPrice.Count(p => p.PartCode == p_excel. && p.VendId == p_excel. && p.EndTime > DateTime.Now && p.StartTime <DateTime.Now && p.Extend3 != "D");
if (price == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在净价", p_excel.));
}
var _count1 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count1 == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在!", p_excel.));
}
if (_count1 > 0)
{
var _part = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part.PartCode.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}填写不正确请注意大小写和空格!", p_excel.));
}
if (_part.Unit.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确,请注意大小写!", p_excel.));
}
var _part5 = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part5.PartCode.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("组件物料号码{0}填写不正确请注意大小写和空格!", p_excel.));
}
if (_part5.Unit.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("组件物料号{0}计量单位填写不正确,请注意大小写!", p_excel.));
}
var _Unit = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Unit == p_excel.);
if (_Unit == 0)
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确!", p_excel.));
}
var _Unit1 = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Unit == p_excel.);
if (_Unit1 == 0)
{
ErrorList.Add(string.Format("组件物料号{0}组件计量单位填写不正确!", p_excel.));
}
if (decimal.Parse(_part.Remark) <= 0)
{
ErrorList.Add(string.Format("物料号码没有标准价格!", p_excel.));
}
}
var _count3 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count3 == 0)
{
ErrorList.Add(string.Format("组件物料号{0}不存在!", p_excel.));
}
var _count2 = db.TA_VENDER.Count(p => p.VendId == p_excel.);
if (_count2 == 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
if (_count2 > 0)
{
var _countvend = db.TA_VENDER.SingleOrDefault(p => p.VendId == p_excel.);
if (_countvend.VendId != p_excel.)
{
ErrorList.Add(string.Format("供应商编号{0}不正确!", p_excel.));
}
}
var _count7 = db.TA_PurchasGroup.Count(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel.);
if (_count7 == 0)
{
ErrorList.Add(string.Format("采购组{0}不存在!", p_excel.));
}
if (_count7 > 0)
{
var _count9 = db.TA_PurchasGroup.SingleOrDefault(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel. && p.ChineseName == p_excel.);
if(_count9.PurchasingGroup.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("采购组{0}填写错误,请注意大小写!", p_excel.));
}
}
var _count8 = db.TA_StorageLocation.Count(p => p.StLocation == p_excel.);
if (_count8 == 0)
{
ErrorList.Add(string.Format("存储地点{0}不存在!", p_excel.));
}
if (_count8 > 0)
{
var _count10= db.TA_StorageLocation.SingleOrDefault(p => p.StLocation == p_excel.);
if (_count10.StLocation.ToString()!= p_excel..ToString())
{
ErrorList.Add(string.Format("存储地点{0}填写错误,请注意大小写!", p_excel.));
}
}
if (
string.IsNullOrEmpty(p_excel.) ||
//string.IsNullOrEmpty(p_excel.零件号) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.)||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("零件名称{0}有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 本特勒订单导入检查
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_BTL(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel)
{
List<string> ErrorList = new List<string>();
var _count = db.TA_Appliance.Count(p => p.PartNumber == p_excel. && p.VendID == p_excel.);
if (_count == 0)
{
ErrorList.Add(string.Format("零件号码{0}与供应商{1}没有对应的基础信息!", p_excel., p_excel.));
}
BomVersion1.JsonService bomVersionRe = new BomVersion1.JsonService();
var _ReturnRelust = bomVersionRe.GetBomVersion(p_excel., p_excel.);
if (p_excel.BOM版本 != _ReturnRelust)
{
ErrorList.Add(string.Format("物料号码{0}的BOM版本号填写错误", p_excel.));
}
var price = db.TB_NetPrice.Count(p => p.PartCode == p_excel. && p.VendId == p_excel. && p.EndTime > DateTime.Now && p.StartTime < DateTime.Now && p.Extend3 != "D");
if (price == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在净价", p_excel.));
}
var _count1 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count1 == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在!", p_excel.));
}
if (_count1 > 0)
{
var _part = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part.PartCode.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}填写不正确请注意大小写和空格!", p_excel.));
}
if (_part.Unit.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确,请注意大小写!", p_excel.));
}
var _zjpart = db.TA_PART.Count(p => p.PartCode == p_excel.);
{
if (_zjpart == 0)
{
ErrorList.Add(string.Format("组件物料号码{0}不存在!", p_excel.));
}
else
{
var _part5 = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part5.PartCode.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("组件物料号码{0}填写不正确请注意大小写和空格!", p_excel.));
}
if (_part5.Unit.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("组件物料号{0}计量单位填写不正确,请注意大小写!", p_excel.));
}
}
}
var _Unit = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Unit == p_excel.);
if (_Unit == 0)
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确!", p_excel.));
}
var _Unit1 = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Unit == p_excel.);
if (_Unit1 == 0)
{
ErrorList.Add(string.Format("组件物料号{0}组件计量单位填写不正确!", p_excel.));
}
if (decimal.Parse(_part.Remark) <= 0)
{
ErrorList.Add(string.Format("物料号码没有标准价格!", p_excel.));
}
}
//var _count3 = db.TA_PART.Count(p => p.PartCode == p_excel.组件物料号);
//if (_count3 == 0)
//{
// ErrorList.Add(string.Format("组件物料号{0}不存在!", p_excel.组件物料号));
//}
var _count2 = db.TA_VENDER.Count(p => p.VendId == p_excel.);
if (_count2 == 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
if (_count2 > 0)
{
var _countvend = db.TA_VENDER.SingleOrDefault(p => p.VendId == p_excel.);
if (_countvend.VendId != p_excel.)
{
ErrorList.Add(string.Format("供应商编号{0}不正确!", p_excel.));
}
}
var _count7 = db.TA_PurchasGroup.Count(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel.);
if (_count7 == 0)
{
ErrorList.Add(string.Format("采购组{0}不存在!", p_excel.));
}
if (_count7 > 0)
{
var _count9 = db.TA_PurchasGroup.SingleOrDefault(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel. && p.ChineseName == p_excel.);
if (_count9.PurchasingGroup.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("采购组{0}填写错误,请注意大小写!", p_excel.));
}
}
var _count8 = db.TA_StorageLocation.Count(p => p.StLocation == p_excel.);
if (_count8 == 0)
{
ErrorList.Add(string.Format("存储地点{0}不存在!", p_excel.));
}
if (_count8 > 0)
{
var _count10 = db.TA_StorageLocation.SingleOrDefault(p => p.StLocation == p_excel.);
if (_count10.StLocation.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("存储地点{0}填写错误,请注意大小写!", p_excel.));
}
}
if (
string.IsNullOrEmpty(p_excel.) ||
//string.IsNullOrEmpty(p_excel.零件号) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("零件名称{0}有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 富维多组件订单导入效验
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_Multicomponent(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel,bool wmsweb)
{
List<string> ErrorList = new List<string>();
if (wmsweb == false) {
BomList.JsonService bomVersionRe = new BomList.JsonService();
var _ReturnRelust = bomVersionRe.GetBomsByVer(p_excel., p_excel.BOM版本);
if (!_ReturnRelust.Contains("Qty"))
{
ErrorList.Add(string.Format("不存在物料号为{0},版本号为{1}的数据", p_excel., p_excel.BOM版本));
}
}
else
{
BomList1.JsonService bomVersionRe = new BomList1.JsonService();
var _ReturnRelust = bomVersionRe.GetBomsByVer(p_excel., p_excel.BOM版本);
if (!_ReturnRelust.Contains("Qty"))
{
ErrorList.Add(string.Format("不存在物料号为{0},版本号为{1}的数据", p_excel., p_excel.BOM版本));
}
}
var _count = db.TA_Appliance.Count(p => p.PartNumber == p_excel. && p.VendID == p_excel.);
if (_count == 0)
{
ErrorList.Add(string.Format("零件号码{0}与供应商{1}没有对应的基础信息!", p_excel., p_excel.));
}
//var price = db.TB_NetPrice.Count(p => p.PartCode == p_excel.物料号码 && p.VendId == p_excel.供应商编号 && p.EndTime > DateTime.Now);
//if (price == 0)
//{
// ErrorList.Add(string.Format("物料号码{0}不存在净价", p_excel.物料号码));
//}
var _count1 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count1 == 0)
{
ErrorList.Add(string.Format("物料号码{0}不存在!", p_excel.));
}
if (_count1 > 0)
{
var _part = db.TA_PART.SingleOrDefault(p => p.PartCode == p_excel.);
if (_part.PartCode.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}填写不正确请注意大小写和空格!", p_excel.));
}
if (_part.Unit.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确,请注意大小写!", p_excel.));
}
var _Unit = db.TA_PART.Count(p => p.PartCode == p_excel. && p.Unit == p_excel.);
if (_Unit == 0)
{
ErrorList.Add(string.Format("物料号码{0}单位填写不正确!", p_excel.));
}
if (decimal.Parse(_part.Remark) <= 0)
{
ErrorList.Add(string.Format("物料号码没有标准价格!", p_excel.));
}
}
var _count2 = db.TA_VENDER.Count(p => p.VendId == p_excel.);
if (_count2 == 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
if (_count2 > 0)
{
var _countvend = db.TA_VENDER.SingleOrDefault(p => p.VendId == p_excel.);
if (_countvend.VendId != p_excel.)
{
ErrorList.Add(string.Format("供应商编号{0}不正确!", p_excel.));
}
}
var _count7 = db.TA_PurchasGroup.Count(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel.);
if (_count7 == 0)
{
ErrorList.Add(string.Format("采购组{0}不存在!", p_excel.));
}
if (_count7 > 0)
{
var _count9 = db.TA_PurchasGroup.SingleOrDefault(p => p.PurchasingGroup == p_excel. && p.ChineseName == p_excel. && p.ChineseName == p_excel.);
if (_count9.PurchasingGroup.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("采购组{0}填写错误,请注意大小写!", p_excel.));
}
}
var _count8 = db.TA_StorageLocation.Count(p => p.StLocation == p_excel.);
if (_count8 == 0)
{
ErrorList.Add(string.Format("存储地点{0}不存在!", p_excel.));
}
if (_count8 > 0)
{
var _count10 = db.TA_StorageLocation.SingleOrDefault(p => p.StLocation == p_excel.);
if (_count10.StLocation.ToString() != p_excel..ToString())
{
ErrorList.Add(string.Format("存储地点{0}填写错误,请注意大小写!", p_excel.));
}
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("零件名称{0}有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 富维冲压件大订单效验
/// </summary>
/// <param name="db"></param>
/// <param name="p_excel"></param>
/// <returns></returns>
private static List<string> CheckExcelMode_MAXPO(ScpEntities db, SCP_MAXPO_EXPORT p_excel)
{
List<string> ErrorList = new List<string>();
var _count1 = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count1 == 0)
{
ErrorList.Add(string.Format("零件号{0}不存在!", p_excel.));
}
var _count = db.TA_PART.Count(p => p.PartCode == p_excel.);
if (_count == 0)
{
ErrorList.Add(string.Format("原材物料号{0}不存在!", p_excel.));
}
var _count2 = db.TA_VENDER.Count(p => p.VendId == p_excel.);
if (_count2 == 0)
{
ErrorList.Add(string.Format("供应商{0}不存在!", p_excel.));
}
if (_count2 > 0)
{
var _countvend = db.TA_VENDER.FirstOrDefault(p => p.VendId == p_excel.);
if (_countvend.VendId != p_excel.)
{
ErrorList.Add(string.Format("供应商编号{0}不正确!", p_excel.));
}
}
BomList1.JsonService bomVersionRe = new BomList1.JsonService();
var _ReturnRelust = bomVersionRe.GetBom(p_excel., p_excel.);
if (_ReturnRelust == "[null]")
{
ErrorList.Add(string.Format("零件号{0}与原材物料号{1}不存在BOM关系!", p_excel., p_excel.));
}
if (
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.) ||
string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("零件名称{0}有填写为空!", p_excel.));
}
return ErrorList;
}
/// <summary>
/// 北京安通林
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_TO_ASK_MOD(List<SCP_PO_DETAIL_EXPORT_MODEL> p_order_list, string p_creator, string p_buyer, DateTime p_time, BillModType p_modtype, bool IsAutoPublish = false)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
p_order_list.ForEach(p =>
{
if (string.IsNullOrEmpty(p.))
{
p. = "0";
}
});
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list.Where(p => p. != "0").ToList();
_lst.ForEach
(p =>
{
var _ls = CheckExcelMode(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
var VenderList = _lst.Select(p => p.).Distinct();
var PartCodeList = _lst.Select(p => p.).Distinct();
var OrderList = _lst.GroupBy(p => p.).ToList();
OrderList.ForEach((p) =>
{
var list = p.ToList();
if (list.Count > 0)
{
var _entity = list.FirstOrDefault();
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode();
_ask.VendId = _entity.;
_ask.State = (int)AskState.New;
_ask.PoBillNum = _entity.;
_ask.ModType = (int)BillModType.Contract;
_ask.Site = _entity.;
_ask.Remark = _entity.;
if (IsAutoPublish)
{
_ask.State = (int)AskState.Release;
}
else
{
_ask.State = (int)AskState.New;
}
_ask.BeginTime = DateTime.Parse(_entity.);
_ask.Buyer = p_buyer;
_ask.BuyerPhone = _entity.;
_ask.ErpBillNum = _entity.;
_ask.EndTime = DateTime.Parse(_entity.);
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = p_creator;
_ask.VendId = _entity.;
_ask.GUID = Guid.NewGuid();
_ask.ReceivedPort = _entity.;
_ask.IsDeleted = false;
db.TB_ASK.Add(_ask);
#region 供应商新任务代办接口
TB_PENING_ITEMS _item = new TB_PENING_ITEMS();
_item.ROLE_NAME = "供应商";
_item.ITEM_NO = _ask.AskBillNum;
_item.ITEM_CONTENT = "要货看盘有信息";
_item.ITEM_TYPE = (int)PENDING_MESSAGE_TYPE.NEW_ASK;
_item.VEND_ID = _ask.VendId;
_item.ITEM_STATE = (int)PENDING_STATE.WAITING;
_item.SENDER = p_buyer;
_item.SENDING_TIME = DateTime.Now;
db.TB_PENING_ITEMS.Add(_item);
#endregion
// int _number = 1;
List<TB_ASK_DETAIL> _ls = new List<TB_ASK_DETAIL>();
list.ForEach((itm) =>
{
var _number = _ls.Count(p1 => p1.PoBillNum == _ask.PoBillNum
&& p1.PoLine == Int32.Parse(itm.) && p1.PartCode == itm. && itm. == p1.Remark);
if (_number > 0)
{
_ret.MessageList.Add(string.Format("已经存在订单为{0}行号为{1}零件编码为{2}", itm., itm., itm.));
}
TB_ASK_DETAIL _t_ASK_Detail = new TB_ASK_DETAIL();
_t_ASK_Detail.PoLine = Int32.Parse(itm.);
_t_ASK_Detail.Currency = itm.;
_t_ASK_Detail.AskBillNum = _ask.AskBillNum;
_t_ASK_Detail.PoBillNum = _ask.PoBillNum;
_t_ASK_Detail.PoUnit = itm.;
_t_ASK_Detail.CreateTime = DateTime.Now;
_t_ASK_Detail.CreateUser = _ask.CreateUser;
_t_ASK_Detail.PartCode = itm.;
_t_ASK_Detail.BeginTime = DateTime.Parse(itm.);
_t_ASK_Detail.EndTime = DateTime.Parse(itm.);
_t_ASK_Detail.TempQty = decimal.Parse(itm.);
_t_ASK_Detail.AskQty = decimal.Parse(itm.);
_t_ASK_Detail.IsDeleted = false;
_t_ASK_Detail.LocUnit = itm.;
_t_ASK_Detail.UnConv = 1;
_t_ASK_Detail.DockCode = itm.;
_t_ASK_Detail.State = _ask.State;
_t_ASK_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.);
_t_ASK_Detail.GUID = Guid.NewGuid();
_t_ASK_Detail.Remark = _ask.Site;
_t_ASK_Detail.UpdateInfo = itm.;
db.TB_ASK_DETAIL.Add(_t_ASK_Detail);
_ls.Add(_t_ASK_Detail);
// _number++;
});
}
else
{
_ret.MessageList.Add("ERP订单编号已存在,请重新导入!");
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
);
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 供应商零件导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_PART_MOD(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的供应商{0}零件编号{1}有重复", p., p.));
ErrorList = lineError;
}
});
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_VenderPart(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _venderpart = db.TA_VEND_PART.SingleOrDefault(t => t.VendId == p..ToUpper() && t.PartCode == p..ToUpper()) ??
new TA_VEND_PART
{
VendId = p..ToUpper(),
PartCode = p..ToUpper(),
State = 1,
CreateTime = DateTime.Now,
CreateUser = p_creator,
IsDeleted = false,
GUID = System.Guid.NewGuid(),
};
_venderpart.VendPartCode = p..ToUpper();
_venderpart.VendPackQty = decimal.Parse(p.);
_venderpart.MinPackQty = decimal.Parse(p.);
_venderpart.PalletPackQty = decimal.Parse(p.);
_venderpart.PoUnit = p.;
_venderpart.Remark = "";
_venderpart.UpdateTime = DateTime.Now;
_venderpart.UpdateUser = p_creator;
_venderpart.Site = site;
db.TA_VEND_PART.AddOrUpdate(_venderpart);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 零件器具导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_PART_MOD1(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm.==p.);
if (_count > 1)
{
lineError.Add(string.Format("零件号码有重复", p.));
ErrorList = lineError;
}
});
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_VenderPart1(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _partdes = db.TA_Appliance.Count(t => t.PartNumber == p. && t.VendID == p.);
if (_partdes == 0)
{
TA_Appliance _entity = new TA_Appliance();
_entity.PartNumber = p.;
_entity.PackNumber = decimal.Parse(p.);
_entity.PartDesc1 = p.;
_entity.ReciteNumber = p.;
_entity.SufanLand = p.;
_entity.BoxType = p.;
_entity.PostEngineering = p.;
_entity.PartNumber = p.;
_entity.Texture = p.;
_entity.Model = p.;
_entity.ReceivingPort = p.;
_entity.VendID = p.;
_entity.OtherVendName = p.;
db.TA_Appliance.Add(_entity);
}
else
{
var _partde = db.TA_Appliance.SingleOrDefault(t => t.PartNumber == p. && t.VendID == p.);
_partde.PackNumber = decimal.Parse(p.);
_partde.PartDesc1 = p.;
_partde.Model = p.;
_partde.ReciteNumber = p.;
_partde.SufanLand = p.;
_partde.BoxType = p.;
_partde.PostEngineering = p.;
_partde.PartNumber = p.;
_partde.Texture = p.;
_partde.ReceivingPort = p.;
_partde.OtherVendName = p.;
db.TA_Appliance.AddOrUpdate(_partde);
}
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 本特勒收货信息导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_TA_RECEIVING(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_Receiving(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _partdes = db.TA_Receiving_Information.Count(t => t.Shift == p.);
if (_partdes == 0)
{
TA_Receiving_Information _entity = new TA_Receiving_Information();
_entity.Shift = p.;
_entity.Name = p.;
_entity.Phone = p.;
db.TA_Receiving_Information.Add(_entity);
}
else
{
var _partde = db.TA_Receiving_Information.FirstOrDefault(t => t.Shift == p.);
_partde.Name = p.;
_partde.Phone = p.;
db.TA_Receiving_Information.AddOrUpdate(_partde);
}
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 子零件导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_PART_MOD2(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _count = _lst.Count(itm => itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("零件号有重复", p.));
ErrorList = lineError;
}
});
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_CousmterPart1(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _coustomerpart = db.TA_SubPart.Count(t => t.PartCode == p..ToUpper());
if (_coustomerpart == 0)
{
TA_SubPart subpa = new TA_SubPart();
subpa.SubPart = p.;
subpa.PartCode = p.;
db.TA_SubPart.AddOrUpdate(subpa);
}
else
{
var subpa = db.TA_SubPart.FirstOrDefault(t => t.PartCode == p..ToUpper());
subpa.SubPart = p.;
db.TA_SubPart.AddOrUpdate(subpa);
}
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 采购组导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_PART_MOD4(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_PurchasingGroup(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _venderpart = db.TA_PurchasGroup.SingleOrDefault(t => t.PurchasingGroup == p..ToUpper() && t.ChineseName == p..ToUpper()) ??
new TA_PurchasGroup
{
PurchasingGroup = p..ToUpper(),
ChineseName = p..ToUpper(),
Describe=p..ToUpper(),
};
//_venderpart.Model = p.车型.ToUpper();
db.TA_PurchasGroup.AddOrUpdate(_venderpart);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 存储地点导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_PART_MOD5(List<SCP_VENDER_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
//_lst.ForEach(p =>
//{
// var _ls = CheckExcelMode_Sort(db, p, site);
// if (_ls.Count > 0)
// {
// lineError.Add(number.ToString());
// ErrorList.Add(string.Join("<br>", _ls.ToArray()));
// }
// number++;
//});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _venderpart = db.TA_StorageLocation.SingleOrDefault(t => t.StLocation == p..ToUpper() && t.Arrangement == p..ToUpper()) ??
new TA_StorageLocation
{
StLocation = p..ToUpper(),
Arrangement = p..ToUpper(),
Leveldescription = p..ToUpper(),
Describe = p..ToUpper(),
Inventoryation = p..ToUpper(),
};
//_venderpart.Model = p.车型.ToUpper();
db.TA_StorageLocation.AddOrUpdate(_venderpart);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 品番导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_PART_MOD6(List<SCP_VENDER_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_Sort(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _venderpart = db.TA_PinFan.SingleOrDefault(t => t.PartCode == p..ToUpper() ) ??
new TA_PinFan
{
PartCode = p..ToUpper(),
Barcodnt = p..ToUpper(),
Identification = p.Code39条码.ToUpper(),
};
//_venderpart.Model = p.车型.ToUpper();
db.TA_PinFan.AddOrUpdate(_venderpart);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 箱种导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_Box_Type(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_Box(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
var _count = _lst.Count(itm => itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("箱种有重复", p.));
ErrorList = lineError;
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _boxtype = db.TA_BOXTYPE.SingleOrDefault(t => t.BoxType == p..ToUpper()) ??
new TA_BOXTYPE
{
BoxType = p.
};
_boxtype.CreateTime = DateTime.Now;
_boxtype.CreateUser = p_creator;
_boxtype.Enabled = p. == "是" ? true : false;
db.TA_BOXTYPE.AddOrUpdate(_boxtype);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 本特勒车型导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_Car_Model(List<SCP_VENDER_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _ls = CheckExcel_Model(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
_lst.ForEach(p =>
{
var _count = _lst.Count(itm => itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("车型【{0}】有重复", p.));
ErrorList = lineError;
}
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
TA_CarModel Car = new TA_CarModel();
Car.Model = p.;
db.TA_CarModel.AddOrUpdate(Car);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> EXCEL_VENDER_PART_MOD3(List<SCP_VENDER_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
//_lst.ForEach(p =>
//{
// var _count = _lst.Count(itm => itm.零件号 == p.零件号);
// if (_count > 1)
// {
// lineError.Add(string.Format("零件编号有重复", p.零件号));
// ErrorList = lineError;
// }
//});
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_VenderPart1(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _venderpart = db.TA_ProductionLine.SingleOrDefault(t => t.ProductionLine == p.线.ToUpper() && t.PartCode == p..ToUpper()) ??
new TA_ProductionLine
{
ProductionLine = p.线.ToUpper(),
PartCode = p..ToUpper(),
};
//_venderpart.Model = p.车型.ToUpper();
db.TA_ProductionLine.AddOrUpdate(_venderpart);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 供应商导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_VENDER_MOD(List<SCP_VENDER_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _count = _lst.Count(itm => itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入零件编号{0}有重复", p.));
ErrorList = lineError;
}
});
_lst.ForEach(p =>
{
var _ls = CheckExcelMode_Vender(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _vender = db.TA_VENDER.SingleOrDefault(t => t.VendId == p..ToUpper()) ??
new TA_VENDER { VendId = p..ToUpper(), State = 1 };
_vender.VendName = p.;
_vender.VendAbbCode = string.IsNullOrEmpty(p.) ? "0" : p.;
_vender.VendType = p.;
_vender.Country = p.;
_vender.City = p.;
_vender.Currency = p.;
_vender.Address = p.;
_vender.ZipCode = p.;
_vender.Contacter = p.;
_vender.Phone = p.;
_vender.Fax = p.;
_vender.Remark = p.;
_vender.Tax = Convert.ToDecimal(p.);
_vender.Site = site;
db.TA_VENDER.AddOrUpdate(_vender);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_VENDER_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 价格导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PRICE_MOD(List<SCP_PRICE_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _ls = CheckExcelMode_Price(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _price = new TB_PRICE();
_price.VendId = p..Trim();
_price.PartCode = p..Trim();
_price.StartTime = DateTime.Parse(p.);
_price.EndTime = DateTime.Parse(p.);
_price.Curr = p.;
_price.Unit = p.;
_price.Amt = decimal.Parse(p.);
_price.Site = site.Trim();
_price.Remarks = p.;
db.TB_PRICE.Add(_price);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PRICE_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PRICE_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PRICE_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PRICE_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 零件导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="site"></param>
/// <param name="p_creator"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PART_MOD(List<SCP_PART_EXPORT> p_order_list, string site, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach(p =>
{
var _count = _lst.Count(itm => itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入零件编号{0}有重复", p.));
ErrorList = lineError;
}
});
_lst.ForEach
(p =>
{
var _ls = CheckExcelMode_Part(db, p, site);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach(p =>
{
var _part = db.TA_PART.SingleOrDefault(t => t.PartCode == p..ToUpper()) ??
new TA_PART { PartCode = p..ToUpper() };
_part.PartCode = p.;
_part.ErpPartCode = p.;
_part.PartDesc1 = p.;
_part.PartDesc2 = "";
_part.ProjectId = p.;
_part.Unit = p.;
_part.PartGroup = p.;
_part.State = p.;
_part.Site = site;
db.TA_PART.AddOrUpdate(_part);
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PART_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PART_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PART_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PART_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 订单导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_MOD(List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, PoState p_modtype)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
DataTable ds = new DataTable();
_lst.ForEach
(p =>
{
var _ls = CheckExcelMode_Po(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
List<TB_PO> poList = new List<TB_PO>();
List<TB_PO_DETAIL> po_Detail = new List<TB_PO_DETAIL>();
List<TB_ASK> askList = new List<TB_ASK>();
List<TB_ASK_DETAIL> askDetailList = new List<TB_ASK_DETAIL>();
List<TS_UNI_API> uniList = new List<TS_UNI_API>();
//先循环找到一个日期的订单
foreach (DataColumn column in ds.Columns)
{
DateTime date = DateTime.MaxValue;
DateTime.TryParse(column.ColumnName, out date);
if (date != DateTime.MaxValue)
{
//找到所有日期下订单
foreach (DataRow dataRow in ds.Rows)//订单分组表
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (_Qty > 0)
{
//创建主单据及看板
var _Po = CreatePo1(poList, dataRow, date, p_creator,site);
//创建主单据及看板
var _PoAsk = CreateAsk1(poList, askList, dataRow, date, p_creator,db,site);
//创建明细
var _PoDetail = CreatePoDetail1(dataRow, _Qty, db, date, _Po, _PoAsk, p_creator,site);
po_Detail.Add(_PoDetail);
var _Askdetail = CreateAskDetail1(db, dataRow, _Po, _PoAsk, _PoDetail, p_creator,site);
askDetailList.Add(_Askdetail);
var Tsuniapi = CreateTsuniapi1(_Po, _PoAsk, _PoDetail, dataRow, _Askdetail,site);
uniList.Add(Tsuniapi);
}
}
}
}
var billGroups= poList.GroupBy(p=>new { p.VendId,p.EndTime});
foreach (var item in billGroups) ;
db.TB_PO.AddRange(poList);
db.TB_ASK.AddRange(askList);
db.TB_PO_DETAIL.AddRange(po_Detail);
db.TB_ASK_DETAIL.AddRange(askDetailList);
db.TS_UNI_API.AddRange(uniList);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
//}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 富维普通订单导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_MOD2(DataTable p_order_list1, List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, PoState p_modtype)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的物料号码{0}有重复", p.));
ErrorList = lineError;
}
var _ls = CheckExcelMode_Po(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
List<TB_PO> poList = new List<TB_PO>();
List<TB_PO_DETAIL> po_DetailList = new List<TB_PO_DETAIL>();
List<TB_ASK> askList = new List<TB_ASK>();
List<TB_ASK_DETAIL> askDetailList = new List<TB_ASK_DETAIL>();
List<TS_UNI_API> uniList = new List<TS_UNI_API>();
//先循环找到一个日期的订单
foreach (DataColumn column in p_order_list1.Columns)
{
DateTime date = DateTime.MaxValue;
DateTime.TryParse(column.ColumnName, out date);
if (date != DateTime.MaxValue && date.Year > 2000)
{
//找到所有日期下订单
foreach (DataRow dataRow in p_order_list1.Rows)//订单分组表
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (_Qty > 0)
{
// 创建主单据及看板
var _Po = CreatePo1( poList, dataRow, date, p_creator, site);
// 创建主单据及看板
var _PoAsk = CreateAsk1(poList, askList, dataRow, date, p_creator,db,site);
//创建明细
var _PoDetail = CreatePoDetail1(dataRow, _Qty, db, date, _Po, _PoAsk, p_creator,site);
po_DetailList.Add(_PoDetail);
var _Askdetail = CreateAskDetail1(db, dataRow, _Po, _PoAsk, _PoDetail, p_creator,site);
askDetailList.Add(_Askdetail);
var Tsuniapi = CreateTsuniapi1(_Po, _PoAsk, _PoDetail,dataRow, _Askdetail,site);
uniList.Add(Tsuniapi);
}
}
}
}
int cnt = 1;
foreach (var item in poList)
{
var oldGuid = item.PoBillNum;
var newBillId = SCP_BILLCODE_CONTROLLER.MakePOCode2();//订单号
if (item.Site != "W21")
{
newBillId=SCP_BILLCODE_CONTROLLER.MakePOCode4();//订单号
}
var newAskNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(cnt);
var add_Po = item.Clone(newBillId, item.Site);
db.TB_PO.Add(add_Po);
var Add_Po_DETAIL = po_DetailList.Where(p => p.PoBillNum == oldGuid).ToList();
int cntPo_detail = 1;
Add_Po_DETAIL.ForEach(p => p.PoBillNum = newBillId);
Add_Po_DETAIL.ForEach(p =>
{
p.PoLine = cntPo_detail;
cntPo_detail++;
});
db.TB_PO_DETAIL.AddRange(Add_Po_DETAIL);
var Add_AskList = askList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_AskList.ForEach(p => p.PoBillNum = newBillId);
Add_AskList.ForEach(p => p.AskBillNum = newAskNum);
Add_AskList.ForEach(p => p.ErpBillNum = newBillId);
db.TB_ASK.AddRange(Add_AskList);
var Add_ASK_DETAIL = askDetailList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_ASK_DETAIL.ForEach(p => p.PoBillNum = newBillId);
int cntAsk_detail = 1;
Add_ASK_DETAIL.ForEach(p => p.AskBillNum = newAskNum);
Add_ASK_DETAIL.ForEach(p =>
{
p.PoLine = cntAsk_detail;
cntAsk_detail++;
});
db.TB_ASK_DETAIL.AddRange(Add_ASK_DETAIL);
var Add_UniList = uniList.Where(p => p.BillNum == oldGuid).ToList();
int cntTS_detail = 1;
Add_UniList.ForEach(p =>
{
p.ErpLineNum = cntTS_detail;
cntTS_detail++;
});
Add_UniList.ForEach(p => p.BillNum = newBillId);
db.TS_UNI_API.AddRange(Add_UniList);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
//}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 富维期货订单导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_QH_MOD(DataTable p_order_list1, List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, PoState p_modtype)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的物料号码{0}有重复", p.));
ErrorList = lineError;
}
var _ls = CheckExcelMode_QH_Po(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
List<TB_PO> poList = new List<TB_PO>();
List<TB_PO_DETAIL> po_DetailList = new List<TB_PO_DETAIL>();
List<TB_ASK> askList = new List<TB_ASK>();
List<TB_ASK_DETAIL> askDetailList = new List<TB_ASK_DETAIL>();
List<TS_UNI_API> uniList = new List<TS_UNI_API>();
List<TB_MAXPO_CONSUME> consum = new List<TB_MAXPO_CONSUME>();
//先循环找到一个日期的订单
foreach (DataColumn column in p_order_list1.Columns)
{
DateTime date = DateTime.MaxValue;
DateTime.TryParse(column.ColumnName, out date);
if (date != DateTime.MaxValue && date.Year > 2000)
{
//找到所有日期下订单
foreach (DataRow dataRow in p_order_list1.Rows)//订单分组表
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (_Qty > 0)
{
// 创建主单据及看板
var _Po = CreatePoQh(poList, dataRow, date, p_creator, site);
// 创建主单据及看板
var _PoAsk = CreateAsk1(poList, askList, dataRow, date, p_creator, db, site);
//创建明细
var _PoDetail = CreatePoDetail1Qh(dataRow, _Qty, db, date, _Po, _PoAsk, p_creator, site);
po_DetailList.Add(_PoDetail);
var _Askdetail = CreateAskDetail1(db, dataRow, _Po, _PoAsk, _PoDetail, p_creator, site);
askDetailList.Add(_Askdetail);
var Tsuniapi = CreateTsuniapiQh(_Po, _PoAsk, _PoDetail, dataRow, _Askdetail, site);
uniList.Add(Tsuniapi);
}
}
}
}
var POdetailCount = po_DetailList.GroupBy(t => new { t.PartCode, t.UpdateInfo,t.EndTime }).ToList();
POdetailCount.ForEach((p) =>
{
var _list = p.ToList();
decimal _PlanQTY = _list.Sum(t => t.PlanQty);
var _ls = _list.First();
var MaxP = db.TB_MAXPO_DETAIL.Where(t => t.PartCode == _ls.PartCode && t.VendId == _ls.UpdateInfo).Sum(t => t.SurplusQty);
if (_PlanQTY > MaxP)
{
_ret.MessageList.Add(string.Format("物料号{0}大订单总剩余数{1}小于本次要货数{2}", _ls.PartCode, MaxP, _PlanQTY));
}
else
{
var _MaxpoList = db.TB_MAXPO_DETAIL.Where(t => t.PartCode == _ls.PartCode && t.SurplusQty > 0 && t.VendId == _ls.UpdateInfo).OrderBy(t => t.ContractMonth).ToList();
foreach (var _maxpo in _MaxpoList)
{
if (_maxpo.SurplusQty > _PlanQTY)
{
_maxpo.SurplusQty = _maxpo.SurplusQty - _PlanQTY;
db.TB_MAXPO_DETAIL.AddOrUpdate(_maxpo);
TB_MAXPO_CONSUME CONSUME = new TB_MAXPO_CONSUME();
CONSUME.PoBillNum = _maxpo.PoBillNum;
CONSUME.BillNum = _ls.PoBillNum;
CONSUME.PartCode = _ls.PartCode;
CONSUME.VendId = _maxpo.VendId;
CONSUME.PoQty = _PlanQTY;
CONSUME.ShipTime = DateTime.Now;
consum.Add(CONSUME);
break;
}
else if (_maxpo.SurplusQty == _PlanQTY)
{
_maxpo.SurplusQty = 0;
db.TB_MAXPO_DETAIL.AddOrUpdate(_maxpo);
TB_MAXPO_CONSUME CONSUME = new TB_MAXPO_CONSUME();
CONSUME.PoBillNum = _maxpo.PoBillNum;
CONSUME.BillNum = _ls.PoBillNum;
CONSUME.PartCode = _ls.PartCode;
CONSUME.VendId = _maxpo.VendId;
CONSUME.PoQty = _PlanQTY;
CONSUME.ShipTime = DateTime.Now;
consum.Add(CONSUME);
break;
}
else if (_maxpo.SurplusQty < _PlanQTY)
{
TB_MAXPO_CONSUME CONSUME = new TB_MAXPO_CONSUME();
CONSUME.BillNum = _ls.PoBillNum;
CONSUME.PoBillNum = _maxpo.PoBillNum;
CONSUME.PartCode = _ls.PartCode;
CONSUME.VendId = _maxpo.VendId;
CONSUME.PoQty = _maxpo.SurplusQty;
CONSUME.ShipTime = DateTime.Now;
consum.Add(CONSUME);
_PlanQTY = _PlanQTY - _maxpo.SurplusQty;
_maxpo.SurplusQty = 0;
db.TB_MAXPO_DETAIL.AddOrUpdate(_maxpo);
}
}
}
});
int cnt = 1;
foreach (var item in poList)
{
var oldGuid = item.PoBillNum;
var newBillId = SCP_BILLCODE_CONTROLLER.MakePOCode2();//冲压件订单号生成逻辑
if (item.Site != "W21")
{
newBillId = SCP_BILLCODE_CONTROLLER.MakePOCode4();//本特勒订单号生成逻辑
}
var newAskNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(cnt);
var add_Po = item.Clone(newBillId, item.Site);
db.TB_PO.Add(add_Po);
var Add_Po_DETAIL = po_DetailList.Where(p => p.PoBillNum == oldGuid).ToList();
int cntPo_detail = 1;
Add_Po_DETAIL.ForEach(p => p.PoBillNum = newBillId);
Add_Po_DETAIL.ForEach(p =>
{
p.PoLine = cntPo_detail;
cntPo_detail++;
});
db.TB_PO_DETAIL.AddRange(Add_Po_DETAIL);
var Add_AskList = askList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_AskList.ForEach(p => p.PoBillNum = newBillId);
Add_AskList.ForEach(p => p.AskBillNum = newAskNum);
Add_AskList.ForEach(p => p.ErpBillNum = newBillId);
db.TB_ASK.AddRange(Add_AskList);
var Add_ASK_DETAIL = askDetailList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_ASK_DETAIL.ForEach(p => p.PoBillNum = newBillId);
int cntAsk_detail = 1;
Add_ASK_DETAIL.ForEach(p => p.AskBillNum = newAskNum);
Add_ASK_DETAIL.ForEach(p =>
{
p.PoLine = cntAsk_detail;
cntAsk_detail++;
});
db.TB_ASK_DETAIL.AddRange(Add_ASK_DETAIL);
var ConsumList = consum.Where(p => p.BillNum == oldGuid).ToList();
ConsumList.ForEach(p => p.BillNum = newBillId);
db.TB_MAXPO_CONSUME.AddRange(ConsumList);
var Add_UniList = uniList.Where(p => p.BillNum == oldGuid).ToList();
int cntTS_detail = 1;
Add_UniList.ForEach(p =>
{
p.ErpLineNum = cntTS_detail;
cntTS_detail++;
});
Add_UniList.ForEach(p => p.BillNum = newBillId);
db.TS_UNI_API.AddRange(Add_UniList);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
//}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static void GroupDataRows(IEnumerable<DataRow> source, List<DataTable> destination, string[] groupByFields, int fieldIndex, DataTable schema)
{
if (fieldIndex >= groupByFields.Length || fieldIndex < 0)
{
DataTable dt = schema.Clone();
foreach (DataRow row in source)
{
DataRow dr = dt.NewRow();
dr.ItemArray = row.ItemArray;
dt.Rows.Add(dr);
}
destination.Add(dt);
return;
}
var results = source.GroupBy(o => o[groupByFields[fieldIndex]]);
foreach (var rows in results)
{
GroupDataRows(rows, destination, groupByFields, fieldIndex + 1, schema);
}
fieldIndex++;
}
/// <summary>
/// 富维订单导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_MOD1(DataTable p_order_list1, List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, PoState p_modtype, string SubSite, string p_chineseName, string p_buyerPhone, bool _wmsweb)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的物料号码{0}有重复", p.));
ErrorList = lineError;
}
var _ls = CheckExcelMode_Po1(db, p, _wmsweb);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
List<TB_PO> poList = new List<TB_PO>();
List<TB_PO_DETAIL> po_DetailList = new List<TB_PO_DETAIL>();
List<TB_ASK> askList = new List<TB_ASK>();
List<TB_ASK_DETAIL> askDetailList = new List<TB_ASK_DETAIL>();
List<TS_UNI_API> uniList = new List<TS_UNI_API>();
//先循环找到一个日期的订单
foreach (DataColumn column in p_order_list1.Columns)
{
DateTime date = DateTime.MaxValue;
DateTime.TryParse(column.ColumnName, out date);
if (date != DateTime.MaxValue && date.Year > 2000)
{
//找到所有日期下订单
foreach (DataRow dataRow in p_order_list1.Rows)//订单分组表
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (_Qty > 0)
{
// 创建主单据及看板
var _Po = CreatePo(db, poList, dataRow, date, p_creator, site);
// 创建主单据及看板
var _PoAsk = CreateAsk(poList, askList, dataRow, date, p_creator, db, site);
//创建明细
var _PoDetail = CreatePoDetail(dataRow, _Qty, db, date, _Po, _PoAsk, p_creator, po_DetailList, site);
po_DetailList.Add(_PoDetail);
var _Askdetail = CreateAskDetail(db, dataRow, _Po, _PoAsk, _PoDetail, p_creator, site);
askDetailList.Add(_Askdetail);
var Tsuniapi = CreateTsuniapi(_Po, _PoAsk, _PoDetail, _Askdetail, dataRow, site);
uniList.Add(Tsuniapi);
}
}
}
}
int cnt = 1;
var podetail = po_DetailList.GroupBy(p => p.PoBillNum).ToList();
foreach (var item in poList)
{
var oldGuid = item.PoBillNum;
var newBillId = SCP_BILLCODE_CONTROLLER.MakePOCode1();//订单号
var newAskNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(cnt);
var add_Po = item.Clone(newBillId, item.Site);
db.TB_PO.Add(add_Po);
var Add_Po_DETAIL = po_DetailList.Where(p => p.PoBillNum == oldGuid).ToList();
int cntPo_detail = 1;
List<string> part = new List<string>();
Add_Po_DETAIL.ForEach(p => p.PoBillNum = newBillId);
Add_Po_DETAIL.ForEach(p =>
{
if (part.Contains(p.PartCode))
{
var pa = Add_Po_DETAIL.FirstOrDefault(itm => itm.PartCode == p.PartCode);
p.PoLine = pa.PoLine;
}
else
{
p.PoLine = cntPo_detail;
cntPo_detail++;
}
part.Add(p.PartCode);
});
db.TB_PO_DETAIL.AddRange(Add_Po_DETAIL);
var Add_AskList = askList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_AskList.ForEach(p => p.PoBillNum = newBillId);
Add_AskList.ForEach(p => p.AskBillNum = newAskNum);
Add_AskList.ForEach(p => p.ErpBillNum = newBillId);
db.TB_ASK.AddRange(Add_AskList);
List<string> part1 = new List<string>();
var Add_ASK_DETAIL = askDetailList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_ASK_DETAIL.ForEach(p => p.PoBillNum = newBillId);
int cntAsk_detail = 1;
Add_ASK_DETAIL.ForEach(p => p.AskBillNum = newAskNum);
Add_ASK_DETAIL.ForEach(p =>
{
if (part1.Contains(p.PartCode))
{
var pa = Add_ASK_DETAIL.FirstOrDefault(itm => itm.PartCode == p.PartCode);
p.PoLine = pa.PoLine;
}
else
{
p.PoLine = cntAsk_detail;
cntAsk_detail++;
}
part1.Add(p.PartCode);
});
db.TB_ASK_DETAIL.AddRange(Add_ASK_DETAIL);
List<string> part2 = new List<string>();
var Add_UniList = uniList.Where(p => p.BillNum == oldGuid).ToList();
int cntTS_detail = 1;
Add_UniList.ForEach(p =>
{
if (part2.Contains(p.PartCode))
{
var pa = Add_UniList.FirstOrDefault(itm => itm.PartCode == p.PartCode);
p.ErpLineNum = pa.ErpLineNum;
}
else
{
p.ErpLineNum = cntTS_detail;
cntTS_detail++;
}
part2.Add(p.PartCode);
});
Add_UniList.ForEach(p => p.BillNum = newBillId);
db.TS_UNI_API.AddRange(Add_UniList);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
//}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 富维多组件订单导入验证
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_Multicomponent(DataTable p_order_list1, List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, bool wmsweb,string site)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的物料号码{0}有重复", p.));
ErrorList = lineError;
}
var _ls = CheckExcelMode_Multicomponent(db, p, wmsweb);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
_lst.ForEach
(p =>
{
if (wmsweb == false)
{
BomList.JsonService bomVersionRe = new BomList.JsonService();
var _ReturnRelust = bomVersionRe.GetBomsByVer(p., p.BOM版本);
var _Bomlist = JsonConvert.DeserializeObject<List<TM_CYJ_BOM>>(_ReturnRelust);
foreach (var bom in _Bomlist)
{
var Bomsub = db.TA_SubPartCode.FirstOrDefault(t => t.PartCode == bom.PartCode && t.SubPartCode == bom.SubPartCode&&t.BOMedtiton==bom.BomFillIn);
if (Bomsub == null)
{
TA_SubPartCode subpart = new TA_SubPartCode();
subpart.PartCode = bom.PartCode;
subpart.SubPartCode = bom.SubPartCode;
subpart.BOMedtiton = p.BOM版本;
subpart.Qty = bom.Qty;
subpart.Site = site;
db.TA_SubPartCode.AddOrUpdate(subpart);
}
else
{
Bomsub.Qty = bom.Qty;
db.TA_SubPartCode.AddOrUpdate(Bomsub);
}
}
}
else
{
BomList1.JsonService bomVersionRe = new BomList1.JsonService();
var _ReturnRelust = bomVersionRe.GetBomsByVer(p., p.BOM版本);
var _Bomlist = JsonConvert.DeserializeObject<List<TM_CYJ_BOM>>(_ReturnRelust);
foreach (var bom in _Bomlist)
{
var Bomsub = db.TA_SubPartCode.FirstOrDefault(t => t.PartCode == bom.PartCode && t.SubPartCode == bom.SubPartCode && t.BOMedtiton == bom.BomFillIn);
if (Bomsub == null)
{
TA_SubPartCode subpart = new TA_SubPartCode();
subpart.PartCode = bom.PartCode;
subpart.SubPartCode = bom.SubPartCode;
subpart.BOMedtiton = p.BOM版本;
subpart.Qty = bom.Qty;
subpart.Site = site;
db.TA_SubPartCode.AddOrUpdate(subpart);
}
else
{
Bomsub.Qty = bom.Qty;
db.TA_SubPartCode.AddOrUpdate(Bomsub);
}
}
}
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> EXCEL_PO_MAX(DataTable p_order_list1, List<SCP_MAXPO_EXPORT> p_order_list, string site, string p_creator, DateTime p_time, PoState p_modtype, string SubSite, string p_chineseName, string time)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
//List<string> PoError= new List<string>();
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的物料号码{0}有重复", p.));
ErrorList = lineError;
}
var _ls = CheckExcelMode_MAXPO(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
var VendidList = _lst.GroupBy(t => t.).ToList();
VendidList.ForEach((p) =>
{
var list = p.ToList();
if (list.Count > 0)
{
var _entity = list.FirstOrDefault();
TB_MAXPO maxp = new TB_MAXPO();
maxp.PoBillNum = SCP_BILLCODE_CONTROLLER.MakemaxPOCode(_entity., time);
maxp.VendId = _entity.;
maxp.CreateUser = p_chineseName;
maxp.CreateTime = DateTime.Now;
maxp.ContractNo = maxp.PoBillNum;
maxp.ContractMonth = time;
maxp.Site = site;
maxp.Remark = _entity.;
db.TB_MAXPO.AddOrUpdate(maxp);
int i = 1;
list.ForEach((itm) =>
{
List<string> yclist = new List<string>();
TB_MAXPO_DETAIL maxpodetail = new TB_MAXPO_DETAIL();
BomList1.JsonService bomVersionRe = new BomList1.JsonService();
var _ReturnRelust = bomVersionRe.GetBom(itm., itm.);
var _Bomlist = JsonConvert.DeserializeObject<List<TM_CYJ_BOM>>(_ReturnRelust);
var _bom = _Bomlist.First();
maxpodetail.Singlecon = _bom.Qty;
var part = db.TA_PART.FirstOrDefault(t => t.PartCode == itm.);
maxpodetail.PoBillNum = maxp.PoBillNum;
maxpodetail.ContractNo = maxp.PoBillNum;
maxpodetail.VendId = itm.;
maxpodetail.PartCode = itm.;
maxpodetail.PartNumber = itm.;
maxpodetail.Texture = part.ProjectId;//材质
maxpodetail.Model = itm.;
maxpodetail.Finprspec = part.PartDesc2;//规格
maxpodetail.TechStandard = itm.;
maxpodetail.MinordQty = decimal.Parse(itm.);
maxpodetail.OrderQtyd = decimal.Parse(itm.);
maxpodetail.OrderQtykg = decimal.Parse(itm.) * 1000;
maxpodetail.OrderNumber = decimal.Parse(itm.);
maxpodetail.SurplusQty = maxpodetail.OrderQtykg;
maxpodetail.CreateTime = DateTime.Now;
maxpodetail.CreateUser = p_chineseName;
maxpodetail.Site = site;
maxpodetail.AsnQty = maxpodetail.OrderQtykg;
maxpodetail.ReceQty = 0;
foreach (DataColumn column in p_order_list1.Columns)//
{
int yuce = int.MaxValue;
int.TryParse(column.ColumnName, out yuce);
if (yuce > 0)
{
foreach (DataRow dataRow in p_order_list1.Rows)
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (dataRow["原材物料号"].ToString() == itm. && dataRow["供应商编号"].ToString()==itm.)
{
string forecast = "";
if (_Qty > 0)
{
forecast = yuce + "/" + _Qty.ToString();
}
else
{
forecast = yuce + "/" + "0";
}
yclist.Add(forecast);
}
}
}
}
maxpodetail.CreateTime = maxp.CreateTime;
maxpodetail.Matermanu = itm.;
maxpodetail.ContractMonth = time;
if (yclist.Count() > 0)
{
int forecascount = 6 - yclist.Count();
if (forecascount > 0)
{
for (int a=1;a<=forecascount; a++)
{
yclist.Add("");
}
}
maxpodetail.forecastone = yclist.First();//预测1
maxpodetail.forecasttwo = yclist[yclist.Count - 5];//预测2
maxpodetail.forecastthree = yclist[yclist.Count - 4];//预测3
maxpodetail.forecastfour = yclist[yclist.Count - 3];//预测4
maxpodetail.forecastfive = yclist[yclist.Count - 2];//预测5
maxpodetail.forecastsix = yclist.Last();//预测6
}
maxpodetail.PoLine = i;
db.TB_MAXPO_DETAIL.AddOrUpdate(maxpodetail);
i++;
TS_UNI_API maxuni = new TS_UNI_API();
maxuni.BillNum = maxpodetail.PoBillNum;
maxuni.InterfaceType = "MaxPobillnum";
maxuni.TableName = "TS_UNI_API";
maxuni.BillType = 701;
maxuni.SubBillType = 0;
maxuni.PartCode = maxpodetail.PartCode;
maxuni.VendId = maxpodetail.VendId;//供应商编号
if (string.IsNullOrEmpty(part.ProjectId))
{
maxuni.Batch = "";
}
else
{
maxuni.Batch = part.ProjectId;//材质
}
maxuni.Qty = decimal.Parse(itm.);
maxuni.State = 1;
maxuni.CreateOper = p_chineseName;//创建者
maxuni.CreateTime = maxp.CreateTime;
maxuni.PutTime = DateTime.Now;
maxuni.Extend1 = itm.;
maxuni.PackQty = decimal.Parse(itm.);
maxuni.Price = decimal.Parse(itm.);
maxuni.VendBatch = time;//合同月
maxuni.Currency = itm.;
maxuni.Buyer = itm.;
maxuni.BuyerPhone = part.PartDesc2;//规格
maxuni.Tax = 0;
maxuni.PoUnit = maxpodetail.forecastone;//预测1
maxuni.LocUnit = maxpodetail.forecasttwo;//预测2
maxuni.Attn = maxpodetail.forecastthree;//预测3
maxuni.Receiver = maxpodetail.forecastfour;//预测4
maxuni.ModType = maxpodetail.forecastfive;//预测5
maxuni.SubSite = maxpodetail.forecastsix;//预测6
maxuni.Site = site;
maxuni.Extend2 = itm.;
maxuni.TaxAmt =_bom.Qty;//单件消耗
maxuni.ValidDate = DateTime.Now;
maxuni.ErpLineNum = maxpodetail.PoLine;
maxuni.Site = site;
maxuni.Domain = site;
maxuni.Extend3 = "A";
db.TS_UNI_API.AddOrUpdate(maxuni);
});
}
});
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// 富维多组件订单导入验证
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_SUBMANY(DataTable p_order_list1, List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string p_creator, string site, string p_chineseName)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
List<TB_PO> poList = new List<TB_PO>();
List<TB_PO_DETAIL> po_DetailList = new List<TB_PO_DETAIL>();
List<TB_ASK> askList = new List<TB_ASK>();
List<TB_ASK_DETAIL> askDetailList = new List<TB_ASK_DETAIL>();
List<TS_UNI_API> uniList = new List<TS_UNI_API>();
List<TB_PO_SUBDETAIL> posub_DetailList = new List<TB_PO_SUBDETAIL>();
List<TA_ASK_SUBPART> asksubpartlist= new List<TA_ASK_SUBPART>();
//先循环找到一个日期的订单
foreach (DataColumn column in p_order_list1.Columns)
{
DateTime date = DateTime.MaxValue;
DateTime.TryParse(column.ColumnName, out date);
if (date != DateTime.MaxValue && date.Year > 2000)
{
//找到所有日期下订单
foreach (DataRow dataRow in p_order_list1.Rows)//订单分组表
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (_Qty > 0)
{
// 创建主单据及看板
var _Po = CreatePo(db, poList, dataRow, date, p_creator, site);
// 创建主单据及看板
var _PoAsk = CreateManyAsk(poList, askList, dataRow, date, p_creator, db, site);
//创建明细
var _PoDetail = CreateManyPoDetail(dataRow, _Qty, db, date, _Po, _PoAsk, p_creator, po_DetailList, site);
po_DetailList.Add(_PoDetail);
var _Askdetail = CreateManyAskDetail(db, dataRow, _Po, _PoAsk, _PoDetail, p_creator, site);
askDetailList.Add(_Askdetail);
List<TS_UNI_API> Tsuniapi = CreateManyTsuniapi(_Po, _PoAsk, _PoDetail, _Askdetail, dataRow, site, db);
foreach(var ts in Tsuniapi)
{
uniList.Add(ts);
}
List<TB_PO_SUBDETAIL> Subdetail = CreateManyPoDetailSubPart(_Po, _PoAsk, _PoDetail, _Askdetail, dataRow, site, db);
foreach (var su in Subdetail)
{
posub_DetailList.Add(su);
}
List<TA_ASK_SUBPART> SubAskdetail = CreateManyAskSubPart(_Po, _PoAsk, _PoDetail, _Askdetail, dataRow, site, db);
foreach (var suask in SubAskdetail)
{
asksubpartlist.Add(suask);
}
}
}
}
}
int cnt = 1;
var podetail = po_DetailList.GroupBy(p => p.PoBillNum).ToList();
foreach (var item in poList)
{
var oldGuid = item.PoBillNum;
var newBillId = SCP_BILLCODE_CONTROLLER.MakePOCode1();//订单号
var newAskNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(cnt);
var add_Po = item.Clone(newBillId, item.Site);
db.TB_PO.Add(add_Po);
var Add_Po_DETAIL = po_DetailList.Where(p => p.PoBillNum == oldGuid).ToList();
int cntPo_detail = 1;
Add_Po_DETAIL.ForEach(p => p.PoBillNum = newBillId);
Add_Po_DETAIL.ForEach(p =>
{
p.PoLine = cntPo_detail;
cntPo_detail++;
});
db.TB_PO_DETAIL.AddRange(Add_Po_DETAIL);
var Add_AskList = askList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_AskList.ForEach(p => p.PoBillNum = newBillId);
Add_AskList.ForEach(p => p.AskBillNum = newAskNum);
Add_AskList.ForEach(p => p.ErpBillNum = newBillId);
db.TB_ASK.AddRange(Add_AskList);
var Add_AskSubList = asksubpartlist.Where(p => p.AskBillNum == oldGuid).ToList();
Add_AskSubList.ForEach(p => p.AskBillNum = newAskNum);
db.TA_ASK_SUBPART.AddRange(Add_AskSubList);
var Add_ASK_DETAIL = askDetailList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_ASK_DETAIL.ForEach(p => p.PoBillNum = newBillId);
int cntAsk_detail = 1;
Add_ASK_DETAIL.ForEach(p => p.AskBillNum = newAskNum);
Add_ASK_DETAIL.ForEach(p =>
{
p.PoLine = cntAsk_detail;
cntAsk_detail++;
});
db.TB_ASK_DETAIL.AddRange(Add_ASK_DETAIL);
var Add_UniList = uniList.Where(p => p.BillNum == oldGuid).ToList();
int cntTS_detail = 1;
Add_UniList.ForEach(p => p.BillNum = newBillId);
//Add_UniList.ForEach(p =>
//{
var unii = Add_UniList.GroupBy(t => t.PartCode).ToList();
unii.ForEach(t =>
{
var uniii = t.ToList();
uniii.ForEach(r => {
r.ErpLineNum = cntTS_detail;
});
cntTS_detail++;
});
//});
db.TS_UNI_API.AddRange(Add_UniList);
var Add_PoSubList = posub_DetailList.Where(p => p.PoBillNum == oldGuid).ToList();
int poSub_detail = 1;
Add_PoSubList.ForEach(p => p.PoBillNum = newBillId);
//Add_PoSubList.ForEach(p =>
//{
var poii = Add_PoSubList.GroupBy(t => t.PartCode).ToList();
poii.ForEach(t =>
{
var poiii = t.ToList();
poiii.ForEach(r => {
r.PoLine = cntTS_detail;
});
poSub_detail++;
});
//});
db.TB_PO_SUBDETAIL.AddRange(Add_PoSubList);
foreach (var sub in Add_UniList)
{
var suu = db.TA_SubPartCode.FirstOrDefault(t => t.PartCode == sub.PartCode && t.SubPartCode == sub.Extend1);
if (suu != null)
{
db.TA_SubPartCode.Remove(suu);
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
//}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
/// <summary>
/// 本特勒订单导入
/// </summary>
/// <param name="p_order_list"></param>
/// <param name="p_creator"></param>
/// <param name="p_time"></param>
/// <param name="p_modtype"></param>
/// <param name="IsAutoPublish"></param>
/// <returns></returns>
public static ResultObject<bool> EXCEL_PO_MOD_BTL(DataTable p_order_list1, List<SCP_PO_EXPORT_IMPORT_MODEL> p_order_list, string site, string p_creator, DateTime p_time, PoState p_modtype, string SubSite, string p_chineseName, string p_buyerPhone)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
var _lst = p_order_list;
_lst.ForEach
(p =>
{
var _count = _lst.Count(itm => itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入的物料号码{0}有重复", p.));
ErrorList = lineError;
}
var _ls = CheckExcelMode_BTL(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
List<TB_PO> poList = new List<TB_PO>();
List<TB_PO_DETAIL> po_DetailList = new List<TB_PO_DETAIL>();
List<TB_ASK> askList = new List<TB_ASK>();
List<TB_ASK_DETAIL> askDetailList = new List<TB_ASK_DETAIL>();
List<TS_UNI_API> uniList = new List<TS_UNI_API>();
//先循环找到一个日期的订单
foreach (DataColumn column in p_order_list1.Columns)
{
DateTime date = DateTime.MaxValue;
DateTime.TryParse(column.ColumnName, out date);
if (date != DateTime.MaxValue && date.Year > 2000)
{
//找到所有日期下订单
foreach (DataRow dataRow in p_order_list1.Rows)//订单分组表
{
decimal _Qty = 0;
decimal.TryParse(dataRow[column.ColumnName].ToString(), out _Qty);
if (_Qty > 0)
{
// 创建主单据及看板
var _Po = CreatePo(db, poList, dataRow, date, p_creator, site);
// 创建主单据及看板
var _PoAsk = CreateAsk(poList, askList, dataRow, date, p_creator, db, site);
//创建明细
var _PoDetail = CreatePoDetail(dataRow, _Qty, db, date, _Po, _PoAsk, p_creator, po_DetailList, site);
po_DetailList.Add(_PoDetail);
var _Askdetail = CreateAskDetail(db, dataRow, _Po, _PoAsk, _PoDetail, p_creator, site);
askDetailList.Add(_Askdetail);
var Tsuniapi = CreateTsuniapi(_Po, _PoAsk, _PoDetail, _Askdetail, dataRow, site);
uniList.Add(Tsuniapi);
}
}
}
}
int cnt = 1;
var podetail = po_DetailList.GroupBy(p => p.PoBillNum).ToList();
foreach (var item in poList)
{
var oldGuid = item.PoBillNum;
var newBillId = SCP_BILLCODE_CONTROLLER.MakePOCode3();//订单号
var newAskNum = SCP_BILLCODE_CONTROLLER.MakeASKCodeByNum(cnt);
var add_Po = item.Clone(newBillId, item.Site);
db.TB_PO.Add(add_Po);
var Add_Po_DETAIL = po_DetailList.Where(p => p.PoBillNum == oldGuid).ToList();
int cntPo_detail = 1;
Add_Po_DETAIL.ForEach(p => p.PoBillNum = newBillId);
Add_Po_DETAIL.ForEach(p =>
{
p.PoLine = cntPo_detail;
cntPo_detail++;
});
db.TB_PO_DETAIL.AddRange(Add_Po_DETAIL);
var Add_AskList = askList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_AskList.ForEach(p => p.PoBillNum = newBillId);
Add_AskList.ForEach(p => p.AskBillNum = newAskNum);
Add_AskList.ForEach(p => p.ErpBillNum = newBillId);
db.TB_ASK.AddRange(Add_AskList);
var Add_ASK_DETAIL = askDetailList.Where(p => p.PoBillNum == oldGuid).ToList();
Add_ASK_DETAIL.ForEach(p => p.PoBillNum = newBillId);
int cntAsk_detail = 1;
Add_ASK_DETAIL.ForEach(p => p.AskBillNum = newAskNum);
Add_ASK_DETAIL.ForEach(p =>
{
p.PoLine = cntAsk_detail;
cntAsk_detail++;
});
db.TB_ASK_DETAIL.AddRange(Add_ASK_DETAIL);
var Add_UniList = uniList.Where(p => p.BillNum == oldGuid).ToList();
int cntTS_detail = 1;
Add_UniList.ForEach(p =>
{
p.ErpLineNum = cntTS_detail;
cntTS_detail++;
});
Add_UniList.ForEach(p => p.BillNum = newBillId);
db.TS_UNI_API.AddRange(Add_UniList);
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
}
//}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
private static TB_PO CreatePo(ScpEntities db,List<TB_PO> p_poList, DataRow p_dataRow,DateTime p_PoBillTime, string str,string site)
{
var _VendId = p_dataRow["供应商编号"].ToString();
var po = p_poList.FirstOrDefault(p=>p.VendId== _VendId
&& p.EndTime== p_PoBillTime);
if (po != null) return po;
TB_PO _po = new TB_PO();
_po.PoBillNum = Guid.NewGuid().ToString(); //
_po.VendId = p_dataRow["供应商编号"].ToString();
_po.Buyer = p_dataRow["采购员"].ToString();
_po.ErpBillNum = _po.PoBillNum;
_po.ModType = (int)BillFwModType.Non_Contract;
_po.BuyerPhone = p_dataRow["采购员电话"].ToString();
_po.Site = site;
_po.State = (int)PoState.Open;
_po.GUID = Guid.NewGuid();
_po.IsDeleted = false;
_po.CreateTime = DateTime.Now;
_po.CreateUser = str;
_po.BeginTime = DateTime.Now;
_po.EndTime = p_PoBillTime;
if (site == "U32")
{
_po.Remark = p_dataRow["备注"].ToString();
}
p_poList.Add(_po);
return _po;
}
private static TB_ASK CreateAsk(List<TB_PO> p_poList, List<TB_ASK> p_askList, DataRow p_dataRow, DateTime p_PoBillTime, string str,ScpEntities db,string site)
{
var _VendId = p_dataRow["供应商编号"].ToString();
var _po = p_poList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
var _Ask = p_askList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
if (_Ask != null) return _Ask;
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = "1";
_ask.GUID = Guid.NewGuid();
_ask.PoBillNum = _po.PoBillNum;
_ask.VendId = _po.VendId;
_ask.IsDeleted = false;
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = str;
_ask.Site = site;
_ask.ReceivedPort = "";//交货口
_ask.State = (int)AskState.New;
_ask.ModType = 2;
_ask.ErpBillNum = _po.PoBillNum;
_ask.BeginTime = DateTime.Parse(_po.BeginTime.ToString());
_ask.Buyer = _po.Buyer;
_ask.EndTime = p_PoBillTime;
_ask.BuyerPhone = _po.BuyerPhone;
_ask.SubSite = site;
if (site == "U32")
{
_ask.Remark = p_dataRow["备注"].ToString();
_po.Remark = p_dataRow["备注"].ToString();
}
p_askList.Add(_ask);
return _ask;
}
private static TB_ASK CreateManyAsk(List<TB_PO> p_poList, List<TB_ASK> p_askList, DataRow p_dataRow, DateTime p_PoBillTime, string str, ScpEntities db, string site)
{
var _VendId = p_dataRow["供应商编号"].ToString();
var _po = p_poList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
var _Ask = p_askList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
if (_Ask != null) return _Ask;
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = "1";
_ask.GUID = Guid.NewGuid();
_ask.PoBillNum = _po.PoBillNum;
_ask.VendId = _po.VendId;
_ask.IsDeleted = false;
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = str;
_ask.Site = site;
_ask.ReceivedPort = "";//交货口
_ask.State = (int)AskState.New;
_ask.ModType = 2;
_ask.ErpBillNum = _po.PoBillNum;
_ask.BeginTime = DateTime.Parse(_po.BeginTime.ToString());
_ask.Buyer = _po.Buyer;
_ask.EndTime = p_PoBillTime;
_ask.BuyerPhone = _po.BuyerPhone;
_ask.SubSite = site;
if (site == "U32")
{
_ask.Remark = p_dataRow["备注"].ToString();
_po.Remark = p_dataRow["备注"].ToString();
}
_ask.Extend3 = "1";
p_askList.Add(_ask);
return _ask;
}
private static TB_ASK_DETAIL CreateAskDetail(ScpEntities db, DataRow p_dataRow, TB_PO p_Po, TB_ASK p_Ask,TB_PO_DETAIL p_PoDetail,string str,string site)
{
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.PoBillNum = p_Po.PoBillNum;
_tDetail.AskBillNum = p_Ask.AskBillNum;
_tDetail.PoLine = p_PoDetail.PoLine;
_tDetail.PoUnit = p_PoDetail.PoUnit;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = str;
_tDetail.PartCode = p_PoDetail.PartCode;
_tDetail.BeginTime = DateTime.Now;
_tDetail.EndTime = p_PoDetail.EndTime;
_tDetail.TempQty = 0;
_tDetail.AskQty = p_PoDetail.PlanQty;
_tDetail.IsDeleted = false;
_tDetail.LocUnit = p_PoDetail.LocUnit;
_tDetail.UnConv = 1;
_tDetail.SubSite = p_dataRow["零件号"].ToString();
var _vender2 = db.TA_Appliance.SingleOrDefault(t => t.PartNumber == _tDetail.SubSite.ToUpper() && t.VendID == p_Po.VendId);
var part = db.TA_PART.SingleOrDefault(t => t.PartCode == _tDetail.PartCode);
_tDetail.DockCode = part.PartGroup;
_tDetail.Extend1 = _vender2.ReceivingPort;//收货口
_tDetail.Extend2 = _vender2.Model;//车型
_tDetail.Extend3 = _vender2.Texture;//材质
_tDetail.State = (int)PoState.Open;
_tDetail.Currency = part.PartDesc2;//规格
_tDetail.GUID = Guid.NewGuid();
_tDetail.Price = p_PoDetail.Price;
_tDetail.Remark = p_Po.VendId;
_tDetail.Remark1= p_Po.VendId;
_tDetail.UpdateInfo= p_dataRow["组件物料号"].ToString();
if (site == "U32")
{
_tDetail.Remark = p_dataRow["备注"].ToString();
}
return _tDetail;
}
private static TB_ASK_DETAIL CreateManyAskDetail(ScpEntities db, DataRow p_dataRow, TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, string str, string site)
{
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.PoBillNum = p_Po.PoBillNum;
_tDetail.AskBillNum = p_Ask.AskBillNum;
_tDetail.PoLine = p_PoDetail.PoLine;
_tDetail.PoUnit = p_PoDetail.PoUnit;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = str;
_tDetail.PartCode = p_PoDetail.PartCode;
_tDetail.BeginTime = DateTime.Now;
_tDetail.EndTime = p_PoDetail.EndTime;
_tDetail.TempQty = 0;
_tDetail.AskQty = p_PoDetail.PlanQty;
_tDetail.IsDeleted = false;
_tDetail.LocUnit = p_PoDetail.LocUnit;
_tDetail.UnConv = 1;
_tDetail.SubSite = p_dataRow["零件号"].ToString();
var _vender2 = db.TA_Appliance.SingleOrDefault(t => t.PartNumber == _tDetail.SubSite.ToUpper() && t.VendID == p_Po.VendId);
var part = db.TA_PART.SingleOrDefault(t => t.PartCode == _tDetail.PartCode);
_tDetail.DockCode = part.PartGroup;
_tDetail.Extend1 = _vender2.ReceivingPort;//收货口
_tDetail.Extend2 = _vender2.Model;//车型
_tDetail.Extend3 = _vender2.Texture;//材质
_tDetail.State = (int)PoState.Open;
_tDetail.Currency = part.PartDesc2;//规格
_tDetail.GUID = Guid.NewGuid();
_tDetail.Price = p_PoDetail.Price;
_tDetail.Remark = p_Po.VendId;
//_tDetail.UpdateInfo = p_dataRow["组件物料号"].ToString();
return _tDetail;
}
private static TB_PO_DETAIL CreatePoDetail(DataRow p_dataRow,decimal p_Qty, ScpEntities db, DateTime p_PoBillTime,TB_PO p_Po,TB_ASK p_Ask,string str, List<TB_PO_DETAIL> po_DetailList,string site)
{
int _rowNumber = 1;
var _Part = p_dataRow["物料号码"].ToString();
TB_PO_DETAIL _detail = new TB_PO_DETAIL();
_detail.PoBillNum = p_Po.PoBillNum;
_detail.PartCode = p_dataRow["物料号码"].ToString();
_detail.PoUnit = p_dataRow["单位"].ToString();
_detail.Extend1 = p_dataRow["零件号"].ToString();
_detail.Currency = "CNY";
_detail.CreateTime =DateTime.Parse( p_dataRow["订单创建时间"].ToString());
_detail.BeginTime = DateTime.Now;
_detail.IsDeleted = false;
_detail.LocUnit = p_dataRow["组件计量单位"].ToString();
_detail.UnConv = 1;
_detail.PackQty = decimal.Parse(p_dataRow["组件数量"].ToString());
_detail.State = (int)PoState.Open;
_detail.GUID = Guid.NewGuid();
_detail.Site = site;
_detail.EndTime = p_PoBillTime;
_detail.PlanQty = p_Qty;
_detail.CreateUser = str;
var _price = db.TB_NetPrice.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.VendId == p_Po.VendId && t.Extend3 != "D");
if (_price == 0)
{
var _price1 = db.TA_PART.SingleOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price1.Remark);
}
else
{
DateTime dateTime = DateTime.Now;
int count = db.TB_NetPrice.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.StartTime <dateTime && t.EndTime > dateTime && t.VendId == p_Po.VendId && t.Extend3 != "D");
if (count > 0)
{
var _price3 = db.TB_NetPrice.Where(t => t.PartCode == _detail.PartCode.ToUpper() && t.StartTime < dateTime && t.EndTime > dateTime && t.VendId == p_Po.VendId && t.Extend3 != "D").OrderByDescending(u=>u.UID).FirstOrDefault();
_detail.Price = _price3.Amt;
}
else
{
var _price4 = db.TA_PART.SingleOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price4.Remark);
}
}
_detail.Extend3 = p_dataRow["BOM版本"].ToString();
_detail.Extend2= p_dataRow["存储地点"].ToString();
_detail.SubSite = p_dataRow["组件物料号"].ToString();
_detail.CreateUser = p_dataRow["采购组"].ToString();//采购组
_rowNumber++;
return _detail;
}
private static TB_PO_DETAIL CreateManyPoDetail(DataRow p_dataRow, decimal p_Qty, ScpEntities db, DateTime p_PoBillTime, TB_PO p_Po, TB_ASK p_Ask, string str, List<TB_PO_DETAIL> po_DetailList, string site)
{
int _rowNumber = 1;
var _Part = p_dataRow["物料号码"].ToString();
TB_PO_DETAIL _detail = new TB_PO_DETAIL();
_detail.PoBillNum = p_Po.PoBillNum;
_detail.PartCode = p_dataRow["物料号码"].ToString();
_detail.PoUnit = p_dataRow["单位"].ToString();
_detail.Extend1 = p_dataRow["零件号"].ToString();
_detail.Currency = "CNY";
_detail.CreateTime = DateTime.Parse(p_dataRow["订单创建时间"].ToString());
_detail.BeginTime = DateTime.Now;
_detail.IsDeleted = false;
_detail.UnConv = 1;
_detail.State = (int)PoState.Open;
_detail.GUID = Guid.NewGuid();
_detail.Site = site;
_detail.EndTime = p_PoBillTime;
_detail.PlanQty = p_Qty;
_detail.CreateUser = str;
var _price = db.TB_NetPrice.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.VendId == p_Po.VendId && t.Extend3!="D");
if (_price == 0)
{
var _price1 = db.TA_PART.SingleOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price1.Remark);
}
else
{
DateTime dateTime = DateTime.Now;
int count = db.TB_NetPrice.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.StartTime < dateTime && t.EndTime > dateTime && t.Extend3 != "D" && t.VendId == p_Po.VendId);
if (count > 0)
{
var _price3 = db.TB_NetPrice.Where(t => t.PartCode == _detail.PartCode.ToUpper() && t.StartTime < dateTime && t.EndTime > dateTime && t.Extend3 != "D" && t.VendId == p_Po.VendId).OrderByDescending(u=>u.UID).FirstOrDefault();
_detail.Price = _price3.Amt;
}
else
{
var _price4 = db.TA_PART.SingleOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price4.Remark);
}
}
_detail.CreateUser = p_dataRow["采购组"].ToString();//采购组
_rowNumber++;
return _detail;
}
private static TS_UNI_API CreateTsuniapi( TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail,TB_ASK_DETAIL p_AskDetail,DataRow p_dataRow,string site)
{
TS_UNI_API uni = new TS_UNI_API();
uni.InterfaceType = "Pobillnum"; //订单标识
uni.TableName = "TS_UNI_API";
uni.BillType = (int)BillType.ReHandleVin;
uni.SubBillType = 0;
uni.BillNum = p_Po.PoBillNum;//订单号
uni.PartCode = p_PoDetail.PartCode; //零件号
uni.Buyer = p_Po.Buyer;//采购员
uni.BuyerPhone = p_Po.BuyerPhone;//采购员电话
uni.ModType = p_PoDetail.CreateUser;//采购组
uni.Qty = p_PoDetail.PlanQty;//零件数量
uni.CreateOper = p_Po.CreateUser;
uni.CreateTime = p_Po.CreateTime;//订单创建时间
uni.VendId = p_Po.VendId;//供应商编号
uni.PoUnit = p_PoDetail.PoUnit;//零件单位
uni.LocUnit = p_PoDetail.LocUnit;//组件单位
uni.ValidDate = DateTime.Now;//当前系统时间
uni.ErpLineNum = p_PoDetail.PoLine;//订单行号
uni.Price = p_PoDetail.Price;//零件价格
uni.Site = p_Po.Site;//地点
uni.Extend3= p_dataRow["存储地点"].ToString();
uni.Domain = site;
uni.Extend2 = "N";//退货凭证
uni.Extend1 = p_PoDetail.SubSite;//组件物料号
if (site == "U32")
{
uni.PutTime = DateTime.Parse(p_PoDetail.EndTime.ToString()); //要求到货日期
uni.Attn = p_dataRow["备注"].ToString();
}
else
{
uni.PutTime = ScpCache.GetServerTime();
}
uni.Batch = p_PoDetail.PoUnit;//采购计量单位
uni.ErpBillNum = p_PoDetail.PackQty.ToString();//组件数量
uni.VendBatch = p_PoDetail.CreateUser;
uni.State = 1;
uni.Invoice = "3";
uni.Currency = p_Po.SubSite;
if (site == "W21")
{
uni.Barcode = "CY03";
}
else
{
uni.Barcode = "FB06";
}
uni.Currency = p_PoDetail.Extend3;
uni.Receiver = "I";//订单类型
uni.SubSite = p_AskDetail.Extend1;
return uni;
}
private static List<TS_UNI_API> CreateManyTsuniapi(TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, TB_ASK_DETAIL p_AskDetail, DataRow p_dataRow, string site, ScpEntities db)
{
List <TS_UNI_API> unilist = new List<TS_UNI_API>();
var _bom = p_dataRow["BOM版本"].ToString();
var subpart = db.TA_SubPartCode.Where(p => p.PartCode == p_PoDetail.PartCode&&p.BOMedtiton == _bom).ToList();
foreach (var sub in subpart)
{
TS_UNI_API uni = new TS_UNI_API();
uni.InterfaceType = "Pobillnum"; //订单标识
uni.TableName = "TS_UNI_API";
uni.BillType = (int)BillType.ReHandleVin;
uni.SubBillType = 0;
uni.BillNum = p_Po.PoBillNum;//订单号
uni.PartCode = p_PoDetail.PartCode; //零件号
uni.Buyer = p_Po.Buyer;//采购员
uni.BuyerPhone = p_Po.BuyerPhone;//采购员电话
uni.ModType = p_PoDetail.CreateUser;//采购组
uni.Qty = p_PoDetail.PlanQty;//零件数量
uni.CreateOper = p_Po.CreateUser;
uni.CreateTime = p_Po.CreateTime;//订单创建时间
uni.PutTime = ScpCache.GetServerTime();
uni.VendId = p_Po.VendId;//供应商编号
uni.PoUnit = p_PoDetail.PoUnit;//零件单位
var unit = db.TA_PART.FirstOrDefault(t=>t.PartCode==sub.SubPartCode);
uni.LocUnit = unit.Unit;//组件单位
uni.ValidDate = DateTime.Now;//当前系统时间
uni.ErpLineNum = p_PoDetail.PoLine;//订单行号
uni.Price = p_PoDetail.Price;//零件价格
uni.Site = p_Po.Site;//地点
uni.Extend3 = p_dataRow["存储地点"].ToString();
uni.Domain = site;
uni.Extend2 = "N";//退货凭证
uni.Extend1 = sub.SubPartCode;//组件物料号
uni.Batch = p_PoDetail.PoUnit;//采购计量单位
uni.ErpBillNum = (sub.Qty* p_PoDetail.PlanQty).ToString();//组件数量
uni.VendBatch = p_PoDetail.CreateUser;
uni.State = 1;
uni.Invoice = "3";
uni.Currency = p_Po.SubSite;
if (site == "W21")
{
uni.Barcode = "CY03";
}
else
{
uni.Barcode = "FB06";
}
uni.Currency = p_dataRow["BOM版本"].ToString();
uni.Receiver = "I";//订单类型
uni.SubSite = p_AskDetail.Extend1;
unilist.Add(uni);
}
return unilist;
}
private static List<TB_PO_SUBDETAIL> CreateManyPoDetailSubPart(TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, TB_ASK_DETAIL p_AskDetail, DataRow p_dataRow, string site, ScpEntities db)
{
List<TB_PO_SUBDETAIL> posublist = new List<TB_PO_SUBDETAIL>();
var _bom = p_dataRow["BOM版本"].ToString();
var subpart = db.TA_SubPartCode.Where(p => p.PartCode == p_PoDetail.PartCode && p.BOMedtiton == _bom).ToList();
foreach (var sub in subpart)
{
TB_PO_SUBDETAIL posub = new TB_PO_SUBDETAIL();
posub.PoBillNum = p_Po.PoBillNum;
posub.PartCode = p_PoDetail.PartCode;
posub.SubPartCode = sub.SubPartCode;
posub.BOMedtiton = sub.BOMedtiton;
posub.Qty = p_PoDetail.PlanQty;
posub.SubQty = p_PoDetail.PlanQty * sub.Qty;
posub.PoLine = p_PoDetail.PoLine;
posublist.Add(posub);
}
return posublist;
}
private static List<TA_ASK_SUBPART> CreateManyAskSubPart(TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, TB_ASK_DETAIL p_AskDetail, DataRow p_dataRow, string site, ScpEntities db)
{
List<TA_ASK_SUBPART> asksublist = new List<TA_ASK_SUBPART>();
var _bom = p_dataRow["BOM版本"].ToString();
var subpart = db.TA_SubPartCode.Where(p => p.PartCode == p_PoDetail.PartCode && p.BOMedtiton == _bom).ToList();
foreach (var sub in subpart)
{
TA_ASK_SUBPART asksub = new TA_ASK_SUBPART();
asksub.PartCode = p_PoDetail.PartCode;
asksub.SubPartCode = sub.SubPartCode;
asksub.BOMedtiton = sub.BOMedtiton;
asksub.Qty = p_PoDetail.PlanQty*sub.Qty;
asksub.AskBillNum = p_AskDetail.PoBillNum;
asksublist.Add(asksub);
}
return asksublist;
}
private static TB_PO CreatePo1(List<TB_PO> p_poList, DataRow p_dataRow, DateTime p_PoBillTime, string str,string site )
{
var _VendId = p_dataRow["供应商编号"].ToString();
var po = p_poList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
if (po != null) return po;
TB_PO _po = new TB_PO();
_po.PoBillNum = Guid.NewGuid().ToString(); //
_po.VendId = p_dataRow["供应商编号"].ToString();
_po.Buyer = p_dataRow["采购员"].ToString();
_po.ErpBillNum = _po.PoBillNum;
_po.ModType = (int)BillFwModType.Contract;
_po.BuyerPhone = p_dataRow["采购员电话"].ToString();
_po.Site = site;
_po.State = (int)PoState.Open;
_po.GUID = Guid.NewGuid();
_po.IsDeleted = false;
_po.CreateTime = DateTime.Now;
_po.CreateUser = str;
_po.BeginTime = DateTime.Now;
_po.EndTime = p_PoBillTime;
if (site == "U32")
{
_po.Remark = p_dataRow["备注"].ToString();
}
p_poList.Add(_po);
return _po;
}
private static TB_PO CreatePoQh(List<TB_PO> p_poList, DataRow p_dataRow, DateTime p_PoBillTime, string str, string site)
{
var _VendId = p_dataRow["供应商编号"].ToString();
var po = p_poList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
if (po != null) return po;
TB_PO _po = new TB_PO();
_po.PoBillNum = Guid.NewGuid().ToString(); //
_po.VendId = p_dataRow["供应商编号"].ToString();
_po.Buyer = p_dataRow["采购员"].ToString();
_po.ErpBillNum = _po.PoBillNum;
_po.ModType = (int)BillFwModType.Qh_Contract;
_po.BuyerPhone = p_dataRow["采购员电话"].ToString();
_po.Site = site;
_po.State = (int)PoState.Open;
_po.GUID = Guid.NewGuid();
_po.IsDeleted = false;
_po.CreateTime = DateTime.Now;
_po.CreateUser = str;
_po.BeginTime = DateTime.Now;
_po.EndTime = p_PoBillTime;
if (site == "U32")
{
_po.Remark = p_dataRow["备注"].ToString();
}
_po.UpdateInfo="Y";
p_poList.Add(_po);
return _po;
}
private static TB_ASK CreateAsk1(List<TB_PO> p_poList, List<TB_ASK> p_askList, DataRow p_dataRow, DateTime p_PoBillTime, string str, ScpEntities db,string site )
{
var _VendId = p_dataRow["供应商编号"].ToString();
var _po = p_poList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
var _Ask = p_askList.FirstOrDefault(p => p.VendId == _VendId
&& p.EndTime == p_PoBillTime);
if (_Ask != null) return _Ask;
int _num = 1;
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = "1";
_ask.GUID = Guid.NewGuid();
_ask.PoBillNum = _po.PoBillNum;
_ask.VendId = _po.VendId;
_ask.IsDeleted = false;
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = str;
_ask.Site = site;
_ask.ReceivedPort = "";//交货口
_ask.State = (int)AskState.New;
//_ask.State = (int)AskState.Release;
_ask.ModType = 2;
_ask.ErpBillNum = _po.PoBillNum;
_ask.BeginTime = DateTime.Parse(_po.BeginTime.ToString());
_ask.Buyer = _po.Buyer;
_ask.BuyerPhone = _po.BuyerPhone;
_ask.EndTime = p_PoBillTime;
_ask.SubSite = site;
if (site == "U32")
{
_ask.Remark = p_dataRow["备注"].ToString();
}
p_askList.Add(_ask);
return _ask;
}
private static TB_ASK_DETAIL CreateAskDetail1(ScpEntities db, DataRow p_dataRow, TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, string str,string site)
{
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.PoBillNum = p_Po.PoBillNum;
_tDetail.AskBillNum = p_Ask.AskBillNum;
_tDetail.PoLine = p_PoDetail.PoLine;
_tDetail.PoUnit = p_PoDetail.PoUnit;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = str;
_tDetail.PartCode = p_PoDetail.PartCode;
_tDetail.BeginTime = DateTime.Now;
_tDetail.EndTime = p_PoDetail.EndTime;
_tDetail.TempQty = 0;
_tDetail.AskQty = p_PoDetail.PlanQty;
_tDetail.IsDeleted = false;
_tDetail.LocUnit = p_PoDetail.LocUnit;
_tDetail.UnConv = 1;
_tDetail.SubSite = p_dataRow["零件号"].ToString();
if (!string.IsNullOrEmpty(_tDetail.SubSite.ToString()))
{
var _vender2 = db.TA_Appliance.FirstOrDefault(t => t.PartNumber == _tDetail.SubSite.ToUpper() && t.VendID == p_Po.VendId);
_tDetail.Extend1 = _vender2.ReceivingPort;//收货口
_tDetail.Extend2 = _vender2.Model;//车型
_tDetail.Extend3 = _vender2.Texture;//材质
}
var part = db.TA_PART.SingleOrDefault(t => t.PartCode == _tDetail.PartCode);
_tDetail.DockCode = part.PartGroup;
_tDetail.State = (int)PoState.Open;
_tDetail.Currency = part.PartDesc2;//规格
_tDetail.GUID = Guid.NewGuid();
_tDetail.Price = p_PoDetail.Price;
_tDetail.Remark = p_Po.VendId;
_tDetail.Remark1 = p_Po.VendId;
if (site == "U32")
{
_tDetail.Remark = p_dataRow["备注"].ToString();
}
return _tDetail;
}
private static TB_PO_DETAIL CreatePoDetail1(DataRow p_dataRow, decimal p_Qty, ScpEntities db, DateTime p_PoBillTime, TB_PO p_Po, TB_ASK p_Ask, string str,string site)
{
int _rowNumber = 1;
TB_PO_DETAIL _detail = new TB_PO_DETAIL();
_detail.PartCode= p_dataRow["物料号码"].ToString();
_detail.PoBillNum = p_Po.PoBillNum;
_detail.PoUnit = p_dataRow["单位"].ToString();
_detail.Extend1 = p_dataRow["零件号"].ToString();
_detail.Currency = "CNY";
_detail.PoLine = _rowNumber;
_detail.CreateTime = DateTime.Parse(p_dataRow["订单创建时间"].ToString());
_detail.BeginTime = DateTime.Now;
_detail.IsDeleted = false;
_detail.UnConv = 1;
_detail.State = (int)PoState.Open;
_detail.GUID = Guid.NewGuid();
_detail.Site = site;
_detail.EndTime = p_PoBillTime;
_detail.PlanQty = p_Qty;
_detail.CreateUser = str;
var _price = db.TB_PRICE.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.VendId == p_Po.VendId && t.Extend3 != "D");
if (_price == 0)
{
var _price1 = db.TA_PART.SingleOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price1.Remark);
}
else
{
int count1 = db.TB_PRICE.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.EndTime > DateTime.Now && t.StartTime < DateTime.Now && t.VendId == p_Po.VendId && t.Extend3 != "D");
if (count1 != 0)
{
var _price3 = db.TB_PRICE.Where(t => t.PartCode == _detail.PartCode.ToUpper() && t.EndTime > DateTime.Now && t.StartTime < DateTime.Now && t.VendId == p_Po.VendId && t.Extend3 != "D").OrderByDescending(o => o.UID).FirstOrDefault(); //获取最新采购的价格
_detail.Price = _price3.Amt;
}
else
{
var _price4 = db.TA_PART.FirstOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price4.Remark);
}
}
_detail.Extend2 = p_dataRow["存储地点"].ToString();
_detail.CreateUser = p_dataRow["采购组"].ToString();//采购组
_rowNumber++;
return _detail;
}
private static TB_PO_DETAIL CreatePoDetail1Qh(DataRow p_dataRow, decimal p_Qty, ScpEntities db, DateTime p_PoBillTime, TB_PO p_Po, TB_ASK p_Ask, string str, string site)
{
int _rowNumber = 1;
TB_PO_DETAIL _detail = new TB_PO_DETAIL();
_detail.PartCode = p_dataRow["物料号码"].ToString();
_detail.PoBillNum = p_Po.PoBillNum;
_detail.PoUnit = p_dataRow["单位"].ToString();
_detail.Extend1 = p_dataRow["零件号"].ToString();
_detail.Currency = "CNY";
_detail.PoLine = _rowNumber;
_detail.CreateTime = DateTime.Parse(p_dataRow["订单创建时间"].ToString());
_detail.BeginTime = DateTime.Now;
_detail.IsDeleted = false;
_detail.UnConv = 1;
_detail.State = (int)PoState.Open;
_detail.GUID = Guid.NewGuid();
_detail.Site = site;
_detail.EndTime = p_PoBillTime;
_detail.PlanQty = p_Qty;
_detail.CreateUser = str;
var _price = db.TB_PRICE.Count(t => t.PartCode == _detail.PartCode.ToUpper() && t.VendId == p_Po.VendId && t.Extend3!="D");
if (_price == 0)
{
var _price1 = db.TA_PART.SingleOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price1.Remark);
}
else
{
var _price2 = db.TB_PRICE.Where(t => t.PartCode == _detail.PartCode.ToUpper() && t.VendId == p_Po.VendId && t.Extend3 != "D").Select(r => r.EndTime).Max();
var _price8 = db.TB_PRICE.Where(t => t.PartCode == _detail.PartCode.ToUpper() && t.VendId == p_Po.VendId && t.Extend3 != "D").Select(r => r.StartTime).Max();
DateTime dateTime = DateTime.Now;
if (_price2 > dateTime || _price2 == dateTime)
{
var _price3 = db.TB_PRICE.FirstOrDefault(t => t.PartCode == _detail.PartCode.ToUpper() && t.EndTime == _price2 && t.VendId == p_Po.VendId && t.Extend3 != "D");
_detail.Price = _price3.Amt;
}
else
{
var _price4 = db.TA_PART.FirstOrDefault(t => t.PartCode == _detail.PartCode.ToUpper());
_detail.Price = decimal.Parse(_price4.Remark);
}
}
_detail.Extend2 = p_dataRow["存储地点"].ToString();
_detail.CreateUser = p_dataRow["采购组"].ToString();//采购组
_detail.UpdateInfo = p_dataRow["供应商编号"].ToString();
_rowNumber++;
return _detail;
}
private static TS_UNI_API CreateTsuniapi1(TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, DataRow p_dataRow,TB_ASK_DETAIL _Askdetail,string site)
{
TS_UNI_API uni = new TS_UNI_API();
uni.InterfaceType = "Pobillnum"; //订单标识
uni.TableName = "TS_UNI_API";
uni.BillType = (int)BillType.ReHandleVin;
uni.SubBillType = 0;
uni.BillNum = p_Po.PoBillNum;//订单号
uni.PartCode = p_PoDetail.PartCode; //零件号
uni.Buyer = p_Po.Buyer;//采购员
uni.BuyerPhone = p_Po.BuyerPhone;//采购员电话
uni.ModType = p_PoDetail.CreateUser;//采购组
uni.Qty = p_PoDetail.PlanQty;//零件数量
uni.CreateOper = p_Po.CreateUser;
uni.CreateTime = p_Po.CreateTime;//订单创建时间
uni.PutTime = ScpCache.GetServerTime();
uni.VendId = p_Po.VendId;//供应商编号
uni.PoUnit = p_PoDetail.PoUnit;//零件单位
uni.LocUnit = p_PoDetail.LocUnit;//组件单位
uni.ValidDate = DateTime.Now;//当前系统时间
uni.ErpLineNum = 1;//订单行号
uni.Price = p_PoDetail.Price;//零件价格
uni.Site = p_Po.Site;//地点
uni.Extend3 = p_dataRow["存储地点"].ToString();
uni.Domain = site;
uni.Extend2 = "N";//退货凭证
uni.PutTime = DateTime.Parse(p_PoDetail.EndTime.ToString()); //要求到货日期
uni.Batch = p_PoDetail.PoUnit;//采购计量单位
uni.VendBatch = p_PoDetail.CreateUser;
uni.State = 1;
uni.Invoice = "0";
if (p_Po.Site == "W21")
{
uni.Barcode = "CY01";
}
else{
uni.Barcode = "FB03";
}
uni.Currency = p_PoDetail.Extend3;
uni.Receiver = "I";
uni.SubSite = _Askdetail.Extend1;
if (site == "U32")
{
uni.Attn = p_dataRow["备注"].ToString();
}
return uni;
}
private static TS_UNI_API CreateTsuniapiQh(TB_PO p_Po, TB_ASK p_Ask, TB_PO_DETAIL p_PoDetail, DataRow p_dataRow, TB_ASK_DETAIL _Askdetail, string site)
{
TS_UNI_API uni = new TS_UNI_API();
uni.InterfaceType = "Pobillnum"; //订单标识
uni.TableName = "TS_UNI_API";
uni.BillType = (int)BillType.ReHandleVin;
uni.SubBillType = 0;
uni.BillNum = p_Po.PoBillNum;//订单号
uni.PartCode = p_PoDetail.PartCode; //零件号
uni.Buyer = p_Po.Buyer;//采购员
uni.BuyerPhone = p_Po.BuyerPhone;//采购员电话
uni.ModType = p_PoDetail.CreateUser;//采购组
uni.Qty = p_PoDetail.PlanQty;//零件数量
uni.CreateOper = p_Po.CreateUser;
uni.CreateTime = p_Po.CreateTime;//订单创建时间
uni.PutTime = ScpCache.GetServerTime();
uni.VendId = p_Po.VendId;//供应商编号
uni.PoUnit = p_PoDetail.PoUnit;//零件单位
uni.LocUnit = p_PoDetail.LocUnit;//组件单位
uni.ValidDate = DateTime.Now;//当前系统时间
uni.ErpLineNum = 1;//订单行号
uni.Price = p_PoDetail.Price;//零件价格
uni.Site = p_Po.Site;//地点
uni.Extend3 = p_dataRow["存储地点"].ToString();
uni.Domain = site;
uni.Extend2 = "N";//退货凭证
uni.PutTime = DateTime.Parse(p_PoDetail.EndTime.ToString()); //要求到货日期
uni.Batch = p_PoDetail.PoUnit;//采购计量单位
uni.VendBatch = p_PoDetail.CreateUser;
uni.State = 1;
uni.Invoice = "0";
if (p_Po.Site == "W21")
{
uni.Barcode = "CY01";
}
else
{
uni.Barcode = "FB03";
}
uni.Currency = p_PoDetail.Extend3;
uni.Receiver = "I";
uni.SubSite = _Askdetail.Extend1;
uni.SubSite = "Y";
return uni;
}
public static List<string> EXCEL_ASK_Check(List<SCP_PO_EXCEL> p_order_list)
{
List<string> ErrorList = new List<string>();
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
p_order_list.ForEach
(p =>
{
//var _ls = CheckExcel(db, p);
var _checkls = CheckExcelPackQty(db, p);
if (_checkls.Count > 0)
{
ErrorList.Add(string.Join("<br>", _checkls.ToArray()));
}
});
}
return ErrorList;
}
public static ResultObject<bool> EXCEL_PO_TO_ASK(List<SCP_PO_EXCEL> p_order_list, string p_creator, string p_buyer, DateTime p_time, BillModType p_modtype, string p_site, bool IsAutoPublish = false)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
p_order_list.ForEach
(p =>
{
var _ls = CheckExcel(db, p);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
}
number++;
});
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
p_order_list = p_order_list.Where(p => int.Parse(p.) != 0).ToList();
//var VenderList = p_order_list.Select(p => p.供应商编号).Distinct();
//var PartCodeList = p_order_list.Select(p => p.零件号).Distinct();
var OrderList = p_order_list.GroupBy(p => new { p., p. }).ToList();
OrderList.ForEach((p) =>
{
var list_distinct = p.GroupBy(t => new { t., t. }).ToList();
var list = p.ToList();
if (list_distinct.Count < list.Count)
{
_ret.MessageList.Add("相同组号,存在同一编号、行号的数据");
return;
}
if (list.Count > 0)
{
var _entity = list.FirstOrDefault();
TB_ASK _ask = new TB_ASK();
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode();
_ask.State = (int)AskState.New;
_ask.PoBillNum = _entity.QAD订单号.ToUpper();
_ask.ModType = (int)BillModType.Contract;
_ask.Site = p_site;
if (IsAutoPublish)
{
_ask.State = (int)AskState.Release;
}
else
{
_ask.State = (int)AskState.New;
}
_ask.BeginTime = DateTime.Now;
_ask.Buyer = _entity.;
_ask.BuyerPhone = _entity.;
_ask.ErpBillNum = _entity.QAD订单号.ToUpper();
_ask.EndTime = DateTime.Parse(_entity.);
_ask.CreateTime = DateTime.Now;
_ask.CreateUser = p_creator;
_ask.VendId = _entity..ToUpper();
_ask.GUID = Guid.NewGuid();
_ask.IsDeleted = false;
db.TB_ASK.Add(_ask);
#region 供应商新任务代办接口
TB_PENING_ITEMS _item = new TB_PENING_ITEMS();
_item.ROLE_NAME = "供应商";
_item.ITEM_NO = _ask.AskBillNum;
_item.ITEM_CONTENT = "要货看盘有信息";
_item.ITEM_TYPE = (int)PENDING_MESSAGE_TYPE.NEW_ASK;
_item.VEND_ID = _ask.VendId;
_item.ITEM_STATE = (int)PENDING_STATE.WAITING;
_item.SENDER = _entity.;
_item.SENDING_TIME = DateTime.Now;
db.TB_PENING_ITEMS.Add(_item);
#endregion
// int _number = 1;
list.ForEach((itm) =>
{
TB_ASK_DETAIL _t_ASK_Detail = new TB_ASK_DETAIL();
//_t_ASK_Detail.PoLine = _number;
_t_ASK_Detail.PoLine = Int32.Parse(itm.);
_t_ASK_Detail.Currency = itm.;
_t_ASK_Detail.AskBillNum = _ask.AskBillNum;
_t_ASK_Detail.PoBillNum = _ask.PoBillNum;
_t_ASK_Detail.PoUnit = itm.;
_t_ASK_Detail.CreateTime = DateTime.Now;
_t_ASK_Detail.CreateUser = _ask.CreateUser;
_t_ASK_Detail.PartCode = (itm..ToUpper()).TrimEnd();
_t_ASK_Detail.BeginTime = _ask.BeginTime;
_t_ASK_Detail.EndTime = DateTime.Parse(itm.);
_t_ASK_Detail.TempQty = decimal.Parse(itm.);
_t_ASK_Detail.AskQty = decimal.Parse(itm.);
_t_ASK_Detail.IsDeleted = false;
_t_ASK_Detail.LocUnit = itm.;
_t_ASK_Detail.UnConv = 1;
_t_ASK_Detail.State = _ask.State;
_t_ASK_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.);
_t_ASK_Detail.GUID = Guid.NewGuid();
_t_ASK_Detail.Remark = itm.;
db.TB_ASK_DETAIL.Add(_t_ASK_Detail);
// _number++;
});
}
else
{
_ret.MessageList.Add("ERP订单编号已存在,请重新导入!");
return;
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
);
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
if (e.InnerException != null)
{
_ret.MessageList.Add(e.InnerException.Message);
}
else
{
_ret.MessageList.Add(e.Message);
}
}
return _ret;
}
public static ResultObject<bool> Save_PO_TO_ASK(V_TB_PO p_order, List<V_TB_PO_DETAIL> p_order_list
, string p_buyer, string p_buyerPhone, string p_creator)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
TB_ASK _t = new TB_ASK();
_t.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode();
_t.PoBillNum = p_order.PoBillNum;
_t.VendId = p_order.VendId;
_t.IsDeleted = false;//操作员
_t.CreateTime = DateTime.Now;
_t.CreateUser = p_creator;
_t.Site = p_order.Site;
_t.ReceivedPort = p_order.ReceivedPort;
_t.Remark = p_order.Remark;
_t.State = (int)AskState.New;
_t.SubSite = p_order.SubSite;
_t.Extend1 = p_order.Extend1;
_t.Extend2 = p_order.Extend2;
_t.Extend3 = p_order.Extend3;
_t.GUID = Guid.NewGuid();
_t.ModType = (int)p_order.ModType;
_t.ErpBillNum = p_order.ErpBillNum;
_t.BeginTime = (DateTime)p_order.BeginTime;
var _date = p_order.BeginTime;
if (p_order_list.Count > 0)
{
_date = p_order_list[0].EndTime;
}
_t.EndTime = p_order.EndTime;
_t.Buyer = p_buyer;
_t.BuyerPhone = p_buyerPhone;
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _t);
List<TB_ASK_DETAIL> _list = new List<TB_ASK_DETAIL>();
foreach (var itm in p_order_list)
{
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.Remark = _t.Remark;
_tDetail.PoBillNum = _t.PoBillNum;
_tDetail.AskBillNum = _t.AskBillNum;
_tDetail.PoLine = itm.PoLine;
_tDetail.PoUnit = itm.PoUnit;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = p_creator;
_tDetail.PartCode = itm.PartCode;
_tDetail.ReceivedPort = itm.ReceivedPort;
_tDetail.BeginTime = itm.BeginTime;
_tDetail.EndTime = _t.EndTime;
_tDetail.TempQty = itm.TempQty == null ? 0 : (decimal)itm.TempQty;
_tDetail.AskQty = (decimal)itm.PublishQty;
_tDetail.IsDeleted = false;
_tDetail.LocUnit = itm.LocUnit;
_tDetail.UnConv = itm.UnConv;
_tDetail.State = (int)p_order.State;
_tDetail.Price = itm.Price;
_tDetail.GUID = Guid.NewGuid();
_tDetail.Currency = itm.Currency;
_tDetail.Site = itm.Site;
_tDetail.SubSite = itm.SubSite;
_tDetail.Extend1 = itm.Extend1;
_tDetail.Extend2 = itm.Extend2;
_tDetail.Extend3 = itm.Extend3;
db.TB_ASK_DETAIL.Add(_tDetail);
var _order_detail = db.TB_PO_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
_order_detail.TempQty = itm.TempQty;
db.TB_PO_DETAIL.AddOrUpdate(p => p.UID, _order_detail);
}
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> ToVoid_ts_uni_api(List<string> ls,List<string> part)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
var pp = ls.First();
var billnum = db.TB_PO_DETAIL.Count(p => p.PoBillNum == pp && p.State > 0);
if (billnum == ls.Count)
{
var po1 = db.TB_PO.FirstOrDefault(t => t.PoBillNum == pp && t.State == 1);
po1.State = 0;
db.TB_PO.AddOrUpdate(po1);
var ask1 = db.TB_ASK.FirstOrDefault(t => t.PoBillNum == pp && t.State > -1);
ask1.State = -1;
ask1.IsDeleted = true;
db.TB_ASK.AddOrUpdate(ask1);
}
foreach(var po in ls)
{
foreach(var pa in part)
{
var asn = db.TB_ASN_DETAIL.Count(p => p.PartCode == pa && p.PoBillNum == po&&p.State>=0);
if (asn > 0)
{
_ret.MessageList.Add("零件号"+pa+"已经存在发货单,订单明细作废失败");
}
else
{
var ponum = db.TB_PO_DETAIL.Where(p => p.PartCode == pa && p.PoBillNum == po&&p.State>0).ToList();
foreach(var poo in ponum)
{
poo.State = 0;
db.TB_PO_DETAIL.AddOrUpdate(poo);
}
var ask = db.TB_ASK_DETAIL.Where(p => p.PartCode == pa && p.PoBillNum == po).ToList();
foreach (var askk in ask)
{
askk.State = -1;
askk.IsDeleted = true;
db.TB_ASK_DETAIL.AddOrUpdate(askk);
}
var uni = db.TS_UNI_API.Where(p => p.PartCode == pa && p.BillNum == po&&p.Receiver=="I");
foreach(var un in uni)
{
un.State = 1;
un.Receiver = "D";
db.TS_UNI_API.AddOrUpdate(un);
}
var coust = db.TB_MAXPO_CONSUME.Where(t => t.BillNum == po&&t.PartCode==pa).ToList();
foreach (var co in coust)
{
var maxpo = db.TB_MAXPO_DETAIL.FirstOrDefault(t => t.PoBillNum == co.PoBillNum && t.PartCode == co.PartCode);
maxpo.SurplusQty = maxpo.SurplusQty + co.PoQty;
}
}
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_ts_uni_api(List<string> ls)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
foreach (var po in ls)
{
var _ls = CheckExce2(db, po);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
number++;
}
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
var po1 = db.TB_PO.FirstOrDefault(t => t.PoBillNum == po&&t.State==1);
po1.State = 0;
db.TB_PO.AddOrUpdate(po1);
var po2 = db.TB_PO_DETAIL.Where(t => t.PoBillNum == po&&t.State==1).ToList();
foreach (var po3 in po2)
{
po3.State = 0;
db.TB_PO_DETAIL.AddOrUpdate(po3);
}
var ask1 = db.TB_ASK.FirstOrDefault(t => t.PoBillNum == po && t.State > -1);
ask1.State = -1;
ask1.IsDeleted = true;
db.TB_ASK.AddOrUpdate(ask1);
var ask2 = db.TB_ASK_DETAIL.Where(t => t.PoBillNum == po&&t.State>-1).ToList();
foreach (var ask3 in ask2)
{
ask3.State = -1;
db.TB_ASK_DETAIL.AddOrUpdate(ask3);
}
var lx = db.TS_UNI_API.Where(t => t.BillNum == po&&t.Receiver=="I").ToList();
foreach (var po4 in lx)
{
po4.State = 1;
po4.Receiver = "D";
db.TS_UNI_API.AddOrUpdate(po4);
}
var coust = db.TB_MAXPO_CONSUME.Where(t => t.BillNum == po).ToList();
if (coust.Count() > 0)
{
foreach (var co in coust)
{
var maxpo = db.TB_MAXPO_DETAIL.FirstOrDefault(t => t.PoBillNum == co.PoBillNum && t.PartCode == co.PartCode);
maxpo.SurplusQty = maxpo.SurplusQty + co.PoQty;
db.TB_MAXPO_CONSUME.Remove(co);
}
}
}
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Maxpo_ts_uni_api(List<string> maxpo)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
{
foreach(var po in maxpo)
{
var _list = db.TB_MAXPO_DETAIL.Where(p=>p.PoBillNum==po).ToList();
foreach(var _li in _list)
{
if (_li.OrderQtykg != _li.SurplusQty)
{
_ret.MessageList.Add("大订单号" + _li.PoBillNum + "已经开始期货订单消耗,作废失败");
}
else
{
UniApiEntities idb = EntitiesFactory.CreateUniApiInstance();
var _wmsret = idb.xxwms_rc_det.Where(p=>p.xxwms_rc_ware_class.Contains(_li.PoBillNum)).ToList();
if (_wmsret.Count() > 0)
{
_ret.MessageList.Add("大订单号" + _li.PoBillNum + "已经开始收货消耗,作废失败");
}
}
}
}
if(_ret.MessageList.Count == 0)
{
foreach (var po in maxpo)
{
var _maxpo = db.TB_MAXPO.FirstOrDefault(p=>p.PoBillNum== po);
_maxpo.IsDeleted = true;
db.TB_MAXPO.AddOrUpdate(_maxpo);
var _maxpodetail=db.TB_MAXPO_DETAIL.Where(p => p.PoBillNum == po).ToList();
_maxpodetail.ForEach(itm => itm.IsDeleted = true);
db.TB_MAXPO_DETAIL.AddOrUpdate(itm => itm.UID, _maxpodetail.ToArray());
var _Ts = db.TS_UNI_API.Where(p => p.BillNum == po).ToList();
foreach(var ts in _Ts)
{
ts.Extend3 = "D";
ts.State = 1;
db.TS_UNI_API.AddOrUpdate(ts);
}
}
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.MessageList= _ret.MessageList.Distinct().ToList();
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Maxpodetail_ts_uni_api(List<string> Uid)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
{
foreach (var ui in Uid)
{
var maxpodetail = db.V_TB_MAXPO_DETAIL.FirstOrDefault(p=>p.UID.ToString()==ui);
if (maxpodetail.SurplusQty != maxpodetail.OrderQtykg || maxpodetail.AnQty > 0 || maxpodetail.ReceQty > 0)
{
_ret.MessageList.Add("零件号"+maxpodetail.PartCode+"已经开始消耗,作废失败!");
}
}
if (_ret.MessageList.Count == 0)
{
foreach (var ui in Uid)
{
var maxpodetail = db.V_TB_MAXPO_DETAIL.FirstOrDefault(p => p.UID.ToString() == ui);
var uni = db.TS_UNI_API.FirstOrDefault(p=>p.PartCode==maxpodetail.PartCode&&p.BillNum==maxpodetail.PoBillNum);
uni.State = 1;
db.TS_UNI_API.AddOrUpdate(uni);
}
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.MessageList = _ret.MessageList.Distinct().ToList();
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Delete_Ta_Subpart()
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
{
var sublist = db.TA_SubPartCode.ToList();
foreach(var sub in sublist)
{
db.TA_SubPartCode.Remove(sub);
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_ts_uni_api1(List<string> ls)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
{
int number = 1;
List<string> lineError = new List<string>();
List<string> ErrorList = new List<string>();
foreach (var po in ls)
{
var _ls = CheckExce3(db, po);
if (_ls.Count > 0)
{
lineError.Add(number.ToString());
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
number++;
}
if (lineError.Count > 0)
{
_ret.State = ReturnStatus.Failed;
_ret.MessageList.AddRange(ErrorList);
_ret.Result = false;
}
else
{
var _entity = db.TB_ASK.FirstOrDefault(p => p.AskBillNum.ToString() == po);
_entity.State = -1;
_entity.IsDeleted = true;
db.TB_ASK.AddOrUpdate(_entity);
if (_entity.Site == "U32")
{
var _po = db.TB_PO.FirstOrDefault(P => P.PoBillNum == _entity.PoBillNum);
_po.State = 0;
db.TB_PO.AddOrUpdate(_po);
var _podetail = db.TB_PO_DETAIL.Where(p=>p.PoBillNum==_entity.PoBillNum).ToList();
_podetail.ForEach(p =>
{
p.State = 0;
db.TB_PO_DETAIL.AddOrUpdate(p);
});
}
var _entity1 = db.TB_ASK_DETAIL.Where(p => p.AskBillNum.ToString() == po).ToList();
foreach(var ask in _entity1)
{
ask.State = -1;
ask.IsDeleted = true;
db.TB_ASK_DETAIL.AddOrUpdate(ask);
}
}
}
}
if (_ret.MessageList.Count == 0)
{
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static void Get_V_TB_PO_DETAIL_OUTPUT_List(V_TB_PO_DETAIL p_entity, Action<ResultObject<IQueryable<V_TB_PO_DETAIL>>> p_action)
{
ResultObject<IQueryable<V_TB_PO_DETAIL>> _ret = new ResultObject<IQueryable<V_TB_PO_DETAIL>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PO_DETAIL> q = db.V_TB_PO_DETAIL;
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
}
if (!string.IsNullOrEmpty(p_entity.ErpBillNum))
{
q = q.Where(p => p.ErpBillNum.Contains(p_entity.ErpBillNum));
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p.BeginTime >= p_entity.BeginTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.BeginTime <= p_entity.EndTime);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (!string.IsNullOrEmpty(p_entity.VendName))
{
q = q.Where(p => p.VendName.Contains(p_entity.VendName));
}
if (p_entity.ModType != null)
{
q = q.Where(p => p.ModType == p_entity.ModType);
}
if (!string.IsNullOrEmpty(p_entity.ProjectId))
{
q = q.Where(p => p.ProjectId.Contains(p_entity.ProjectId));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
}
if (p_entity.State != null)
{
q = q.Where(p => p.State == p_entity.State);
}
//q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
//IQueryable<TB_ASK_DETAIL> _aq = db.TB_ASK_DETAIL;
//_aq = _aq.Where(p => p.PoBillNum == p_entity.PoBillNum);
//var _a=_aq.GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Max(itm=>itm .AskQty),PoLine=p.Key });
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
if (!string.IsNullOrEmpty(p_entity.SubSite))
{
q = q.Where(p => p.SubSite == p_entity.SubSite);
}
if (!string.IsNullOrEmpty(p_entity.Extend1))
{
q = q.Where(p => p.Extend1 == p_entity.Extend1);
}
if (!string.IsNullOrEmpty(p_entity.Extend2))
{
q = q.Where(p => p.Extend1 == p_entity.Extend2);
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend1 == p_entity.Extend3);
}
if (!string.IsNullOrEmpty(p_entity.SubSite))
{
q = q.Where(p => p.SubSite.Contains(p_entity.SubSite));
}
if (!string.IsNullOrEmpty(p_entity.Extend1))
{
q = q.Where(p => p.Extend1.Contains(p_entity.Extend1));
}
if (!string.IsNullOrEmpty(p_entity.Extend2))
{
q = q.Where(p => p.Extend2.Contains(p_entity.Extend2));
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
public static void Get_V_TB_PO_DETAIL_List(V_TB_PO_DETAIL p_entity, Action<ResultObject<IQueryable<V_TB_PO_DETAIL>>> p_action)
{
ResultObject<IQueryable<V_TB_PO_DETAIL>> _ret = new ResultObject<IQueryable<V_TB_PO_DETAIL>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PO_DETAIL> q = db.V_TB_PO_DETAIL;
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
}
if (!string.IsNullOrEmpty(p_entity.ErpBillNum))
{
q = q.Where(p => p.ErpBillNum.Contains(p_entity.ErpBillNum));
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p.BeginTime >= p_entity.BeginTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.BeginTime <= p_entity.EndTime);
}
if (!string.IsNullOrEmpty(p_entity.VendName))
{
q = q.Where(p => p.VendName == p_entity.VendName);
}
if (p_entity.ModType != null)
{
q = q.Where(p => p.ModType == p_entity.ModType);
}
if (!string.IsNullOrEmpty(p_entity.ProjectId))
{
q = q.Where(p => p.ProjectId == p_entity.ProjectId);
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode == p_entity.PartCode);
}
if (p_entity.State != null)
{
q = q.Where(p => p.State == p_entity.State);
}
//q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
//IQueryable<TB_ASK_DETAIL> _aq = db.TB_ASK_DETAIL;
//_aq = _aq.Where(p => p.PoBillNum == p_entity.PoBillNum);
//var _a=_aq.GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode }).Select(p => new { AskSum = p.Max(itm=>itm .AskQty),PoLine=p.Key });
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
public static void Get_V_TB_MAXPO_DETAIL_List(V_TB_MAXPO_DETAIL p_entity, Action<ResultObject<IQueryable<V_TB_MAXPO_DETAIL>>> p_action)
{
ResultObject<IQueryable<V_TB_MAXPO_DETAIL>> _ret = new ResultObject<IQueryable<V_TB_MAXPO_DETAIL>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_MAXPO_DETAIL> q = db.V_TB_MAXPO_DETAIL;
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
}
if (!string.IsNullOrEmpty(p_entity.ContractMonth))
{
q = q.Where(p => p.ContractMonth == p_entity.ContractMonth);
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode == p_entity.PartCode);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId == p_entity.VendId);
}
if (!string.IsNullOrEmpty(p_entity.CreateUser))
{
q = q.Where(p => p.CreateUser == p_entity.CreateUser);
}
if (!string.IsNullOrEmpty(p_entity.PartNumber))
{
q = q.Where(p => p.PartNumber == p_entity.PartNumber);
}
if (!string.IsNullOrEmpty(p_entity.BeginTime.ToString()))
{
q = q.Where(p => p.CreateTime >= p_entity.BeginTime);
}
if (!string.IsNullOrEmpty(p_entity.EndTime.ToString()))
{
q = q.Where(p => p.CreateTime <= p_entity.EndTime);
}
q = q.Where(p=>p.IsDeleted==p_entity.IsDeleted);
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
public static void Get_V_TB_MAXPO_INCOMPLETE_DETAIL(V_TB_MAXPO_CONSUME p_entity, Action<ResultObject<IQueryable<V_TB_MAXPO_CONSUME>>> p_action)
{
ResultObject<IQueryable<V_TB_MAXPO_CONSUME>> _ret = new ResultObject<IQueryable<V_TB_MAXPO_CONSUME>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_MAXPO_CONSUME> q = db.V_TB_MAXPO_CONSUME;
//if (!string.IsNullOrEmpty(p_entity.PoBillNum))
//{
// q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
//}
//if (!string.IsNullOrEmpty(p_entity.PartCode))
//{
// q = q.Where(p => p.PartCode == p_entity.PartCode);
//}
if (p_entity.PoList != null && p_entity.PoList.Count > 0)
{
q = q.Where(p => p_entity.PoList.Contains(p.PoBillNum));
}
if (p_entity.PartList != null && p_entity.PartList.Count > 0)
{
q = q.Where(p => p_entity.PartList.Contains(p.PartCode));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
public static void Get_V_TB_MAXPO_List(V_TB_MAXPO p_entity, Action<ResultObject<IQueryable<V_TB_MAXPO>>> p_action)
{
ResultObject<IQueryable<V_TB_MAXPO>> _ret = new ResultObject<IQueryable<V_TB_MAXPO>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_MAXPO> q = db.V_TB_MAXPO;
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId == p_entity.VendId);
}
if (!string.IsNullOrEmpty(p_entity.CreateUser))
{
q = q.Where(p => p.CreateUser == p_entity.CreateUser);
}
if (!string.IsNullOrEmpty(p_entity.ContractMonth))
{
q = q.Where(p => p.ContractMonth == p_entity.ContractMonth);
}
if (!string.IsNullOrEmpty(p_entity.BeginTime.ToString()))
{
q = q.Where(p => p.CreateTime >= p_entity.BeginTime);
}
if (!string.IsNullOrEmpty(p_entity.EndTime.ToString()))
{
q = q.Where(p => p.CreateTime <= p_entity.EndTime);
}
q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
public static void Get_V_TB_PO_SUBDETAIL(V_TB_PO_SUBDETAIL p_entity, Action<ResultObject<IQueryable<V_TB_PO_SUBDETAIL>>> p_action)
{
ResultObject<IQueryable<V_TB_PO_SUBDETAIL>> _ret = new ResultObject<IQueryable<V_TB_PO_SUBDETAIL>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PO_SUBDETAIL> q = db.V_TB_PO_SUBDETAIL;
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
#region 沈阳金杯
public static ResultObject<bool> Save_PO_TO_ASK_SYJB(V_TB_PO p_order, List<V_TB_PO_DETAIL> p_order_list
, string p_buyer, string p_buyerPhone)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
TB_ASK _t = new TB_ASK();
_t.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode();
_t.PoBillNum = p_order.PoBillNum;
_t.VendId = p_order.VendId;
_t.IsDeleted = false;//操作员
_t.CreateTime = DateTime.Now;
_t.CreateUser = p_buyer;
_t.Site = p_order.Site;
_t.Remark = p_order.Remark;
_t.State = (int)AskState.Release;
_t.Remark = p_order.Remark;
_t.GUID = p_order.GUID;
_t.ModType = (int)p_order.ModType;
_t.ErpBillNum = p_order.ErpBillNum;
_t.BeginTime = (DateTime)p_order.BeginTime;
_t.EndTime = p_order.BeginTime;
_t.Buyer = p_buyer;
_t.BuyerPhone = p_buyerPhone;
db.TB_ASK.AddOrUpdate(p => p.AskBillNum, _t);
List<TB_ASK_DETAIL> _list = new List<TB_ASK_DETAIL>();
foreach (var itm in p_order_list)
{
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
_tDetail.PoBillNum = _t.PoBillNum;
_tDetail.AskBillNum = _t.AskBillNum;
_tDetail.PoLine = itm.PoLine;
_tDetail.PoUnit = itm.PoUnit;
_tDetail.CreateTime = DateTime.Now;
_tDetail.CreateUser = p_buyer;
_tDetail.PartCode = itm.PartCode;
_tDetail.BeginTime = itm.BeginTime;
_tDetail.EndTime = itm.EndTime;
_tDetail.Currency = itm.Currency;
_tDetail.TempQty = itm.TempQty == null ? 0 : (decimal)itm.TempQty;
_tDetail.AskQty = (decimal)itm.PlanQty;
_tDetail.IsDeleted = false;
_tDetail.LocUnit = itm.LocUnit;
_tDetail.UnConv = itm.UnConv;
_tDetail.State = (int)p_order.State;
_tDetail.Price = itm.Price;
_tDetail.GUID = itm.GUID;
db.TB_ASK_DETAIL.Add(_tDetail);
var _order_detail = db.TB_PO_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
_order_detail.TempQty = itm.TempQty;
db.TB_PO_DETAIL.AddOrUpdate(p => p.UID, _order_detail);
}
int state = db.SaveChanges();
if (state != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_PO), "Save_PO_TO_ASK", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static void Get_V_TA_VENDER(V_TB_PO_DETAIL p_entity, Action<ResultObject<IQueryable<V_TA_VENDER>>> p_action)
{
ResultObject<IQueryable<V_TA_VENDER>> _ret = new ResultObject<IQueryable<V_TA_VENDER>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
List<V_TA_VENDER> result = new List<V_TA_VENDER>();
IQueryable<V_TA_VENDER> q = db.V_TA_VENDER;
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (!string.IsNullOrEmpty(p_entity.VendName))
{
q = q.Where(p => p.VendName.Contains(p_entity.VendName));
}
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
IQueryable<TB_ASN> q2 = db.TB_ASN;
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q2 = q2.Where(p => p.PoBillNum.Contains(p_entity.PoBillNum));
}
if (p_entity.BeginTime != null)
{
q2 = q2.Where(p => p.ShipTime >= p_entity.BeginTime);
}
if (p_entity.EndTime != null)
{
q2 = q2.Where(p => p.ShipTime <= p_entity.EndTime);
}
//返回全部供应商
if (string.IsNullOrEmpty(p_entity.PoBillNum) && p_entity.BeginTime == null && p_entity.EndTime == null)
{
result = q.ToList();
}
//返回符合条件发货单里的供应商
else
{
List<string> lsVendId = new List<string>();
q.ToList().ForEach(p =>
{
q2.ToList().ForEach(itm =>
{
if (p.VendId == itm.VendId)
{
if (!lsVendId.Contains(p.VendId))
{
result.Add(p);
lsVendId.Add(p.VendId);
}
}
});
});
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = result.AsQueryable();
p_action(_ret);
}
}
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);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(ex);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", ex.ToString());
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null) throw ex.InnerException;
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Get_V_TB_PO_DETAIL_List", e.Message);
throw e;
}
}
public static List<V_TA_VENDER> LOAD_PO_DETAIL_SUM_PROMPTNESS(V_TB_PO_DETAIL p_entity, List<V_TA_VENDER> p_list)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
if (p_list.Count > 0)
{
//var _detail = p_list[0];
foreach (V_TA_VENDER _detail in p_list)
{
IQueryable<TB_ASN> q = db.TB_ASN.Where(p => p.VendId == _detail.VendId && p_entity.UserInAddress.Contains(p.Site));
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum.Contains(p_entity.PoBillNum));
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p.ShipTime >= p_entity.BeginTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.ShipTime <= p_entity.EndTime);
}
int asnNo = q.ToList().Count;//是发货数量
int arriveNo = 0;
q.ToList().ForEach(p =>
{
TB_ARRIVE q2 = db.TB_ARRIVE.FirstOrDefault(p1 => p1.AsnBillNum == p.AsnBillNum && p_entity.UserInAddress.Contains(p1.Site) && p1.BillType.ToString() == "0");
if (q2 != null && q2.ShipTime != null && p.ShipTime != null && q2.ShipTime <= p.ShipTime)
{
arriveNo += 1;
}
});
_detail.ShippedQty = asnNo.ToString();//发货数量
_detail.ArriveQty = arriveNo.ToString();//到货数量
if (asnNo == 0)
{
_detail.Promptness = "0%";//及时率
}
else
{
double temp = (arriveNo / asnNo) * 100;
_detail.Promptness = temp.ToString("0.00") + "% ";//及时率
}
//arrive.ToList().ForEach(itm =>
//{
// if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
// {
// _detail.ArriveQty = itm.ArriveSum.ToString();
// }
//});
}
}
}
return p_list;
}
#endregion
}
}