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; namespace EMIS.CommonLogic.SelectCourse { public class FreeSelectionCourseServices : BaseWorkflowServices, IFreeSelectionCourseServices { public FreeSelectionCoursePlanDAL FreeSelectionCoursePlanDAL { get; set; } public FreeSelectionCourseDAL FreeSelectionCourseDAL { get; set; } public FreeSelectionCouseTeachingModeRepository FreeSelectionCouseTeachingModeRepository { get; set; } public IGridResultSet GetFreeSelectionCourseViewGrid(ConfiguretView configuretView, Guid? coursematerialID,Guid? departmentID, int? schoolcodeID, int? starttermID, int? isEnable, int pageIndex, int pageSize) { List list = new List(); var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var queryTeachingModeType = FreeSelectionCourseDAL.GetTeachingModeTypeViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (coursematerialID.HasValue) { query = query.Where(x => x.CoursematerialID == coursematerialID); queryTeachingModeType = queryTeachingModeType.Where(x => x.CoursematerialID == coursematerialID); } if (departmentID.HasValue) { query = query.Where(x => x.DepartmentID == departmentID); queryTeachingModeType = queryTeachingModeType.Where(x => x.DepartmentID == departmentID); } //if (schoolcodeID.HasValue) //{ // query = query.Where(x => x.SchoolcodeID == schoolcodeID); // queryTeachingModeType = queryTeachingModeType.Where(x => x.SchoolcodeID == schoolcodeID); //} //if (starttermID.HasValue) //{ // query = query.Where(x => x.StarttermID == starttermID); // queryTeachingModeType = queryTeachingModeType.Where(x => x.StarttermID == starttermID); //} if (isEnable.HasValue) { query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false)); queryTeachingModeType = queryTeachingModeType.Where(x => x.IsEnable == (isEnable == 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.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.TeachingModeName = string.Join(",", queryTeachingModeType.Where(w => w.FreeSelectionCouseID == x.FreeSelectionCouseID).Select(w => w.TeachingModeName))); return result; } public List GetFreeSelectionCourseViewList(ConfiguretView configuretView, Guid? coursematerialID,Guid? departmentID, int? schoolcodeID, int? starttermID, int? isEnable) { List list = new List(); var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var queryTeachingModeType = FreeSelectionCourseDAL.GetTeachingModeTypeViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (coursematerialID.HasValue) { query = query.Where(x => x.CoursematerialID == coursematerialID); queryTeachingModeType = queryTeachingModeType.Where(x => x.CoursematerialID == coursematerialID); } if (departmentID.HasValue) { query = query.Where(x => x.DepartmentID == departmentID); queryTeachingModeType = queryTeachingModeType.Where(x => x.DepartmentID == departmentID); } if (schoolcodeID.HasValue) { query = query.Where(x => x.SchoolcodeID == schoolcodeID); queryTeachingModeType = queryTeachingModeType.Where(x => x.SchoolcodeID == schoolcodeID); } if (starttermID.HasValue) { query = query.Where(x => x.StarttermID == starttermID); queryTeachingModeType = queryTeachingModeType.Where(x => x.StarttermID == starttermID); } if (isEnable.HasValue) { query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false)); queryTeachingModeType = queryTeachingModeType.Where(x => x.IsEnable == (isEnable == 1 ? true : false)); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) list = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList(); else list = this.GetQueryByDataRangeByCollege(query).ToList(); list.ForEach(x => x.TeachingModeName = string.Join(",", queryTeachingModeType.Where(w => w.FreeSelectionCouseID == x.FreeSelectionCouseID).Select(w => w.TeachingModeName))); return list.OrderBy(x => x.CreateTime).ToList(); } 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 string GetFreeSelectionCourseNo(EM_FreeSelectionCouse freeSelectionCourse) { var course = this.FreeSelectionCourseDAL.CoursematerialDAL.Value.CoursematerialRepository.GetSingle(x => x.CoursematerialID == freeSelectionCourse.CoursematerialID); if (course == null) { throw new Exception("找不到所选的课程资料。"); } string code = course.CourseCode + "-" + (freeSelectionCourse.SchoolyearNumID ?? 0).ToString() + "-" + (freeSelectionCourse.SchoolcodeID ?? 0).ToString(); return code; } public bool FreeSelectionCourseAdd(FreeSelectionCourseView freeSelectionCourseView) { EM_FreeSelectionCouse freeSelectionCourse; EM_FreeSelectionCouseTeachingSetting freeSelectionCourseTeachingSetting; try { if (this.FreeSelectionCourseDAL.FreeSelectionCouseRepository .GetList( x => x.CoursematerialID == freeSelectionCourseView.CoursematerialID && x.DepartmentID == freeSelectionCourseView.DepartmentID && x.CourseTypeID == freeSelectionCourseView.CourseTypeID).Count() > 0) { throw new Exception("该教研室对应的课程已经存在,请重新输入。"); } freeSelectionCourse = new EM_FreeSelectionCouse(); freeSelectionCourse.FreeSelectionCouseID = Guid.NewGuid(); freeSelectionCourse.DepartmentID = freeSelectionCourseView.DepartmentID; freeSelectionCourse.CoursematerialID = freeSelectionCourseView.CoursematerialID; freeSelectionCourse.CourseStructureID = freeSelectionCourseView.CourseStructureID; freeSelectionCourse.CourseCategoryID = freeSelectionCourseView.CourseCategoryID; freeSelectionCourse.CourseTypeID = freeSelectionCourseView.CourseTypeID; freeSelectionCourse.CourseQualityID = freeSelectionCourseView.CourseQualityID; freeSelectionCourse.PracticeTypeID = freeSelectionCourseView.PracticeTypeID; freeSelectionCourse.ExaminationModeID = freeSelectionCourseView.ExaminationModeID; freeSelectionCourse.TeachinglanguageID = freeSelectionCourseView.TeachinglanguageID; freeSelectionCourse.SchoolyearNumID = freeSelectionCourseView.SchoolyearNumID; freeSelectionCourse.SchoolcodeID = freeSelectionCourseView.SchoolcodeID; //freeSelectionCourse.StarttermID = freeSelectionCourseView.StarttermID; freeSelectionCourse.IsEnable = freeSelectionCourseView.IsEnable; freeSelectionCourse.ResultTypeID = freeSelectionCourseView.ResultTypeID; freeSelectionCourse.Remark = freeSelectionCourseView.Remark; //最后计算选课编号 //freeSelectionCourse.No = this.GetFreeSelectionCourseNo(freeSelectionCourse); this.SetNewStatus(freeSelectionCourse); freeSelectionCourseTeachingSetting = new EM_FreeSelectionCouseTeachingSetting(); freeSelectionCourseTeachingSetting.FreeSelectionCouseID = freeSelectionCourse.FreeSelectionCouseID; freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseView.Credit; freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseView.TheoryCourse; freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseView.Practicehours; freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseView.Trialhours; freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseView.WeeklyNum; freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseView.TheoryWeeklyNum; freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseView.PracticeWeeklyNum; freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseView.TrialWeeklyNum; freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseView.StartWeeklyNum; freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseView.EndWeeklyNum; freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseView.WeeklyHours; if (freeSelectionCourseView.TeachingModeID != null) { TeachingModeTypeAdd(freeSelectionCourseView.TeachingModeID, freeSelectionCourse.FreeSelectionCouseID); } UnitOfWork.Add(freeSelectionCourse); UnitOfWork.Add(freeSelectionCourseTeachingSetting); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } public bool FreeSelectionCourseUpdate(FreeSelectionCourseView freeSelectionCourseView) { EM_FreeSelectionCouse freeSelectionCourse; EM_FreeSelectionCouseTeachingSetting freeSelectionCourseTeachingSetting; try { if (this.FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetList( x => x.CoursematerialID == freeSelectionCourseView.CoursematerialID && x.DepartmentID == freeSelectionCourseView.DepartmentID && x.CourseTypeID == freeSelectionCourseView.CourseTypeID && x.FreeSelectionCouseID != freeSelectionCourseView.FreeSelectionCouseID).Count() > 0) { throw new Exception("该课程已经存在,请重新输入。"); } freeSelectionCourse = GetFreeSelectionCourse(freeSelectionCourseView.FreeSelectionCouseID); freeSelectionCourseTeachingSetting = GetFreeSelectionCourseTeachingSetting(freeSelectionCourseView.FreeSelectionCouseID); freeSelectionCourse.FreeSelectionCouseID = freeSelectionCourseView.FreeSelectionCouseID; freeSelectionCourse.DepartmentID = freeSelectionCourseView.DepartmentID; freeSelectionCourse.CoursematerialID = freeSelectionCourseView.CoursematerialID; freeSelectionCourse.CourseStructureID = freeSelectionCourseView.CourseStructureID; freeSelectionCourse.CourseCategoryID = freeSelectionCourseView.CourseCategoryID; freeSelectionCourse.CourseTypeID = freeSelectionCourseView.CourseTypeID; freeSelectionCourse.CourseQualityID = freeSelectionCourseView.CourseQualityID; freeSelectionCourse.PracticeTypeID = freeSelectionCourseView.PracticeTypeID; freeSelectionCourse.ExaminationModeID = freeSelectionCourseView.ExaminationModeID; freeSelectionCourse.TeachinglanguageID = freeSelectionCourseView.TeachinglanguageID; freeSelectionCourse.SchoolyearNumID = freeSelectionCourseView.SchoolyearNumID; freeSelectionCourse.SchoolcodeID = freeSelectionCourseView.SchoolcodeID; //freeSelectionCourse.StarttermID = freeSelectionCourseView.StarttermID; freeSelectionCourse.IsEnable = freeSelectionCourseView.IsEnable; freeSelectionCourse.ResultTypeID = freeSelectionCourseView.ResultTypeID; freeSelectionCourse.Remark = freeSelectionCourseView.Remark; this.SetModifyStatus(freeSelectionCourse); freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseView.Credit; freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseView.TheoryCourse; freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseView.Practicehours; freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseView.Trialhours; freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseView.WeeklyNum; freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseView.TheoryWeeklyNum; freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseView.PracticeWeeklyNum; freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseView.TrialWeeklyNum; freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseView.StartWeeklyNum; freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseView.EndWeeklyNum; freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseView.WeeklyHours; if (freeSelectionCourseView.TeachingModeID != null) { TeachingModeTypeAdd(freeSelectionCourseView.TeachingModeID, freeSelectionCourse.FreeSelectionCouseID); } UnitOfWork.Update(freeSelectionCourse); UnitOfWork.Update(freeSelectionCourseTeachingSetting); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } private bool TeachingModeTypeAdd(List list, Guid? freeSelectionCourseID) { try { if (list.Count > 0) { UnitOfWork.Delete(x => x.FreeSelectionCouseID == freeSelectionCourseID); foreach (var i in list) { EM_FreeSelectionCouseTeachingMode teachingModeType = new EM_FreeSelectionCouseTeachingMode(); teachingModeType.FreeSelectionCouseTeachingModeID = Guid.NewGuid(); teachingModeType.FreeSelectionCouseID = freeSelectionCourseID; teachingModeType.TeachingModeID = i; this.SetNewStatus(teachingModeType); UnitOfWork.Add(teachingModeType); } } return true; } catch (Exception) { throw; } } public bool FreeSelectionCourseDelete(List freeSelectionCourseIDs) { try { if (freeSelectionCourseIDs.Count > 0) { UnitOfWork.Delete(x => freeSelectionCourseIDs.Contains(x.FreeSelectionCouseID)); UnitOfWork.Delete(x => freeSelectionCourseIDs.Contains(x.FreeSelectionCouseID)); UnitOfWork.Delete(x => freeSelectionCourseIDs.Contains(x.FreeSelectionCouseID)); UnitOfWork.Commit(); } return true; } catch (Exception) { throw; } } /// /// 根据任选课程获取授课方式 /// /// /// public List GetTeachingModeType(Guid? freeSelectionCourseID) { List list = new List(); return FreeSelectionCourseDAL.GetTeachingModeType(x => x.FreeSelectionCouseID == freeSelectionCourseID) .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 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(); } } }