using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.EvaluationManage;
using EMIS.ViewModel;
using EMIS.DataLogic.Common.EvaluationManage;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
namespace EMIS.CommonLogic.EvaluationManage
{
public class EvaluationOpenControlServices : BaseServices,IEvaluationOpenControlServices
{
public EvaluationOpenControlDAL evaluationOpenControlDAL { get; set; }
///
/// 查询评价控制信息
///
/// 查询条件实体
/// 页码
/// 显示页数
///
public IGridResultSet GetEvaluationOpenControlViewGrid(ConfiguretView configuretView, Guid? SchoolYearID, Guid? CollegeID, int? Year, int? Standard, int? education, int? Learningform, string LearnSystem, int pageIndex, int pageSize)
{
Expression> exp = (x =>true);
if (SchoolYearID.HasValue)
exp=exp.And(x => x.SchoolyearID == SchoolYearID);
if (CollegeID.HasValue)
exp = exp.And(x => x.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == CollegeID);
if(Year.HasValue)
exp = exp.And(x => x.CF_Grademajor.GradeID == Year);
if (Standard.HasValue)
exp = exp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == Standard);
if(education.HasValue)
exp = exp.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education);
if(Learningform.HasValue)
exp = exp.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == Learningform);
if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(LearnSystem);
exp = exp.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
}
var query = evaluationOpenControlDAL.GetEvaluationControlQueryable(exp);
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.SchoolyearID).ToGridResultSet(pageIndex, pageSize);
return query.OrderByDescending(x => x.SchoolyearID).ToGridResultSet(pageIndex, pageSize);
}
///
/// 通过ID查询开放控制
///
///
///
public EvaluationOpenControlView GetEvaluationOpenControlView(Guid? evaluationGradeControlID)
{
var query = evaluationOpenControlDAL.GetEvaluationControlQueryable(x => x.EvaluationGradeControlID == evaluationGradeControlID).FirstOrDefault();
return query;
}
///
/// 查询开放控制信息
///
/// 查询条件实体
/// 页码
/// 显示页数
///
public IGridResultSet GrademajorViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? standardID, int? educationID, int? learningformID, int? schoolyear, string LearnSystem,Guid? SchoolYearID, int pageIndex, int pageSize)
{
Expression> exp = (x => true);
Expression> exps=(x=>true);
if (campusID.HasValue)
exp = exp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID);
if (collegeID.HasValue)
exp = exp.And(x => x.CF_Facultymajor.CF_College.CollegeID == collegeID);
if(standardID.HasValue)
exp = exp.And(x => x.CF_Facultymajor.StandardID == standardID);
if(educationID.HasValue)
exp = exp.And(x => x.CF_Facultymajor.EducationID == educationID);
if (learningformID.HasValue)
exp = exp.And(x => x.CF_Facultymajor.LearningformID == learningformID);
if (schoolyear.HasValue)
exp = exp.And(x => x.GradeID == schoolyear);
if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
{
var LearnSystems = Convert.ToDecimal(LearnSystem);
exp = exp.And(x => x.CF_Facultymajor.LearnSystem == LearnSystems);
}
if (SchoolYearID.HasValue)
exps= exps.And(x => x.SchoolyearID == SchoolYearID);
var query = evaluationOpenControlDAL.GrademajorViewGridQueryable(exp, exps);
return query.OrderByDescending(x => x.CollegeID).OrderBy(x => x.FacultymajorID).ToGridResultSet(pageIndex, pageSize);
}
///
/// 新增修改开放控制
///
///
///
public bool EvaluationOpenControlEdit(EvaluationOpenControlView evaluationOpenControlView, List GrademajorList)
{
if (evaluationOpenControlView.EvaluationGradeControlID == null || evaluationOpenControlView.EvaluationGradeControlID==Guid.Empty)
{
EvaluationOpenControlAdd(evaluationOpenControlView, GrademajorList);
}
else
{
EvaluationOpenControlUpdate(evaluationOpenControlView);
}
UnitOfWork.Commit();
return true;
}
public void EvaluationOpenControlAdd(EvaluationOpenControlView evaluationOpenControlView, List GrademajorList)
{
List EM_EvaluationGradeControlList = new List();
foreach (var g in GrademajorList){
EM_EvaluationGradeControl EvaluationGradeControl = new EM_EvaluationGradeControl();
EvaluationGradeControl.EvaluationGradeControlID = Guid.NewGuid();
EvaluationGradeControl.GrademajorID = g.GrademajorID;
EvaluationGradeControl.SchoolyearID = evaluationOpenControlView.SchoolyearID;
EvaluationGradeControl.StartTime = evaluationOpenControlView.StartTime;
var endTime = evaluationOpenControlView.EndTime.Value.AddHours(23).AddMinutes(59).AddSeconds(59);
EvaluationGradeControl.EndTime = endTime;
EvaluationGradeControl.Number = evaluationOpenControlView.EvaluationCount;
SetNewStatus(EvaluationGradeControl);
EM_EvaluationGradeControlList.Add(EvaluationGradeControl);
}
UnitOfWork.BulkInsert(EM_EvaluationGradeControlList);
UnitOfWork.Commit();
}
public void EvaluationOpenControlUpdate(EvaluationOpenControlView evaluationOpenControlView)
{
EM_EvaluationGradeControl EvaluationGradeControl = new EM_EvaluationGradeControl();
EvaluationGradeControl = evaluationOpenControlDAL.EvaluationGradeControlRepository.Entities.Where(x => x.EvaluationGradeControlID == evaluationOpenControlView.EvaluationGradeControlID).FirstOrDefault();
EvaluationGradeControl.GrademajorID = evaluationOpenControlView.GrademajorID;
EvaluationGradeControl.SchoolyearID = evaluationOpenControlView.SchoolyearID;
EvaluationGradeControl.StartTime = evaluationOpenControlView.StartTime;
EvaluationGradeControl.EndTime = evaluationOpenControlView.EndTime;
EvaluationGradeControl.Number = evaluationOpenControlView.EvaluationCount;
SetModifyStatus(EvaluationGradeControl);
}
public string Verification(Guid? SchoolYearID, List list, string StartTime, string EndTime)
{
//获取所有的开放控制
var EvaluationGradeControlList = evaluationOpenControlDAL.EvaluationGradeControlRepository.GetList(x => true).ToList();
//获取存在的开放控制
var existList = EvaluationGradeControlList.Where(x => x.SchoolyearID == SchoolYearID && list.Contains(x.GrademajorID)).Select(x => x.GrademajorID).ToList();
//获取存在的开放控制的年级专业
var GrademajorList = evaluationOpenControlDAL.GrademajorRepository.GetList(x => existList.Contains(x.GrademajorID));
//获取参评类型
var EvaluationType = evaluationOpenControlDAL.EvaluationTypeRepository.GetList(x => x.IsStudent == true).FirstOrDefault();
StringBuilder sb = new StringBuilder();
if (EvaluationType != null)
{
if (EvaluationType.StartTime.Value.Date.CompareTo(Convert.ToDateTime(StartTime)) > 0)
{
sb.Append("开始时间早于参评类型设置的开始时间、");
}
if (EvaluationType.EndTime.Value.Date.CompareTo(Convert.ToDateTime(StartTime)) < 0)
{
sb.Append("开始时间晚于参评类型设置的结束时间、");
}
if (EvaluationType.StartTime.Value.Date.CompareTo(Convert.ToDateTime(EndTime)) > 0)
{
sb.Append("结束时间早于参评类型设置的开始时间、");
}
if (EvaluationType.EndTime.Value.Date.CompareTo(Convert.ToDateTime(EndTime)) < 0)
{
sb.Append("结束时间晚于参评类型设置的结束时间、");
}
if (Convert.ToDateTime(EndTime).CompareTo(Convert.ToDateTime(StartTime)) < 0)
{
sb.Append("结束时间早于开始时间、");
}
if (existList.Count > 0)
{
if (sb.ToString() == "")
{
foreach (var g in GrademajorList)
{
sb.Append(g.Name + "、");
}
sb.Remove(sb.ToString().LastIndexOf('、'), 1);
sb.Append("等专业已存在,请检查!");
return sb.ToString();
}
else
{
sb.Remove(sb.ToString().LastIndexOf('、'), 1);
return sb.ToString();
}
}
else
{
if (sb.ToString() != "")
{
sb.Remove(sb.ToString().LastIndexOf('、'), 1);
return sb.ToString();
}
return "成功";
}
}
else
{
sb.Append("请设置适用于学生参评类型。");
return sb.ToString();
}
}
public void Delete(List list)
{
UnitOfWork.Remove(x => list.Contains(x.EvaluationGradeControlID));
UnitOfWork.Commit();
}
}
}