using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.Entity; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.SelectCourse; using EMIS.ViewModel; using EMIS.Entities; using EMIS.DataLogic.SelectCourse; using EMIS.DataLogic.Repositories; using EMIS.CommonLogic.SystemServices; using EMIS.Utility.FormValidate; using EMIS.ViewModel.EnrollManage.SpecialtyManage; using System.Transactions; namespace EMIS.CommonLogic.SelectCourse { public class FreeSelectionCourseApplyServices : BaseWorkflowServices, IFreeSelectionCourseApplyServices { public ExecutableFreeSelectionCouseDAL ExecutableFreeSelectionCouseDAL { get; set; } public FreeSelectionCoursePlanDAL FreeSelectionCoursePlanDAL { get; set; } public FreeSelectionCourseDAL FreeSelectionCourseDAL { get; set; } public IStudentSelectCourseServices IStudentSelectCourseServices { get; set; } public FreeSelectionCouseTeachingModeRepository FreeSelectionCouseTeachingModeRepository { get; set; } public StaffRepository staffRepository { get; set; } public UserRepository userRepository { get; set; } private IGridResultSet GetFreeSelectionCourseApplyView(ConfiguretView configuretView, Expression> exp, int? pageIndex = null, int? pageSize = null, bool? isApproveView = false) { var freeSelectionCourseView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyViewQueryable(exp); var teacherView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyTeacherViewQueryable(exp); var schedulingView = FreeSelectionCoursePlanDAL.GetScheduling(exp).ToList(); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { freeSelectionCourseView = freeSelectionCourseView.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } freeSelectionCourseView = this.GetQueryByDataRangeByCollege(freeSelectionCourseView); IGridResultSet result; IList teacherViewList; if (pageIndex.HasValue && pageSize.HasValue) { if (isApproveView == true) { result = this.QueryByPendingJob(freeSelectionCourseView, CustomPrincipal.Current.UserID, (x => x.FreeSelectionCouseApplyID), (x => x.CreateTime), true, pageIndex, pageSize); } else { result = freeSelectionCourseView.OrderByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); } //由于分页后数据量较少,可以考虑用Contains方法在数据库端筛选一下,不分页的情况就不要了 var freeSelectionCourseIDList = result.rows.Select(x => x.FreeSelectionCouseApplyID).ToList(); teacherViewList = teacherView.Where(x => freeSelectionCourseIDList.Contains(x.FreeSelectionCourseApplyID)).ToList(); } else { var list = freeSelectionCourseView.ToList(); if (isApproveView == true) { result = this.QueryByPendingJob(freeSelectionCourseView, CustomPrincipal.Current.UserID, (x => x.FreeSelectionCouseApplyID), (x => x.CreateTime), true); } else { result = new GridResultSet() { rows = list, total = list.Count }; } teacherViewList = teacherView.ToList(); } var statusViewList = this.GetStatusViewList(); result.rows.ForEach(x => { x.Teachers = new HashSet(teacherViewList .Where(w => x.FreeSelectionCouseApplyID == w.FreeSelectionCourseApplyID)); x.ApprovalStatusName = statusViewList.Where(w => w.ID == x.ApprovalStatus) .Select(w => w.Name).FirstOrDefault(); }); if (schedulingView.Count > 0) { var schedulingList = IStudentSelectCourseServices.GetWeekdayTimesSegmentName(schedulingView); result.rows.ForEach(x => { var list = schedulingList.Where(w => w.ID == x.FreeSelectionCouseApplyID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); }); } return result; } public EM_FreeSelectionCouse GetFreeSelectionCourse(Guid? freeSelectionCourseID) { System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.FreeSelectionCouseID == freeSelectionCourseID); return FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetSingle(expression, (x => x.CF_Department), (x => x.EM_Coursematerial)); } public FreeSelectionCourseView GetFreeSelectionCourseView(Guid? freeSelectionCourseID) { var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); return query.Where(x => x.FreeSelectionCouseID == freeSelectionCourseID).FirstOrDefault(); } public EM_FreeSelectionCouseTeachingSetting GetFreeSelectionCourseTeachingSetting(Guid? freeSelectionCourseID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => true); expression = (x => x.FreeSelectionCouseID == freeSelectionCourseID); return FreeSelectionCourseDAL.FreeSelectionCouseTeachingSettingRepository.GetSingle(expression); } private bool TeachingModeTypeAdd(List list, Guid? freeSelectionCourseApplyID) { try { if (list.Count > 0) { UnitOfWork.Delete(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID); foreach (var i in list) { EM_FreeSelectionCouseApplyTeachingMode teachingModeType = new EM_FreeSelectionCouseApplyTeachingMode(); teachingModeType.FreeSelectionCouseApplyTeachingModeID = Guid.NewGuid(); teachingModeType.FreeSelectionCouseApplyID = freeSelectionCourseApplyID; teachingModeType.TeachingModeID = i; this.SetNewStatus(teachingModeType); UnitOfWork.Add(teachingModeType); } } return true; } catch (Exception) { throw; } } /// /// 根据任选开课获取授课方式 /// /// /// public List GetCourseApplyTeachingModeType(Guid? FreeSelectionCouseApplyID) { var list = FreeSelectionCoursePlanDAL.GetTeachingModeType(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID) .Select(x => x.Value ?? 0).ToList(); if (list.Count > 0) list.Add((int)EMIS.ViewModel.CF_TeachingMode.Theory); return list; } /// /// 根据任选开课获取授课方式 /// /// /// public List GetCourseApplyGradeYear(Guid? FreeSelectionCouseApplyID) { List list = new List(); return FreeSelectionCoursePlanDAL.GetGradeYear(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID) .Select(x => x.Value ?? 0).ToList(); } public EM_FreeSelectionCouse GetFreeSelectionCourseCourse(Guid? coursematerialID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.CoursematerialID == coursematerialID); return FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetSingle(expression, (x => x.CF_Department), (x => x.EM_Coursematerial)); } public IGridResultSet GetFreeSelectionCoursePlanViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (campusID.HasValue) exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID); if (collegeID.HasValue) exp = exp.And(x => x.CF_Department.CollegeID == collegeID); if (departmentID.HasValue) exp = exp.And(x => x.DepartmentID == departmentID); if (approvalStatus.HasValue) exp = exp.And(x => x.ApprovalStatus == approvalStatus); return this.GetFreeSelectionCourseApplyView(configuretView, exp, pageIndex, pageSize); } public List GetFreeSelectionCoursePlanViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (campusID.HasValue) exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID); if (collegeID.HasValue) exp = exp.And(x => x.CF_Department.CollegeID == collegeID); if (departmentID.HasValue) exp = exp.And(x => x.DepartmentID == departmentID); if (approvalStatus.HasValue) exp = exp.And(x => x.ApprovalStatus == approvalStatus); return this.GetFreeSelectionCourseApplyView(configuretView, exp).rows; } public IGridResultSet GetFreeSelectionCoursePlanApprovalViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus, int pageIndex, int pageSize) { List approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && approveStatusList.Contains(x.ApprovalStatus)); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (campusID.HasValue) exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID); if (collegeID.HasValue) exp = exp.And(x => x.CF_Department.CollegeID == collegeID); if (departmentID.HasValue) exp = exp.And(x => x.DepartmentID == departmentID); if (approvalStatus.HasValue) exp = exp.And(x => x.ApprovalStatus == approvalStatus); if (approveStatusList.Count > 0) exp = exp.And(x => approveStatusList.Contains(x.ApprovalStatus)); return this.GetFreeSelectionCourseApplyView(configuretView, exp, pageIndex, pageSize, true); } public List GetFreeSelectionCoursePlanApprovalView(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus) { List approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && approveStatusList.Contains(x.ApprovalStatus)); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (campusID.HasValue) exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID); if (collegeID.HasValue) exp = exp.And(x => x.CF_Department.CollegeID == collegeID); if (departmentID.HasValue) exp = exp.And(x => x.DepartmentID == departmentID); if (approvalStatus.HasValue) exp = exp.And(x => x.ApprovalStatus == approvalStatus); if (approveStatusList.Count > 0) exp = exp.And(x => approveStatusList.Contains(x.ApprovalStatus)); return this.GetFreeSelectionCourseApplyView(configuretView, exp, null, null, true).rows; } public FreeSelectionCourseApplyView GetFreeSelectionCourseApplyView(Guid? freeSelectionCourseApplyID) { return FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyViewQueryable(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID) .FirstOrDefault(); } public EM_FreeSelectionCouseApply GetFreeSelectionCourseApply(Guid? freeSelectionCourseApplyID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID); return FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetSingle(expression); } /// /// 提交申请 /// /// 申请ID /// 提交人 /// 备注 public void Submit(List freeSelectionCourseApplyIDs, Guid userID, string comment = "") { try { var startStatus = this.GetStartStatus(); List approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList(); var freeSelectionCouseApplyList = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetList(x => freeSelectionCourseApplyIDs.Contains(x.FreeSelectionCouseApplyID)).ToList(); List submitIDList = new List(); List approveIDList = new List(); if (freeSelectionCouseApplyList.Count > 0) { for (int i = 0; i < freeSelectionCouseApplyList.Count; i++) { if (freeSelectionCouseApplyList[i].ApprovalStatus == startStatus) { submitIDList.Add(freeSelectionCouseApplyList[i].FreeSelectionCouseApplyID); } else if (approveStatusList.Contains(freeSelectionCouseApplyList[i].ApprovalStatus)) { throw new Exception("数据已提交申请,不能重复提交"); } else { approveIDList.Add(freeSelectionCouseApplyList[i].FreeSelectionCouseApplyID); } } approveIDList = approveIDList.Where(x => !submitIDList.Contains(x)).ToList(); if (submitIDList.Count > 0) { StartUp(submitIDList, userID, ""); } if (approveIDList.Count > 0) { Approve(approveIDList, userID, Guid.Empty, comment); } } } catch (Exception) { throw; } } public void Approved(List FreeSelectionCouseApplyIDList, Guid userID) { var freeSelectionCourseApplyList = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetList(x => FreeSelectionCouseApplyIDList.Contains(x.FreeSelectionCouseApplyID), x => x.EM_FreeSelectionCouse, x => x.EM_FreeSelectionCouseApplyGradeYear, x => x.EM_FreeSelectionCouseApplyTeachingSetting, x => x.EM_FreeSelectionCouseApplyTeachingMode, x => x.EM_FreeSelectionCouseApplyGradeYear, x => x.EM_FreeSelectionCouseApplySpecialty, x => x.EM_FreeSelectionCouseApplyScheduling, x => x.EM_FreeSelectionCouseApplyTeacher).ToList(); foreach (var freeSelectionCourseApply in freeSelectionCourseApplyList) { //任选课开课申请表 EM_ExecutableFreeSelectionCouse executableFreeSelectionCouse = new EM_ExecutableFreeSelectionCouse(); executableFreeSelectionCouse.ExecutableFreeSelectionCouseID = Guid.NewGuid(); executableFreeSelectionCouse.FreeSelectionCouseID = freeSelectionCourseApply.FreeSelectionCouseID; executableFreeSelectionCouse.SchoolyearID = freeSelectionCourseApply.SchoolyearID; executableFreeSelectionCouse.DefaultClassName = freeSelectionCourseApply.DefaultClassName; executableFreeSelectionCouse.DepartmentID = freeSelectionCourseApply.DepartmentID; executableFreeSelectionCouse.CourseStructureID = freeSelectionCourseApply.CourseStructureID; executableFreeSelectionCouse.CourseCategoryID = freeSelectionCourseApply.CourseCategoryID; executableFreeSelectionCouse.CourseTypeID = freeSelectionCourseApply.CourseTypeID; executableFreeSelectionCouse.CourseQualityID = freeSelectionCourseApply.CourseQualityID; executableFreeSelectionCouse.PracticeTypeID = freeSelectionCourseApply.PracticeTypeID; executableFreeSelectionCouse.ExaminationModeID = freeSelectionCourseApply.ExaminationModeID; executableFreeSelectionCouse.TeachinglanguageID = freeSelectionCourseApply.TeachinglanguageID; executableFreeSelectionCouse.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial; executableFreeSelectionCouse.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower; executableFreeSelectionCouse.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit; executableFreeSelectionCouse.HandleModeID = freeSelectionCourseApply.HandleModeID; executableFreeSelectionCouse.ResultTypeID = freeSelectionCourseApply.ResultTypeID; executableFreeSelectionCouse.Remarks = freeSelectionCourseApply.Remarks; this.SetNewStatus(executableFreeSelectionCouse); UnitOfWork.Add(executableFreeSelectionCouse); //任选课开课申请教学设置表 EM_ExecutableFreeSelectionCouseTeachingSetting executableFreeSelectionCouseTeachingSetting = new EM_ExecutableFreeSelectionCouseTeachingSetting(); executableFreeSelectionCouseTeachingSetting.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID; executableFreeSelectionCouseTeachingSetting.Credit = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.Credit; executableFreeSelectionCouseTeachingSetting.TheoryCourse = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.TheoryCourse; executableFreeSelectionCouseTeachingSetting.Practicehours = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.Practicehours; executableFreeSelectionCouseTeachingSetting.Trialhours = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.Trialhours; executableFreeSelectionCouseTeachingSetting.WeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.WeeklyNum; executableFreeSelectionCouseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.TheoryWeeklyNum; executableFreeSelectionCouseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.PracticeWeeklyNum; executableFreeSelectionCouseTeachingSetting.TrialWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.TrialWeeklyNum; executableFreeSelectionCouseTeachingSetting.StartWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.StartWeeklyNum; executableFreeSelectionCouseTeachingSetting.EndWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.EndWeeklyNum; executableFreeSelectionCouseTeachingSetting.WeeklyHours = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.WeeklyHours; //SetNewStatus(freeSelectionCourseTeachingSetting); UnitOfWork.Add(executableFreeSelectionCouseTeachingSetting); //任选课开课申请课程表 if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling != null) { //首先查出至少一个教室 var firstClassroomID = freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling.Select(x => x.ClassroomID).FirstOrDefault(); freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling.ToList().ForEach(x => { var scheduling = new EM_ExecutableFreeSelectionCouseScheduling { ExecutableFreeSelectionCouseSchedulingID = Guid.NewGuid(), ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID, ClassroomID = x.ClassroomID != null ? x.ClassroomID : firstClassroomID, //这一行没有教室时,填查询到的其它行的教室,如果都没有就为空 CoursesTimeID = x.CoursesTimeID, Weekday = x.Weekday, }; this.SetNewStatus(scheduling); this.UnitOfWork.Add(scheduling); }); //var freeSelectionCouseApplyScheduling = freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling.FirstOrDefault(); //EM_ExecutableFreeSelectionCouseScheduling executableFreeSelectionCouseScheduling = new EM_ExecutableFreeSelectionCouseScheduling(); //executableFreeSelectionCouseScheduling.ExecutableFreeSelectionCouseSchedulingID = Guid.NewGuid(); //executableFreeSelectionCouseScheduling.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID; //executableFreeSelectionCousefreeSelectionCourseApply.ClassroomID = freeSelectionCouseApplyfreeSelectionCourseApply.ClassroomID; //executableFreeSelectionCouseScheduling.CoursesTimeID = freeSelectionCouseApplyScheduling.CoursesTimeID; //executableFreeSelectionCouseScheduling.Weekday = freeSelectionCouseApplyScheduling.Weekday; //SetNewStatus(executableFreeSelectionCouseScheduling); //UnitOfWork.Add(executableFreeSelectionCouseScheduling); } //任选课开课申请授课方式表 if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingMode != null) { var list = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingMode; if (list.Count > 0) { //UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID); foreach (var i in list) { EM_ExecutableFreeSelectionCouseTeachingMode teachingModeType = new EM_ExecutableFreeSelectionCouseTeachingMode(); teachingModeType.ExecutableFreeSelectionCouseTeachingModeID = Guid.NewGuid(); teachingModeType.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID; teachingModeType.TeachingModeID = i.TeachingModeID; //this.SetNewStatus(teachingModeType); UnitOfWork.Add(teachingModeType); } } } //任选课开课申请年级范围表 if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyGradeYear != null) { var list = freeSelectionCourseApply.EM_FreeSelectionCouseApplyGradeYear; if (list.Count > 0) { //UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID); foreach (var i in list) { EM_ExecutableFreeSelectionCouseGradeYear gradeYear = new EM_ExecutableFreeSelectionCouseGradeYear(); gradeYear.ExecutableFreeSelectionCouseGradeYearID = Guid.NewGuid(); gradeYear.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID; gradeYear.GradeYear = i.GradeYear; this.SetNewStatus(gradeYear); UnitOfWork.Add(gradeYear); } } } //任选课开课申请专业范围表 if (freeSelectionCourseApply.EM_FreeSelectionCouseApplySpecialty != null) { //UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID); foreach (var i in freeSelectionCourseApply.EM_FreeSelectionCouseApplySpecialty) { EM_ExecutableFreeSelectionCouseSpecialty specialty = new EM_ExecutableFreeSelectionCouseSpecialty(); specialty.ExecutableFreeSelectionCouseSpecialtyID = Guid.NewGuid(); specialty.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID; specialty.SpecialtyID = i.SpecialtyID; this.SetNewStatus(specialty); UnitOfWork.Add(specialty); } } //任选课开课申请教师表 if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher != null) { freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher.ToList().ForEach(x => { var freeSelectionTeacher = new EM_ExecutableFreeSelectionCouseTeacher { ExecutableFreeSelectionCouseStaffID = Guid.NewGuid(), ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID, UserID = x.UserID, TeachingMethod = x.TeachingMethod }; this.SetNewStatus(freeSelectionTeacher); this.UnitOfWork.Add(freeSelectionTeacher); }); } executableFreeSelectionCouse.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen; } UnitOfWork.Commit(); ////任选课开课申请教学设置表 //EM_FreeSelectionCouseApplyTeachingSetting freeSelectionCourseTeachingSetting = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyTeachingSettingRepository.Entities.Where(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID).FirstOrDefault(); ////任选课开课申请课程表 //EM_FreeSelectionCouseApplyScheduling freeSelectionCouseApplyScheduling = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplySchedulingRepository.Entities.Where(x => x.FreeSelectionCouseApplySchedulingID == FreeSelectionCouseApplyID).FirstOrDefault(); ////任选课开课申请授课方式表 //EM_FreeSelectionCouseApplyTeachingMode // EM_FreeSelectionCouseApplyGradeYear // EM_FreeSelectionCouseApplySpecialty // EM_FreeSelectionCouseApplyScheduling } public bool FreeSelectionCourseApplyAdd(FreeSelectionCourseApplyView freeSelectionCourseApply, IList teacherList, IList specialtyList, IList schedulingList, out int? type) { try { var StartStatus = this.GetStartStatus(); var EndStatus = this.GetCorrectEndStatus(); //schedulingList = schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null && x.ClassroomID != null).ToList(); if (schedulingList.Where(x => x.CoursesTimeID == null || x.Weekday == null).ToList().Count > 0) { throw new Exception("排课信息不能为空"); } //else //{ // var repeat = schedulingList.GroupBy(x => new { x.Weekday, x.CoursesTimeID }).Max().ToList(); // if (repeat.Count > 1) // throw new Exception("上课时间不能重复"); //} var SpecialtyIDList = specialtyList.Select(x => x.SpecialtyID).ToList(); var freeSelectionCourse = this.GetFreeSelectionCourseView(freeSelectionCourseApply.FreeSelectionCouseID); if (this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName && x.DepartmentID == freeSelectionCourseApply.DepartmentID && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID && x.EM_FreeSelectionCouseApplySpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID)) ).Count() > 0) { throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期已经申请过了,无需重复申请。"); } if (this.ExecutableFreeSelectionCouseDAL.ExecutableFreeSelectionCouseRepository .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName && x.DepartmentID == freeSelectionCourseApply.DepartmentID && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID && x.EM_ExecutableFreeSelectionCouseSpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID)) ).Count() > 0) { throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期存在相同的任选设定。"); } //如果IsNeedVerify为false时,不验证冲突 if (freeSelectionCourseApply.IsNeedVerify != false) { //判断教室和教室冲突 foreach (var scheduling in schedulingList) { if (freeSelectionCourseApply.ClassroomID != null) { //任选设定冲突 var repeatExecutableClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatExecutableClassroom != null) { type = 1; throw new Exception(repeatExecutableClassroom.WeekdayName + "第" + repeatExecutableClassroom.StartTimes + "节时间段教室与任选设定【" + repeatExecutableClassroom.DefaultClassName + "】有冲突"); } //任选申请冲突 var repeatApplyClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, EndStatus).FirstOrDefault(); if (repeatApplyClassroom != null) { type = 1; throw new Exception(repeatApplyClassroom.WeekdayName + "第" + repeatApplyClassroom.StartTimes + "节时间段教室与开课申请【" + repeatApplyClassroom.DefaultClassName + "】有冲突"); } //教学任务冲突 var repeatEducationClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatEducationClassroom != null) { type = 1; throw new Exception("该设定上课时间段教室与教学任务班【" + repeatEducationClassroom.DefaultClassName + "】有冲突"); } } //任选设定冲突 var repeatExecutableTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatExecutableTeacher != null) { type = 1; throw new Exception(repeatExecutableTeacher.WeekdayName + "第" + repeatExecutableTeacher.StartTimes + "节时间段教师与任选设定【" + repeatExecutableTeacher.DefaultClassName + "】有冲突"); } //任选申请冲突 var repeatApplyTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, EndStatus).FirstOrDefault(); if (repeatApplyTeacher != null) { type = 1; throw new Exception(repeatApplyTeacher.WeekdayName + "第" + repeatApplyTeacher.StartTimes + "节时间段教师与开课申请【" + repeatApplyTeacher.DefaultClassName + "】有冲突"); } //教学任务冲突 var repeatEducationTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatEducationTeacher != null) { type = 1; throw new Exception("该设定上课时间段教师与教学任务班【" + repeatEducationTeacher.DefaultClassName + "】有冲突"); } } } using (TransactionScope ts = new TransactionScope()) { //任选课开课申请表 EM_FreeSelectionCouseApply freeSelectionCourseApplyEntity = new EM_FreeSelectionCouseApply(); freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID = Guid.NewGuid(); freeSelectionCourseApplyEntity.FreeSelectionCouseID = freeSelectionCourseApply.FreeSelectionCouseID; freeSelectionCourseApplyEntity.SchoolyearID = freeSelectionCourseApply.SchoolyearID; freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourseApply.DefaultClassName; //freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourse.DepartmentName + "-" // + freeSelectionCourse.CourseName + "班(任选)"; freeSelectionCourseApplyEntity.DepartmentID = freeSelectionCourseApply.DepartmentID; freeSelectionCourseApplyEntity.CourseStructureID = freeSelectionCourseApply.CourseStructureID; freeSelectionCourseApplyEntity.CourseCategoryID = freeSelectionCourseApply.CourseCategoryID; freeSelectionCourseApplyEntity.CourseTypeID = freeSelectionCourseApply.CourseTypeID; freeSelectionCourseApplyEntity.CourseQualityID = freeSelectionCourseApply.CourseQualityID; freeSelectionCourseApplyEntity.PracticeTypeID = freeSelectionCourseApply.PracticeTypeID; freeSelectionCourseApplyEntity.ExaminationModeID = freeSelectionCourseApply.ExaminationModeID; freeSelectionCourseApplyEntity.TeachinglanguageID = freeSelectionCourseApply.TeachinglanguageID; freeSelectionCourseApplyEntity.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial; freeSelectionCourseApplyEntity.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower; freeSelectionCourseApplyEntity.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit; freeSelectionCourseApplyEntity.HandleModeID = freeSelectionCourseApply.HandleModeID; freeSelectionCourseApplyEntity.IsOpened = freeSelectionCourseApply.IsOpened; freeSelectionCourseApplyEntity.ApprovalStatus = StartStatus; freeSelectionCourseApplyEntity.ResultTypeID = freeSelectionCourseApply.ResultTypeID; freeSelectionCourseApplyEntity.Remarks = freeSelectionCourseApply.Remarks; this.SetNewStatus(freeSelectionCourseApplyEntity); UnitOfWork.Add(freeSelectionCourseApplyEntity); //任选课开课申请教学设置表 EM_FreeSelectionCouseApplyTeachingSetting freeSelectionCourseTeachingSetting; freeSelectionCourseTeachingSetting = new EM_FreeSelectionCouseApplyTeachingSetting(); freeSelectionCourseTeachingSetting.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseApply.Credit; freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseApply.TheoryCourse; freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseApply.Practicehours; freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseApply.Trialhours; freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseApply.WeeklyNum; freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseApply.TheoryWeeklyNum; freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseApply.PracticeWeeklyNum; freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseApply.TrialWeeklyNum; freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseApply.StartWeeklyNum; freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseApply.EndWeeklyNum; freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseApply.WeeklyHours; //SetNewStatus(freeSelectionCourseTeachingSetting); UnitOfWork.Add(freeSelectionCourseTeachingSetting); //任选设定课程表 schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null).ToList().ForEach(x => { var scheduling = new EM_FreeSelectionCouseApplyScheduling { FreeSelectionCouseApplySchedulingID = Guid.NewGuid(), FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID, ClassroomID = freeSelectionCourseApply.ClassroomID, //这一行没有教室时,填查询到的其它行的教室,如果都没有就为空 CoursesTimeID = x.CoursesTimeID, Weekday = x.Weekday, }; this.SetNewStatus(scheduling); this.UnitOfWork.Add(scheduling); }); //任选课开课申请授课方式表,没有时默认为理论 if (freeSelectionCourseApply.TeachingModeID != null) { var list = freeSelectionCourseApply.TeachingModeID; if (list.Count > 0) { //UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID); foreach (var i in list) { EM_FreeSelectionCouseApplyTeachingMode teachingModeType = new EM_FreeSelectionCouseApplyTeachingMode(); teachingModeType.FreeSelectionCouseApplyTeachingModeID = Guid.NewGuid(); teachingModeType.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; teachingModeType.TeachingModeID = i; //this.SetNewStatus(teachingModeType); UnitOfWork.Add(teachingModeType); } } } else { EM_FreeSelectionCouseApplyTeachingMode teachingModeType = new EM_FreeSelectionCouseApplyTeachingMode(); teachingModeType.FreeSelectionCouseApplyTeachingModeID = Guid.NewGuid(); teachingModeType.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; teachingModeType.TeachingModeID = (int)EMIS.ViewModel.CF_TeachingMode.Theory; UnitOfWork.Add(teachingModeType); } //任选课开课申请年级范围表 if (freeSelectionCourseApply.GradeYear != null) { var list = freeSelectionCourseApply.GradeYear; if (list.Count > 0) { //UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID); foreach (var i in list) { EM_FreeSelectionCouseApplyGradeYear gradeYear = new EM_FreeSelectionCouseApplyGradeYear(); gradeYear.FreeSelectionCouseApplyGradeYearID = Guid.NewGuid(); gradeYear.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; gradeYear.GradeYear = i; this.SetNewStatus(gradeYear); UnitOfWork.Add(gradeYear); } } } //任选课开课申请专业范围表 if (specialtyList.Count > 0) { //UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID); foreach (var i in specialtyList) { EM_FreeSelectionCouseApplySpecialty specialty = new EM_FreeSelectionCouseApplySpecialty(); specialty.FreeSelectionCouseApplySpecialtyID = Guid.NewGuid(); specialty.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; specialty.SpecialtyID = i.SpecialtyID; this.SetNewStatus(specialty); UnitOfWork.Add(specialty); } } //任选课开课申请教师表,没有授课老师时,默认为申请人 if (teacherList.Count > 0) { var ids = teacherList.Select(w => w.UserID).ToList(); var noExistStaff = userRepository.GetList(x => ids.Contains(x.UserID) && x.CF_Staff == null).FirstOrDefault(); if (noExistStaff != null) throw new Exception(noExistStaff.Name + "账号不是教职工账号,不能设为授课老师"); teacherList.ToList().ForEach(x => { var freeSelectionTeacher = new EM_FreeSelectionCouseApplyTeacher { FreeSelectionCouseApplyStaffID = Guid.NewGuid(), FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID, UserID = x.UserID, TeachingMethod = x.TeachingMethod }; this.SetNewStatus(freeSelectionTeacher); this.UnitOfWork.Add(freeSelectionTeacher); }); } else { if (CustomPrincipal.Current.StaffID == null) throw new Exception("当前账号不是教职工账号,不能设为授课老师"); var freeSelectionTeacher = new EM_FreeSelectionCouseApplyTeacher(); freeSelectionTeacher.FreeSelectionCouseApplyStaffID = Guid.NewGuid(); freeSelectionTeacher.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; freeSelectionTeacher.UserID = CustomPrincipal.Current.UserID; freeSelectionTeacher.TeachingMethod = (int)EMIS.ViewModel.EM_TeachingMethod.Lecturer; this.SetNewStatus(freeSelectionTeacher); this.UnitOfWork.Add(freeSelectionTeacher); } UnitOfWork.Commit(); ts.Complete(); } type = 0; return true; } catch (Exception) { throw; } } public bool FreeSelectionCourseApplyUpdate(FreeSelectionCourseApplyView freeSelectionCourseApply, IList teacherList, IList specialtyList, IList schedulingList, out int? type) { try { var ApprovalStatus = this.GetCorrectEndStatus(); //schedulingList = schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null && x.ClassroomID != null).ToList(); if (schedulingList.Where(x => x.CoursesTimeID == null || x.Weekday == null).ToList().Count > 0) { throw new Exception("排课信息不能为空"); } //else //{ // var repeat = schedulingList.GroupBy(x => new { x.Weekday, x.CoursesTimeID }).Max().ToList(); // if (repeat.Count > 1) // throw new Exception("上课时间不能重复"); //} var SpecialtyIDList = specialtyList.Select(x => x.SpecialtyID).ToList(); var freeSelectionCourse = this.GetFreeSelectionCourseView(freeSelectionCourseApply.FreeSelectionCouseID); List approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList(); approveStatusList.Add(this.GetCorrectEndStatus()); if (approveStatusList.Contains(freeSelectionCourseApply.ApprovalStatus)) throw new Exception("数据已进入审核环节,不能修改。"); if (this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID && x.FreeSelectionCouseApplyID != freeSelectionCourseApply.FreeSelectionCouseApplyID && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName && x.DepartmentID == freeSelectionCourseApply.DepartmentID && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID && x.EM_FreeSelectionCouseApplySpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID)) ).Count() > 0) { throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期已经申请过了,无需重复申请。"); } if (this.ExecutableFreeSelectionCouseDAL.ExecutableFreeSelectionCouseRepository .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName && x.DepartmentID == freeSelectionCourseApply.DepartmentID && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID && x.EM_ExecutableFreeSelectionCouseSpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID)) ).Count() > 0) { throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期存在相同的任选设定。"); } if (freeSelectionCourseApply.IsNeedVerify != false) { //判断教室和教师冲突 foreach (var scheduling in schedulingList) { if (freeSelectionCourseApply.ClassroomID != null) { //任选设定冲突 var repeatExecutableClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatExecutableClassroom != null) { type = 1; throw new Exception(repeatExecutableClassroom.WeekdayName + "第" + repeatExecutableClassroom.StartTimes + "节时间段教室与任选设定【" + repeatExecutableClassroom.DefaultClassName + "】有冲突"); } //任选申请冲突 var repeatApplyClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, ApprovalStatus) .Where(x => x.ID != freeSelectionCourseApply.FreeSelectionCouseApplyID).FirstOrDefault(); if (repeatApplyClassroom != null) { type = 1; throw new Exception(repeatApplyClassroom.WeekdayName + "第" + repeatApplyClassroom.StartTimes + "节时间段教室与开课申请【" + repeatApplyClassroom.DefaultClassName + "】有冲突"); }//教学任务冲突 var repeatEducationClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatEducationClassroom != null) { type = 1; throw new Exception("该设定上课时间段教室与教学任务班【" + repeatEducationClassroom.DefaultClassName + "】有冲突"); } } //任选设定冲突 var repeatExecutableTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatExecutableTeacher != null) { type = 1; throw new Exception(repeatExecutableTeacher.WeekdayName + "第" + repeatExecutableTeacher.StartTimes + "节时间段教师与任选设定【" + repeatExecutableTeacher.DefaultClassName + "】有冲突"); } //任选申请冲突 var repeatApplyTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, ApprovalStatus) .Where(x => x.ID != freeSelectionCourseApply.FreeSelectionCouseApplyID).FirstOrDefault(); if (repeatApplyTeacher != null) { type = 1; throw new Exception(repeatApplyTeacher.WeekdayName + "第" + repeatApplyTeacher.StartTimes + "节时间段教师与开课申请【" + repeatApplyTeacher.DefaultClassName + "】有冲突"); } //教学任务冲突 var repeatEducationTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault(); if (repeatEducationTeacher != null) { type = 1; throw new Exception("该设定上课时间段教师与教学任务班【" + repeatEducationTeacher.DefaultClassName + "】有冲突"); } } } using (TransactionScope ts = new TransactionScope()) { EM_FreeSelectionCouseApply freeSelectionCourseApplyEntity = GetFreeSelectionCourseApply(freeSelectionCourseApply.FreeSelectionCouseApplyID); freeSelectionCourseApplyEntity.FreeSelectionCouseID = freeSelectionCourseApply.FreeSelectionCouseID; freeSelectionCourseApplyEntity.SchoolyearID = freeSelectionCourseApply.SchoolyearID; freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourseApply.DefaultClassName; //freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourse.DepartmentName + "-" // + freeSelectionCourse.CourseName + "班(任选)"; freeSelectionCourseApplyEntity.DepartmentID = freeSelectionCourseApply.DepartmentID; freeSelectionCourseApplyEntity.CourseStructureID = freeSelectionCourseApply.CourseStructureID; freeSelectionCourseApplyEntity.CourseCategoryID = freeSelectionCourseApply.CourseCategoryID; freeSelectionCourseApplyEntity.CourseTypeID = freeSelectionCourseApply.CourseTypeID; freeSelectionCourseApplyEntity.CourseQualityID = freeSelectionCourseApply.CourseQualityID; freeSelectionCourseApplyEntity.PracticeTypeID = freeSelectionCourseApply.PracticeTypeID; freeSelectionCourseApplyEntity.ExaminationModeID = freeSelectionCourseApply.ExaminationModeID; freeSelectionCourseApplyEntity.TeachinglanguageID = freeSelectionCourseApply.TeachinglanguageID; freeSelectionCourseApplyEntity.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial; freeSelectionCourseApplyEntity.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower; freeSelectionCourseApplyEntity.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit; freeSelectionCourseApplyEntity.HandleModeID = freeSelectionCourseApply.HandleModeID; freeSelectionCourseApplyEntity.IsOpened = freeSelectionCourseApply.IsOpened; freeSelectionCourseApplyEntity.ResultTypeID = freeSelectionCourseApply.ResultTypeID; //freeSelectionCourseApplyEntity.ApprovalStatus = freeSelectionCourseApply.ApprovalStatus;//(int)EMIS.ViewModel.CF_PlanApplicationStatus.NotSubmitted; freeSelectionCourseApplyEntity.Remarks = freeSelectionCourseApply.Remarks; //任选课开课申请教学设置表 EM_FreeSelectionCouseApplyTeachingSetting freeSelectionCourseTeachingSetting = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyTeachingSettingRepository.Entities.Where(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID).FirstOrDefault(); //freeSelectionCourseTeachingSetting = new EM_FreeSelectionCouseApplyTeachingSetting(); freeSelectionCourseTeachingSetting.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseApply.Credit; freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseApply.TheoryCourse; freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseApply.Practicehours; freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseApply.Trialhours; freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseApply.WeeklyNum; freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseApply.TheoryWeeklyNum; freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseApply.PracticeWeeklyNum; freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseApply.TrialWeeklyNum; freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseApply.StartWeeklyNum; freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseApply.EndWeeklyNum; freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseApply.WeeklyHours; //SetNewStatus(freeSelectionCourseTeachingSetting); //任选课开课申请课程表 this.UnitOfWork.Delete(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID); //首先查出至少一个教室 var firstClassroomID = schedulingList.Select(x => x.ClassroomID).FirstOrDefault(); schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null).ToList().ForEach(x => { var scheduling = new EM_FreeSelectionCouseApplyScheduling { FreeSelectionCouseApplySchedulingID = Guid.NewGuid(), FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID, ClassroomID = freeSelectionCourseApply.ClassroomID, //这一行没有教室时,填查询到的其它行的教室,如果都没有就为空 CoursesTimeID = x.CoursesTimeID, Weekday = x.Weekday, }; this.SetNewStatus(scheduling); this.UnitOfWork.Add(scheduling); }); //任选课开课申请授课方式表 if (freeSelectionCourseApply.TeachingModeID != null) { TeachingModeTypeAdd(freeSelectionCourseApply.TeachingModeID, freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID); } this.SetModifyStatus(freeSelectionCourseApplyEntity); // UnitOfWork.Delete(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID); if (freeSelectionCourseApply.GradeYear != null) { foreach (var i in freeSelectionCourseApply.GradeYear) { EM_FreeSelectionCouseApplyGradeYear gradeYear = new EM_FreeSelectionCouseApplyGradeYear(); gradeYear.FreeSelectionCouseApplyGradeYearID = Guid.NewGuid(); gradeYear.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; gradeYear.GradeYear = i; this.SetNewStatus(gradeYear); UnitOfWork.Add(gradeYear); } } // if (specialtyList.Count > 0) { UnitOfWork.Delete(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID); foreach (var i in specialtyList) { EM_FreeSelectionCouseApplySpecialty specialty = new EM_FreeSelectionCouseApplySpecialty(); specialty.FreeSelectionCouseApplySpecialtyID = Guid.NewGuid(); specialty.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID; specialty.SpecialtyID = i.SpecialtyID; this.SetNewStatus(specialty); UnitOfWork.Add(specialty); } } this.UnitOfWork.Delete(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID); teacherList.ToList().ForEach(x => { var freeSelectionTeacher = new EM_FreeSelectionCouseApplyTeacher { FreeSelectionCouseApplyStaffID = Guid.NewGuid(), FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID, UserID = x.UserID, TeachingMethod = x.TeachingMethod }; this.SetNewStatus(freeSelectionTeacher); this.UnitOfWork.Add(freeSelectionTeacher); }); this.SetModifyStatus(freeSelectionCourseApplyEntity); UnitOfWork.Commit(); ts.Complete(); } type = 0; return true; } catch (Exception) { throw; } } public bool FreeSelectionCourseApplyUpdate(IList freeSelectionCourseApplyList) { try { foreach (var freeSelectionCourseApply in freeSelectionCourseApplyList) { EM_FreeSelectionCouseApply freeSelectionCourseApplyEntity = GetFreeSelectionCourseApply(freeSelectionCourseApply.FreeSelectionCouseApplyID); freeSelectionCourseApplyEntity.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower; freeSelectionCourseApplyEntity.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit; freeSelectionCourseApplyEntity.IsOpened = freeSelectionCourseApply.IsOpened; freeSelectionCourseApplyEntity.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial; this.SetModifyStatus(freeSelectionCourseApplyEntity); } UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } public bool FreeSelectionCourseApplyDelete(List freeSelectionCourseApplyIDs) { try { if (freeSelectionCourseApplyIDs.Count > 0) { var statusList = this.GetStatusViewList(); var startStatus = this.GetStartStatus(); //所有审核环节 var status = statusList.Where(x =>x.Description.Contains("[AP]") && x.ID != startStatus || x.ID == this.GetCorrectEndStatus()).Select(x => x.ID).ToList(); foreach (var freeSelectionCourseApplyID in freeSelectionCourseApplyIDs) { EM_FreeSelectionCouseApply freeSelectionCourseApply = GetFreeSelectionCourseApply(freeSelectionCourseApplyID); if (freeSelectionCourseApply.ApprovalStatus == startStatus) //未提交状态 { UnitOfWork.Remove(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID); UnitOfWork.Remove(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID); UnitOfWork.Remove(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID); UnitOfWork.Remove(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID); UnitOfWork.Remove(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID); UnitOfWork.Remove(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID); UnitOfWork.Remove(freeSelectionCourseApply); } else if (!status.Contains(freeSelectionCourseApply.ApprovalStatus)) { ModifyProcessState(freeSelectionCourseApply.FreeSelectionCouseApplyID, "D", ""); UnitOfWork.Remove(freeSelectionCourseApply); } else { throw new Exception("数据已进入审核环节,不能删除"); //不属于以上两种情况不能删除 } } this.UnitOfWork.Commit(); return true; } return false; } catch (Exception) { throw; } } public Entities.CF_Staff GetStaff(Guid? userID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.UserID == userID); return staffRepository.GetSingle(expression, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffProfile), (x => x.Sys_User)); } public List GetFreeSelectionCourseApplyTeacherListView(Guid freeSelectionCourseApplyID) { var teacherView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyTeacherViewQueryable(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID).ToList(); if (teacherView.Count == 0) { var staff = GetStaff(CustomPrincipal.Current.UserID); FreeSelectionCourseApplyTeacherListView teacherList = new FreeSelectionCourseApplyTeacherListView(); teacherList.UserID = staff.UserID; teacherList.TeachingMethod = (int)EMIS.ViewModel.EM_TeachingMethod.Lecturer; } return teacherView; } //查询专业范围 public List GetFreeSelectionCourseApplySpecialtyListView(Guid freeSelectionCourseApplyID) { var specialtyView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplySpecialtyViewQueryable(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID); return specialtyView.ToList(); } public void SaveFreeSelectionCourseTeachers(Guid freeSelectionCourseApplyID, IList teacherList) { var freeSelectionCourseApply = this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository .GetSingle(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID, (x => x.EM_FreeSelectionCouseApplyTeacher)); freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher.ToList().ForEach(x => this.UnitOfWork.Remove(x)); //teacherList.ToList().ForEach(x => //{ // var freeSelectionCourseApplyStaffEntity = new EM_FreeSelectionCouseApplyStaff // { // FreeSelectionCouseApplyStaffID = Guid.NewGuid(), // FreeSelectionCouseApplyID = freeSelectionCourseApplyID, // UserID = x.UserID, // TeachingMethod = x.TeachingMethod // }; // this.SetNewStatus(freeSelectionCourseApplyStaffEntity); // this.UnitOfWork.Add(freeSelectionCourseApplyStaffEntity); //}); this.UnitOfWork.Commit(); } /// /// 根据起止周次定义班号顺序 /// /// /// /// /// /// public string DefaultClassNo(Guid SchoolyearID, Guid freeSelectionCourseID, string StartWeeklyNum, string EndWeeklyNum) { if (StartWeeklyNum != "" && EndWeeklyNum != "") { //var freeSelectionCouseApply = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetList(x => x.SchoolyearID == SchoolyearID && x.FreeSelectionCouseID == freeSelectionCourseID, x => x.EM_FreeSelectionCouseApplyTeachingSetting).ToList(); var FreeSelectionCouseApplyTeachingSetting = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyTeachingSettingRepository.GetList(x => x.EM_FreeSelectionCouseApply.SchoolyearID == SchoolyearID && x.EM_FreeSelectionCouseApply.FreeSelectionCouseID == freeSelectionCourseID); var list = FreeSelectionCouseApplyTeachingSetting.Select(x => new { WeeklyNum = x.StartWeeklyNum.Value + x.EndWeeklyNum.Value }).ToList(); List l = new List { Convert.ToInt32(StartWeeklyNum) + Convert.ToInt32(EndWeeklyNum) }; list.ForEach(x => l.Add(x.WeeklyNum)); l.Sort(); int index = l.IndexOf(Convert.ToInt32(StartWeeklyNum) + Convert.ToInt32(EndWeeklyNum)) + 1; return index.ToString(); } return ""; } public List GetSchedulingView(Guid FreeSelectionCouseApplyID) { //2016年12月1日15:28:47 //TODO :调整教学任务课程进度统计规则[将原按教学任务获取该教学任务下所对应的教学任务班课程进度信息调整为按对应教学任务班进行统计] //var courseViewList = this.educationMissionClassDAL.GetCourseProcessView(x => x.EducationMissionID == educationMissionID) // .OrderBy(x => x.Week).ToList(); var courseViewList = this.FreeSelectionCoursePlanDAL.GetSchedulingView(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID) .OrderBy(x => x.Weekday).ToList(); return courseViewList; } } }