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.
306 lines
12 KiB
306 lines
12 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.AppBoxEntity;
|
||
|
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_TA_ADDRESS_CONTROLLER
|
||
|
{
|
||
|
|
||
|
|
||
|
public static ResultObject<List<TA_ADDRESS>> Get_TA_ADDRESS_List(TA_ADDRESS p_entity)
|
||
|
{
|
||
|
|
||
|
ResultObject<List<TA_ADDRESS>> _ret = new ResultObject<List<TA_ADDRESS>>();
|
||
|
try
|
||
|
{
|
||
|
using (AppBoxContext db = EntitiesFactory.CreateAppBoxInstance())
|
||
|
{
|
||
|
IQueryable<TA_ADDRESS> q = db.TA_ADDRESS;
|
||
|
if (!string.IsNullOrEmpty(p_entity.ADDRESS_NO))
|
||
|
{
|
||
|
q = q.Where(p => p.ADDRESS_NO.Contains(p_entity.ADDRESS_NO));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.REGION))
|
||
|
{
|
||
|
q = q.Where(p => p.REGION.Contains(p_entity.REGION));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.ACCOUNTING_UNIT))
|
||
|
{
|
||
|
q = q.Where(p => p.ACCOUNTING_UNIT.Contains(p_entity.ACCOUNTING_UNIT));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.ADDRESS_DESCRIPTION))
|
||
|
{
|
||
|
q = q.Where(p => p.ADDRESS_DESCRIPTION.Contains(p_entity.ADDRESS_DESCRIPTION));
|
||
|
}
|
||
|
if (p_entity.ID != 0)
|
||
|
{
|
||
|
q = q.Where(p => p.ID == p_entity.ID);
|
||
|
}
|
||
|
|
||
|
|
||
|
if (!string.IsNullOrEmpty(p_entity.FactoryId))
|
||
|
{
|
||
|
q = q.Where(p => p.FactoryId.Contains(p_entity.FactoryId));
|
||
|
}
|
||
|
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.EXTEND4))
|
||
|
{
|
||
|
q = q.Where(p => p.EXTEND4.Contains(p_entity.EXTEND4));
|
||
|
}
|
||
|
_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_TA_ADDRESS_CONTROLLER), "Get_TA_ADDRESS_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_TA_ADDRESS_CONTROLLER), "Get_TA_ADDRESS_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_TA_ADDRESS_CONTROLLER), "Get_TA_ADDRESS_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_TA_ADDRESS_CONTROLLER), "Get_TA_ADDRESS_List", e.Message);
|
||
|
throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
public static ResultObject<bool> Save_TA_ADDRESS(List<TA_ADDRESS> p_entitys)
|
||
|
{
|
||
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
||
|
try
|
||
|
{
|
||
|
using (AppBoxContext db = EntitiesFactory.CreateAppBoxInstance())
|
||
|
{
|
||
|
foreach (var itm in p_entitys)
|
||
|
{
|
||
|
db.TA_ADDRESS.AddOrUpdate(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_TA_ADDRESS_CONTROLLER), "Save_TA_ADDRESS", 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_TA_ADDRESS_CONTROLLER), "Save_TA_ADDRESS", 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_TA_ADDRESS_CONTROLLER), "Save_TA_ADDRESS", 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_TA_ADDRESS_CONTROLLER), "Save_TA_ADDRESS", e.Message);
|
||
|
_ret.Result = false;
|
||
|
_ret.ErrorList.Add(e);
|
||
|
throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public static ResultObject<bool> Del_TA_ADDRESS(List<TA_ADDRESS> p_entitys)
|
||
|
{
|
||
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
||
|
try
|
||
|
{
|
||
|
using (AppBoxContext db = EntitiesFactory.CreateAppBoxInstance())
|
||
|
{
|
||
|
foreach (var itm in p_entitys)
|
||
|
{
|
||
|
db.TA_ADDRESS.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_TA_ADDRESS_CONTROLLER), "Del_TA_ADDRESS", 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_TA_ADDRESS_CONTROLLER), "Del_TA_ADDRESS", 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_TA_ADDRESS_CONTROLLER), "Del_TA_ADDRESS", 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_TA_ADDRESS_CONTROLLER), "Del_TA_ADDRESS", e.Message); throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|