using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Common.EvaluationManage;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.ViewModel;
using System.Linq.Expressions;
using EMIS.ViewModel.EvaluationManage;
using EMIS.CommonLogic.SystemServices;
using Bowin.Common.Linq;
namespace EMIS.CommonLogic.EvaluationManage
{
public class EvaluationProjectServices : BaseServices, IEvaluationProjectServices
{
public EvaluationProjectDAL evaluationProjectDAL { get; set; }
public ISerialNumberServices SerialNumberServices { get; set; }
///
/// 查询评价项目信息
///
/// 查询条件实体
/// 评价指标
/// 评价表
/// 评价标准
/// 页码
/// 显示页数
///
public IGridResultSet GetEvaluationProjectViewGrid(ConfiguretView configuretView, Guid? targetID, Guid? tableID, Guid? normID, int pageIndex, int pageSize)
{
var query = evaluationProjectDAL.GetEvaluationProjectQueryable(x => true);
if (targetID.HasValue && targetID != Guid.Empty)
query = query.Where(x => x.TargetID == targetID);
if (tableID.HasValue && tableID != Guid.Empty)
query = query.Where(x => x.TableID == tableID);
if (normID.HasValue && normID != Guid.Empty)
query = query.Where(x => x.NormID == normID);
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet(pageIndex, pageSize);
return query.OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询评价项目信息
///
/// 查询条件实体
/// 评价指标
/// 评价表
/// 评价标准
///
public List GetEvaluationProjectViewList(ConfiguretView configuretView, Guid? targetID, Guid? tableID, Guid? normID)
{
var query = evaluationProjectDAL.GetEvaluationProjectQueryable(x => true);
if (targetID.HasValue && targetID != Guid.Empty)
query = query.Where(x => x.TargetID == targetID);
if (tableID.HasValue && tableID != Guid.Empty)
query = query.Where(x => x.TableID == tableID);
if (normID.HasValue && normID != Guid.Empty)
query = query.Where(x => x.NormID == normID);
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.OrderID).ToList();
return query.OrderBy(x => x.OrderID).ToList();
}
///
/// 获取评价项目信息
///
/// 主键ID
///
public EM_EvaluationProject GetEvaluationProject(Guid? projectID)
{
//查询条件
Expression> expression = (x => x.EvaluationProjectID == projectID.Value);
return evaluationProjectDAL.evaluationProjectRepository.GetSingle(expression);
}
///
/// 获取评价项目信息
///
/// 项目名称
///
public EM_EvaluationProject GetEvaluationProject(string Name)
{
//查询条件
Expression> expression = (x => x.Name == Name);
return evaluationProjectDAL.evaluationProjectRepository.GetSingle(expression);
}
///
/// 获取评价项目信息
///
/// 主键ID
///
public EvaluationProjectView GetEvaluationProjectView(Guid? projectID)
{
EvaluationProjectView evaluationProjectView = new EvaluationProjectView();
if (projectID.HasValue)
evaluationProjectView = evaluationProjectDAL.GetEvaluationProjectQueryable(x => true).Where(x => x.ProjectID == projectID).FirstOrDefault();
return evaluationProjectView;
}
public void SaveOrUpdateEvaluationProject(EvaluationProjectView model)
{
ValidateEvaluationProject(model);
var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
EM_EvaluationProject entity;
if (!model.ProjectID.HasValue || model.ProjectID == Guid.Empty)
{
var targer = evaluationProjectDAL.evaluationTargetRepository.GetSingle(w => w.EvaluationTargetID == model.TargetID);
entity = new EM_EvaluationProject();
entity.EvaluationProjectID = Guid.NewGuid();
entity.Code = SerialNumberServices.SetSN(targer.Code);
entity.CreateTime = DateTime.Now;
entity.CreateUserID = user.UserID;
UnitOfWork.Add(entity);
}
else
{
entity = GetEvaluationProject(model.ProjectID);
Guid? tableID = evaluationProjectDAL.evaluationTargetRepository.GetList(x => x.EvaluationTargetID == entity.EvaluationTargetID).FirstOrDefault().EvaluationTableID;
//评价表被使用,不能修改
if (evaluationProjectDAL.evaluationEnterRepository.Entities.Any(x => x.EM_EvaluationTable.EvaluationTableID == tableID))
{
throw new Exception("该信息已经被使用不能进行修改");
}
}
entity.Name = model.Name;
entity.EvaluationTargetID = model.TargetID;
entity.OrderNo = model.OrderID;
entity.Weight = model.Weight;
entity.Remark = model.Remark;
entity.ModifyUserID = user.UserID;
entity.ModifyTime = DateTime.Now;
UnitOfWork.Commit();
}
///
/// 添加
///
/// 实体
///
public bool EvaluationProjectAdd(EM_EvaluationProject evaluationProject)
{
try
{
UnitOfWork.Add(evaluationProject);
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 修改
///
/// 实体
///
public bool EvaluationProjectUpdate(EM_EvaluationProject evaluationProject)
{
try
{
UnitOfWork.Update(evaluationProject);
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 删除
///
///
///
public bool EvaluationProjectDelete(List projectIDs)
{
try
{
UnitOfWork.Delete(x => projectIDs.Contains(x.EvaluationProjectID));
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
public bool ValidateEvaluationProject(EvaluationProjectView model)
{
if (string.IsNullOrWhiteSpace(model.Name))
{
throw new Exception("项目名称不能为空!");
}
model.Name = model.Name.Trim();
if (evaluationProjectDAL.evaluationProjectRepository.GetList(x => x.Name == model.Name && x.EM_EvaluationTarget.EvaluationTableID == model.TableID
&& x.EvaluationProjectID != model.ProjectID).Count() > 0)
{
throw new Exception("项目名称对应的评价表已存在!");
}
// Expression> nameFilter = w => w.Name == model.Name;
//if (model.ProjectID.HasValue && model.ProjectID != Guid.Empty) //编辑状态
//{
// EM_EvaluationProject evaluationProjectEntity = evaluationProjectDAL.evaluationProjectRepository.GetSingle(x => x.ProjectID == model.ProjectID, (x => x.EM_EvaluationTarget));
// if (model.Name == evaluationProjectEntity.Name && model.TableID == evaluationProjectEntity.EM_EvaluationTarget.TableID && evaluationProjectEntity != null)
// {
// throw new Exception("项目名称对应的评价表已存在!");
// }
//}
return true;
}
}
}