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.
 
 
 
 
 

970 lines
41 KiB

using CK.SCP.Models;
using CK.SCP.Models.Enums;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Utils;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
namespace CK.SCP.Controller
{
public class SCP_TB_PRICE_CONTROLLER
{
public static List<TB_PRICE> Getlist()
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.TB_PRICE.ToList();
}
}
public static void Get_PRICE_List( TB_PRICE p_entity, Action<ResultObject<IQueryable<TB_PRICE>>> p_action)
{
ResultObject<IQueryable<TB_PRICE>> _ret = new ResultObject<IQueryable<TB_PRICE>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<TB_PRICE> q = db.TB_PRICE;
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
if (!string.IsNullOrEmpty(p_entity.Creator))
{
q = q.Where(p => p.Creator == p_entity.Creator);
}
if (p_entity.StartTime != null)
{
q = q.Where(p => p.StartTime >= p_entity.StartTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.EndTime <= p_entity.EndTime);
}
if (p_entity.State != 3)//3是查询所有
{
q = q.Where(p => p.State == p_entity.State);
}
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
{
var sb = new StringBuilder();
foreach (var error in dbEx.EntityValidationErrors.ToList())
{
error.ValidationErrors.ToList().ForEach(i =>
{
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
});
}
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(dbEx);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_PRICE_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_TB_PRICE_CONTROLLER), "Get_PRICE_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_TB_PRICE_CONTROLLER), "Get_PRICE_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_TB_PRICE_CONTROLLER), "Get_PRICE_List", e.Message);
throw e;
}
}
public static void Get_TB_PRICE_List(bool p_flag, V_TB_PRICE p_entity, Action<ResultObject<IQueryable<V_TB_PRICE>>> p_action)
{
ResultObject<IQueryable<V_TB_PRICE>> _ret = new ResultObject<IQueryable<V_TB_PRICE>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PRICE> q = db.V_TB_PRICE;
if (p_flag)
{
q = q.Where(p => p.Amt==0);
}
if (p_entity.UID!=0)
{
q = q.Where(p => p.UID==p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
}
if (p_entity.Amt>0)
{
q = q.Where(p => p.Amt==p_entity.Amt);
}
if (p_entity.TemporaryPrice > 0)
{
q = q.Where(p => p.TemporaryPrice == p_entity.TemporaryPrice);
}
if (p_entity.SharingPrice > 0)
{
q = q.Where(p => p.SharingPrice == p_entity.SharingPrice);
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
if (!string.IsNullOrEmpty(p_entity.Extend2))
{
q = q.Where(p => p.Extend2.Contains(p_entity.Extend2));
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
if (!string.IsNullOrEmpty(p_entity.PartName))
{
q = q.Where(p => p.PartName.Contains(p_entity.PartName));
}
if (!string.IsNullOrEmpty(p_entity.Creator))
{
q = q.Where(p => p.Creator== p_entity.Creator);
}
if (p_entity.StartTime != null)
{
q = q.Where(p => p.StartTime >= p_entity.StartTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.EndTime <= p_entity.EndTime);
}
if (p_entity.State!=3)//3是查询所有
{
q = q.Where(p => p.State == p_entity.State);
}
if (!string.IsNullOrEmpty(p_entity.SubSite))
{
q = q.Where(p => p.SubSite == p_entity.SubSite);
}
if (p_entity.UIDList != null && p_entity.UIDList.Count > 0)
{
q = q.Where(p => p_entity.UIDList.Contains(p.UID));
}
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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", sb.ToString());
if (dbEx.InnerException != null)
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List(DbEntityValidationException)", LogHelper.GetExceptionMessage(dbEx).Message);
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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", ex.Message.ToString());
if (ex.InnerException != null)
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List(OptimisticConcurrencyException)", LogHelper.GetExceptionMessage(ex).Message);
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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", ex.Message.ToString());
if (ex.InnerException != null)
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List(ScpException)", LogHelper.GetExceptionMessage(ex).Message);
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
{
var inner = (UpdateException)ex.InnerException;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", inner.Message.ToString());
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
}
else
{
if (ex.InnerException != null)
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", ex.InnerException.Message.ToString());
throw ex.InnerException;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", e.Message);
if (e.InnerException != null)
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List(Exception)", LogHelper.GetExceptionMessage(e).Message);
throw e;
}
}
public static void Get_TB_PRICEDC_List( V_TB_PRICE p_entity, Action<ResultObject<IQueryable<V_TB_PRICE>>> p_action)
{
ResultObject<IQueryable<V_TB_PRICE>> _ret = new ResultObject<IQueryable<V_TB_PRICE>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PRICE> q = db.V_TB_PRICE;
if (p_entity.UIDList != null && p_entity.UIDList.Count > 0)
{
q = q.Where(p => p_entity.UIDList.Contains(p.UID));
}
_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", e.Message);
throw e;
}
}
public static void Get_TB_PRICE_TemporaryPrice_CQ_List(bool p_flag, V_TB_PRICE_TemporaryPrice p_entity, Action<ResultObject<IQueryable<V_TB_PRICE_TemporaryPrice>>> p_action)
{
ResultObject<IQueryable<V_TB_PRICE_TemporaryPrice>> _ret = new ResultObject<IQueryable<V_TB_PRICE_TemporaryPrice>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_PRICE_TemporaryPrice> q = db.V_TB_PRICE_TemporaryPrice;
if (p_flag)
{
q = q.Where(p => p.Amt == 0);
}
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
}
if (p_entity.Amt > 0)
{
q = q.Where(p => p.Amt == p_entity.Amt);
}
if (p_entity.TemporaryPrice > 0)
{
q = q.Where(p => p.TemporaryPrice == p_entity.TemporaryPrice);
}
if (p_entity.SharingPrice > 0)
{
q = q.Where(p => p.SharingPrice == p_entity.SharingPrice);
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
if (!string.IsNullOrEmpty(p_entity.Extend2))
{
q = q.Where(p => p.Extend2.Contains(p_entity.Extend2));
}
if (!string.IsNullOrEmpty(p_entity.Extend3))
{
q = q.Where(p => p.Extend3.Contains(p_entity.Extend3));
}
if (!string.IsNullOrEmpty(p_entity.PartName))
{
q = q.Where(p => p.PartName.Contains(p_entity.PartName));
}
if (!string.IsNullOrEmpty(p_entity.Creator))
{
q = q.Where(p => p.Creator == p_entity.Creator);
}
if (p_entity.StartTime != null)
{
q = q.Where(p => p.StartTime >= p_entity.StartTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.EndTime <= p_entity.EndTime);
}
if (p_entity.State != 3)//3是查询所有
{
q = q.Where(p => p.State == p_entity.State);
}
if (!string.IsNullOrEmpty(p_entity.SubSite))
{
q = q.Where(p => p.SubSite == p_entity.SubSite);
}
//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));
//}
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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_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_TB_PRICE_CONTROLLER), "Get_TB_PRICE_List", e.Message);
throw e;
}
}
public static ResultObject<bool> Save_TB_PRICE(List<TB_PRICE> p_entitys,PriceState p_state)
{
ResultObject<bool> _ret = new ResultObject<bool>();
List<string> errorlist = new List<string>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_entitys)
{
var _entity = db.TB_PRICE.Where(p => p.UID == itm.UID).FirstOrDefault();
_entity.State = (int)p_state;
_entity.Amt = itm.Amt;
_entity.TemporaryPrice = itm.TemporaryPrice;
_entity.Creator = itm.Creator;
_entity.EndTime = itm.EndTime;
if (_entity.EndTime<_entity.StartTime)
{
errorlist.Add("修改后的结束日期不允许小于开始日期!");
break;
}
//_entity.UpdateTime = itm.UpdateTime;
//_entity.UpdateUser = itm.UpdateUser;
//_entity.UpdateInfo = itm.UpdateInfo;
db.TB_PRICE.AddOrUpdate(p => p.UID, _entity);
}
//if (p_state == PriceState.FConfirm)
//{
//}
// 如果错误存在 就抛
if (errorlist.Count>0)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.Message = errorlist.FirstOrDefault();
return _ret;
}
else 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_TB_PRICE(List<TB_PRICE> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_entitys)
{
var _entity = db.TB_PRICE.Where(p => p.UID == itm.UID).FirstOrDefault();
_entity.State = (int)PriceState.New;
_entity.Amt = itm.Amt;
_entity.TemporaryPrice = itm.TemporaryPrice;
_entity.Creator = itm.Creator;
_entity.EndTime = itm.EndTime;
_entity.StartTime = itm.StartTime;
//_entity.UpdateTime = itm.UpdateTime;
//_entity.UpdateUser = itm.UpdateUser;
//_entity.UpdateInfo = itm.UpdateInfo;
db.TB_PRICE.AddOrUpdate(p => p.UID, _entity);
}
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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", 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_TB_PRICE_CONTROLLER), "Save_TB_PRICE", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static List<TB_PRICE> Get_TB_VendPrice_List (List<TB_PRICE> p_entitys)
{
foreach(TB_PRICE _item in p_entitys)
{
// if (_item.VendAmt == 0) _item.VendAmt = _item.Amt;
if (_item.State == (int)PriceState.New)
{
_item.Extend1 = "新建";
}
else if (_item.State == (int)PriceState.PConfirm)
{
_item.Extend1 = "采购确认";
}
else if (_item.State == (int)PriceState.FConfirm)
{
_item.Extend1 = "财务确认";
}
}
return p_entitys;
}
public static ResultObject<bool> Save_TB_PRICE_TemporaryPrice(List<long> p_list, string p_user)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
var _ls = db.TB_PRICE.Where(p => p_list.Contains(p.UID)).ToList();
_ls.ForEach(p =>
{
p.TemporaryPrice=0;
}
);
db.TB_PRICE.AddOrUpdate(p => p.UID, _ls.ToArray());
if (_ret.MessageList.Count == 0)
{
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.Message = "数据更新失败!";
}
}
}
}
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_FORECAST_CONTROLLER), "Save_TB_FORECAST_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_FORECAST_CONTROLLER), "Save_TB_FORECAST_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_FORECAST_CONTROLLER), "Save_TB_FORECAST_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_FORECAST_CONTROLLER), "Save_TB_FORECAST_STATE", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_TB_PRICE_STATE(List<long> p_list, string p_user, int State)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
if (State == (int)PriceState.FConfirm)
{
var _ls = db.TB_PRICE.Where(p => p_list.Contains(p.UID)).ToList();
_ls.ForEach(p =>
{
p.State = (int)PriceState.FConfirm;
var _first = db.TA_PART.Where(itm => itm.PartCode == p.PartCode).FirstOrDefault();
if (_first != null)
{
p.Unit = _first.Unit;
}
p.IsPost = 1;//传过接口标志
//p.UpdateUser = p_user;
//p.UpdateTime = DateTime.Now;
//p.UpdateInfo = "信息确认";
}
);
db.TB_PRICE.AddOrUpdate(p => p.UID, _ls.ToArray());
}
if (State == (int)PriceState.PConfirm)
{
var _ls = db.TB_PRICE.Where(p => p_list.Contains(p.UID)).ToList();
_ls.ForEach(p =>
{
p.State = (int)PriceState.PConfirm;
}
);
db.TB_PRICE.AddOrUpdate(p => p.UID, _ls.ToArray());
}
if (State == (int)PriceState.Reject)
{
var _ls = db.TB_PRICE.Where(p => p_list.Contains(p.UID)).ToList();
_ls.ForEach(p =>
{
var _itm = db.TA_MoldSharing.FirstOrDefault(t => t.PartCode == p.PartCode && t.VendId == p.VendId && t.Site == p.Site);
if (_itm != null)
{
if (_itm.Count > 0)
{
_ret.MessageList.Add("供应商为"+p.VendId+"零件号为"+p.PartCode+"以存在分摊数量不能删除");
}
if (_itm.Count == 0)
{
db.TA_MoldSharing.Remove(_itm);
}
}
p.State = (int)PriceState.Reject;
}
);
db.TB_PRICE.AddOrUpdate(p => p.UID, _ls.ToArray());
}
if (_ret.MessageList.Count==0)
{
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.Message = "数据更新失败!";
}
}
}
}
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_FORECAST_CONTROLLER), "Save_TB_FORECAST_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_FORECAST_CONTROLLER), "Save_TB_FORECAST_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_FORECAST_CONTROLLER), "Save_TB_FORECAST_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_FORECAST_CONTROLLER), "Save_TB_FORECAST_STATE", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
}
}