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.
 
 
 
 
 

2904 lines
131 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;
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.Contains( 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.EndTime != null)
{
q = q.Where(p => p.EndTime <= p_entity.EndTime);
}
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 (!string.IsNullOrEmpty(p_entity.PartCode))
//{
// var _po = db.TB_PO_DETAIL.Where(p => p.PartCode == p_entity.PartCode && p.IsDeleted== false);
// 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 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 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 _count = db.TB_PO_DETAIL.Count(p => p.PoBillNum == p_excel.QAD订单号 && p.PartCode == p_excel. && p.PoLine.ToString() == p_excel.);
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.) ||
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.));
}
if (_count == 0)
{
ErrorList.Add(string.Format("分组【{2}】零件号【{0}】行号【{1}】不存在!", p_excel., p_excel., p_excel.));
}
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.) ||
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_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.))
{
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.TA_PART.Count(p => p.PartCode == 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.));
}
//if (_count == 0)
//{
// ErrorList.Add(string.Format("分组【{2}】零件名称【{0}】行号【{1}】不存在!", p_excel.零件号, p_excel.行号, 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_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;
_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 _count = _lst.Count(itm => itm. == p. && itm. == p. && itm. == p.);
if (_count > 1)
{
lineError.Add(string.Format("导入订单编号{0}行号{1}零件编码{2}有重复", p.,p., p.));
ErrorList = lineError;
}
});
_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
{
var OrderList = _lst.GroupBy(p => p.).ToList();
OrderList.ForEach((p) =>
{
var list = p.ToList();
if (list.Count > 0)
{
var _entity = list.FirstOrDefault();
TB_PO _po = new TB_PO();
_po.PoBillNum = _entity..ToUpper();
_po.ErpBillNum = _entity..ToUpper();
_po.VendId = _entity..ToUpper();
_po.ModType = (int)BillModType.Contract;
_po.Contacter = _entity.;
_po.Site = site;
_po.Remark = _entity.;
_po.State = (int)PoState.Open;
_po.GUID = Guid.NewGuid();
_po.IsDeleted = false;
_po.CreateTime = DateTime.Parse(_entity.);
_po.CreateUser = p_creator;
_po.BeginTime = p_time;
_po.EndTime = DateTime.Parse(_entity.);
_po.Site = site;
db.TB_PO.Add(_po);
// int _number = 1;
list.ForEach((itm) =>
{
TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL();
_PO_Detail.PoLine = Int32.Parse(itm.);
_PO_Detail.Currency = "CNY";
_PO_Detail.PoBillNum = itm.;
_PO_Detail.PoUnit = itm.;
_PO_Detail.CreateTime = DateTime.Parse(itm.);
_PO_Detail.CreateUser = p_creator;
_PO_Detail.PartCode = itm..ToUpper();
_PO_Detail.BeginTime = p_time;
_PO_Detail.EndTime = 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.State = (int)PoState.Open;
_PO_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.);
_PO_Detail.GUID = Guid.NewGuid();
db.TB_PO_DETAIL.Add(_PO_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_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 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, 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
{
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 => 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.VendId = _entity.;
_ask.State = (int)AskState.New;
_ask.PoBillNum = _entity.QAD订单号.ToUpper();
_ask.ModType = (int)BillModType.Contract;
_ask.Site = _entity.;
if (IsAutoPublish)
{
_ask.State = (int)AskState.Release;
}
else
{
_ask.State = (int)AskState.New;
}
_ask.BeginTime = DateTime.Parse(_entity.);
_ask.Buyer = _entity.;
_ask.BuyerPhone = _entity.;
_ask.ErpBillNum = _entity.QAD订单号.ToUpper();
_ask.EndTime = DateTime.Parse(_entity.);
_ask.CreateTime = DateTime.Parse(_entity.);
_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();
_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.State = _ask.State;
_t_ASK_Detail.Price = string.IsNullOrEmpty(itm.) ? 0 : decimal.Parse(itm.);
_t_ASK_Detail.GUID = Guid.NewGuid();
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);
throw e;
}
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 = _date;
_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 = itm.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.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 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;
}
}
#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_TB_PO_DETAIL_List_STATISTICS(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.Contains(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.Contains(p_entity.VendName));
}
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);
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
{
q = q.Where(p => p_entity.UserInVendIds.Contains(p.VendId));
}
//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.Address));
//}
_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_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
}
}