using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Transactions; using Bowin.Common.Utility; using EMIS.Entities; using EMIS.DataLogic.CultureplanManage.PlanManagement; using EMIS.ViewModel.CultureplanManage; namespace EMIS.ExtensionLogic.ServiceLogic.CultureplanManage.PlanManagement { public class SpecialtyCourseServices : EMIS.CommonLogic.CultureplanManage.PlanManagement.SpecialtyCourseServices { /// /// 编辑(新增、修改,业务主键:专业信息ID、开课学期、课程信息ID、开课教研室(2020.11.17梁剑提出)) /// /// public override void SpecialtyCourseEdit(SpecialtyCourseView specialtyCourseView) { try { //查询数据库进行验证 var specialtyCourseVerify = SpecialtyCourseDAL.SpecialtyCourseRepository .GetList(x => x.SpecialtyCourseID != specialtyCourseView.SpecialtyCourseID && x.SpecialtyID == specialtyCourseView.SpecialtyID && x.StarttermID == specialtyCourseView.StarttermID && x.CoursematerialID == specialtyCourseView.CoursematerialID && x.DepartmentID == specialtyCourseView.DepartmentID).SingleOrDefault(); if (specialtyCourseVerify == null) { //查询对应的专业信息 var specialty = SpecialtyCourseDAL.SpecialtyRepository .GetList(x => x.SpecialtyID == specialtyCourseView.SpecialtyID).SingleOrDefault(); if (specialty == null) { throw new Exception("专业信息不存在,请检查。"); } //对学制和开课学期进行判断 var maxStartterm = Convert.ToInt32(Math.Ceiling(specialty.LearnSystem.Value * 2 - 1)) + 1; if (specialtyCourseView.StarttermID > maxStartterm) { throw new Exception("开课学期超出学制范围,请检查。"); } List newSpecialtyCourseInList = new List(); List newSpecialtyCourseUpList = new List(); List newTeachingSettingInList = new List(); List newTeachingSettingUpList = new List(); List newTeachingModeTypeInList = new List(); List newTeachingPlaceInList = new List(); List specialtyCourseTMDelList = new List(); List specialtyCourseTPDelList = new List(); //数据有误验证 if (specialtyCourseView.SpecialtyCourseID != Guid.Empty) { var specialtyCourse = SpecialtyCourseDAL.SpecialtyCourseRepository .GetList(x => x.SpecialtyCourseID == specialtyCourseView.SpecialtyCourseID, (x => x.EM_SpecialtyCourseTeachingSetting)).SingleOrDefault(); if (specialtyCourse == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 specialtyCourse.SpecialtyID = specialtyCourseView.SpecialtyID; specialtyCourse.StarttermID = specialtyCourseView.StarttermID; specialtyCourse.CoursematerialID = specialtyCourseView.CoursematerialID; specialtyCourse.CourseStructureID = specialtyCourseView.CourseStructureID; specialtyCourse.CourseCategoryID = specialtyCourseView.CourseCategoryID; specialtyCourse.CourseTypeID = specialtyCourseView.CourseTypeID; specialtyCourse.CourseQualityID = specialtyCourseView.CourseQualityID; specialtyCourse.DepartmentID = specialtyCourseView.DepartmentID; specialtyCourse.IsSpecialtycore = specialtyCourseView.IsSpecialtycore; specialtyCourse.IsCooperation = specialtyCourseView.IsCooperation; specialtyCourse.IsRequired = specialtyCourseView.IsRequired; specialtyCourse.IsElective = specialtyCourseView.IsElective; specialtyCourse.IsNetworkCourse = specialtyCourseView.IsNetworkCourse; specialtyCourse.IsMainCourse = specialtyCourseView.IsMainCourse; specialtyCourse.IsNeedMaterial = specialtyCourseView.IsNeedMaterial; specialtyCourse.CourseFineID = specialtyCourseView.CourseFineID; specialtyCourse.PracticeTypeID = specialtyCourseView.PracticeTypeID; specialtyCourse.TeachinglanguageID = specialtyCourseView.TeachinglanguageID; specialtyCourse.ExaminationModeID = specialtyCourseView.ExaminationModeID; specialtyCourse.ResultTypeID = specialtyCourseView.ResultTypeID; specialtyCourse.HandleModeID = specialtyCourseView.HandleModeID; specialtyCourse.IsEnable = specialtyCourseView.IsEnable; specialtyCourse.Remark = specialtyCourseView.Remark; SetModifyStatus(specialtyCourse); newSpecialtyCourseUpList.Add(specialtyCourse); if (specialtyCourse.EM_SpecialtyCourseTeachingSetting == null) { var newTeachingSetting = new EM_SpecialtyCourseTeachingSetting(); newTeachingSetting.SpecialtyCourseID = specialtyCourse.SpecialtyCourseID; newTeachingSetting.Credit = specialtyCourseView.Credit; newTeachingSetting.TheoryCourse = specialtyCourseView.TheoryCourse; newTeachingSetting.Practicehours = specialtyCourseView.Practicehours; newTeachingSetting.Trialhours = specialtyCourseView.Trialhours; newTeachingSetting.TheoryWeeklyNum = specialtyCourseView.TheoryWeeklyNum; newTeachingSetting.PracticeWeeklyNum = specialtyCourseView.PracticeWeeklyNum; newTeachingSetting.TrialWeeklyNum = specialtyCourseView.TrialWeeklyNum; newTeachingSetting.WeeklyHours = specialtyCourseView.WeeklyHours; newTeachingSetting.WeeklyNum = specialtyCourseView.WeeklyNum; newTeachingSetting.StartWeeklyNum = specialtyCourseView.StartWeeklyNum; newTeachingSetting.EndWeeklyNum = specialtyCourseView.EndWeeklyNum; newTeachingSettingInList.Add(newTeachingSetting); } else { specialtyCourse.EM_SpecialtyCourseTeachingSetting.Credit = specialtyCourseView.Credit; specialtyCourse.EM_SpecialtyCourseTeachingSetting.TheoryCourse = specialtyCourseView.TheoryCourse; specialtyCourse.EM_SpecialtyCourseTeachingSetting.Practicehours = specialtyCourseView.Practicehours; specialtyCourse.EM_SpecialtyCourseTeachingSetting.Trialhours = specialtyCourseView.Trialhours; specialtyCourse.EM_SpecialtyCourseTeachingSetting.TheoryWeeklyNum = specialtyCourseView.TheoryWeeklyNum; specialtyCourse.EM_SpecialtyCourseTeachingSetting.PracticeWeeklyNum = specialtyCourseView.PracticeWeeklyNum; specialtyCourse.EM_SpecialtyCourseTeachingSetting.TrialWeeklyNum = specialtyCourseView.TrialWeeklyNum; specialtyCourse.EM_SpecialtyCourseTeachingSetting.WeeklyHours = specialtyCourseView.WeeklyHours; specialtyCourse.EM_SpecialtyCourseTeachingSetting.WeeklyNum = specialtyCourseView.WeeklyNum; specialtyCourse.EM_SpecialtyCourseTeachingSetting.StartWeeklyNum = specialtyCourseView.StartWeeklyNum; specialtyCourse.EM_SpecialtyCourseTeachingSetting.EndWeeklyNum = specialtyCourseView.EndWeeklyNum; newTeachingSettingUpList.Add(specialtyCourse.EM_SpecialtyCourseTeachingSetting); } if (specialtyCourseView.TeachingModeIDList != null && specialtyCourseView.TeachingModeIDList.Count() > 0) { specialtyCourseTMDelList.Add(specialtyCourse.SpecialtyCourseID); foreach (var teachingModeID in specialtyCourseView.TeachingModeIDList) { var newTeachingMode = new EM_TeachingModeType(); newTeachingMode.TeachingModeTypeID = Guid.NewGuid(); newTeachingMode.SpecialtyCourseID = specialtyCourse.SpecialtyCourseID; newTeachingMode.TeachingModeID = teachingModeID; SetNewStatus(newTeachingMode); newTeachingModeTypeInList.Add(newTeachingMode); } } else { specialtyCourseTMDelList.Add(specialtyCourse.SpecialtyCourseID); } if (specialtyCourseView.TeachingPlaceIDList != null && specialtyCourseView.TeachingPlaceIDList.Count() > 0) { specialtyCourseTPDelList.Add(specialtyCourse.SpecialtyCourseID); foreach (var teachingPlaceID in specialtyCourseView.TeachingPlaceIDList) { var newTeachingPlace = new EMIS.Entities.EM_TeachingPlace(); newTeachingPlace.TeachingPlaceID = Guid.NewGuid(); newTeachingPlace.SpecialtyCourseID = specialtyCourse.SpecialtyCourseID; newTeachingPlace.TeachingPlace = teachingPlaceID; SetNewStatus(newTeachingPlace); newTeachingPlaceInList.Add(newTeachingPlace); } } else { specialtyCourseTPDelList.Add(specialtyCourse.SpecialtyCourseID); } } } else { //表示新增 var newSpecialtyCourse = new EM_SpecialtyCourse(); newSpecialtyCourse.SpecialtyCourseID = Guid.NewGuid(); newSpecialtyCourse.SpecialtyID = specialtyCourseView.SpecialtyID; newSpecialtyCourse.StarttermID = specialtyCourseView.StarttermID; newSpecialtyCourse.CoursematerialID = specialtyCourseView.CoursematerialID; newSpecialtyCourse.CourseStructureID = specialtyCourseView.CourseStructureID; newSpecialtyCourse.CourseCategoryID = specialtyCourseView.CourseCategoryID; newSpecialtyCourse.CourseTypeID = specialtyCourseView.CourseTypeID; newSpecialtyCourse.CourseQualityID = specialtyCourseView.CourseQualityID; newSpecialtyCourse.DepartmentID = specialtyCourseView.DepartmentID; newSpecialtyCourse.IsSpecialtycore = specialtyCourseView.IsSpecialtycore; newSpecialtyCourse.IsCooperation = specialtyCourseView.IsCooperation; newSpecialtyCourse.IsRequired = specialtyCourseView.IsRequired; newSpecialtyCourse.IsElective = specialtyCourseView.IsElective; newSpecialtyCourse.IsNetworkCourse = specialtyCourseView.IsNetworkCourse; newSpecialtyCourse.IsMainCourse = specialtyCourseView.IsMainCourse; newSpecialtyCourse.IsNeedMaterial = specialtyCourseView.IsNeedMaterial; newSpecialtyCourse.CourseFineID = specialtyCourseView.CourseFineID; newSpecialtyCourse.PracticeTypeID = specialtyCourseView.PracticeTypeID; newSpecialtyCourse.TeachinglanguageID = specialtyCourseView.TeachinglanguageID; newSpecialtyCourse.ExaminationModeID = specialtyCourseView.ExaminationModeID; newSpecialtyCourse.ResultTypeID = specialtyCourseView.ResultTypeID; newSpecialtyCourse.HandleModeID = specialtyCourseView.HandleModeID; newSpecialtyCourse.IsEnable = specialtyCourseView.IsEnable; newSpecialtyCourse.Remark = specialtyCourseView.Remark; SetNewStatus(newSpecialtyCourse); newSpecialtyCourseInList.Add(newSpecialtyCourse); var newTeachingSetting = new EM_SpecialtyCourseTeachingSetting(); newTeachingSetting.SpecialtyCourseID = newSpecialtyCourse.SpecialtyCourseID; newTeachingSetting.Credit = specialtyCourseView.Credit; newTeachingSetting.TheoryCourse = specialtyCourseView.TheoryCourse; newTeachingSetting.Practicehours = specialtyCourseView.Practicehours; newTeachingSetting.Trialhours = specialtyCourseView.Trialhours; newTeachingSetting.TheoryWeeklyNum = specialtyCourseView.TheoryWeeklyNum; newTeachingSetting.PracticeWeeklyNum = specialtyCourseView.PracticeWeeklyNum; newTeachingSetting.TrialWeeklyNum = specialtyCourseView.TrialWeeklyNum; newTeachingSetting.WeeklyHours = specialtyCourseView.WeeklyHours; newTeachingSetting.WeeklyNum = specialtyCourseView.WeeklyNum; newTeachingSetting.StartWeeklyNum = specialtyCourseView.StartWeeklyNum; newTeachingSetting.EndWeeklyNum = specialtyCourseView.EndWeeklyNum; newTeachingSettingInList.Add(newTeachingSetting); if (specialtyCourseView.TeachingModeIDList != null && specialtyCourseView.TeachingModeIDList.Count() > 0) { foreach (var teachingModeID in specialtyCourseView.TeachingModeIDList) { var newTeachingMode = new EM_TeachingModeType(); newTeachingMode.TeachingModeTypeID = Guid.NewGuid(); newTeachingMode.SpecialtyCourseID = newSpecialtyCourse.SpecialtyCourseID; newTeachingMode.TeachingModeID = teachingModeID; SetNewStatus(newTeachingMode); newTeachingModeTypeInList.Add(newTeachingMode); } } if (specialtyCourseView.TeachingPlaceIDList != null && specialtyCourseView.TeachingPlaceIDList.Count() > 0) { foreach (var teachingPlaceID in specialtyCourseView.TeachingPlaceIDList) { var newTeachingPlace = new EMIS.Entities.EM_TeachingPlace(); newTeachingPlace.TeachingPlaceID = Guid.NewGuid(); newTeachingPlace.SpecialtyCourseID = newSpecialtyCourse.SpecialtyCourseID; newTeachingPlace.TeachingPlace = teachingPlaceID; SetNewStatus(newTeachingPlace); newTeachingPlaceInList.Add(newTeachingPlace); } } } //事务提交 //UnitOfWork.Commit(); using (TransactionScope ts = new TransactionScope()) { //删除 UnitOfWork.Delete(x => specialtyCourseTPDelList.Contains(x.SpecialtyCourseID)); UnitOfWork.Delete(x => specialtyCourseTMDelList.Contains(x.SpecialtyCourseID)); //批量插入 UnitOfWork.BulkInsert(newSpecialtyCourseInList); UnitOfWork.BulkInsert(newTeachingSettingInList); UnitOfWork.BulkInsert(newTeachingModeTypeInList); UnitOfWork.BulkInsert(newTeachingPlaceInList); //批量统一提交更新 if (newSpecialtyCourseUpList != null && newSpecialtyCourseUpList.Count() > 0) { UnitOfWork.BatchUpdate(newSpecialtyCourseUpList); } //批量统一提交更新 if (newTeachingSettingUpList != null && newTeachingSettingUpList.Count() > 0) { UnitOfWork.BatchUpdate(newTeachingSettingUpList); } ts.Complete(); } } else { throw new Exception("已存在相同的专业课程信息(专业信息、开课学期、课程信息唯一),请核查。"); } } catch (Exception ex) { throw new Exception(ex.Message); } } } }