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.

153 lines
5.9 KiB

4 years 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 System.Data.Entity.Core;
using CK.SCP.Models.Enums;
using CK.SCP.Utils;
namespace CK.SCP.Controller
{
public class SCP_PLAN_MONTH_CONTROLLER
{
public static TB_PlanMonth GetPlanMonthById(int id)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.TB_PlanMonth.SingleOrDefault(p => p.ID == id);
}
}
public static bool UpdatePlanMonthById(TB_PlanMonth model)
{
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
model.IsSend = "是";
model.SendTime = DateTime.Now;
db.TB_PlanMonth.AddOrUpdate(model);
db.SaveChanges();
}
}
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);
});
}
Utils.LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "UpdatePlanMonthById", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "UpdatePlanMonthById", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "UpdatePlanMonthById", 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)
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "UpdatePlanMonthById", e.Message); throw e;
}
return true;
}
public static TA_VENDER GetVend()
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.TA_VENDER.OrderByDescending(p => p.Email).SingleOrDefault(p => p.Email != null);
}
}
public static List<TA_VENDER> GetVendList()
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
return db.TA_VENDER.ToList();
}
}
public static bool SaveTbPlanMonth(TB_PlanMonth model)
{
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
db.TB_PlanMonth.AddOrUpdate(model);
db.SaveChanges();
}
}
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);
});
}
Utils.LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "SaveTbPlanMonth", sb.ToString());
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "SaveTbPlanMonth", ex.ToString());
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
}
catch (ScpException ex)
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "SaveTbPlanMonth", 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)
{
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_PLAN_MONTH_CONTROLLER), "SaveTbPlanMonth", e.Message); throw e;
}
return true;
}
}
}