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.
298 lines
12 KiB
298 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity.Migrations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CK.SCP.Models;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Utils;
|
|
using System.Data.Entity.Core;
|
|
using CK.SCP.Models.Enums;
|
|
|
|
namespace CK.SCP.Controller
|
|
{
|
|
public class SCP_PENING_ITEMS_CONTROLLER
|
|
{
|
|
public static ResultObject<List<TB_PENING_ITEMS>> Get_TB_PENING_ITEMS_List(TB_PENING_ITEMS p_entity)
|
|
{
|
|
ResultObject<List<TB_PENING_ITEMS>> _ret = new ResultObject<List<TB_PENING_ITEMS>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TB_PENING_ITEMS> q = db.TB_PENING_ITEMS;
|
|
if (!string.IsNullOrEmpty(p_entity.ITEM_NO))
|
|
{
|
|
q = q.Where(p => p.ITEM_NO.Contains(p_entity.ITEM_NO));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.ITEM_CONTENT))
|
|
{
|
|
q = q.Where(p => p.ITEM_CONTENT.Contains(p_entity.ITEM_CONTENT));
|
|
}
|
|
if (p_entity.ITEM_TYPE!=0)
|
|
{
|
|
q = q.Where(p => p.ITEM_TYPE==p_entity.ITEM_TYPE);
|
|
}
|
|
if (!string.IsNullOrEmpty(p_entity.SENDER))
|
|
{
|
|
q = q.Where(p => p.SENDER.Contains(p_entity.SENDER));
|
|
}
|
|
//if (p_entity.MESSAGE_STATE!=0)
|
|
//{
|
|
q = q.Where(p => p.MESSAGE_STATE == p_entity.MESSAGE_STATE);
|
|
//}
|
|
|
|
q = q.Where(p => p.ITEM_STATE==p_entity.ITEM_STATE);
|
|
|
|
if (p_entity.UserInAddress!=null && p_entity.UserInAddress.Count>0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInAddress.Contains(p.ITEM_ADDRESS));
|
|
}
|
|
|
|
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count>0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInVendIds.Contains(p.VEND_ID));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.RENEWER))
|
|
{
|
|
q = q.Where(p => p.RENEWER.Contains(p_entity.RENEWER));
|
|
}
|
|
|
|
|
|
var _time = DateTime.Now.AddMonths(-1);
|
|
q = q.Where(p => p.SENDING_TIME>_time );
|
|
|
|
|
|
if (p_entity.UserInRoles != null && p_entity.UserInRoles.Count > 0)
|
|
{
|
|
q = q.Where(p => p_entity.UserInRoles.Contains(p.ROLE_NAME));
|
|
}
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = q.ToList();
|
|
}
|
|
}
|
|
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_PENING_ITEMS_CONTROLLER), "Get_TB_PENING_ITEMS_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_PENING_ITEMS_CONTROLLER), "Get_TB_PENING_ITEMS_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_PENING_ITEMS_CONTROLLER), "Get_TB_PENING_ITEMS_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_PENING_ITEMS_CONTROLLER), "Get_TB_PENING_ITEMS_List", e.Message);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
|
|
public static ResultObject<bool> Save_TB_PENING_ITEMS(List<TB_PENING_ITEMS> p_entitys)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
db.TB_PENING_ITEMS.AddOrUpdate(p=>p.GUID,p_entitys.ToArray());
|
|
|
|
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_PENING_ITEMS_CONTROLLER), "Save_TB_PENING_ITEMS", 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_PENING_ITEMS_CONTROLLER), "Save_TB_PENING_ITEMS", 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_PENING_ITEMS_CONTROLLER), "Save_TB_PENING_ITEMS", 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_PENING_ITEMS_CONTROLLER), "Save_TB_PENING_ITEMS", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
|
|
|
|
public static ResultObject<bool> Del_TB_PENING_ITEMS(List<TB_PENING_ITEMS> p_entitys)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
foreach (var itm in p_entitys)
|
|
{
|
|
db.TB_PENING_ITEMS.Remove(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_PENING_ITEMS_CONTROLLER), "Del_TB_PENING_ITEMS", 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_PENING_ITEMS_CONTROLLER), "Del_TB_PENING_ITEMS", 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_PENING_ITEMS_CONTROLLER), "Del_TB_PENING_ITEMS", 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.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PENING_ITEMS_CONTROLLER), "Del_TB_PENING_ITEMS", e.Message); throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
}
|
|
}
|
|
|