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.
255 lines
10 KiB
255 lines
10 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.ScpEntity;
|
||
|
using CK.SCP.Utils;
|
||
|
using CK.SCP.Controller;
|
||
|
using System.Data.Entity.Core;
|
||
|
using CK.SCP.Models.Enums;
|
||
|
|
||
|
namespace CK.SCP.Controller
|
||
|
{
|
||
|
public class SCP_RECIVE_PORT_CONTROLLER
|
||
|
{
|
||
|
|
||
|
|
||
|
public static ResultObject<List<TA_REVICE_PORT>> Get_TA_REVICE_PORT_List(TA_REVICE_PORT p_entity)
|
||
|
{
|
||
|
ResultObject<List<TA_REVICE_PORT>> _ret = new ResultObject<List<TA_REVICE_PORT>>();
|
||
|
try
|
||
|
{
|
||
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
||
|
{
|
||
|
IQueryable<TA_REVICE_PORT> q = db.TA_REVICE_PORT;
|
||
|
if (!string.IsNullOrEmpty(p_entity.PORT_NO))
|
||
|
{
|
||
|
q = q.Where(p => p.PORT_NO.Contains(p_entity.PORT_NO));
|
||
|
}
|
||
|
if (!string.IsNullOrEmpty(p_entity.PORT_DESCRIPTION))
|
||
|
{
|
||
|
q = q.Where(p => p.PORT_DESCRIPTION.Contains(p_entity.PORT_DESCRIPTION));
|
||
|
}
|
||
|
_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_RECIVE_PORT_CONTROLLER), "Get_TA_REVICE_PORT_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_RECIVE_PORT_CONTROLLER), "Get_TA_REVICE_PORT_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_RECIVE_PORT_CONTROLLER), "Get_TA_REVICE_PORT_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_RECIVE_PORT_CONTROLLER), "Get_TA_REVICE_PORT_List", e.Message);
|
||
|
throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
public static ResultObject<bool> Save_TA_REVICE_PORT(TA_REVICE_PORT p_entity)
|
||
|
{
|
||
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
||
|
try
|
||
|
{
|
||
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
||
|
{
|
||
|
db.TA_REVICE_PORT.AddOrUpdate(p_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_RECIVE_PORT_CONTROLLER), "Save_TA_REVICE_PORT", 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_RECIVE_PORT_CONTROLLER), "Save_TA_REVICE_PORT", 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_RECIVE_PORT_CONTROLLER), "Save_TA_REVICE_PORT", 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_RECIVE_PORT_CONTROLLER), "Save_TA_REVICE_PORT", e.Message);
|
||
|
_ret.Result = false;
|
||
|
_ret.ErrorList.Add(e);
|
||
|
throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public static ResultObject<bool> Del_TA_REVICE_PORT(TA_REVICE_PORT p_entity)
|
||
|
{
|
||
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
||
|
try
|
||
|
{
|
||
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
||
|
{
|
||
|
db.TA_REVICE_PORT.Remove(p_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_RECIVE_PORT_CONTROLLER), "Del_TA_REVICE_PORT", 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_RECIVE_PORT_CONTROLLER), "Del_TA_REVICE_PORT", 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_RECIVE_PORT_CONTROLLER), "Del_TA_REVICE_PORT", 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_RECIVE_PORT_CONTROLLER), "Del_TA_REVICE_PORT", e.Message); throw e;
|
||
|
}
|
||
|
return _ret;
|
||
|
}
|
||
|
}
|
||
|
}
|