using System;
using System.Collections.Generic;
using System.Linq;
using Bowin.Common.Linq;
using System.Linq.Expressions;
using EMIS.Entities;
using EMIS.ViewModel.EducationManagement;
using EMIS.DataLogic.EducationManage;
using Bowin.Common.Linq.Entity;
using EMIS.DataLogic.EducationSchedule;
using EMIS.ViewModel;
using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
namespace EMIS.CommonLogic.EducationSchedule
{
public class EducationMissionClassScheduleServices : BaseServices, IEducationMissionClassScheduleServices
{
public EducationMissionClassDAL educationMissionClassDAL { get; set; }
public EducationMissionClassScheduleDAL educationMissionClassScheduleDAL { get; set; }
public CollegePriorityDAL collegePriorityDAL { get; set; }
///
/// 无数据范围限制
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public Bowin.Common.Linq.Entity.IGridResultSet GetEducationMissionClassScheduleViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID, int? StandardID, int pageIndex, int pageSize)
{
Expression> exp = (x => true);
Expression> executablePlanExp = (x => true);
Expression> executableOptionalCourseExp = (x => true);
Expression> executableFreeSelectionCourseCourseExp = (x => true);
//if(StandardID.HasValue)
//{
// executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == StandardID);
//}
if (campusID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (departmentID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
}
//if (gradeYearID.HasValue)
//{
// //exp = exp.And(x => x.EM_ExecutablePlan.CF_Grademajor.SchoolyearID == gradeYearID);
// executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.SchoolyearID == gradeYearID);
// executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.SchoolyearID == gradeYearID);
//}
//if (grademajorID.HasValue)
//{
// //exp = exp.And(x => x.EM_ExecutablePlan.GrademajorID == grademajorID);
// executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
// executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
//}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
}
if (coursematerialID.HasValue)
{
exp = exp.And(x => x.CoursematerialID == coursematerialID);
executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
}
if (approvalStatus.HasValue)
{
exp = exp.And(x => x.RecordStatus == approvalStatus);
}
if (teachingModeID.HasValue)
{
exp = exp.And(x => x.TeachingModeID == teachingModeID);
}
var query = educationMissionClassScheduleDAL.GetEducationMissionClassViewQueryble(exp, executablePlanExp,
executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
if (StandardID.HasValue)
{
query = query.Where(x => x.StandardID == StandardID);
}
if (grademajorID.HasValue)
{
query = query.Where(x => x.GrademajorID == grademajorID);
}
if (gradeYearID.HasValue)
{
query = query.Where(x => x.GradeYearID == gradeYearID);
}
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
}
query = this.GetQueryByDataRangeByCollege(query);
var result = query.OrderByDescending(x => x.SchoolyearCode)
.ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
.ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
.ToGridResultSet(pageIndex, pageSize);
var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
return result;
}
public List GetEducationMissionClassScheduleViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID)
{
Expression> exp = (x => true);
Expression> executablePlanExp = (x => true);
Expression> executableOptionalCourseExp = (x => true);
Expression> executableFreeSelectionCourseCourseExp = (x => true);
if (campusID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (departmentID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
}
if (gradeYearID.HasValue)
{
//exp = exp.And(x => x.EM_ExecutablePlan.CF_Grademajor.SchoolyearID == gradeYearID);
executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
}
if (grademajorID.HasValue)
{
//exp = exp.And(x => x.EM_ExecutablePlan.GrademajorID == grademajorID);
executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
}
if (coursematerialID.HasValue)
{
exp = exp.And(x => x.CoursematerialID == coursematerialID);
executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
}
if (approvalStatus.HasValue)
{
exp = exp.And(x => x.RecordStatus == approvalStatus);
}
if (teachingModeID.HasValue)
{
exp = exp.And(x => x.TeachingModeID == teachingModeID);
}
var query = educationMissionClassScheduleDAL.GetEducationMissionClassViewQueryble(exp, executablePlanExp,
executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
}
query = this.GetQueryByDataRangeByCollege(query);
var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
.ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
.ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
.ToList();
result.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
return result;
}
public void Delete(List educationMissionClassIDs)
{
#region 检查课表是否已提交
var submittedCollege = this.educationMissionClassDAL.GetSchedulingSubmittedCollege(educationMissionClassIDs).ToList();
if (submittedCollege.Count != 0)
{
string collegeNameString = string.Join("、", submittedCollege.Select(x => x.Name));
throw new Exception(collegeNameString + "的课表已经提交并形成正式课表,因此无法撤销。");
}
#endregion
#region 根据教学任务、删除排课未提交状态的相关信息
var educationSchedulingClassList = this.educationMissionClassDAL.EducationSchedulingClassRepository
.GetList(x => educationMissionClassIDs.Contains(x.EM_EducationMissionClass.EducationMissionClassID)).Select(w => w.EducationSchedulingClassID)
.ToList();
var educationSchedulingList = this.educationMissionClassDAL.EducationSchedulingRepository
.GetList(x => educationSchedulingClassList.Contains(x.EM_EducationSchedulingClass.EducationSchedulingClassID)
, (x => x.ES_EducationSchedulingTeacher), (x => x.ES_EducationSchedulingWeekNum))
.ToList();
foreach (var educationScheduling in educationSchedulingList)
{
UnitOfWork.Delete(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID);
UnitOfWork.Delete(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID);
UnitOfWork.Delete(x => x.EducationSchedulingID == educationScheduling.EducationSchedulingID);
}
var educationMissionClassList = educationMissionClassDAL.EducationMissionClassRepository.GetList(x => educationMissionClassIDs.Contains(x.EducationMissionClassID)).ToList();
educationMissionClassList.ForEach(x =>
{
x.RecordStatus = (int)EM_EducationMissionClassStatus.Submitted;
UnitOfWork.Update(x);
});
#endregion
UnitOfWork.Commit();
}
}
}