using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Bowin.Common.Linq;
using Bowin.Common.Data;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.ViewModel;
using EMIS.ViewModel.EvaluationManage.EvaluationTable;
using EMIS.DataLogic.EvaluationManage.EvaluationTable;
namespace EMIS.CommonLogic.EvaluationManage.EvaluationTable
{
public class EvaluationProjectServices : BaseServices, IEvaluationProjectServices
{
public EvaluationProjectDAL EvaluationProjectDAL { get; set; }
///
/// 查询对应的评价项目信息View
///
///
///
///
///
///
///
///
///
public IGridResultSet GetEvaluationProjectViewGrid(ConfiguretView configuretView, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, Guid? evaluationTableID, Guid? evaluationTargetID, int pageIndex, int pageSize)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (evaluationTargetID.HasValue)
{
exp = exp.And(x => x.EvaluationTargetID == evaluationTargetID);
}
var query = EvaluationProjectDAL.GetEvaluationProjectViewQueryable(exp);
if (evaluationParticipateTypeID.HasValue)
{
query = query.Where(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
}
if (evaluationTypeID.HasValue)
{
query = query.Where(x => x.EvaluationTypeID == evaluationTypeID);
}
if (evaluationTableID.HasValue)
{
query = query.Where(x => x.EvaluationTableID == evaluationTableID);
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.EvaluationTargetCode.Length).ThenBy(x => x.EvaluationTargetCode).ThenBy(x => x.EvaluationTargetOrderNo).ThenBy(x => x.OrderNo).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的评价项目信息List
///
///
///
///
///
///
///
public IList GetEvaluationProjectViewList(ConfiguretView configuretView, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, Guid? evaluationTableID, Guid? evaluationTargetID)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (evaluationTargetID.HasValue)
{
exp = exp.And(x => x.EvaluationTargetID == evaluationTargetID);
}
var query = EvaluationProjectDAL.GetEvaluationProjectViewQueryable(exp);
if (evaluationParticipateTypeID.HasValue)
{
query = query.Where(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
}
if (evaluationTypeID.HasValue)
{
query = query.Where(x => x.EvaluationTypeID == evaluationTypeID);
}
if (evaluationTableID.HasValue)
{
query = query.Where(x => x.EvaluationTableID == evaluationTableID);
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.EvaluationTargetCode.Length).ThenBy(x => x.EvaluationTargetCode).ThenBy(x => x.EvaluationTargetOrderNo).ThenBy(x => x.OrderNo).ToList();
}
///
/// 查询对应的评价项目信息List
///
///
///
public IList GetEvaluationProjectList(Guid? evaluationTargetID)
{
Expression> expEvaluationProject = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expEvaluationProject = expEvaluationProject.And(x => x.EvaluationTargetID == evaluationTargetID);
var query = EvaluationProjectDAL.EvaluationProjectRepository.GetList(expEvaluationProject);
return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.OrderNo).ToList();
}
///
/// 查询对应的评价项目信息EvaluationProjectView
///
///
///
public EvaluationProjectView GetEvaluationProjectView(Guid? evaluationProjectID)
{
try
{
Expression> exp = (x => x.EvaluationProjectID == evaluationProjectID);
var query = EvaluationProjectDAL.GetEvaluationProjectViewQueryable(exp).SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑
///
///
public void EvaluationProjectEdit(EvaluationProjectView evaluationProjectView)
{
try
{
var evaluationProjectVerify = EvaluationProjectDAL.EvaluationProjectRepository.GetList(x => x.EvaluationProjectID != evaluationProjectView.EvaluationProjectID && x.Code == evaluationProjectView.Code.Trim()).SingleOrDefault();
if (evaluationProjectVerify == null)
{
if (evaluationProjectView.EvaluationProjectID != Guid.Empty)
{
var evaluationProject = EvaluationProjectDAL.EvaluationProjectRepository.GetList(x => x.EvaluationProjectID == evaluationProjectView.EvaluationProjectID).SingleOrDefault();
if (evaluationProject == null)
{
throw new Exception("数据有误,请核查。");
}
else
{
//表示修改
evaluationProject.OrderNo = evaluationProjectView.OrderNo;
evaluationProject.Code = evaluationProjectView.Code.Trim();
evaluationProject.Name = evaluationProjectView.Name.Trim();
evaluationProject.EvaluationTargetID = evaluationProjectView.EvaluationTargetID;
evaluationProject.Weight = evaluationProjectView.Weight;
evaluationProject.Remark = evaluationProjectView.Remark;
SetModifyStatus(evaluationProject);
}
}
else
{
//表示新增
var newEvaluationProject = new EM_EvaluationProject();
newEvaluationProject.EvaluationProjectID = Guid.NewGuid();
newEvaluationProject.OrderNo = evaluationProjectView.OrderNo;
newEvaluationProject.Code = evaluationProjectView.Code.Trim();
newEvaluationProject.Name = evaluationProjectView.Name.Trim();
newEvaluationProject.EvaluationTargetID = evaluationProjectView.EvaluationTargetID;
newEvaluationProject.Weight = evaluationProjectView.Weight;
newEvaluationProject.Remark = evaluationProjectView.Remark;
SetNewStatus(newEvaluationProject);
UnitOfWork.Add(newEvaluationProject);
}
}
else
{
throw new Exception("已存在相同的评价项目信息(项目编号唯一),请核查。");
}
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool EvaluationProjectDelete(List evaluationProjectIDs)
{
try
{
UnitOfWork.Delete(x => evaluationProjectIDs.Contains(x.EvaluationProjectID));
return true;
}
catch (Exception)
{
throw;
}
}
}
}