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.
5446 lines
275 KiB
5446 lines
275 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity.Migrations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CK.SCP.Models;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Models.ScpEntity.ExcelImportEntity;
|
|
using CK.SCP.Utils;
|
|
using System.Data.Entity.Core;
|
|
using CK.SCP.Models.ScpEntity.ExcelExportEnttity;
|
|
using System.Text.RegularExpressions;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace CK.SCP.Controller
|
|
{
|
|
public class SCP_PO_CONTROLLER
|
|
{
|
|
|
|
public static void Get_V_TB_PO_List(V_TB_PO p_entity, Action<ResultObject<IQueryable<V_TB_PO>>> p_action)
|
|
{
|
|
ResultObject<IQueryable<V_TB_PO>> _ret = new ResultObject<IQueryable<V_TB_PO>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<V_TB_PO> q = db.V_TB_PO;
|
|
if (p_entity.UID != 0)
|
|
{
|
|
q = q.Where(p => p.UID == p_entity.UID);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
|
|
{
|
|
q = q.Where(p => p.PoBillNum == p_entity.PoBillNum);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.ErpBillNum))
|
|
{
|
|
q = q.Where(p => p.ErpBillNum.Contains(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.BeginTime <= p_entity.EndTime);
|
|
}
|
|
//if (p_entity.UserInAddress.FirstOrDefault() != 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 (p_entity.UserInSubSite != null && p_entity.UserInSubSite.Count > 0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInSubSite.Contains(p.SubSite));
|
|
}
|
|
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, p.SubSite }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode, Subsite = p.Key.SubSite });
|
|
var reject = db.TB_ARRIVE_DETAIL.Where(p => p.PoBillNum == _detail.PoBillNum && p.IsDeleted == false && p.State == (int)ArriveState.OK && p.BillType == (int)ArriveBillType.Reject)
|
|
.GroupBy(p => new { p.PoBillNum, p.PoLine, p.PartCode, p.SubSite }).Select(p => new { RejectSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode, Subsite = p.Key.SubSite });
|
|
_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.SubSite == itm.Subsite)
|
|
{
|
|
_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.SubSite == itm.Subsite)
|
|
{
|
|
_detail.ArriveQty = itm.ArriveSum.ToString();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|
|
return p_list;
|
|
}
|
|
|
|
|
|
public static List<V_TB_PO_DETAIL> LOAD_PO_DETAIL_SUM_ASK(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 });
|
|
_ask.ToList().ForEach(itm =>
|
|
{
|
|
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
{
|
|
_detail.TempQty = itm.AskSum;
|
|
}
|
|
});
|
|
_detail.PartDesc1 = _detail.PartDesc1 + _detail.PartDesc2;
|
|
}
|
|
}
|
|
|
|
}
|
|
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 (p_state == PoState.Close)
|
|
{
|
|
var _pols = db.TB_PO.Where(t => p_list.Contains(t.PoBillNum) && t.IsDeleted == false).ToList();
|
|
if (_pols.Count > 0)
|
|
{
|
|
_pols.ForEach(p =>
|
|
{
|
|
p.State = (int)PoState.Close;
|
|
var _list = db.TB_PO_DETAIL.Where(itm => itm.PoBillNum == p.PoBillNum).ToList();
|
|
_list.ForEach(itm => itm.State = (int)PoState.Close);
|
|
db.TB_PO_DETAIL.AddOrUpdate(itm => itm.UID, _list.ToArray());
|
|
}
|
|
);
|
|
db.TB_PO.AddOrUpdate(t => t.UID, _pols.ToArray());
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.Message = "选择的记录,有不是发布状态记录!";
|
|
}
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
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_ASK_CONTROLLER), "Save_TB_ASK_STATE", sb.ToString());
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", ex.ToString());
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
}
|
|
catch (ScpException ex)
|
|
{
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", ex.ToString());
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
{
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<bool> Save_TB_PO_STATE_Detail(List<string> p_list, List<string> p_list1, PoState p_state)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
foreach (var po in p_list)
|
|
{
|
|
foreach (var po1 in p_list1)
|
|
{
|
|
var PoDetail = db.TB_PO_DETAIL.SingleOrDefault(p => p.PoBillNum == po && p.PartCode == po1);
|
|
PoDetail.State = (int)PoState.Close;
|
|
db.TB_PO_DETAIL.AddOrUpdate(PoDetail);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
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_ASK_CONTROLLER), "Save_TB_ASK_STATE", sb.ToString());
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", ex.ToString());
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
}
|
|
catch (ScpException ex)
|
|
{
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", ex.ToString());
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
{
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<bool> Save_TB_PO_STATE_Detail_Close(List<string> p_list, List<string> p_list1, PoState p_state)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
foreach (var po in p_list)
|
|
{
|
|
foreach (var po1 in p_list1)
|
|
{
|
|
var PoDetail = db.TB_ASK_DETAIL.SingleOrDefault(p => p.PoBillNum == po && p.PartCode == po1);
|
|
PoDetail.AskQty=0;
|
|
db.TB_ASK_DETAIL.AddOrUpdate(PoDetail);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
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_ASK_CONTROLLER), "Save_TB_ASK_STATE", sb.ToString());
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", ex.ToString());
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
}
|
|
catch (ScpException ex)
|
|
{
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", ex.ToString());
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
{
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Save_TB_ASK_STATE", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
//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.订单编号));
|
|
}
|
|
|
|
var _askDate = DateTime.Parse(p_excel.订货日期);
|
|
|
|
var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件编码 && p.Site == p_excel.域名 && p.SubSite == p_excel.地点 && p.State == (int)PriceState.FConfirm && p.VendId == p_excel.供应商编码 && p.StartTime <= _askDate && _askDate <= p.EndTime).ToList();
|
|
if (checkcount.Count == 0)
|
|
{
|
|
|
|
ErrorList.Add(string.Format("零件名称【{0}】供应编码【{1}】价格表没有维护信息!", p_excel.零件编码, p_excel.供应商编码));
|
|
}
|
|
else
|
|
{
|
|
p_excel.价格 = checkcount[0].Amt.ToString();
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
if (!string.IsNullOrEmpty(p_excel.供应商代码))
|
|
{
|
|
int count = db.TA_VENDER.Count(p => p.VendId == p_excel.供应商代码 && p.Site == p_excel.域);
|
|
if (count <= 0)
|
|
{
|
|
ErrorList.Add(string.Format("域{1}供应商{0}不存在!", p_excel.供应商代码, 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 == p_excel.域);
|
|
if (count <= 0)
|
|
{
|
|
ErrorList.Add(string.Format("域{1}零件编号{0}不存在!", p_excel.零件号, 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("域【{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_Vender(ScpEntities db, SCP_VENDER_EXPORT p_excel)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
if (
|
|
string.IsNullOrEmpty(p_excel.供应商编号) ||
|
|
string.IsNullOrEmpty(p_excel.供应商名称) ||
|
|
string.IsNullOrEmpty(p_excel.域))
|
|
{
|
|
ErrorList.Add(string.Format("供应商编号【{0}】有填写为空!", p_excel.供应商编号));
|
|
}
|
|
return ErrorList;
|
|
|
|
}
|
|
private static List<string> CheckExcelMode_Vender1(ScpEntities db, SCP_PRICE_EXPORT p_excel)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
|
|
if (
|
|
|
|
string.IsNullOrEmpty(p_excel.零件最新价格) ||
|
|
string.IsNullOrEmpty(p_excel.最新开始时间))
|
|
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】有填写为空!", p_excel.标识, p_excel.供应商编号));
|
|
|
|
}
|
|
else
|
|
{
|
|
if (p_excel.币种 != "CNY" && p_excel.币种 != "EUR" && p_excel.币种 != "USD")
|
|
{
|
|
ErrorList.Add(string.Format("供应商编号为【{0}】的零件编号【{1}】币种填写错误,只能是CNY或者EUR或者USD!", p_excel.供应商编号, p_excel.零件编码));
|
|
}
|
|
DateTime st6 = DateTime.Parse(p_excel.结束时间);
|
|
DateTime st2 = DateTime.Parse(st6.ToShortDateString());
|
|
|
|
DateTime st7 = DateTime.Parse(p_excel.最新开始时间);
|
|
DateTime st1 = DateTime.Parse(st7.ToShortDateString());
|
|
|
|
DateTime st5 = DateTime.Parse(p_excel.开始时间);
|
|
DateTime st3=DateTime.Parse( st5.ToShortDateString());
|
|
|
|
Decimal st4 = Decimal.Parse(p_excel.零件基础价格);
|
|
DateTime dd = st2.AddDays(1);
|
|
DateTime dd1 = st1.AddYears(10);
|
|
int b = int.Parse(p_excel.是否临时价格);
|
|
var Th = db.TB_PRICE.SingleOrDefault(p => p.UID.ToString() == p_excel.标识 && p.VendId == p_excel.供应商编号 && p.PartCode == p_excel.零件编码
|
|
&& p.Amt == st4 && p.SubSite == p_excel.地点 &&p.Curr==p_excel.币种&&p.Unit==p_excel.单位
|
|
);
|
|
if (Th == null)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】的导出数据不能修改!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
else
|
|
{
|
|
if ((DateTime.Parse(Th.StartTime.ToString())).ToShortDateString()!=st3.ToShortDateString()|| (DateTime.Parse(Th.EndTime.ToString())).ToShortDateString() != st2.ToShortDateString())
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】的导出数据不能修改!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
DateTime STA =DateTime.Parse(Th.StartTime.ToString());
|
|
if(DateTime.Parse(STA.ToShortDateString())!= st3)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】的导出数据不能修改!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
if (Th.State != (int)PriceState.FConfirm)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】不是财务已审核的数据,不能导入!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
if (st1 <= st3 || st1 > dd || st1 == st2)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】最新开始时间填写错误!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
if(st1>st2&& st1 < dd)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】最新开始时间填写错误!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
if (string.IsNullOrEmpty(p_excel.最新结束时间))
|
|
{
|
|
p_excel.最新结束时间 = dd1.ToShortDateString();
|
|
}
|
|
else
|
|
{
|
|
if (DateTime.Parse(p_excel.最新结束时间) <= st1 || DateTime.Parse(p_excel.最新结束时间) <= st2 || DateTime.Parse(p_excel.最新结束时间) <= st3)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】最新结束时间填写错误!", p_excel.标识, p_excel.供应商编号));
|
|
}
|
|
|
|
}
|
|
var _second1 = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件编码 && p.VendId == p_excel.供应商编号&&p.SubSite== p_excel.地点&&p.State!=-1).Select(r => r.UID).Max();
|
|
int a = 0;
|
|
int.TryParse(p_excel.标识, out a);
|
|
if (a < _second1)
|
|
{
|
|
ErrorList.Add(string.Format("标识【{0}】供应商编号为【{1}】的零件编号【{2}】价格表里已经存在!", p_excel.标识, p_excel.供应商编号, p_excel.零件编码));
|
|
|
|
|
|
}
|
|
return ErrorList;
|
|
}
|
|
|
|
return ErrorList;
|
|
}
|
|
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)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
if (string.IsNullOrEmpty(p_excel.供应商编号) || string.IsNullOrEmpty(p_excel.结束时间) || string.IsNullOrEmpty(p_excel.开始时间) ||
|
|
string.IsNullOrEmpty(p_excel.零件编码) || string.IsNullOrEmpty(p_excel.币种) || string.IsNullOrEmpty(p_excel.单位) ||
|
|
string.IsNullOrEmpty(p_excel.零件基础价格) || string.IsNullOrEmpty(p_excel.域) || string.IsNullOrEmpty(p_excel.地点) ||
|
|
string.IsNullOrEmpty(p_excel.是否临时价格))
|
|
{
|
|
ErrorList.Add(string.Format("供应商编码【{0}】零件编号【{1}】有填写为空!", p_excel.供应商编号, p_excel.零件编码));
|
|
}
|
|
else
|
|
{
|
|
if (p_excel.币种 != "CNY"&& p_excel.币种 != "EUR" && p_excel.币种 != "USD")
|
|
{
|
|
ErrorList.Add(string.Format("供应商编号为【{0}】的零件编号【{1}】币种填写错误,只能是CNY或者EUR或者USD!", p_excel.供应商编号, p_excel.零件编码));
|
|
}
|
|
var Site = db.TB_FACTORY.Where(p=>p.ErpSite== p_excel.域).FirstOrDefault();
|
|
var _first = db.TA_PART.Where(p => p.PartCode == p_excel.零件编码.Trim() &&p.Site== p_excel.域).FirstOrDefault();
|
|
if (_first == null)
|
|
{
|
|
ErrorList.Add(string.Format("供应商编号为【{0}】的零件编号【{1}】零件表里无数据,无法导入!", p_excel.供应商编号, p_excel.零件编码));
|
|
}
|
|
else
|
|
{
|
|
p_excel.单位 = _first.Unit;
|
|
if (_first.State == "SP")
|
|
{
|
|
ErrorList.Add(string.Format("零件编号【{0}】状态为SP,无法导入!", p_excel.零件编码));
|
|
}
|
|
}
|
|
|
|
p_excel.供应商编号 = !string.IsNullOrEmpty(p_excel.供应商编号) ? p_excel.供应商编号.Trim() : string.Empty;
|
|
|
|
var _count = db.TA_VENDER.Where(p => p.VendId == p_excel.供应商编号&&p.Site== p_excel.域).Count();
|
|
if (_count == 0)
|
|
{
|
|
ErrorList.Add(string.Format("未找到供应商编号为【{0}】无法导入!", p_excel.供应商编号));
|
|
}
|
|
|
|
|
|
DateTime st = DateTime.Parse(p_excel.开始时间);
|
|
DateTime et = DateTime.Parse(p_excel.结束时间);
|
|
DateTime st_st = Convert.ToDateTime(st.ToShortDateString());
|
|
DateTime et_st = Convert.ToDateTime(et.ToShortDateString());
|
|
var _Site = new SqlParameter("@Site", p_excel.域);
|
|
var _SubSite = new SqlParameter("@SubSite", p_excel.地点);
|
|
var _VendId = new SqlParameter("@VendId", p_excel.供应商编号);
|
|
var _PartCode = new SqlParameter("@PartCode", p_excel.零件编码.Trim());
|
|
if (st > et)
|
|
{
|
|
ErrorList.Add(string.Format("供应商{0}零件编号{1}的结束时间需要大于开始时间!", p_excel.供应商编号, p_excel.零件编码));
|
|
}
|
|
//var price = db.TB_PRICE.Count(p => p.PartCode == p_excel.零件编码.Trim() && p.VendId == p_excel.供应商编号.Trim() && p.StartTime == st && p.EndTime == et && p.Site == p_excel.域&&p.State!=-1);
|
|
//if (price > 0)
|
|
//{
|
|
// ErrorList.Add(string.Format("供应商{0}零件编号{1}价格单已经存在!", p_excel.供应商编号, p_excel.零件编码));
|
|
//}
|
|
string check = "select * from tb_price where uid in\n" +
|
|
"(\n" +
|
|
" select max(uid) uid\n" +
|
|
" from tb_price WHERE\n" +
|
|
" state<>-1 and Site=@Site AND SubSite=@SubSite AND VendId =@VendId AND PartCode=@PartCode \n" +
|
|
" group by vendid,partcode,subsite,site\n" +
|
|
") ";
|
|
var _price = db.Database.SqlQuery<TB_PRICE>(check, _Site, _SubSite, _VendId, _PartCode).FirstOrDefault();
|
|
|
|
if (_price != null)
|
|
{
|
|
ErrorList.Add(string.Format("供应商{0}零件编号{1}价格单已经存在,如要修改价格单信息请到价格单修改菜单进行操作!", p_excel.供应商编号, p_excel.零件编码));
|
|
//if (st_st < Convert.ToDateTime(_price.StartTime.Value.ToShortDateString()) || st_st > et_st || st_st == et_st)//更新价格时间判断
|
|
//{
|
|
// ErrorList.Add(string.Format("供应商{0}零件编号{1}开始时间结束时间不正确!", p_excel.供应商编号, p_excel.零件编码));
|
|
//}
|
|
//if (st_st > Convert.ToDateTime(_price.StartTime.Value.ToShortDateString()))//添加价格记录时间判断
|
|
//{
|
|
// if (st.ToShortDateString() != (_price.EndTime.Value.AddDays(1)).ToShortDateString())
|
|
// {
|
|
// ErrorList.Add(string.Format("供应商{0}零件编号{1}开始日期必须为{2}", p_excel.供应商编号, p_excel.零件编码, _price.EndTime.Value.AddDays(1).ToShortDateString().Replace("-", "/")));
|
|
// }
|
|
// if (_price.State != (int)PriceState.FConfirm)
|
|
// {
|
|
// 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_Part(ScpEntities db, SCP_PART_EXPORT p_excel)
|
|
{
|
|
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.项目编号) ||
|
|
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, BillModType p_modtype, string site, 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 _checkpartcode = db.TA_PART.Count(p => p.PartCode == p_excel.零件号&&p.State.ToUpper()!="SP");
|
|
//if (_checkpartcode == 0)
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号为【{0}】的零件编号【{1}】零件表里无数据,无法导入!", p_excel.订单编号,p_excel.零件号 ));
|
|
//}
|
|
|
|
var _checkpart = db.TA_PART.FirstOrDefault(p => p.PartCode == p_excel.零件号.Trim()&&p.Site== site);
|
|
if (_checkpart != null)
|
|
{
|
|
if (_checkpart.State.ToUpper() != "SP")
|
|
{
|
|
p_excel.单位 = _checkpart.Unit;
|
|
}
|
|
else
|
|
{
|
|
ErrorList.Add(string.Format("订单编号为【{0}】的零件编号【{1}】零件表零件停用,无法导入!", p_excel.订单编号, p_excel.零件号));
|
|
}
|
|
}
|
|
var _checkpart1= db.TA_PART.Count(p => p.PartCode == p_excel.零件号.Trim() && p.Site == site);
|
|
if (_checkpart1 == 0)
|
|
{
|
|
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.数量) ||
|
|
string.IsNullOrEmpty(p_excel.税率))
|
|
{
|
|
ErrorList.Add(string.Format("分组【{1}】零件名称【{0}】有填写为空!", p_excel.零件号, p_excel.订单编号));
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(p_excel.备注)&&p_excel.备注.Length > 50)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的备注长度必须小于50", 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.订单编号));
|
|
}
|
|
}
|
|
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.零件号.Trim() && 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.零件号.Trim());
|
|
if (linecount > 0)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】已经存在,请更换行号!", p_excel.订单编号, p_excel.行号));
|
|
}
|
|
var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件号.Trim() && p.Site == site && p.SubSite == subsite && p.State != (int)PriceState.Reject && 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 (string.IsNullOrEmpty(p_excel.订单类型))
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】订单类型为空,委外订单填 S,普通订单填 M!", p_excel.订单编号, p_excel.行号));
|
|
}
|
|
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 (DateTime.Parse(p_excel.零件开始时间) > DateTime.Parse(p_excel.零件截至日期))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件截止日期不能小于零件开始日期!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件开始时间) < DateTime.Parse(p_excel.订单创建时间))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件开始时间不能小于订单创建时间!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件截至日期) > DateTime.Parse(p_excel.要求到货日期))
|
|
//{
|
|
// 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.订单编号))
|
|
//{
|
|
// 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("订单编号为空!"));
|
|
//}
|
|
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
|
|
{
|
|
if (!string.IsNullOrEmpty(p_excel.备注) && p_excel.备注.Length > 50)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的备注长度必须小于50", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
decimal a = decimal.Parse(p_excel.数量);
|
|
if (a <= 0)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的数量不能小于等于0", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_excel.零件截至日期))
|
|
{
|
|
DateTime year = DateTime.Parse(p_excel.零件截至日期);
|
|
if (year.Year > 2049)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的零件截止日期必须大于等于2049年!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(p_excel.订单截至日期))
|
|
{
|
|
DateTime year =DateTime.Parse(p_excel.订单截至日期);
|
|
if (year.Year > 2049)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单截止日期必须大于等于2049年!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
}
|
|
var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件号.Trim() && p.Site == site && p.SubSite == subsite && p.State == (int)PriceState.FConfirm && 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 (DateTime.Parse(p_excel.零件开始时间) > DateTime.Parse(p_excel.零件截至日期))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件截止日期不能小于零件开始日期!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件开始时间) < DateTime.Parse(p_excel.订单创建时间))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件开始时间不能小于订单创建时间!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件截至日期) > DateTime.Parse(p_excel.要求到货日期))
|
|
//{
|
|
// 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_Po_CQ(ScpEntities db, SCP_PO_EXPORT_IMPORT_MODEL p_excel, BillModType p_modtype, string site , string subsite )
|
|
{
|
|
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 _checkpartcode = db.TA_PART.Count(p => p.PartCode == p_excel.零件号&&p.State.ToUpper()!="SP");
|
|
//if (_checkpartcode == 0)
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号为【{0}】的零件编号【{1}】零件表里无数据,无法导入!", p_excel.订单编号,p_excel.零件号 ));
|
|
//}
|
|
|
|
var _checkpart = db.TA_PART.FirstOrDefault(p => p.PartCode == p_excel.零件号.Trim()&&p.Site== site);
|
|
if (_checkpart != null)
|
|
{
|
|
if (_checkpart.State.ToUpper() != "SP")
|
|
{
|
|
p_excel.单位 = _checkpart.Unit;
|
|
}
|
|
else
|
|
{
|
|
ErrorList.Add(string.Format("订单编号为【{0}】的零件编号【{1}】零件表零件停用,无法导入!", p_excel.订单编号, p_excel.零件号));
|
|
}
|
|
}
|
|
var _checkpart1 = db.TA_PART.Count(p => p.PartCode == p_excel.零件号.Trim() && p.Site == site);
|
|
if (_checkpart1 == 0)
|
|
{
|
|
|
|
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.数量) ||
|
|
string.IsNullOrEmpty(p_excel.税率))
|
|
{
|
|
ErrorList.Add(string.Format("分组【{1}】零件名称【{0}】有填写为空!", p_excel.零件号, p_excel.订单编号));
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(p_excel.备注) && p_excel.备注.Length > 50)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的备注长度必须小于50", 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 pode = db.TB_PO_DETAIL.Count(p=>p.PoBillNum== p_excel.订单编号&&p.PartCode==p_excel.零件号.Trim());
|
|
if (pode > 0)
|
|
{
|
|
ErrorList.Add(string.Format("订单号【{1}】零件号【{0}】已存在!", 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.零件号.Trim() && 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.零件号.Trim());
|
|
if (linecount > 0)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】已经存在,请更换行号!", p_excel.订单编号, p_excel.行号));
|
|
}
|
|
var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件号.Trim() && p.Site == site && p.SubSite == subsite && p.State != (int)PriceState.Reject && 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.零件号.Trim(), 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 (DateTime.Parse(p_excel.零件开始时间) > DateTime.Parse(p_excel.零件截至日期))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件截止日期不能小于零件开始日期!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件开始时间) < DateTime.Parse(p_excel.订单创建时间))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件开始时间不能小于订单创建时间!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件截至日期) > DateTime.Parse(p_excel.要求到货日期))
|
|
//{
|
|
// 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.订单编号))
|
|
//{
|
|
// 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("订单编号为空!"));
|
|
//}
|
|
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
|
|
{
|
|
if (!string.IsNullOrEmpty(p_excel.备注) && p_excel.备注.Length > 50)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的备注长度必须小于50", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
decimal a = decimal.Parse(p_excel.数量);
|
|
if (a <= 0)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的数量不能小于等于0", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_excel.零件截至日期))
|
|
{
|
|
DateTime year = DateTime.Parse(p_excel.零件截至日期);
|
|
if (year.Year > 2049)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的零件截止日期必须大于等于2049年!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(p_excel.订单截至日期))
|
|
{
|
|
DateTime year = DateTime.Parse(p_excel.订单截至日期);
|
|
if (year.Year > 2049)
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】的订单截止日期必须大于等于2049年!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
}
|
|
}
|
|
var checkcount = db.TB_PRICE.Where(p => p.PartCode == p_excel.零件号.Trim() && p.Site == site && p.SubSite == subsite && p.State == (int)PriceState.FConfirm && 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 (DateTime.Parse(p_excel.零件开始时间) > DateTime.Parse(p_excel.零件截至日期))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件截止日期不能小于零件开始日期!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件开始时间) < DateTime.Parse(p_excel.订单创建时间))
|
|
//{
|
|
// ErrorList.Add(string.Format("订单编号【{2}】零件名称【{0}】供应编码【{1}】零件开始时间不能小于订单创建时间!", p_excel.零件号, p_excel.供应商编号, p_excel.订单编号));
|
|
//}
|
|
//if (DateTime.Parse(p_excel.零件截至日期) > DateTime.Parse(p_excel.要求到货日期))
|
|
//{
|
|
// 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;
|
|
}
|
|
/// <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 => new { 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.SubSite = _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 = _entity.计划员;
|
|
_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 = _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.零件编码;
|
|
_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.Site = _ask.Site;
|
|
_t_ASK_Detail.SubSite = _ask.SubSite;
|
|
_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;
|
|
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="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_BJMS(List<SCP_PO_DETAIL_EXPORT_MODEL> p_order_list, string p_creator, string str1, 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 => new { 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.SubSite = _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;
|
|
_ask.Extend1 = str1;
|
|
_ask.Remark = _entity.备注;
|
|
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<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 = _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.零件编码;
|
|
_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.Site = _ask.Site;
|
|
_t_ASK_Detail.SubSite = _ask.SubSite;
|
|
_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;
|
|
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 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.零件号.Trim() == p.零件号 && itm.域 == p.域);
|
|
if (_count > 1)
|
|
{
|
|
lineError.Add(string.Format("导入的域{2}供应商{0}零件编号{1}有重复", p.供应商代码, p.零件号, p.域));
|
|
ErrorList = lineError;
|
|
}
|
|
});
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _ls = CheckExcelMode_VenderPart(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
|
|
{
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _venderpart = db.TA_VEND_PART.SingleOrDefault(t => t.VendId == p.供应商代码.ToUpper() && t.PartCode == p.零件号.ToUpper() && t.Site == p.域) ??
|
|
new TA_VEND_PART
|
|
{
|
|
VendId = p.供应商代码.ToUpper(),
|
|
PartCode = p.零件号.ToUpper(),
|
|
State = 1,
|
|
CreateTime = DateTime.Now,
|
|
CreateUser = p_creator,
|
|
IsDeleted = false,
|
|
GUID = System.Guid.NewGuid(),
|
|
Site = p.域,
|
|
};
|
|
_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.VendPartCode = p.供应商零件号.ToUpper();
|
|
_venderpart.UpdateTime = DateTime.Now;
|
|
_venderpart.UpdateUser = p_creator;
|
|
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 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("导入零件域{1}编号{0}有重复", p.供应商编号, p.域));
|
|
ErrorList = lineError;
|
|
}
|
|
});
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _ls = CheckExcelMode_Vender(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
|
|
{
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _vender = db.TA_VENDER.SingleOrDefault(t => t.VendId == p.供应商编号.ToUpper() && t.Site == p.域) ??
|
|
new TA_VENDER { VendId = p.供应商编号.ToUpper(), State = 1, Site = p.域 };
|
|
_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.税率);
|
|
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;
|
|
}
|
|
public static List<string> CheckMode_MoldSharing(ScpEntities db, SCP_PRICE_EXPORT p_excel)
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
int count = db.TA_MoldSharing.Count(p => p.VendId == p_excel.供应商编号.ToUpper() && p.Site == p_excel.域 && p.PartCode == p_excel.零件编码.Trim().ToUpper() && p.Count != 0);
|
|
if (count > 0)
|
|
{
|
|
ErrorList.Add(string.Format("供应商{0}零件编码{1}已存在分摊数据,不可修改分摊价格和数量!", p_excel.供应商编号, p_excel.零件编码));
|
|
}
|
|
return ErrorList;
|
|
}
|
|
/// <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 p_createuser, List<String> p_rolelist)
|
|
{
|
|
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;
|
|
int _state = (int)PriceState.New;
|
|
_lst.ForEach
|
|
(p =>
|
|
{
|
|
var _count = _lst.Count(itm => itm.域 == p.域 && itm.地点 == p.地点 && itm.供应商编号 == p.供应商编号 && itm.零件编码.Trim() == p.零件编码.Trim());
|
|
if (_count > 1)
|
|
{
|
|
lineError.Add(string.Format("导入的模板供应商编号{0}零件编号{3}有重复,请修改时间!", p.供应商编号, p.开始时间, p.结束时间, p.零件编码.Trim()));
|
|
ErrorList = lineError;
|
|
}
|
|
|
|
var _ls = CheckExcelMode_Price(db, p);
|
|
if (_ls.Count > 0)
|
|
{
|
|
lineError.Add(number.ToString());
|
|
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
|
|
}
|
|
number++;
|
|
});
|
|
var _sharinglist = _lst.Where(t => !string.IsNullOrEmpty(t.供应商编号) && !string.IsNullOrEmpty(t.零件编码.Trim()) && t.累计分摊价格 != "0" && t.累计分摊数量 != "0" && !string.IsNullOrEmpty(t.累计分摊价格) && !string.IsNullOrEmpty(t.累计分摊数量)).ToList().DistinctBy(x => new { x.供应商编号, x.零件编码, x.累计分摊价格, x.累计分摊数量, x.域 }).ToList();
|
|
if (_sharinglist.Count > 0)
|
|
{
|
|
_sharinglist.ForEach(p =>
|
|
{
|
|
var _ls = CheckMode_MoldSharing(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
|
|
{
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _price = new TB_PRICE();
|
|
string starttime = DateTime.Parse(p.开始时间).ToShortDateString();
|
|
string endtime = DateTime.Parse(p.结束时间).ToShortDateString();
|
|
DateTime st = DateTime.Parse(p.开始时间);
|
|
|
|
DateTime et = DateTime.Parse(p.结束时间);
|
|
#region 201909011修改
|
|
var _Site = new SqlParameter("@Site", p.域);
|
|
var _SubSite = new SqlParameter("@SubSite", p.地点);
|
|
var _VendId = new SqlParameter("@VendId", p.供应商编号);
|
|
var _PartCode = new SqlParameter("@PartCode", p.零件编码.Trim());
|
|
string sqlString = "select * from tb_price where uid in\n" +
|
|
"(\n" +
|
|
" select max(uid) uid\n" +
|
|
" from tb_price WHERE\n" +
|
|
" state<>-1 and Site=@Site AND SubSite=@SubSite AND VendId =@VendId AND PartCode=@PartCode \n" +
|
|
" group by vendid,partcode,subsite,site\n" +
|
|
") ";
|
|
var updaet_price = db.Database.SqlQuery<TB_PRICE>(sqlString, _Site, _SubSite, _VendId, _PartCode).FirstOrDefault();
|
|
#endregion
|
|
if (updaet_price != null && updaet_price.StartTime.Value == st)
|
|
{
|
|
_price = updaet_price;
|
|
}
|
|
_price.State = _state;
|
|
_price.VendId = p.供应商编号.Trim();
|
|
_price.PartCode = p.零件编码.Trim();
|
|
_price.StartTime = DateTime.Parse(starttime);
|
|
_price.EndTime = DateTime.Parse(endtime);
|
|
_price.Curr = p.币种;
|
|
_price.Unit = p.单位;
|
|
_price.Amt = decimal.Parse(p.零件基础价格);
|
|
_price.Site = p.域.Trim();
|
|
_price.SubSite = p.地点.Trim();
|
|
_price.Remarks = p.备注;
|
|
_price.TemporaryPrice = Int32.Parse(p.是否临时价格);
|
|
_price.Creator = p_createuser;
|
|
_price.IsPost = 0;
|
|
|
|
_price.EndTime = (_price.EndTime > DateTime.Parse("2049-12-31")) ? DateTime.Parse("2049-12-31") : _price.EndTime;
|
|
|
|
//_price.IsDeleted = false;
|
|
//_price.CreateUser = p_createuser;
|
|
//_price.CreateTime = DateTime.Now;
|
|
//_price.GUID = Guid.NewGuid();
|
|
db.TB_PRICE.AddOrUpdate(_price);
|
|
});
|
|
_sharinglist.ForEach(p =>
|
|
{
|
|
var _moldsharing = db.TA_MoldSharing.SingleOrDefault(t => t.VendId == p.供应商编号.ToUpper() && t.PartCode == p.零件编码.Trim().ToUpper() && t.Site == p.域) ??
|
|
new TA_MOLDSHARING
|
|
{
|
|
VendId = p.供应商编号.ToUpper().Trim(),
|
|
PartCode = p.零件编码.ToUpper().Trim(),
|
|
CreateTime = DateTime.Now,
|
|
CreateUser = p_createuser,
|
|
IsDeleted = false,
|
|
Count = 0,
|
|
};
|
|
_moldsharing.Price = decimal.Round((decimal.Parse(p.累计分摊价格) / decimal.Parse(p.累计分摊数量)), 2);
|
|
_moldsharing.Qty = decimal.Parse(p.累计分摊数量);
|
|
_moldsharing.UpdateTime = DateTime.Now;
|
|
_moldsharing.UpdateUser = p_createuser;
|
|
_moldsharing.TotalPrice = decimal.Parse(p.累计分摊价格);
|
|
_moldsharing.Site = p.域;
|
|
db.TA_MoldSharing.AddOrUpdate(_moldsharing);
|
|
});
|
|
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);
|
|
_ret.MessageList.Add(e.Message);
|
|
//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 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("导入零件域{1}编号{0}有重复", p.零件编号, p.域));
|
|
ErrorList = lineError;
|
|
}
|
|
});
|
|
_lst.ForEach
|
|
(p =>
|
|
{
|
|
var _ls = CheckExcelMode_Part(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
|
|
{
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _part = db.TA_PART.SingleOrDefault(t => t.PartCode == p.零件编号.ToUpper() && t.Site == p.域) ??
|
|
new TA_PART { PartCode = p.零件编号.ToUpper(), Site = p.域 };
|
|
_part.PartCode = p.零件编号;
|
|
_part.ErpPartCode = p.零件编号;
|
|
_part.PartDesc1 = p.零件名称;
|
|
_part.PartDesc2 = "";
|
|
_part.ProjectId = p.项目编号;
|
|
_part.Unit = p.单位;
|
|
_part.PartGroup = p.零件类型;
|
|
_part.State = p.状态;
|
|
_part.Remark = p.备注;
|
|
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;
|
|
}
|
|
public static ResultObject<bool> EXCEL_PRICE_MOD1(List<SCP_PRICE_EXPORT> p_order_list, string p_createuser, List<String> p_rolelist)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
int number = 1;
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
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.零件编码.Trim() == p.零件编码.Trim());
|
|
if (_count > 1)
|
|
{
|
|
lineError.Add(string.Format("导入的模板供应商编号{0}零件编号{3}有重复,请修改时间!", p.供应商编号, p.开始时间, p.结束时间, p.零件编码));
|
|
ErrorList = lineError;
|
|
}
|
|
|
|
});
|
|
|
|
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _ls = CheckExcelMode_Vender1(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
|
|
{
|
|
|
|
_lst.ForEach(p =>
|
|
{
|
|
string starttime = Convert.ToDateTime(p.最新开始时间).ToShortDateString();
|
|
string endtime = Convert.ToDateTime(p.最新结束时间).ToShortDateString();
|
|
var _vender = db.TB_PRICE.SingleOrDefault(t => t.VendId == p.供应商编号.ToUpper() && t.PartCode == p.零件编码.Trim() && t.UID.ToString() == p.标识 && t.SubSite == p.地点 && t.Site == p.域);
|
|
if (_vender == null)
|
|
{
|
|
lineError.Add(string.Format("供应商编号{0}零件编号{3}数据不存在", p.供应商编号, p.开始时间, p.结束时间, p.零件编码.Trim()));
|
|
ErrorList = lineError;
|
|
}
|
|
if (DateTime.Parse(p.最新开始时间)< DateTime.Parse(p.结束时间) && DateTime.Parse(p.最新开始时间) >DateTime.Parse(p.开始时间))
|
|
{
|
|
|
|
_vender.EndTime = Convert.ToDateTime(DateTime.Parse(starttime).AddDays(-1));
|
|
_vender.Extend3 = "价格表修改";
|
|
var _PR = db.V_TB_PRICE.FirstOrDefault(t => t.VendId == p.供应商编号.ToUpper() && t.PartCode == p.零件编码.Trim() && t.UID.ToString() == p.标识 && t.SubSite == p.地点 && t.Site == p.域);
|
|
if (_PR != null)
|
|
{
|
|
TS_UNI_API TS = new TS_UNI_API();
|
|
TS.InterfaceType = "Price";
|
|
TS.BillNum = (_PR.VendId + _PR.SubSite.Substring(1, 1) + _PR.SubSite.Substring(3, 1)).Trim();
|
|
TS.PartCode = _PR.PartCode;
|
|
if (_PR.TemporaryPrice == 0)
|
|
{
|
|
TS.Batch = "No";
|
|
}
|
|
else
|
|
{
|
|
TS.Batch = "Yes";
|
|
}
|
|
TS.Qty = _PR.Amt + _PR.SharingPrice;
|
|
TS.Price = _PR.Amt;
|
|
TS.State = 1;
|
|
TS.ValidDate = DateTime.Now;
|
|
TS.ErpLineNum = 1;
|
|
TS.Domain = _PR.Site;//域
|
|
TS.Site = _PR.SubSite;//地点
|
|
TS.Extend1 = _PR.Remarks;
|
|
TS.CreateTime = Convert.ToDateTime(_PR.StartTime);//开始时间
|
|
TS.PutTime = Convert.ToDateTime(DateTime.Parse(starttime).AddDays(-1));//结束时间
|
|
TS.CreateOper = _PR.Creator;
|
|
TS.Currency = _PR.Curr;//货币
|
|
var _first = db.TA_PART.Where(itm => itm.PartCode == p.零件编码.Trim()).FirstOrDefault();
|
|
if (_first != null)
|
|
{
|
|
TS.PoUnit = _first.Unit;
|
|
}
|
|
else
|
|
{
|
|
TS.PoUnit = _PR.Unit;//单位
|
|
}
|
|
db.TS_UNI_API.Add(TS);
|
|
}
|
|
|
|
db.TB_PRICE.AddOrUpdate(_vender);
|
|
}
|
|
TB_PRICE tb = new TB_PRICE();
|
|
tb.State = 0;
|
|
tb.Extend3 = "价格表修改增加";
|
|
tb.VendId = p.供应商编号;
|
|
tb.PartCode = p.零件编码.Trim();
|
|
tb.Curr = p.币种;
|
|
tb.Unit = p.单位;
|
|
tb.Remarks = p.备注;
|
|
tb.Amt = Convert.ToDecimal(p.零件最新价格);
|
|
tb.Site = p.域;
|
|
tb.SubSite = p.地点;
|
|
tb.StartTime = Convert.ToDateTime(starttime);
|
|
tb.EndTime = Convert.ToDateTime(endtime);
|
|
tb.Creator = p_createuser;
|
|
tb.IsPost = 0;
|
|
tb.TemporaryPrice = Int32.Parse(p.是否临时价格);
|
|
db.TB_PRICE.Add(tb);
|
|
});
|
|
|
|
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
|
|
db.BulkSaveChanges();
|
|
|
|
_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);
|
|
_ret.MessageList.Add(e.Message);
|
|
//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, BillModType p_modtype, 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;
|
|
_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.零件号.Trim() == p.零件号.Trim() && 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, p_modtype,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
|
|
{
|
|
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.订单编号;
|
|
_po.ErpBillNum = _entity.订单编号;
|
|
_po.VendId = _entity.供应商编号.ToUpper();
|
|
_po.ModType = (int)p_modtype;
|
|
_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;
|
|
_po.SubSite = subsite;
|
|
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.零件号.Trim();
|
|
_PO_Detail.BeginTime = DateTime.Parse(itm.零件开始时间);
|
|
_PO_Detail.EndTime = DateTime.Parse(itm.零件截至日期);
|
|
_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();
|
|
_PO_Detail.SubSite = subsite;
|
|
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 ResultObject<bool> Check_PO_ASK(List<string> p_list)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
var _ls = db.TB_ASK.Where(p => p_list.Contains(p.PoBillNum) && p.IsDeleted == false).ToList();
|
|
if (_ls.Count > 0)
|
|
{
|
|
var polist = _ls.Select(p => p.PoBillNum).Distinct().ToList();
|
|
polist.ForEach(t =>
|
|
{
|
|
ErrorList.Add(string.Format("订单编号【{0}】已有要货看板无法关闭!", t));
|
|
});
|
|
}
|
|
if (ErrorList.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), "Check_PO_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), "Check_PO_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), "Check_PO_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), "Check_PO_ASK", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<bool> Check_PO_ASK_Detail(List<string> p_list, List<string> p_list1)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
foreach(var po in p_list)
|
|
{
|
|
foreach(var po1 in p_list1)
|
|
{
|
|
var _ls = db.TB_ASK_DETAIL.Count(p =>p.PoBillNum==po&&p.PartCode==po1 && p.IsDeleted == false);
|
|
if (_ls > 0)
|
|
{
|
|
ErrorList.Add("订单号【{0}】零件号【{1}】已生成看板,不能关闭");
|
|
}
|
|
}
|
|
}
|
|
if (ErrorList.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), "Check_PO_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), "Check_PO_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), "Check_PO_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), "Check_PO_ASK", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
public static ResultObject<bool> Check_PO_ASK_Close_Detail(List<string> p_list, List<string> p_list1)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
List<string> ErrorList = new List<string>();
|
|
foreach (var po in p_list)
|
|
{
|
|
foreach (var po1 in p_list1)
|
|
{
|
|
var _ls = db.TB_ASK_DETAIL.Count(p => p.PoBillNum == po && p.PartCode == po1 && p.IsDeleted == false);
|
|
if (_ls == 0)
|
|
{
|
|
ErrorList.Add("订单号【{0}】零件号【{1}】还没有对应的看板呢");
|
|
}
|
|
}
|
|
}
|
|
if (ErrorList.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), "Check_PO_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), "Check_PO_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), "Check_PO_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), "Check_PO_ASK", 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 _cl = p_order_list.GroupBy(p => new { p.订单编号, p.供应商编号, p.订单创建时间, p.要求到货日期 }).ToList();
|
|
//var _ctl = p_order_list.GroupBy(p => p.订单编号).ToList();
|
|
//if (_cl.Count != _ctl.Count)
|
|
//{
|
|
// lineError.Add("相同订单号下存在订单创建日期和要求到货日期不相同的数据!");
|
|
// ErrorList = lineError;
|
|
//}
|
|
//注释结束
|
|
var _lst = p_order_list;
|
|
var PoList = _lst.Select(itm => itm.订单编号).Distinct().ToList();
|
|
foreach (var po in PoList)
|
|
{
|
|
var vendcount = _lst.Where(itm => itm.订单编号 == po).Select(itm => itm.供应商编号).Distinct().ToList();
|
|
if (vendcount.Count() > 1)
|
|
{
|
|
lineError.Add(string.Format("导入订单编号【{0}】对应两个供应商了,麻烦修改", po));
|
|
ErrorList = lineError;
|
|
}
|
|
}
|
|
p_order_list.ForEach(p =>
|
|
{
|
|
var _count1 = _lst.Count(itm => itm.订单编号 == p.订单编号 && itm.行号 == p.行号);
|
|
var _count2 = _lst.Count(itm => itm.订单编号 == p.订单编号 && itm.零件号.Trim() == p.零件号.Trim());
|
|
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)
|
|
{
|
|
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
|
|
}
|
|
});
|
|
if (ErrorList.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;
|
|
|
|
}
|
|
public static ResultObject<bool> Check_EXCEL_PO_MOD_CQ(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 _cl = p_order_list.GroupBy(p => new { p.订单编号, p.供应商编号, p.订单创建时间, p.要求到货日期 }).ToList();
|
|
//var _ctl = p_order_list.GroupBy(p => p.订单编号).ToList();
|
|
//if (_cl.Count != _ctl.Count)
|
|
//{
|
|
// lineError.Add("相同订单号下存在订单创建日期和要求到货日期不相同的数据!");
|
|
// ErrorList = lineError;
|
|
//}
|
|
//注释结束
|
|
var _lst = p_order_list;
|
|
var VenderList = _lst.Select(itm => itm.订单编号).Distinct().ToList();
|
|
var PartCodeList = _lst.Select(itm => itm.供应商编号).Distinct().ToList();
|
|
if (VenderList.Count != PartCodeList.Count)
|
|
{
|
|
lineError.Add(string.Format("存在多个供应商编号对应一个订单号"));
|
|
ErrorList = lineError;
|
|
}
|
|
p_order_list.ForEach(p =>
|
|
{
|
|
var _count1 = _lst.Count(itm => itm.订单编号 == p.订单编号 && itm.行号 == p.行号);
|
|
var _count2 = _lst.Count(itm => itm.订单编号 == p.订单编号 && itm.零件号.Trim() == p.零件号.Trim());
|
|
|
|
|
|
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.零件号.Trim()));
|
|
ErrorList = lineError;
|
|
}
|
|
|
|
});
|
|
p_order_list.ForEach
|
|
(p =>
|
|
{
|
|
var _ls = CheckExcelMode_Po_CQ(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);
|
|
return _ret;
|
|
}
|
|
return _ret;
|
|
|
|
}
|
|
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 = "";
|
|
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.要求到货日期);
|
|
_po.Pricelist = _entity.供应商编号.ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1);
|
|
_po.Taxclass = _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.零件号.Trim() && t.PoLine == _poline && t.PoBillNum == itm.订单编号 /*&& t.State == state*/ && t.Site == site && t.SubSite == subsite) ??
|
|
new TB_PO_DETAIL { GUID = Guid.NewGuid(), PartCode = itm.零件号.Trim().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.单价);
|
|
_PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号);
|
|
_PO_Detail.PoType = itm.订单类型;
|
|
_PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序);
|
|
_PO_Detail.Location = itm.库位;
|
|
_PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数);
|
|
_PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数);
|
|
_PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数);
|
|
_PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数);
|
|
_PO_Detail.Supplieritem = itm.供应商零件.ToUpper();
|
|
_PO_Detail.Dliverypatterncode = itm.发货样式;
|
|
_PO_Detail.Deliverytimecode = itm.发货时间样式;
|
|
_PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.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();
|
|
_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.要求到货日期);
|
|
_po.Pricelist = _entity.供应商编号.ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1);
|
|
_po.Taxclass = _entity.税率;
|
|
db.TB_PO.AddOrUpdate(_po);
|
|
TB_ASK _ask = new TB_ASK();
|
|
_ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode();
|
|
_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.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号);
|
|
_PO_Detail.PoType = itm.订单类型;
|
|
_PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序);
|
|
_PO_Detail.Location = itm.库位;
|
|
_PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数);
|
|
_PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数);
|
|
_PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数);
|
|
_PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数);
|
|
_PO_Detail.Supplieritem = itm.供应商零件.Trim();
|
|
_PO_Detail.Dliverypatterncode = itm.发货样式;
|
|
_PO_Detail.Deliverytimecode = itm.发货时间样式;
|
|
_PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.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("ERP订单编号已存在,请重新导入!");
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
int state = db.SaveChanges();
|
|
if (state != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = true;
|
|
_ret.Message = _polist;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
{
|
|
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
{
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
});
|
|
}
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", sb.ToString());
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
}
|
|
catch (ScpException ex)
|
|
{
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", ex.ToString());
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
{
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "EXCEL_PO_MOD", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
|
|
}
|
|
public static 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.零件号.Trim().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())
|
|
{
|
|
//foreach (var itm in p_order_list)
|
|
//{
|
|
|
|
// var checkcount = db.TB_PRICE.Where(p => p.PartCode == itm.PartCode && p.Site == itm.Site && p.SubSite == itm.SubSite && p.State == (int)PriceState.FConfirm && p.VendId == itm.VendId && p.StartTime <= DateTime.Now && DateTime.Now <= p.EndTime).ToList();
|
|
// if (checkcount.Count == 0)
|
|
// {
|
|
|
|
// _ret.MessageList.Add(string.Format("零件名称【{0}】供应编码【{1}】价格表没有信息或没财务审核!", itm.PartCode,p_order.VendId ));
|
|
// }
|
|
// else
|
|
// {
|
|
// itm.Price = checkcount[0].Amt;
|
|
// }
|
|
//}
|
|
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.Remark = p_order.Remark;
|
|
_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;
|
|
_t.SubSite = p_order.SubSite;
|
|
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.SubSite = itm.SubSite;
|
|
_tDetail.Site = itm.Site;
|
|
_tDetail.Price = itm.Price;
|
|
_tDetail.Remark = itm.Remark;
|
|
_tDetail.GUID = Guid.NewGuid();
|
|
_tDetail.Currency = itm.Currency;
|
|
db.TB_ASK_DETAIL.Add(_tDetail);
|
|
var _order_detail = db.TB_PO_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
|
|
_order_detail.TempQty = itm.TempQty;
|
|
db.TB_PO_DETAIL.AddOrUpdate(p => p.UID, _order_detail);
|
|
}
|
|
int state = db.SaveChanges();
|
|
if (state != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = true;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
{
|
|
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
{
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
});
|
|
}
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", sb.ToString());
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
}
|
|
catch (ScpException ex)
|
|
{
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", ex.ToString());
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
{
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PO_CONTROLLER), "Save_PO_TO_ASK", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
|
|
public static ResultObject<bool> Save_PO_TO_ASK_CQ(V_TB_PO p_order, List<V_TB_PO_DETAIL> p_order_list, string p_buyer, string p_buyerPhone, string p_creator,string remark,string Ssite)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
//foreach (var itm in p_order_list)
|
|
//{
|
|
|
|
// var checkcount = db.TB_PRICE.Where(p => p.PartCode == itm.PartCode && p.Site == itm.Site && p.SubSite == itm.SubSite && p.State == (int)PriceState.FConfirm && p.VendId == itm.VendId && p.StartTime <= DateTime.Now && DateTime.Now <= p.EndTime).ToList();
|
|
// if (checkcount.Count == 0)
|
|
// {
|
|
|
|
// _ret.MessageList.Add(string.Format("零件名称【{0}】供应编码【{1}】价格表没有信息或没财务审核!", itm.PartCode,p_order.VendId ));
|
|
// }
|
|
// else
|
|
// {
|
|
// itm.Price = checkcount[0].Amt;
|
|
// }
|
|
//}
|
|
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.State = (int)AskState.New;
|
|
_t.Remark = remark;
|
|
_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;
|
|
_t.SubSite = p_order.SubSite;
|
|
_t.Extend1 = Ssite;
|
|
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 = 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.SubSite = itm.SubSite;
|
|
_tDetail.Site = itm.Site;
|
|
if (itm.Site == "BJBMPT")
|
|
{
|
|
var price = db.TB_PRICE.Where(p => p.PartCode == itm.PartCode&&p.State>-1&&p.VendId== p_order.VendId).Max(p => p.UID);
|
|
var pri = db.TB_PRICE.FirstOrDefault(t=>t.UID==price);
|
|
_tDetail.Price = pri.Amt;
|
|
}
|
|
else
|
|
{
|
|
_tDetail.Price = itm.Price;
|
|
}
|
|
|
|
_tDetail.Remark = itm.Remark;
|
|
_tDetail.GUID = Guid.NewGuid();
|
|
_tDetail.Currency = itm.Currency;
|
|
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 (p_entity.UserInSubSite != null && p_entity.UserInSubSite.Count > 0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInSubSite.Contains(p.SubSite));
|
|
}
|
|
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInVendIds.Contains(p.VendId));
|
|
}
|
|
_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.FirstOrDefault() != null && p_entity.UserInAddress.Count > 0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
|
|
}
|
|
if (p_entity.UserInSubSite != null && p_entity.UserInSubSite.Count > 0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInSubSite.Contains(p.SubSite));
|
|
}
|
|
_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
|
|
|
|
public static List<V_TB_ASK_DETAIL_PO> LOAD_ASK_DETAIL_PO_SUM(List<V_TB_ASK_DETAIL_PO> p_list)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
if (p_list.Count > 0)
|
|
{
|
|
foreach (V_TB_ASK_DETAIL_PO _detail in p_list)
|
|
{
|
|
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 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, p.SubSite }).Select(p => new { ArriveSum = p.Sum(itm => itm.Qty), PoLine = p.Key.PoLine, PoBillNum = p.Key.PoBillNum, PartCode = p.Key.PartCode, Subsite = p.Key.SubSite });
|
|
|
|
rec.ToList().ForEach(itm =>
|
|
{
|
|
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
{
|
|
_detail.ReceivedQty = itm.ReceiveSum;
|
|
}
|
|
});
|
|
|
|
asn.ToList().ForEach(itm =>
|
|
{
|
|
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode)
|
|
{
|
|
_detail.ShippedQty = itm.AsSum;
|
|
}
|
|
});
|
|
|
|
arrive.ToList().ForEach(itm =>
|
|
{
|
|
if (_detail.PoBillNum == itm.PoBillNum && _detail.PoLine == itm.PoLine && _detail.PartCode == itm.PartCode && _detail.SubSite == itm.Subsite)
|
|
{
|
|
_detail.ArriveQty = itm.ArriveSum;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|
|
return p_list;
|
|
}
|
|
}
|
|
}
|
|
|