using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.EducationManage; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.EducationManagement; using EMIS.ViewModel; using EMIS.Entities; using EMIS.ViewModel.EducationManage; using EMIS.ViewModel.CacheManage; using System.Linq.Expressions; using Bowin.Common.Linq; using EMIS.DataLogic.Common.CalendarManage; using EMIS.ViewModel.UniversityManage.ClassroomManage; using EMIS.DataLogic.EducationSchedule; using EMIS.CommonLogic.Students; using EMIS.DataLogic.Common.Students; using EMIS.DataLogic.UniversityManage.TeacherManage; using EMIS.ViewModel.UniversityManage.TeacherManage; using EMIS.DataLogic; namespace EMIS.CommonLogic.EducationManage { public partial class AdultEducationMissionClassServices : BaseServices, IAdultEducationMissionClassServices { public AdultEducationMissionClassDAL educationMissionClassDAL { get; set; } public ClassroomScheduleDAL ClassroomScheduleDAL { get; set; } public SchoolYearDAL schoolYearDAL { get; set; } public IStudentsServices studentServices { get; set; } public Lazy StudentsDAL { get; set; } public Lazy staffDAL { get; set; } public CoursesTimeDAL coursesTimeDAL { get; set; } #region 查询任务班 /// /// 查询教学任务班 /// /// 查询条件 /// 学年学期ID /// 课程代码 /// 课程名称 /// 排课班级 /// 页数 /// 显示数 /// public Bowin.Common.Linq.Entity.IGridResultSet GetEducationMissionClassViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, int? standardID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? classmajorID, int? gradeYearID, Guid? CoursesTimeID, int? learningformID, int? education, string LearnSystem, int pageIndex, int pageSize) { bool hasClassmajorFilter = false; Expression> exp = (x => true); Expression> classmajorFilter = 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 (CoursesTimeID.HasValue) { exp = exp.And(x => x.EM_CoursesTime.Any(c => c.CoursesTimeID == CoursesTimeID)); } if (standardID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (learningformID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { hasClassmajorFilter = true; var LearnSystems = Convert.ToDecimal(LearnSystem); classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } if (gradeYearID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == gradeYearID); } if (classmajorID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.ClassmajorID == classmajorID); } //if (hasClassmajorFilter) //{ // exp = exp.And(w => w.CF_Classmajor.AsQueryable().Any(classmajorFilter)); //} if (schoolyearID.HasValue) { exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } if (approvalStatus.HasValue) { exp = exp.And(x => x.RecordStatus == approvalStatus); } if (teachingModeID.HasValue) { exp = exp.And(x => x.TeachingModeID == teachingModeID); } var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp, classmajorFilter).Distinct(); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var resultQuery = this.GetQueryByDataRangeByCollege(query, (x => x.ClassmajorCollegeID)).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); var result = resultQuery.ToGridResultSet(pageIndex, pageSize); var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList(); var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).Distinct().ToList(); result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID))); return result; } public List GetEducationMissionClassViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, int? standardID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? classmajorID, int? gradeYearID, int? learningformID, int? education, string LearnSystem) { bool hasClassmajorFilter = false; Expression> exp = (x => true); Expression> classmajorFilter = 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.CF_Department.CollegeID == collegeID); } if (standardID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (learningformID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { hasClassmajorFilter = true; var LearnSystems = Convert.ToDecimal(LearnSystem); classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } if (gradeYearID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == gradeYearID); } if (classmajorID.HasValue) { hasClassmajorFilter = true; classmajorFilter = classmajorFilter.And(x => x.ClassmajorID == classmajorID); } //if (hasClassmajorFilter) //{ // exp = exp.And(w => w.CF_Classmajor.AsQueryable().Any(classmajorFilter)); //} if (schoolyearID.HasValue) { exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } if (approvalStatus.HasValue) { exp = exp.And(x => x.RecordStatus == approvalStatus); } if (teachingModeID.HasValue) { exp = exp.And(x => x.TeachingModeID == teachingModeID); } var query = educationMissionClassDAL.GetEducationMissionClassViewQueryble(exp, classmajorFilter); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); 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(); var educationMissionClassID = result.Select(x => x.EducationMissionClassID).ToList(); var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList(); result.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID))); return result; } #endregion /// /// 获取任务班信息 /// /// /// public EducationMissionImportClassView GetEducationMissionClassView(Guid? educationMissionClassID) { return educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.EducationMissionClassID == educationMissionClassID,w=>true).FirstOrDefault(); } /// /// 获取任务班信息 /// /// /// public Entities.EM_EducationMissionClass GetEducationMissionClass(Guid? educationMissionClassID) { return educationMissionClassDAL.educationMissionClassRepository.GetSingle(x => x.EducationMissionClassID == educationMissionClassID, (x => x.EM_EducationMission), (x => x.CF_Classmajor), (x => x.EM_CoursesTime), (x => x.EM_MissionClassTeacher), (x => x.EM_EducationMissionClassSettings), (x => x.EM_CourseProcess), (x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher)), (x => x.EM_EducationSchedulingClass), (x => x.EM_EducationMissionClassTeachingSetting), (x => x.CF_Classroom)); } public void BatchModifyCoursesTime(List educationMissionClassIDs, Guid? CourseTimeID, int? ClassroomTypeID) { try { foreach (var id in educationMissionClassIDs) { EM_EducationMissionClass educationMissionClass = GetEducationMissionClass(id); educationMissionClass.ClassroomTypeID = ClassroomTypeID; List coursesTime = coursesTimeDAL.coursesTimeRepository.Entities.Where(x => x.CoursesTimeID == CourseTimeID).ToList(); educationMissionClass.EM_CoursesTime = new HashSet(); //educationMissionClass.EM_CoursesTime = new HashSet(); foreach (var time in coursesTime) { EM_CoursesTime c = time; educationMissionClass.EM_CoursesTime.Add(c); } SetModifyStatus(educationMissionClass); } UnitOfWork.Commit(); } catch { } } /// /// 更新教学任务班表 处理状态 /// /// public void EducationMissionClassUpdate(List educationMissionClassIDs) { try { string massge = string.Empty; var educationMissionClassList = educationMissionClassDAL.educationMissionClassRepository .GetList(x => educationMissionClassIDs.Contains(x.EducationMissionClassID), (x => x.CF_Classmajor), (x => x.EM_EducationMission), (x => x.EM_EducationMissionClassTeachingSetting), (x => x.EM_EducationMissionClassSettings), (x => x.EM_EducationSchedulingClass), (x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student)), (x => x.EM_MissionClassTeacher), (x => x.EM_CourseProcess), (x => x.EM_CoursesTime), (x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher))).ToList(); var educationMissionIDList = educationMissionClassList.Select(x => x.EducationMissionID).Distinct(); foreach (var educationMissionClass in educationMissionClassList) { if (educationMissionClass.RecordStatus != (int)EMIS.ViewModel.EM_EducationMissionClassStatus.NotSubmitted) massge += educationMissionClass.Name + "任务班,已提交,不能重复提交。"; if (educationMissionClass.EM_CoursesTime.Count == 0) massge += educationMissionClass.Name + "任务班,未设置课时类别。"; //if (educationMissionClass.EM_EducationMissionClassSettings.Count == 0) // massge += educationMissionClass.Name + "任务班,未设置授课周次。"; if (educationMissionClass.ClassroomTypeID == null) massge += educationMissionClass.Name + "任务班,未设置教室类型。"; var courseProcessList = educationMissionClassDAL.GetRelatedCourseProcess(x => x.EducationMissionClassID == educationMissionClass.EducationMissionClassID) .ToList(); var hours = courseProcessList.Select(x => x.Times).Sum(); //总学时 int? totalHours = (educationMissionClass.EM_EducationMissionClassTeachingSetting.TheoryCourse ?? 0) + (educationMissionClass.EM_EducationMissionClassTeachingSetting.Practicehours ?? 0); //TODO:兵良说:排课学时要小于等于总学时 2016年10月17日18:48:49 if (hours > totalHours) { massge += educationMissionClass.Name + "任务班,课程进度设置错误,请检查并重新设置后提交。"; } if (!string.IsNullOrEmpty(massge)) massge += ","; } //20161110 MM姐提的要求, 先提交数据检测是否问题,有问题把所有问题反馈回页面让客户进行修改,再重新提交 if (!string.IsNullOrEmpty(massge)) throw new Exception(massge.TrimEnd(',')); foreach (var educationMissionClass in educationMissionClassList) { educationMissionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Submitted; } UnitOfWork.Commit(); } catch (Exception) { throw; } } } }