|
@ -12,6 +12,7 @@ using CK.SCP.Utils; |
|
|
using System.Data.Entity.Core; |
|
|
using System.Data.Entity.Core; |
|
|
using CK.SCP.Models.ScpEntity.ExcelExportEnttity; |
|
|
using CK.SCP.Models.ScpEntity.ExcelExportEnttity; |
|
|
using System.Text.RegularExpressions; |
|
|
using System.Text.RegularExpressions; |
|
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
namespace CK.SCP.Controller |
|
|
namespace CK.SCP.Controller |
|
|
{ |
|
|
{ |
|
@ -634,9 +635,622 @@ namespace CK.SCP.Controller |
|
|
return ErrorList; |
|
|
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.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> 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).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 |
|
|
|
|
|
{ |
|
|
|
|
|
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) |
|
|
private static List<string> CheckExcelMode(ScpEntities db, SCP_PO_DETAIL_EXPORT_MODEL p_excel) |
|
|
{ |
|
|
{ |
|
|
List<string> ErrorList = new List<string>(); |
|
|
List<string> ErrorList = new List<string>(); |
|
|