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.

5573 lines
284 KiB

1 year ago
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;
using System.Security.Policy;
using System.ComponentModel;
1 year ago
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);
}
1 year ago
//if (p_entity.UserInAddress.FirstOrDefault() != null && p_entity.UserInAddress.Count > 0)
//{
// q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
//}
1 year ago
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.SubSite))
{
q = q.Where(p => p.SubSite == p_entity.SubSite);
}
1 year ago
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;
}
1 year ago
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
{
1 year ago
if (p_excel. != "CNY" && p_excel. != "EUR" && p_excel. != "USD")
1 year ago
{
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.
1 year ago
&& p.Amt == st4 && p.SubSite == p_excel. &&p.Curr==p_excel.&&p.Unit==p_excel.
1 year ago
);
if (Th == null)
{
ErrorList.Add(string.Format("标识【{0}】供应商编号【{1}】的导出数据不能修改!", p_excel., p_excel.));
}
else
{
1 year ago
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.));
}
1 year ago
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
{
1 year ago
if (p_excel. != "CNY"&& p_excel. != "EUR" && p_excel. != "USD")
1 year ago
{
1 year ago
ErrorList.Add(string.Format("供应商编号为【{0}】的零件编号【{1}】币种填写错误,只能是CNY或者EUR或者USD!", p_excel., p_excel.));
1 year ago
}
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();
1 year ago
if (_first == null)
{
ErrorList.Add(string.Format("供应商编号为【{0}】的零件编号【{1}】零件表里无数据,无法导入!", p_excel., p_excel.));
}
else
{
p_excel. = _first.Unit;
1 year ago
if (_first.State == "SP")
{
ErrorList.Add(string.Format("零件编号【{0}】状态为SP,无法导入!", p_excel.));
}
1 year ago
}
1 year ago
1 year ago
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.));
}
1 year ago
1 year ago
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());
1 year ago
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.零件编码));
//}
1 year ago
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();
1 year ago
1 year ago
if (_price != null)
{
1 year ago
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.零件编码));
// }
1 year ago
1 year ago
//}
1 year ago
}
1 year ago
1 year ago
}
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);
1 year ago
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);
1 year ago
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.));
}
}
if (!string.IsNullOrEmpty(subsite))
1 year ago
{
switch (subsite)
{
case "BJ01":
string bj01ponum = p_excel..ToUpper() + "J1";
string bj01newponum = p_excel..ToUpper() + "B1";
if (p_excel..ToUpper() != bj01ponum.ToUpper() && p_excel..ToUpper() != bj01newponum.ToUpper())
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】零件号【{2}】的订单编号不正确,请更换订单编号!", p_excel., p_excel., p_excel.));
}
break;
case "BJ02":
string bj02ponum = p_excel..ToUpper() + "J2";
string bj02newponum = p_excel..ToUpper() + "B2";
if (p_excel..ToUpper() != bj02ponum.ToUpper() && p_excel..ToUpper() != bj02newponum.ToUpper())
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】零件号【{2}】的订单编号不正确,请更换订单编号!", p_excel., p_excel., p_excel.));
}
break;
case "CQ01":
string cq01ponum = p_excel..ToUpper() + "Q1";
string cq01newponum = p_excel..ToUpper() + "Q2";
if (p_excel..ToUpper() != cq01ponum.ToUpper() || p_excel..ToUpper() != cq01newponum.ToUpper())
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】零件号【{2}】的订单编号不正确,请更换订单编号!", p_excel., p_excel., p_excel.));
}
break;
case "ZZ01":
string zz01ponum = p_excel..ToUpper() + "Z1";
string zz01newponum = p_excel..ToUpper() + "Z2";
if (p_excel..ToUpper() != zz01ponum.ToUpper() && p_excel..ToUpper() != zz01newponum.ToUpper())
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】零件号【{2}】的订单编号不正确,请更换订单编号!", p_excel., p_excel., p_excel.));
}
break;
case "HF01":
string hf01ponum = p_excel..ToUpper() + "F1";
string hf01newponum = p_excel..ToUpper() + "F2";
if (p_excel..ToUpper() != hf01ponum.ToUpper() && p_excel..ToUpper() != hf01newponum.ToUpper())
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】零件号【{2}】的订单编号不正确,请更换订单编号!", p_excel., p_excel., p_excel.));
}
break;
}
1 year ago
}
else
{
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.));
}
}
1 year ago
int _polinr = Int32.Parse(p_excel.);
if (string.IsNullOrEmpty(subsite))
1 year ago
{
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));
}
1 year ago
}
// 判断北汽多次导入 是否存在零件号重复现象
else
{
var _partlist = db.V_TB_PO_DETAIL.Where(p => p.VendId == p_excel..Trim()&&p.SubSite == subsite && p.PartCode == p_excel..Trim()).ToList();
if (_partlist.Count > 0)
{
var pobillnum = db.V_TB_PO_DETAIL.FirstOrDefault(p => p.VendId == p_excel..Trim() && p.SubSite == subsite && p.PartCode == p_excel..Trim()).PoBillNum;
ErrorList.Add(string.Format("订单编号【{0}】零件号【{1}】在【{2}】中存在,请更换零件号!", p_excel., p_excel., pobillnum));
}
int lcount = db.V_TB_PO_DETAIL.Count(p => p.VendId == p_excel..Trim() && p.PoLine == _polinr && p.SubSite == subsite && p.PartCode == p_excel..Trim());
if (lcount > 0)
{
var pobillnum = db.V_TB_PO_DETAIL.FirstOrDefault(p => p.VendId == p_excel..Trim() && p.SubSite == subsite && p.PoLine == _polinr && p.PartCode == p_excel..Trim()).PoBillNum;
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】在【{2}】订单中已经存在,请更换行号!", p_excel., p_excel.,pobillnum));
}
}
int linecount = db.V_TB_PO_DETAIL.Count(p => p.PoBillNum == p_excel. && p.PoLine == _polinr && p.PartCode != p_excel..Trim());
1 year ago
if (linecount > 0)
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】已经存在,请更换行号!", p_excel., p_excel.));
}
int partcodeCount = db.TB_PO_DETAIL.Count(p => p.PoBillNum == p_excel. && p.PoLine == _polinr && p.PartCode == p_excel..Trim());
if (partcodeCount > 0)
{
ErrorList.Add(string.Format("订单编号【{0}】零件号【{1}】行号【{2}】已经存在", 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.Reject && p.VendId == p_excel. && p.StartTime <= DateTime.Now && DateTime.Now <= p.EndTime).ToList();
if (checkcount.Count() == 0)
1 year ago
{
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;
}
1 year ago
if (string.IsNullOrEmpty(p_excel.))
{
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】订单类型为空,委外订单填 S,普通订单填 M!", p_excel., p_excel.));
}
1 year ago
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.));
}
1 year ago
//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.订单编号));
// }
// //注释结束
1 year ago
1 year ago
//}
1 year ago
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)
1 year ago
{
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);
1 year ago
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);
1 year ago
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());
1 year ago
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));
//}
var _partlist = db.V_TB_PO_DETAIL.Where(p => p.VendId == p_excel..Trim() && p.SubSite == subsite && p.PartCode == p_excel..Trim()).ToList();
1 year ago
if (_partlist.Count > 0)
{
var pobillnum = db.V_TB_PO_DETAIL.FirstOrDefault(p => p.VendId == p_excel..Trim() && p.SubSite == subsite && p.PartCode == p_excel..Trim()).PoBillNum;
ErrorList.Add(string.Format("订单编号【{0}】零件号【{1}】在【{2}】中存在,请更换零件号!", p_excel., p_excel., pobillnum));
}
int lcount = db.V_TB_PO_DETAIL.Count(p => p.VendId == p_excel..Trim() && p.PoLine == _polinr && p.SubSite == subsite && p.PartCode == p_excel..Trim());
if (lcount > 0)
{
var pobillnum = db.V_TB_PO_DETAIL.FirstOrDefault(p => p.VendId == p_excel..Trim() && p.SubSite == subsite && p.PoLine == _polinr && p.PartCode == p_excel..Trim()).PoBillNum;
ErrorList.Add(string.Format("订单编号【{0}】行号【{1}】在【{2}】订单中已经存在,请更换行号!", p_excel., p_excel., pobillnum));
1 year ago
}
int linecount = db.TB_PO_DETAIL.Count(p => p.PoBillNum == p_excel. && p.PoLine == _polinr && p.PartCode != p_excel..Trim());
1 year ago
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();
1 year ago
if (checkcount.Count == 0)
{
ErrorList.Add(string.Format("零件编号【{0}】供应编码【{1}】价格表没有维护信息!", p_excel..Trim(), p_excel.));
1 year ago
}
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.));
}
1 year ago
//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.订单编号));
// }
// //注释结束
1 year ago
1 year ago
//}
1 year ago
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();
1 year ago
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;
}
1 year ago
/// <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..Trim();
1 year ago
_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;
}
1 year ago
/// <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.);
1 year ago
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);
1 year ago
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());
1 year ago
if (_count > 1)
{
lineError.Add(string.Format("导入的模板供应商编号{0}零件编号{3}有重复,请修改时间!", p., p., p., p..Trim()));
1 year ago
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();
1 year ago
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
{
List<string> PartList = _lst.Select(q => q..Trim()).ToList();
List<TA_PART> _partList = db.TA_PART.Where(q => PartList.Contains(q.PartCode)).ToList();
1 year ago
_lst.ForEach(p =>
{
var _price = new TB_PRICE();
1 year ago
string starttime = DateTime.Parse(p.).ToShortDateString();
string endtime = DateTime.Parse(p.).ToShortDateString();
1 year ago
DateTime st = DateTime.Parse(p.);
1 year ago
1 year ago
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());
1 year ago
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();
1 year ago
_price.StartTime = DateTime.Parse(starttime);
_price.EndTime = DateTime.Parse(endtime);
1 year ago
_price.Curr = p.;
_price.Unit = _partList.Where(q=>q.PartCode == p..Trim()) != null? _partList.First(q => q.PartCode == p..Trim()).Unit : p.;
1 year ago
_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.) ??
1 year ago
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());
1 year ago
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
{
List<string> PartList = _lst.Select(q => q..Trim()).ToList();
List<TA_PART> _partList = db.TA_PART.Where(q => PartList.Contains(q.PartCode)).ToList();
1 year ago
_lst.ForEach(p =>
{
1 year ago
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.);
1 year ago
if (_vender == null)
{
lineError.Add(string.Format("供应商编号{0}零件编号{3}数据不存在", p., p., p., p..Trim()));
1 year ago
ErrorList = lineError;
}
if (DateTime.Parse(p.)< DateTime.Parse(p.) && DateTime.Parse(p.) >DateTime.Parse(p.))
{
1 year ago
_vender.EndTime = Convert.ToDateTime(DateTime.Parse(starttime).AddDays(-1));
1 year ago
_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.);
1 year ago
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();
1 year ago
if (_first != null)
{
TS.PoUnit = _first.Unit;
}
else
{
TS.PoUnit = _PR.Unit;//单位
}
db.TS_UNI_API.Add(TS);
}
1 year ago
db.TB_PRICE.AddOrUpdate(_vender);
1 year ago
}
1 year ago
TB_PRICE tb = new TB_PRICE();
tb.State = 0;
tb.Extend3 = "价格表修改增加";
tb.VendId = p.;
tb.PartCode = p..Trim();
1 year ago
tb.Curr = p.;
tb.Unit = _partList.Where(q => q.PartCode == p..Trim()) != null ? _partList.First(q => q.PartCode == p..Trim()).Unit : p.;
1 year ago
tb.Remarks = p.;
tb.Amt = Convert.ToDecimal(p.);
tb.Site = p.;
tb.SubSite = p.;
1 year ago
tb.StartTime = Convert.ToDateTime(starttime);
tb.EndTime = Convert.ToDateTime(endtime);
1 year ago
tb.Creator = p_createuser;
tb.IsPost = 0;
tb.TemporaryPrice = Int32.Parse(p.);
db.TB_PRICE.Add(tb);
});
if (_ret.MessageList.Count == 0)
{
1 year ago
db.BulkSaveChanges();
1 year ago
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
1 year ago
//}
//else
//{
// _ret.State = ReturnStatus.Failed;
// _ret.Result = false;
//}
1 year ago
}
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.);
1 year ago
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,subsite);
1 year ago
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();
1 year ago
_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())
{
1 year ago
//int number = 1;
1 year ago
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;
//}
//注释结束
1 year ago
var _lst = p_order_list;
1 year ago
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;
// }
//});
1 year ago
p_order_list.ForEach(p =>
{
// 导入规则校验
1 year ago
var _ls = CheckExcelMode_Po(db, p, p_modtype, site, subsite);
if (_ls.Count > 0)
1 year ago
{
1 year ago
ErrorList.Add(string.Join("<br>", _ls.ToArray()));
1 year ago
}
1 year ago
});
var groupList = _lst.GroupBy(g => new { g., g., g. }).Where(g => g.Count() > 1).ToList();
foreach (var gl in groupList)
{
lineError.Add(string.Format("模板中【{0}】相同订单号,相同行号零件号不能重复!", gl.Key));
ErrorList = lineError;
}
1 year ago
if (ErrorList.Count > 0)
1 year ago
{
_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;
1 year ago
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;
}
1 year ago
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());
1 year ago
1 year ago
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()));
1 year ago
ErrorList = lineError;
1 year ago
}
1 year ago
});
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;
1 year ago
}
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 };
1 year ago
_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 =string.IsNullOrEmpty(itm.)? itm. :itm..ToUpper();
1 year ago
_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 = string.IsNullOrEmpty(itm.) ? itm. : itm..Trim().ToUpper();
1 year ago
_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();
1 year ago
_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 = string.IsNullOrEmpty(itm.) ? itm. : itm..Trim().ToUpper();
1 year ago
_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();
1 year ago
_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;
1 year ago
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;
}
1 year ago
_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;
}
public static List<string> GetPriceError(List<V_TB_PO_DETAIL> details,V_TB_PO po)
{
List<string> errorlist = new List<string>();
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var item in details)
{
var checkcount = db.TB_PRICE.Where(p => p.PartCode == item.PartCode && p.Site == item.Site && p.SubSite == po.SubSite && p.State == (int)PriceState.FConfirm && p.VendId == po.VendId && p.StartTime <= DateTime.Now && DateTime.Now <= p.EndTime).ToList();
if (checkcount.Count == 0)
{
errorlist.Add(string.Format("零件编号【{0}】供应编码【{1}】价格表没有维护信息!", item.PartCode.Trim(), po.VendId));
}
}
}
return errorlist;
}
1 year ago
}
}