123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- 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; }
- /// <summary>
- /// 查询评价项目信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="targetID">评价指标</param>
- /// <param name="tableID">评价表</param>
- /// <param name="normID">评价标准</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示页数</param>
- /// <returns></returns>
- public IGridResultSet<EvaluationProjectView> 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<EvaluationProjectView>(pageIndex, pageSize);
- return query.OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationProjectView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询评价项目信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="targetID">评价指标</param>
- /// <param name="tableID">评价表</param>
- /// <param name="normID">评价标准</param>
- /// <returns></returns>
- public List<EvaluationProjectView> 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();
- }
- /// <summary>
- /// 获取评价项目信息
- /// </summary>
- /// <param name="projectID">主键ID</param>
- /// <returns></returns>
- public EM_EvaluationProject GetEvaluationProject(Guid? projectID)
- {
- //查询条件
- Expression<Func<EM_EvaluationProject, bool>> expression = (x => x.EvaluationProjectID == projectID.Value);
- return evaluationProjectDAL.evaluationProjectRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取评价项目信息
- /// </summary>
- /// <param name="Name">项目名称</param>
- /// <returns></returns>
- public EM_EvaluationProject GetEvaluationProject(string Name)
- {
- //查询条件
- Expression<Func<EM_EvaluationProject, bool>> expression = (x => x.Name == Name);
- return evaluationProjectDAL.evaluationProjectRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取评价项目信息
- /// </summary>
- /// <param name="projectID">主键ID</param>
- /// <returns></returns>
- 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();
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="evaluationProject">实体</param>
- /// <returns></returns>
- public bool EvaluationProjectAdd(EM_EvaluationProject evaluationProject)
- {
- try
- {
- UnitOfWork.Add(evaluationProject);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="evaluationProject">实体</param>
- /// <returns></returns>
- public bool EvaluationProjectUpdate(EM_EvaluationProject evaluationProject)
- {
- try
- {
- UnitOfWork.Update(evaluationProject);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="projectIDs"></param>
- /// <returns></returns>
- public bool EvaluationProjectDelete(List<Guid> projectIDs)
- {
- try
- {
- UnitOfWork.Delete<EM_EvaluationProject>(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<Func<EM_EvaluationProject, bool>> 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;
- }
- }
- }
|