using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Linq.Expressions; using System.Text; using EMIS.DataLogic.CultureplanManage.PlanManagement; using EMIS.ViewModel.SelectCourse; using EMIS.ViewModel; using EMIS.DataLogic.SelectCourse; using EMIS.Entities; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.CacheManage; using EMIS.CommonLogic.SystemServices; using EMIS.DataLogic.GraduationManage.GraduationManage; using EMIS.DataLogic.GraduationManage.GraduationSetting; using EMIS.ViewModel.GraduationManage.GraduationManage; using EMIS.ViewModel.CultureplanManage.PlanManagement; using EMIS.DataLogic.Common.CalendarManage; using EMIS.DataLogic.UniversityManage.SpecialtyClassManage; using Bowin.Common.Exceptions; using EMIS.DataLogic.Repositories; namespace EMIS.CommonLogic.SelectCourse { public class OptionalCourseSettingServices : BaseServices, IOptionalCourseSettingServices { public ExecutableOptionalCourseTeachingSettingRepository executableOptionalCourseTeachingSettingRepository { get; set; } public ExecutableOptionalCourseTeacherRepository executableOptionalCourseTeacherRepository { get; set; } public ExecutableOptionalCourseTeachingModeRepository executableOptionalCourseTeachingModeRepository { get; set; } public ClassmajorDAL classmajorDAL { get; set; } public OptionalCourseSettingDAL optionalCourseSettingDAL { get; set; } public OptionalCoursePlanDAL optionalCoursePlanDAL { get; set; } public SchoolYearDAL schoolYearDAL { get; set; } public GrademajorDAL GrademajorDAL { get; set; } public IGridResultSet GetOptionalCourseSettingViewGrid(ConfiguretView configuretView, Guid? collegeID, int? standardID, Guid? coursematerialID, Guid? schoolYearID, int? Years, int? Status, int? isOpened, int pageIndex, int pageSize) { Expression> openControlSettingExp = (x => true); Expression> exp = (x => true); Expression> schoolYearExp = (x => true); Expression> gradeMajorExp = (x => true); //IQueryable query = // optionalCourseSettingDAL.GetOpenControlSettingView(exp,openControlSettingExp, schoolYearExp, gradeMajorExp) // .OrderByDescending(x => x.SchoolYearCode); var query = optionalCourseSettingDAL.GetOpenControlSettingView(openControlSettingExp, exp, schoolYearExp, gradeMajorExp); if (collegeID.HasValue) query = query.Where(x => x.CollegeID == collegeID); if (standardID.HasValue) query = query.Where(x => x.StandardID == standardID); if (coursematerialID.HasValue) query = query.Where(x => x.CoursematerialID == coursematerialID); if (schoolYearID.HasValue) query = query.Where(x => x.SchoolyearID == schoolYearID); if (Years.HasValue) query = query.Where(x => x.Years == Years); if (Status.HasValue) query = query.Where(x => x.RecordStatus == Status); //if (schoolYearNumID.HasValue) // query = query.Where(x => x.SchoolyearNumID == schoolYearNumID); //if (schoolCodeID.HasValue) // query = query.Where(x => x.SchoolcodeID == schoolCodeID); //if (isEnable.HasValue) // query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false)); if (isOpened.HasValue) query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false)); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolYearCode).ThenBy(x => x.GrademajorCode). ThenBy(x => x.CourseCode).ThenBy(x => x.DefaultClassName).ToGridResultSet(pageIndex, pageSize); //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolYearCode).ThenByDescending(x => x.GrademajorCode).ThenBy(x => x.DefaultClassName).ToGridResultSet(pageIndex, pageSize); return result; } public List GetOptionalCourseSettingViewList(ConfiguretView configuretView, Guid? collegeID, int? standardID, Guid? coursematerialID, Guid? schoolYearID, int? Years, int? Status, int? isOpened) { Expression> openControlSettingExp = (x => true); Expression> exp = (x => true); Expression> schoolYearExp = (x => true); Expression> gradeMajorExp = (x => true); //IQueryable query = // optionalCourseSettingDAL.GetOpenControlSettingView(exp,openControlSettingExp, schoolYearExp, gradeMajorExp) // .OrderByDescending(x => x.SchoolYearCode); var query = optionalCourseSettingDAL.GetOpenControlSettingView(openControlSettingExp, exp, schoolYearExp, gradeMajorExp); if (collegeID.HasValue) query = query.Where(x => x.CollegeID == collegeID); if (standardID.HasValue) query = query.Where(x => x.StandardID == standardID); if (coursematerialID.HasValue) query = query.Where(x => x.CoursematerialID == coursematerialID); if (schoolYearID.HasValue) query = query.Where(x => x.SchoolyearID == schoolYearID); if (Years.HasValue) query = query.Where(x => x.Years == Years); if (Status.HasValue) query = query.Where(x => x.RecordStatus == Status); //if (schoolYearNumID.HasValue) // query = query.Where(x => x.SchoolyearNumID == schoolYearNumID); //if (schoolCodeID.HasValue) // query = query.Where(x => x.SchoolcodeID == schoolCodeID); //if (isEnable.HasValue) // query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false)); if (isOpened.HasValue) query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false)); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolYearCode).ThenByDescending(x => x.GrademajorCode).ThenBy(x => x.DefaultClassName).ToList(); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolYearCode).ThenBy(x => x.GrademajorCode).ThenBy(x => x.CourseCode).ToList(); return result; } /// /// 获取限选计划实体 /// /// /// public EM_ExecutableOptionalCourse GetOptionalCourseSettingEntity(Guid? executableOptionalCourseID) { return optionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetSingle(x => x.ExecutableOptionalCourseID == executableOptionalCourseID); } // /// 获取限选计划视图 /// /// /// public OptionalCourseSettingView GetOptionalCourseSettingView(Guid? executableOptionalCourseID) { var query = optionalCourseSettingDAL.GetOpenControlSettingView(x => x.ExecutableOptionalCourseID == executableOptionalCourseID, x => true, x => true, x => true).FirstOrDefault(); return query; } /// /// 添加 /// /// /// public void OptionalCourseSettingCreate(OptionalCourseSettingCreateView OptionalCourseSettingView) { int susCount = 0; //成功数 int susAddCount = 0; //新增数 int susUpdateCount = 0; //修改数 int susNoUpdateCount = 0; //不能修改数 try { // var schoolYearList = this.schoolYearDAL.schoolyearRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList(); var courseSchoolyear = schoolYearDAL.schoolyearRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).FirstOrDefault(x => x.SchoolyearID == OptionalCourseSettingView.SchoolyearID); //所选年级专业与限选计划的专业匹配,关联出限选计划 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> opExp = (x => x.IsEnable == true);//&& x.RecordStatus > 0); var query = optionalCoursePlanDAL.GetGrademajorOptionalCoursePlanViewQueryable(opExp, exp); if (OptionalCourseSettingView.GrademajorID != null) //年级专业不为空时,以年级专业和学年学期为条件查询专业计划表 { query = query.Where(x => x.GrademajorID == OptionalCourseSettingView.GrademajorID); } else //年级专业为空时,以学年学期为关键条件,联合校区、院系所、年级、专业代码查询专业计划表 { if (OptionalCourseSettingView.CampusID != null) { query = query.Where(x => x.CampusID == OptionalCourseSettingView.CampusID); } if (OptionalCourseSettingView.CollegeID != null) { query = query.Where(x => x.CollegeID == OptionalCourseSettingView.CollegeID); } if (OptionalCourseSettingView.Years != null) { query = query.Where(x => x.Years == OptionalCourseSettingView.Years); } if (OptionalCourseSettingView.StandardID != null) { query = query.Where(x => x.StandardID == OptionalCourseSettingView.StandardID); } } if (OptionalCourseSettingView.CoursematerialID != null) { query = query.Where(x => x.CoursematerialID == OptionalCourseSettingView.CoursematerialID); } query = query.Where(x => x.SchoolValue == courseSchoolyear.Value); List optionalCoursePlanViewList = query.ToList(); var executableOptionalCourseList = query.Join(optionalCourseSettingDAL.ExecutableOptionalCourseRepository.Entities, (x => new { OptionalCourseID = (Guid?)x.OptionalCourseID, x.GrademajorID, SchoolyearID = OptionalCourseSettingView.SchoolyearID }), (x => new { x.OptionalCourseID, x.GrademajorID, x.SchoolyearID }), (x, y) => y).Include(x => x.EM_ExecutableOptionalCourseTeachingSetting).ToList(); if (optionalCoursePlanViewList == null || optionalCoursePlanViewList.Count < 1) { throw new Exception("未能匹配到已启用但未生成的限选计划数据,请核查。"); } var insertList = new List(); var insertTeachingSettingList = new List(); var insertTeachingModeList = new List(); var updateList = new List(); var updateTechingSettingList = new List(); foreach (var optionalCourse in optionalCoursePlanViewList) { EM_ExecutableOptionalCourse executableOptionalCourse = executableOptionalCourseList.FirstOrDefault( x => x.OptionalCourseID == optionalCourse.OptionalCourseID && x.GrademajorID == optionalCourse.GrademajorID && x.SchoolyearID == OptionalCourseSettingView.SchoolyearID); if (executableOptionalCourse != null) { if (executableOptionalCourse.RecordStatus == (int)EM_SelectCourseResultStatus.NotOpen) { EM_ExecutableOptionalCourseTeachingSetting ExecutableOptionalCourseTeachingSetting = executableOptionalCourse.EM_ExecutableOptionalCourseTeachingSetting; ExecutableOptionalCourseTeachingSetting.Credit = optionalCourse.Credit; ExecutableOptionalCourseTeachingSetting.TheoryCourse = optionalCourse.TheoryCourse; ExecutableOptionalCourseTeachingSetting.Practicehours = optionalCourse.Practicehours; ExecutableOptionalCourseTeachingSetting.Trialhours = optionalCourse.Trialhours; ExecutableOptionalCourseTeachingSetting.WeeklyNum = optionalCourse.WeeklyNum; ExecutableOptionalCourseTeachingSetting.TheoryWeeklyNum = optionalCourse.TheoryWeeklyNum; ExecutableOptionalCourseTeachingSetting.PracticeWeeklyNum = optionalCourse.PracticeWeeklyNum; ExecutableOptionalCourseTeachingSetting.TrialWeeklyNum = optionalCourse.TrialWeeklyNum; ExecutableOptionalCourseTeachingSetting.StartWeeklyNum = optionalCourse.StartWeeklyNum; ExecutableOptionalCourseTeachingSetting.EndWeeklyNum = optionalCourse.EndWeeklyNum; ExecutableOptionalCourseTeachingSetting.WeeklyHours = optionalCourse.WeeklyHours; SetModifyStatus(executableOptionalCourse); executableOptionalCourse.RecordStatus = (int)EM_SelectCourseResultStatus.NotOpen; susUpdateCount++; updateTechingSettingList.Add(ExecutableOptionalCourseTeachingSetting); updateList.Add(executableOptionalCourse); } else { susNoUpdateCount++; } } else { executableOptionalCourse = new EM_ExecutableOptionalCourse(); executableOptionalCourse.ExecutableOptionalCourseID = Guid.NewGuid(); executableOptionalCourse.DefaultClassName = optionalCourse.DefaultClassName + "_" + optionalCourse.CourseName + "(限选)"; executableOptionalCourse.IsEnable = false; executableOptionalCourse.IsOpened = false; SetNewStatus(executableOptionalCourse); executableOptionalCourse.RecordStatus = (int)EM_SelectCourseResultStatus.NotOpen; //插入限选设定关联班数据 CF_Classmajor clas = GetClassmajor(optionalCourse.ClassmajorID); if (clas != null) { executableOptionalCourse.CF_Classmajor = new HashSet(); executableOptionalCourse.CF_Classmajor.Add(clas); } susAddCount++; executableOptionalCourse.GrademajorID = optionalCourse.GrademajorID; executableOptionalCourse.OptionalCourseID = optionalCourse.OptionalCourseID; executableOptionalCourse.SchoolyearID = OptionalCourseSettingView.SchoolyearID; executableOptionalCourse.DepartmentID = optionalCourse.DepartmentID; executableOptionalCourse.CourseStructureID = optionalCourse.CourseStructureID; executableOptionalCourse.CourseCategoryID = optionalCourse.CourseCategoryID; executableOptionalCourse.CourseTypeID = optionalCourse.CourseTypeID; executableOptionalCourse.CourseQualityID = optionalCourse.CourseQualityID; executableOptionalCourse.PracticeTypeID = optionalCourse.PracticeTypeID; executableOptionalCourse.ExaminationModeID = optionalCourse.ExaminationModeID; executableOptionalCourse.TeachinglanguageID = optionalCourse.TeachinglanguageID; executableOptionalCourse.PeopleNumlower = optionalCourse.PeopleNumlower; executableOptionalCourse.PeopleNumlimit = optionalCourse.PeopleNumlimit; executableOptionalCourse.ResultTypeID = optionalCourse.ResultTypeID; insertList.Add(executableOptionalCourse); EM_ExecutableOptionalCourseTeachingSetting optionalCourseTeachingSetting = new EM_ExecutableOptionalCourseTeachingSetting(); optionalCourseTeachingSetting.ExecutableOptionalCourseID = executableOptionalCourse.ExecutableOptionalCourseID; optionalCourseTeachingSetting.Credit = optionalCourse.Credit; optionalCourseTeachingSetting.TheoryCourse = optionalCourse.TheoryCourse; optionalCourseTeachingSetting.Practicehours = optionalCourse.Practicehours; optionalCourseTeachingSetting.Trialhours = optionalCourse.Trialhours; optionalCourseTeachingSetting.WeeklyNum = optionalCourse.WeeklyNum; optionalCourseTeachingSetting.TheoryWeeklyNum = optionalCourse.TheoryWeeklyNum; optionalCourseTeachingSetting.PracticeWeeklyNum = optionalCourse.PracticeWeeklyNum; optionalCourseTeachingSetting.TrialWeeklyNum = optionalCourse.TrialWeeklyNum; optionalCourseTeachingSetting.StartWeeklyNum = optionalCourse.StartWeeklyNum; optionalCourseTeachingSetting.EndWeeklyNum = optionalCourse.EndWeeklyNum; optionalCourseTeachingSetting.WeeklyHours = optionalCourse.WeeklyHours; insertTeachingSettingList.Add(optionalCourseTeachingSetting); if (optionalCourse.TeachingModeID != null) { foreach (var i in optionalCourse.TeachingModeID) { EM_ExecutableOptionalCourseTeachingMode optionalCourseTeachingMode = new EM_ExecutableOptionalCourseTeachingMode(); optionalCourseTeachingMode.ExecutableOptionalCourseTeachingModeID = Guid.NewGuid(); optionalCourseTeachingMode.ExecutableOptionalCourseID = executableOptionalCourse.ExecutableOptionalCourseID; optionalCourseTeachingMode.TeachingModeID = i; SetNewStatus(optionalCourseTeachingMode); insertTeachingModeList.Add(optionalCourseTeachingMode); } } } susCount++; } UnitOfWork.BatchUpdate(updateList); UnitOfWork.BatchUpdate(updateTechingSettingList); UnitOfWork.BulkInsert(insertList); UnitOfWork.BulkInsert(insertTeachingSettingList); UnitOfWork.BulkInsert(insertTeachingModeList); //UnitOfWork.Commit(); if (susNoUpdateCount > 0) { throw new SuccessException(string.Format("保存成功{0}条记录,其中新增{1}条,更新{2}条,有{3}条已开放,不能修改。", susCount, susAddCount, susUpdateCount,susNoUpdateCount)); } else throw new SuccessException(string.Format("保存成功{0}条记录,其中新增{1}条,更新{2}条。", susCount, susAddCount, susUpdateCount)); //throw new SuccessException(string.Format("新增{0}条。", susAddCount)); } catch (Exception ex) { throw; //throw new Exception(string.Format("保存成功{0}条记录,第{1}条出错," + ex.Message, susCount, susCount + 1)); } } /// /// 更新 /// /// /// public void OptionalCourseSettingUpdate(OptionalCourseSettingView optionalCourseSettingView, IList teacherList, IList classList) { try { if (optionalCourseSettingView.ExecutableOptionalCourseID != null && optionalCourseSettingView.ExecutableOptionalCourseID != Guid.Empty) { EM_ExecutableOptionalCourse optionalCoursePlan = GetOptionalCourseSettingEntity(optionalCourseSettingView.ExecutableOptionalCourseID); //EM_ExecutableOptionalCourseTeachingMode optionalCourseTeachingMode = executableOptionalCourseTeachingModeRepository.Entities.Where(x => x.ExecutableOptionalCourseID == optionalCoursePlan.ExecutableOptionalCourseID).SingleOrDefault(); EM_ExecutableOptionalCourseTeachingSetting optionalCourseTeachingSetting = executableOptionalCourseTeachingSettingRepository.Entities.Where(x => x.ExecutableOptionalCourseID == optionalCoursePlan.ExecutableOptionalCourseID).SingleOrDefault(); //EM_ExecutableOptionalCourseTeacher optionalCourseTeacher = executableOptionalCourseTeacherRepository.Entities.Where(x=>x.ExecutableOptionalCourseID==optionalCoursePlan.ExecutableOptionalCourseID).SingleOrDefault(); //CF_Classmajor clas=GetClassmajor(optionalCourseSettingView.ClassmajorID); //var classList = GetClassmajorList(optionalCourseSettingView.ExecutableOptionalCourseID); if (optionalCoursePlan != null) { //if (optionalCoursePlan.IsOpened == true && optionalCoursePlan.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen) // throw new Exception("只能开放“已提交”状态的数据,请核查,请核查。"); //var query = optionalCourseSettingDAL.GetOpenControlSettingClassmajorView(x => x.RecordStatus > 0 && x.ExecutableOptionalCourseID == optionalCoursePlan.ExecutableOptionalCourseID).ToList(); var query = optionalCourseSettingDAL.GetExecutableOptionalCourseClassmajorList().Where(x => x.ExecutableOptionalCourseID == optionalCoursePlan.ExecutableOptionalCourseID).ToList(); optionalCoursePlan.CF_Classmajor = new HashSet(); if (query.Count > 0 && classList.Count > 0) { //if (optionalCourseSettingIDs.Count > 0) //{ // for (int i = 0; i < optionalCourseSettingIDs.Count; i++) // { // Guid optionalCourseSettingID = optionalCourseSettingIDs[i]; // var executableOptionalCourse = optionalCourseSettingDAL.executableOptionalCourseRepository.GetSingle( // x => x.ExecutableOptionalCourseID == optionalCourseSettingID); // executableOptionalCourse.CF_Classmajor = new HashSet(); // UnitOfWork.Delete(executableOptionalCourse, (x => x.CF_Classmajor)); // } //} //optionalCoursePlan.CF_Classmajor.Clear(); //optionalCoursePlan.CF_Classmajor.r; //删除限选设定关联班数据 UnitOfWork.Delete(optionalCoursePlan, (x => x.CF_Classmajor)); } optionalCoursePlan.CF_Classmajor = new HashSet(); //插入限选设定关联班数据 foreach (var list in classList) { CF_Classmajor clas = GetClassmajor(list.ClassmajorID); optionalCoursePlan.CF_Classmajor.Add(clas); } optionalCoursePlan.DefaultClassName = optionalCourseSettingView.DefaultClassName; optionalCoursePlan.DepartmentID = optionalCourseSettingView.DepartmentID; optionalCoursePlan.CourseStructureID = optionalCourseSettingView.CourseStructureID; optionalCoursePlan.CourseCategoryID = optionalCourseSettingView.CourseCategoryID; optionalCoursePlan.CourseTypeID = optionalCourseSettingView.CourseTypeID; optionalCoursePlan.CourseQualityID = optionalCourseSettingView.CourseQualityID; optionalCoursePlan.PracticeTypeID = optionalCourseSettingView.PracticeTypeID; optionalCoursePlan.ExaminationModeID = optionalCourseSettingView.ExaminationModeID; optionalCoursePlan.TeachinglanguageID = optionalCourseSettingView.TeachinglanguageID; optionalCoursePlan.IsEnable = optionalCourseSettingView.IsEnable; //optionalCoursePlan.No = optionalCourseSettingView.No; //optionalCoursePlan.HandleModeID = optionalCourseSettingView.HandleModeID; //optionalCoursePlan.IsNeedMaterial = optionalCourseSettingView.IsNeedMaterial; optionalCoursePlan.PeopleNumlower = optionalCourseSettingView.PeopleNumlower; optionalCoursePlan.PeopleNumlimit = optionalCourseSettingView.PeopleNumlimit; optionalCoursePlan.IsOpened = optionalCourseSettingView.IsOpened; optionalCoursePlan.ResultTypeID = optionalCourseSettingView.ResultTypeID; optionalCoursePlan.Remarks = optionalCourseSettingView.Remarks; if (optionalCourseSettingView.TeachingModeID != null) { UnitOfWork.Delete(x => x.ExecutableOptionalCourseID == optionalCourseSettingView.ExecutableOptionalCourseID); foreach (var i in optionalCourseSettingView.TeachingModeID) { EM_ExecutableOptionalCourseTeachingMode optionalCourseTeachingMode = new EM_ExecutableOptionalCourseTeachingMode(); optionalCourseTeachingMode.ExecutableOptionalCourseTeachingModeID = Guid.NewGuid(); optionalCourseTeachingMode.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; optionalCourseTeachingMode.TeachingModeID = i; SetNewStatus(optionalCourseTeachingMode); UnitOfWork.Add(optionalCourseTeachingMode); } } //限选设定授课方式表 //if (optionalCourseTeachingMode != null) //{ // SetModifyStatus(optionalCourseTeachingMode); //} //else //{ // optionalCourseTeachingMode = new EM_ExecutableOptionalCourseTeachingMode(); // optionalCourseTeachingMode.ExecutableOptionalCourseTeachingModeID = Guid.NewGuid(); // optionalCourseTeachingMode.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; // optionalCourseTeachingMode.TeachingModeID = optionalCourseSettingView.TeachingModeID; // SetNewStatus(optionalCourseTeachingMode); // UnitOfWork.Add(optionalCourseTeachingMode); //} //optionalCourseTeachingMode.TeachingModeID = optionalCourseSettingView.TeachingModeID; ////限选设定授课老师表 //if (optionalCourseTeacher != null) //{ // SetModifyStatus(optionalCourseTeacher); //} //else //{ // optionalCourseTeacher = new EM_ExecutableOptionalCourseTeacher(); // optionalCourseTeacher.ExecutableOptionalCourseTeacherID = Guid.NewGuid(); // optionalCourseTeacher.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; // SetNewStatus(optionalCourseTeacher); // UnitOfWork.Add(optionalCourseTeacher); //} ////optionalCourseTeacher.UserID = optionalCourseSettingView.TeacherID; //optionalCourseTeacher.TeachingMethod = optionalCourseSettingView.TeachingMethod; //删除教师 UnitOfWork.Delete(x => x.ExecutableOptionalCourseID == optionalCoursePlan.ExecutableOptionalCourseID); //添加教师 if (teacherList.Count > 0) { foreach (var teacher in teacherList) { EM_ExecutableOptionalCourseTeacher executableOptionalCourseTeacher = new EM_ExecutableOptionalCourseTeacher(); executableOptionalCourseTeacher.ExecutableOptionalCourseTeacherID = Guid.NewGuid(); executableOptionalCourseTeacher.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; executableOptionalCourseTeacher.UserID = teacher.UserID; executableOptionalCourseTeacher.TeachingMethod = teacher.TeachingMethod; SetNewStatus(executableOptionalCourseTeacher); UnitOfWork.Add(executableOptionalCourseTeacher); } } //限选设定教学设置表 if (optionalCourseTeachingSetting != null) { UnitOfWork.Update(optionalCourseTeachingSetting); } else { optionalCourseTeachingSetting = new EM_ExecutableOptionalCourseTeachingSetting(); optionalCourseTeachingSetting.ExecutableOptionalCourseID = optionalCourseSettingView.ExecutableOptionalCourseID.Value; UnitOfWork.Add(optionalCourseTeachingSetting); } optionalCourseTeachingSetting.Credit = optionalCourseSettingView.Credit; optionalCourseTeachingSetting.TheoryCourse = optionalCourseSettingView.TheoryCourse; optionalCourseTeachingSetting.Practicehours = optionalCourseSettingView.Practicehours; optionalCourseTeachingSetting.Trialhours = optionalCourseSettingView.Trialhours; optionalCourseTeachingSetting.WeeklyNum = optionalCourseSettingView.WeeklyNum; if (optionalCourseSettingView.WeeklyNum == 0 || optionalCourseSettingView.WeeklyNum == null) { var t = (optionalCourseSettingView.TheoryCourse.Value + optionalCourseSettingView.Practicehours.Value); var w = (optionalCourseSettingView.TheoryWeeklyNum.Value + optionalCourseSettingView.PracticeWeeklyNum.Value); if (w != 0 && t != 0) optionalCourseTeachingSetting.WeeklyNum = t / w / 2; } optionalCourseTeachingSetting.TheoryWeeklyNum = optionalCourseSettingView.TheoryWeeklyNum; optionalCourseTeachingSetting.PracticeWeeklyNum = optionalCourseSettingView.PracticeWeeklyNum; optionalCourseTeachingSetting.TrialWeeklyNum = optionalCourseSettingView.TrialWeeklyNum; optionalCourseTeachingSetting.StartWeeklyNum = optionalCourseSettingView.StartWeeklyNum; optionalCourseTeachingSetting.EndWeeklyNum = optionalCourseSettingView.EndWeeklyNum; optionalCourseTeachingSetting.WeeklyHours = optionalCourseSettingView.WeeklyHours; this.SetModifyStatus(optionalCoursePlan); UnitOfWork.Commit(); } } else { var optionalCourse=optionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetSingle( x => x.OptionalCourseID==optionalCourseSettingView.OptionalCourseID &&x.SchoolyearID==optionalCourseSettingView.SchoolyearID &&x.GrademajorID==optionalCourseSettingView.GrademajorID); if (optionalCourse!=null) { throw new Exception("已存在重复的数据。"); } EM_ExecutableOptionalCourse optionalCoursePlan = new EM_ExecutableOptionalCourse(); optionalCoursePlan.ExecutableOptionalCourseID = Guid.NewGuid(); optionalCoursePlan.OptionalCourseID = optionalCourseSettingView.OptionalCourseID; optionalCoursePlan.SchoolyearID = optionalCourseSettingView.SchoolyearID; optionalCoursePlan.GrademajorID = optionalCourseSettingView.GrademajorID; optionalCoursePlan.DepartmentID = optionalCourseSettingView.DepartmentID; optionalCoursePlan.DefaultClassName = optionalCourseSettingView.DefaultClassName; optionalCoursePlan.CourseStructureID=optionalCourseSettingView.CourseStructureID; optionalCoursePlan.CourseCategoryID=optionalCourseSettingView.CourseCategoryID; optionalCoursePlan.CourseTypeID=optionalCourseSettingView.CourseTypeID; optionalCoursePlan.CourseQualityID=optionalCourseSettingView.CourseQualityID; optionalCoursePlan.PracticeTypeID=optionalCourseSettingView.PracticeTypeID; optionalCoursePlan.ExaminationModeID=optionalCourseSettingView.ExaminationModeID; optionalCoursePlan.TeachinglanguageID=optionalCourseSettingView.TeachinglanguageID; optionalCoursePlan.IsEnable = optionalCourseSettingView.IsEnable; optionalCoursePlan.ResultTypeID=optionalCourseSettingView.ResultTypeID; optionalCoursePlan.Remarks=optionalCourseSettingView.Remarks; optionalCoursePlan.PeopleNumlimit=optionalCourseSettingView.PeopleNumlimit; optionalCoursePlan.PeopleNumlower=optionalCourseSettingView.PeopleNumlower; optionalCoursePlan.IsOpened = optionalCourseSettingView.IsOpened; this.SetNewStatus(optionalCoursePlan); optionalCoursePlan.CF_Classmajor = new HashSet(); //插入限选设定关联班数据 foreach (var list in classList) { CF_Classmajor clas = GetClassmajor(list.ClassmajorID); optionalCoursePlan.CF_Classmajor.Add(clas); } UnitOfWork.Add(optionalCoursePlan); if (optionalCourseSettingView.TeachingModeID != null) { foreach (var i in optionalCourseSettingView.TeachingModeID) { EM_ExecutableOptionalCourseTeachingMode optionalCourseTeachingMode = new EM_ExecutableOptionalCourseTeachingMode(); optionalCourseTeachingMode.ExecutableOptionalCourseTeachingModeID = Guid.NewGuid(); optionalCourseTeachingMode.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; optionalCourseTeachingMode.TeachingModeID = i; SetNewStatus(optionalCourseTeachingMode); UnitOfWork.Add(optionalCourseTeachingMode); } } if (teacherList.Count > 0) { foreach (var teacher in teacherList) { EM_ExecutableOptionalCourseTeacher executableOptionalCourseTeacher = new EM_ExecutableOptionalCourseTeacher(); executableOptionalCourseTeacher.ExecutableOptionalCourseTeacherID = Guid.NewGuid(); executableOptionalCourseTeacher.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; executableOptionalCourseTeacher.UserID = teacher.UserID; executableOptionalCourseTeacher.TeachingMethod = teacher.TeachingMethod; SetNewStatus(executableOptionalCourseTeacher); UnitOfWork.Add(executableOptionalCourseTeacher); } } EM_ExecutableOptionalCourseTeachingSetting optionalCourseTeachingSetting = new EM_ExecutableOptionalCourseTeachingSetting(); optionalCourseTeachingSetting.ExecutableOptionalCourseID = optionalCoursePlan.ExecutableOptionalCourseID; optionalCourseTeachingSetting.Credit = optionalCourseSettingView.Credit; optionalCourseTeachingSetting.TheoryCourse = optionalCourseSettingView.TheoryCourse; optionalCourseTeachingSetting.Practicehours = optionalCourseSettingView.Practicehours; optionalCourseTeachingSetting.Trialhours = optionalCourseSettingView.Trialhours; optionalCourseTeachingSetting.WeeklyNum = optionalCourseSettingView.WeeklyNum; if (optionalCourseSettingView.WeeklyNum == 0 || optionalCourseSettingView.WeeklyNum == null) { var t = (optionalCourseSettingView.TheoryCourse.Value + optionalCourseSettingView.Practicehours.Value); var w = (optionalCourseSettingView.TheoryWeeklyNum.Value + optionalCourseSettingView.PracticeWeeklyNum.Value); if (w != 0 && t != 0) optionalCourseTeachingSetting.WeeklyNum = t / w / 2; } optionalCourseTeachingSetting.TheoryWeeklyNum = optionalCourseSettingView.TheoryWeeklyNum; optionalCourseTeachingSetting.PracticeWeeklyNum = optionalCourseSettingView.PracticeWeeklyNum; optionalCourseTeachingSetting.TrialWeeklyNum = optionalCourseSettingView.TrialWeeklyNum; optionalCourseTeachingSetting.StartWeeklyNum = optionalCourseSettingView.StartWeeklyNum; optionalCourseTeachingSetting.EndWeeklyNum = optionalCourseSettingView.EndWeeklyNum; optionalCourseTeachingSetting.WeeklyHours = optionalCourseSettingView.WeeklyHours; UnitOfWork.Commit(); } } catch (Exception) { throw; } } public List GetTeachingModeType(Guid? specialtyCourseID) { return optionalCourseSettingDAL.GetTeachingModeTypeQueryble(specialtyCourseID); } /// /// 删除 /// /// /// public bool OptionalCourseSettingDelete(List optionalCourseSettingIDs) { try { if (optionalCourseSettingIDs.Count > 0) { for (int i = 0; i < optionalCourseSettingIDs.Count; i++) { Guid optionalCourseSettingID = optionalCourseSettingIDs[i]; var executableOptionalCourse = optionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetSingle( x => x.ExecutableOptionalCourseID == optionalCourseSettingID); if (executableOptionalCourse != null) { if (executableOptionalCourse.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen) throw new Exception("只能删除未开放状态的信息。"); //if (executableOptionalCourse.IsEnable==true) // throw new Exception("该限选已启用不能能删除。"); if (executableOptionalCourse.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Opened) throw new Exception("只能删除未开放状态的信息。"); } executableOptionalCourse.CF_Classmajor = new HashSet(); executableOptionalCourse.CF_Student = new HashSet(); UnitOfWork.Delete(executableOptionalCourse, (x => x.CF_Classmajor)); UnitOfWork.Delete(executableOptionalCourse, (x => x.CF_Student)); } //EM_ExecutableOptionalCourse em = new EM_ExecutableOptionalCourse(); //em.CF_Classmajor = new HashSet(); ////optionalCoursePlan.CF_Classmajor.Clear(); ////optionalCoursePlan.CF_Classmajor.r; //UnitOfWork.Delete(em.ExecutableOptionalCourseID., x => x.CF_Classmajor); //限选设定教学设置表 UnitOfWork.Delete(x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID)); //限选设定授课老师表 UnitOfWork.Delete(x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID.Value)); //限选设定授课方式表 UnitOfWork.Delete(x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID.Value)); //限选计划 UnitOfWork.Delete(x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID)); return true; } return false; } catch (Exception) { throw; } } /// /// 现在是开放操作 /// /// /// public bool OptionalCourseSettingSubmit(List optionalCourseSettingIDs) { try { if (optionalCourseSettingIDs.Count > 0) { //Expression> exp = (x => true); //Expression> exp1 = (x => true); //Expression> exp2 = (x => true); //Expression> exp3 = (x => true); for (int i = 0; i < optionalCourseSettingIDs.Count; i++) { Guid optionalCourseSettingID = optionalCourseSettingIDs[i]; var executableOptionalCourse = optionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetSingle( x => x.ExecutableOptionalCourseID == optionalCourseSettingID && (x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen || x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate)); if (executableOptionalCourse != null) { EM_OptionalCoursePlan ocp = optionalCoursePlanDAL.OptionalCoursePlanRepository.GetSingle(x => x.OptionalCourseID == executableOptionalCourse.OptionalCourseID); //查询要开放的限选设定及相关班级 var query = optionalCourseSettingDAL.GetSubmitcompareClassmajor().Where(x => x.ExecutableOptionalCourseID == executableOptionalCourse.ExecutableOptionalCourseID); List clas = query.Select(x => x.ClassmajorID).ToList(); //相关班级ID //查询所有限选设定及相关班级 var query1 = optionalCourseSettingDAL.GetSubmitcompareClassmajor().Where(x => x.ExecutableOptionalCourseID != executableOptionalCourse.ExecutableOptionalCourseID && x.SchoolyearID == executableOptionalCourse.SchoolyearID && x.CoursematerialID == ocp.CoursematerialID); var list = query1.ToList(); //查询要开放的限选设定及相关授课老师ID var teacherList = optionalCourseSettingDAL.GetEducationMissionClassTeacherListViewQueryble(). Where(x => x.ExecutableOptionalCourseID == executableOptionalCourse.ExecutableOptionalCourseID). Select(x => x.UserID).ToList(); if (teacherList.Count > 0) //有授课老师才进行判断 { //查询要开放的数据中班级是否有重复 var result = list.Where(x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID) && clas.Contains(x.ClassmajorID)).ToList(); if (result.Count > 0) { //班级重复的数据中查询老师是否也是重复 var IDs = result.Select(x => x.ExecutableOptionalCourseID).ToList(); var teacher = optionalCourseSettingDAL.ExecutableOptionalCourseRepository.Entities.Where(x => IDs.Contains(x.ExecutableOptionalCourseID) && x.ExecutableOptionalCourseID != executableOptionalCourse.ExecutableOptionalCourseID && x.EM_ExecutableOptionalCourseTeacher.Count() == teacherList.Count && x.EM_ExecutableOptionalCourseTeacher.Count() == (x.EM_ExecutableOptionalCourseTeacher. Where(w => teacherList.Contains(w.UserID.Value)).Count())); if (teacher.ToList().Count > 0) throw new Exception(string.Format("【{0}】和【{1}】存在相同的开放班级和授课老师,请核查。", result[0].DefaultClassName, executableOptionalCourse.DefaultClassName)); //throw new Exception(string.Format("【{0}】和【{1}】存在相同的开放班级,请核查。", result[0].DefaultClassName, executableOptionalCourse.DefaultClassName)); } var result1 = list.Where(x => x.RecordStatus > (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen && clas.Contains(x.ClassmajorID)).ToList(); if (result1.Count > 0) { var IDs = result1.Select(x => x.ExecutableOptionalCourseID).ToList(); var teacher = optionalCourseSettingDAL.ExecutableOptionalCourseRepository.Entities.Where(x => IDs.Contains(x.ExecutableOptionalCourseID) && x.EM_ExecutableOptionalCourseTeacher.Count() == teacherList.Count && x.EM_ExecutableOptionalCourseTeacher.Count() == (x.EM_ExecutableOptionalCourseTeacher. Where(w => teacherList.Contains(w.UserID.Value)).Count())); if (teacher.ToList().Count > 0) throw new Exception(string.Format("已开放的【{0}】和准备开放的【{1}】存在相同的开放班级和授课老师,请核查。", result1[0].DefaultClassName, executableOptionalCourse.DefaultClassName)); //throw new Exception(string.Format("已开放的【{0}】和准备开放的【{1}】存在相同的开放班级,请核查。", result1[0].DefaultClassName, executableOptionalCourse.DefaultClassName)); } } executableOptionalCourse.RecordStatus = (int)EM_SelectCourseResultStatus.Opened; } else throw new Exception("当前状态的数据不能开放,请核查"); } UnitOfWork.Commit(); return true; } return false; } catch (Exception) { throw; } } //取消开放 public bool OptionalCourseSettingCancel(List optionalCourseSettingIDs) { try { if (optionalCourseSettingIDs.Count > 0) { var ExecutableOptionalCourseList = optionalCourseSettingDAL.ExecutableOptionalCourseRepository.GetList(x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID)).ToList(); foreach (var ExecutableOptionalCourse in ExecutableOptionalCourseList) { if (ExecutableOptionalCourse.RecordStatus < (int)EMIS.ViewModel.EM_SelectCourseResultStatus.Opened) //开放状态 { throw new Exception("限选设定未开放"); } } UnitOfWork.Update(x => new EM_ExecutableOptionalCourse { RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen }, x => optionalCourseSettingIDs.Contains(x.ExecutableOptionalCourseID)); this.UnitOfWork.Commit(); return true; } return false; } catch (Exception) { throw; } } /// /// 获取授课老师 /// /// /// public List GetEducationMissionClassTeacherListViewList(Guid executableOptionalCourseID) { return optionalCourseSettingDAL.GetEducationMissionClassTeacherListViewQueryble().Where(x => x.ExecutableOptionalCourseID == executableOptionalCourseID).OrderBy(x => x.TeachingMethod).ToList(); } public List GetClassmajorList(Guid? executableOptionalCourseID) { //查询条件 var query = optionalCourseSettingDAL.GetExecutableOptionalCourseClassmajorList().Where(x => x.ExecutableOptionalCourseID == executableOptionalCourseID).OrderBy(x => x.No).ToList(); return query; //return classmajorDAL.classmajorRepository.GetSingle(w => w.ClassmajorID == classmajorID); } public CF_Classmajor GetClassmajor(Guid? classmajorID) { //查询条件 return classmajorDAL.ClassmajorRepository.GetSingle(w => w.ClassmajorID == classmajorID); } } }