using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.Text.RegularExpressions; using System.Linq.Expressions; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using Bowin.Common.Utility; using EMIS.Utility; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.CacheManage; using EMIS.ViewModel.CultureplanManage; using EMIS.DataLogic.CultureplanManage.PlanManagement; namespace EMIS.CommonLogic.CultureplanManage.PlanManagement { public class SpecialtyCourseServices : BaseServices, ISpecialtyCourseServices { public SpecialtyCourseDAL SpecialtyCourseDAL { get; set; } /// /// 查询专业课程信息SpecialtyCourseView /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSpecialtyCourseViewGrid(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? coursematerialID, int? courseTypeID, int? starttermID, int? teachingModeID, int? handleModeID, int? isEnable, int pageIndex, int pageSize) { //专业课程 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (departmentID.HasValue) { //开课教研室ID exp = exp.And(x => x.DepartmentID == departmentID); } if (coursematerialID.HasValue) { //课程信息ID exp = exp.And(x => x.CoursematerialID == coursematerialID); } if (courseTypeID.HasValue) { //课程类型 exp = exp.And(x => x.CourseTypeID == courseTypeID); } if (starttermID.HasValue) { //开课学期 exp = exp.And(x => x.StarttermID == starttermID); } if (handleModeID.HasValue) { //处理方式 exp = exp.And(x => x.HandleModeID == handleModeID); } if (isEnable.HasValue) { //是否启用 if (isEnable == 1) { exp = exp.And(x => x.IsEnable == true); } if (isEnable == 0) { exp = exp.And(x => x.IsEnable != true); } } var query = SpecialtyCourseDAL.GetSpecialtyCourseViewQueryable(exp); if (collegeID.HasValue) { //开课院系ID query = query.Where(x => x.CollegeID == collegeID); } if (standardID.HasValue) { //专业ID(Value) query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { //培养方式 query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { //学习形式 query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } if (teachingModeID.HasValue) { //授课方式 query = query.Where(x => x.TeachingModeIDList.Contains(teachingModeID)); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StandardID).ThenBy(x => x.EducationID) .ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem) .ThenBy(x => x.StarttermID).ThenBy(x => x.CourseTypeID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询专业课程信息List /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IList GetSpecialtyCourseViewList(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? coursematerialID, int? courseTypeID, int? starttermID, int? teachingModeID, int? handleModeID, int? isEnable) { //专业课程 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (departmentID.HasValue) { //开课教研室ID exp = exp.And(x => x.DepartmentID == departmentID); } if (coursematerialID.HasValue) { //课程信息ID exp = exp.And(x => x.CoursematerialID == coursematerialID); } if (courseTypeID.HasValue) { //课程类型 exp = exp.And(x => x.CourseTypeID == courseTypeID); } if (starttermID.HasValue) { //开课学期 exp = exp.And(x => x.StarttermID == starttermID); } if (handleModeID.HasValue) { //处理方式 exp = exp.And(x => x.HandleModeID == handleModeID); } if (isEnable.HasValue) { //是否启用 if (isEnable == 1) { exp = exp.And(x => x.IsEnable == true); } if (isEnable == 0) { exp = exp.And(x => x.IsEnable != true); } } var query = SpecialtyCourseDAL.GetSpecialtyCourseViewQueryable(exp); if (collegeID.HasValue) { //开课院系ID query = query.Where(x => x.CollegeID == collegeID); } if (standardID.HasValue) { //专业ID(Value) query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { //培养方式 query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { //学习形式 query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } if (teachingModeID.HasValue) { //授课方式 query = query.Where(x => x.TeachingModeIDList.Contains(teachingModeID)); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StandardID).ThenBy(x => x.EducationID) .ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem) .ThenBy(x => x.StarttermID).ThenBy(x => x.CourseTypeID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ToList(); } /// /// 查询对应的专业课程信息SpecialtyCourseView /// /// /// public SpecialtyCourseView GetSpecialtyCourseView(Guid? specialtyCourseID) { try { var specialtyCourseView = SpecialtyCourseDAL.GetSpecialtyCourseViewQueryable(x => x.SpecialtyCourseID == specialtyCourseID) .SingleOrDefault(); return specialtyCourseView; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改,业务主键:专业信息ID、开课学期、课程信息ID) /// /// public virtual 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).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); } } /// /// 删除 /// /// /// public bool SpecialtyCourseDelete(List specialtyCourseIDs) { try { using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => specialtyCourseIDs.Contains(x.SpecialtyCourseID)); UnitOfWork.Delete(x => specialtyCourseIDs.Contains(x.SpecialtyCourseID)); UnitOfWork.Delete(x => specialtyCourseIDs.Contains(x.SpecialtyCourseID)); UnitOfWork.Delete(x => specialtyCourseIDs.Contains(x.SpecialtyCourseID)); ts.Complete(); return true; } } catch (Exception) { throw; } } /// /// 查询专业课程对应的授课方式List /// /// /// public List GetTeachingModeTypeList(Guid? specialtyCourseID) { //专业课程 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.SpecialtyCourseID == specialtyCourseID); var query = SpecialtyCourseDAL.GetTeachingModeTypeQueryble(exp); return query.OrderBy(x => x.Value).Select(x => x.ToString()).ToList(); } /// /// 查询专业课程对应的授课地点List /// /// /// public List GetTeachingPlaceList(Guid? specialtyCourseID) { //专业课程 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.SpecialtyCourseID == specialtyCourseID); var query = SpecialtyCourseDAL.GetTeachingPlaceQueryble(exp); return query.OrderBy(x => x.Value).Select(x => x.ToString()).ToList(); } /// /// 专业课程信息Excel导入 /// /// /// /// /// /// /// public void SpecialtyCourseImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { try { StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); // 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage) List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "未导入原因"); //对List集合进行有效性校验 if (enlist.Count() <= 0) { throw new Exception("Excel文件数据为空,请检查。"); } Regex reg = null; //正则表达式 //DateTime result; //用于返回判断日期字段格式 bool isListPass = true; //List判断标识 inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 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(); //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询) //专业代码、专业名称、专业ID(Value) var standardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard).ToList(); //培养层次(所修学历) var educationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Education).ToList(); //学习形式 var learningFormList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningform).ToList(); //专业信息 var specialtyList = SpecialtyCourseDAL.SpecialtyRepository.GetList(x => true).ToList(); //开课学期 var starttermList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Startterm).ToList(); //课程信息 var courseList = SpecialtyCourseDAL.CoursematerialRepository.GetList(x => true).ToList(); //课程代码 var courseCodeList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.CourseCode)).Select(x => x.CourseCode.Trim()).ToList(); //对比后的newCourseList var newCourseList = courseList.Where(x => courseCodeList.Contains(x.CourseCode)).ToList(); //对比后的coursematerialIDList var coursematerialIDList = newCourseList.Select(x => (Guid?)x.CoursematerialID).ToList(); //课程结构 var courseStructureList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseStructure).ToList(); //课程属性 var courseCategoryList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseCategory).ToList(); //课程类型 var courseTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseType).ToList(); //课程性质 var courseQualityList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseQuality).ToList(); //教研室信息 var departmentList = SpecialtyCourseDAL.DepartmentRepository.GetList(x => true).ToList(); //开课教研室 var departmentNameList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.DepartmentName)).Select(x => x.DepartmentName.Trim()).ToList(); //对比后的newDepartmentList var newDepartmentList = departmentList.Where(x => departmentNameList.Contains(x.Name)).ToList(); //通用是否 var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList(); //精品课程 var courseFineList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseFine).ToList(); //实践类型 var practiceTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.EM_PracticeType).ToList(); //授课语言 var teachinglanguageList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Teachinglanguage).ToList(); //考试方式 var examinationModeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ExaminationMode).ToList(); //成绩类型 var resultTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ResultType).ToList(); //处理方式 var handleModeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HandleMode).ToList(); //授课方式 var teachingModeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeachingMode).ToList(); //授课地点 var teachingPlaceList = IdNameExt.GetDictionaryItem(DictionaryItem.EM_TeachingPlace).ToList(); //专业课程 var specialtyCourseList = SpecialtyCourseDAL.SpecialtyCourseRepository .GetList(x => true, (x => x.EM_SpecialtyCourseTeachingSetting)).ToList(); //对比后的newSpecialtyCourseList(暂时只对比课程信息ID) var newSpecialtyCourseList = specialtyCourseList.Where(x => coursematerialIDList.Contains(x.CoursematerialID)).ToList(); //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { SpecialtyCourseView en = enlist[i]; //Excel表数据视图 EM_SpecialtyCourse newSpecialtyCourse = new EM_SpecialtyCourse(); EM_SpecialtyCourseTeachingSetting newTeachingSetting = new EM_SpecialtyCourseTeachingSetting(); List newModeTypeList = new List(); List newPlaceList = new List(); //专业代码 if (string.IsNullOrWhiteSpace(en.StandardCodeStr)) { errCount++; errorMsgStr = "专业代码不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var standard = standardList.Where(x => x.Code == en.StandardCodeStr.Trim()).FirstOrDefault(); if (standard == null) { errCount++; errorMsgStr = "专业代码不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业代码 } } //专业名称 if (string.IsNullOrWhiteSpace(en.StandardNameStr)) { errCount++; errorMsgStr = "专业名称不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var standard = standardList.Where(x => x.Name == en.StandardNameStr.Trim()).FirstOrDefault(); if (standard == null) { errCount++; errorMsgStr = "专业名称不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业名称 } } //专业代码与专业名称查询专业ID(Value) if (string.IsNullOrWhiteSpace(en.StandardCodeStr) || string.IsNullOrWhiteSpace(en.StandardNameStr)) { errCount++; errorMsgStr = "专业代码或专业名称不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var standard = standardList.Where(x => x.Code == en.StandardCodeStr.Trim() && x.Name == en.StandardNameStr.Trim()).SingleOrDefault(); if (standard == null) { errCount++; errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业ID(Value) en.StandardID = standard.Value; } } //培养层次 if (string.IsNullOrWhiteSpace(en.EducationStr)) { errCount++; errorMsgStr = RSL.Get("EducationID") + "不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var education = educationList.Where(x => x.Name == en.EducationStr.Trim()).SingleOrDefault(); if (education == null) { errCount++; errorMsgStr = RSL.Get("EducationID") + "不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //培养层次 en.EducationID = education.Value; } } //学习形式 if (string.IsNullOrWhiteSpace(en.LearningformStr)) { errCount++; errorMsgStr = "学习形式不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var learningForm = learningFormList.Where(x => x.Name == en.LearningformStr.Trim()).SingleOrDefault(); if (learningForm == null) { errCount++; errorMsgStr = "学习形式不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //学习形式 en.LearningformID = learningForm.Value; } } //学制 if (string.IsNullOrWhiteSpace(en.LearnSystemStr)) { errCount++; errorMsgStr = "学制不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式(数字) if (!reg.IsMatch(en.LearnSystemStr.Trim())) { errCount++; errorMsgStr = "学制格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //学制 en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr.Trim()); } } //查询对应的专业信息ID if (en.StandardID.HasValue && en.EducationID.HasValue && en.LearningformID.HasValue && en.LearnSystem.HasValue) { //查询对应的专业信息 var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.EducationID == en.EducationID && x.LearningformID == en.LearningformID && x.LearnSystem == en.LearnSystem).SingleOrDefault(); if (specialty == null) { errCount++; errorMsgStr = "对应的专业信息不存在(以专业代码、专业名称、" + RSL.Get("EducationID") + "、学习形式、学制查询),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //判断对应的专业信息状态(启用、禁用状态) if (specialty.RecordStatus > (int)SYS_STATUS.UNUSABLE) { newSpecialtyCourse.SpecialtyID = specialty.SpecialtyID; } else { newSpecialtyCourse.SpecialtyID = specialty.SpecialtyID; errCount++; errorMsgStr = "对应的专业信息为禁用状态,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } } else { errCount++; errorMsgStr = "数据有误,请检查(专业ID(Value)、" + RSL.Get("EducationID") + "、学习形式或学制不能为空)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } //开课学期 if (string.IsNullOrWhiteSpace(en.StarttermStr)) { errCount++; errorMsgStr = "开课学期不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var startterm = starttermList.Where(x => x.Name == en.StarttermStr.Trim()).SingleOrDefault(); if (startterm == null) { errCount++; errorMsgStr = "开课学期不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //对学制和开课学期进行判断 var maxStartterm = Convert.ToInt32(Math.Ceiling(en.LearnSystem.Value * 2 - 1)) + 1; if (startterm.Value > maxStartterm) { errCount++; errorMsgStr = "开课学期超出学制范围,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //开课学期 newSpecialtyCourse.StarttermID = startterm.Value; } } } //课程代码 if (string.IsNullOrWhiteSpace(en.CourseCode)) { errCount++; errorMsgStr = "课程代码不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母) if (!reg.IsMatch(en.CourseCode.Trim())) { errCount++; errorMsgStr = "课程代码格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var course = newCourseList.Where(x => x.CourseCode == en.CourseCode.Trim()).SingleOrDefault(); if (course == null) { errCount++; errorMsgStr = "课程代码不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //判断课程代码与课程名称(以课程代码为准) if (string.IsNullOrWhiteSpace(en.CourseName)) { //暂不考虑 } else { //课程代码与课程名称不对应 if (course.CourseName.Trim() != en.CourseName.Trim()) { errCount++; errorMsgStr = "课程代码与课程名称不对应(以课程代码为准),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } //判断对应的课程信息状态(启用、禁用状态) if (course.IsEnable == true) { //课程信息ID newSpecialtyCourse.CoursematerialID = course.CoursematerialID; } else { newSpecialtyCourse.CoursematerialID = course.CoursematerialID; errCount++; errorMsgStr = "对应的课程信息为禁用状态,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } } } //课程名称 if (string.IsNullOrWhiteSpace(en.CourseName)) { //暂不考虑 } else { //暂不考虑 } //课程结构 if (string.IsNullOrWhiteSpace(en.CourseStructureStr)) { newSpecialtyCourse.CourseStructureID = (int)CF_CourseStructure.ClassroomTeaching; } else { var courseStructure = courseStructureList.Where(x => x.Name == en.CourseStructureStr.Trim()).SingleOrDefault(); if (courseStructure == null) { errCount++; errorMsgStr = "课程结构不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //课程结构 newSpecialtyCourse.CourseStructureID = courseStructure.Value; } } //课程属性 if (string.IsNullOrWhiteSpace(en.CourseCategoryStr)) { newSpecialtyCourse.CourseCategoryID = (int)CF_CourseCategory.Publiccourse; } else { var courseCategory = courseCategoryList.Where(x => x.Name == en.CourseCategoryStr.Trim()).SingleOrDefault(); if (courseCategory == null) { errCount++; errorMsgStr = "课程属性不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //课程属性 newSpecialtyCourse.CourseCategoryID = courseCategory.Value; } } //课程类型 if (string.IsNullOrWhiteSpace(en.CourseTypeStr)) { errCount++; errorMsgStr = "课程类型不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var courseType = courseTypeList.Where(x => x.Name == en.CourseTypeStr.Trim()).SingleOrDefault(); if (courseType == null) { errCount++; errorMsgStr = "课程类型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //课程类型 newSpecialtyCourse.CourseTypeID = courseType.Value; } } //课程性质 if (string.IsNullOrWhiteSpace(en.CourseQualityStr)) { newSpecialtyCourse.CourseQualityID = (int)CF_CourseQuality.Required; } else { var courseQuality = courseQualityList.Where(x => x.Name == en.CourseQualityStr.Trim()).SingleOrDefault(); if (courseQuality == null) { errCount++; errorMsgStr = "课程性质不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //课程性质 newSpecialtyCourse.CourseQualityID = courseQuality.Value; } } //课程学分 if (string.IsNullOrWhiteSpace(en.CreditStr)) { errCount++; errorMsgStr = "课程学分不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //课程学分字段正则表达式(数字) if (!reg.IsMatch(en.CreditStr.Trim())) { errCount++; errorMsgStr = "课程学分格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //课程学分 newTeachingSetting.Credit = Convert.ToDecimal(en.CreditStr.Trim()); } } //理论学时 if (string.IsNullOrWhiteSpace(en.TheoryCourseStr)) { errCount++; errorMsgStr = "理论学时不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^\d+$"); //正则表达式(非负整数) if (!reg.IsMatch(en.TheoryCourseStr.Trim())) { errCount++; errorMsgStr = "理论学时格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //理论学时 newTeachingSetting.TheoryCourse = Convert.ToInt32(en.TheoryCourseStr.Trim()); } } //实践学时 if (string.IsNullOrWhiteSpace(en.PracticehoursStr)) { //默认为0 newTeachingSetting.Practicehours = 0; } else { reg = new Regex(@"^\d+$"); //正则表达式(非负整数) if (!reg.IsMatch(en.PracticehoursStr.Trim())) { errCount++; errorMsgStr = "实践学时格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //实践学时 newTeachingSetting.Practicehours = Convert.ToInt32(en.PracticehoursStr.Trim()); } } //实验学时 if (string.IsNullOrWhiteSpace(en.TrialhoursStr)) { //默认为0 newTeachingSetting.Trialhours = 0; } else { reg = new Regex(@"^\d+$"); //正则表达式(非负整数) if (!reg.IsMatch(en.TrialhoursStr.Trim())) { errCount++; errorMsgStr = "实验学时格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //实验学时 newTeachingSetting.Trialhours = Convert.ToInt32(en.TrialhoursStr.Trim()); } } //开课教研室 if (string.IsNullOrWhiteSpace(en.DepartmentName)) { errCount++; errorMsgStr = "开课教研室不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var department = newDepartmentList.Where(x => x.Name == en.DepartmentName.Trim()).SingleOrDefault(); if (department == null) { errCount++; errorMsgStr = "开课教研室不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //开课教研室ID newSpecialtyCourse.DepartmentID = department.DepartmentID; } } //是否专业核心 if (string.IsNullOrWhiteSpace(en.IsSpecialtycoreStr)) { //是否专业核心(默认为否) newSpecialtyCourse.IsSpecialtycore = false; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsSpecialtycoreStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = "是否专业核心不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否专业核心 newSpecialtyCourse.IsSpecialtycore = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //是否合作开发 if (string.IsNullOrWhiteSpace(en.IsCooperationStr)) { //是否合作开发(默认为否) newSpecialtyCourse.IsCooperation = false; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsCooperationStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = "是否合作开发不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否合作开发 newSpecialtyCourse.IsCooperation = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //是否必修课 if (string.IsNullOrWhiteSpace(en.IsRequiredStr)) { //是否必修课(默认为否) newSpecialtyCourse.IsRequired = false; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsRequiredStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = RSL.Get("IsRequired") + "不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否必修课 newSpecialtyCourse.IsRequired = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //是否网上选修 if (string.IsNullOrWhiteSpace(en.IsElectiveStr)) { //是否网上选修(默认为否) newSpecialtyCourse.IsElective = false; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsElectiveStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = "是否网上选修不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否网上选修 newSpecialtyCourse.IsElective = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //是否网络课程 if (string.IsNullOrWhiteSpace(en.IsNetworkCourseStr)) { //是否网络课程(默认为否) newSpecialtyCourse.IsNetworkCourse = false; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsNetworkCourseStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = "是否网络课程不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否网络课程 newSpecialtyCourse.IsNetworkCourse = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //是否学位课程 if (string.IsNullOrWhiteSpace(en.IsMainCourseStr)) { //是否学位课程(默认为否) newSpecialtyCourse.IsMainCourse = false; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsMainCourseStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = "是否学位课程不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否学位课程 newSpecialtyCourse.IsMainCourse = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //是否需要教材 if (string.IsNullOrWhiteSpace(en.IsNeedMaterialStr)) { //是否需要教材(默认为是) newSpecialtyCourse.IsNeedMaterial = true; } else { var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsNeedMaterialStr.Trim()).SingleOrDefault(); if (generalPurpose == null) { errCount++; errorMsgStr = "是否需要教材不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //是否需要教材 newSpecialtyCourse.IsNeedMaterial = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //精品课程 if (string.IsNullOrWhiteSpace(en.CourseFineStr)) { newSpecialtyCourse.CourseFineID = (int)CF_CourseFine.No; } else { var courseFine = courseFineList.Where(x => x.Name == en.CourseFineStr.Trim()).SingleOrDefault(); if (courseFine == null) { errCount++; errorMsgStr = "精品课程不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //精品课程 newSpecialtyCourse.CourseFineID = courseFine.Value; } } //实践类型 if (string.IsNullOrWhiteSpace(en.PracticeTypeStr)) { //不考虑 } else { var practiceType = practiceTypeList.Where(x => x.Name == en.PracticeTypeStr.Trim()).SingleOrDefault(); if (practiceType == null) { errCount++; errorMsgStr = "实践类型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //实践类型 newSpecialtyCourse.PracticeTypeID = practiceType.Value; } } //授课语言 if (string.IsNullOrWhiteSpace(en.TeachinglanguageStr)) { newSpecialtyCourse.TeachinglanguageID = (int)CF_Teachinglanguage.Chinese; } else { var teachinglanguage = teachinglanguageList.Where(x => x.Name == en.TeachinglanguageStr.Trim()).SingleOrDefault(); if (teachinglanguage == null) { errCount++; errorMsgStr = "授课语言不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //授课语言 newSpecialtyCourse.TeachinglanguageID = teachinglanguage.Value; } } //考试方式 if (string.IsNullOrWhiteSpace(en.ExaminationModeStr)) { newSpecialtyCourse.ExaminationModeID = (int)CF_ExaminationMode.WrittenExam; } else { var examinationMode = examinationModeList.Where(x => x.Name == en.ExaminationModeStr.Trim()).SingleOrDefault(); if (examinationMode == null) { errCount++; errorMsgStr = "考试方式不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //考试方式 newSpecialtyCourse.ExaminationModeID = examinationMode.Value; } } //成绩类型 if (string.IsNullOrWhiteSpace(en.ResultTypeStr)) { //默认为百分制 newSpecialtyCourse.ResultTypeID = (int)CF_ResultType.Percentage; } else { var resultType = resultTypeList.Where(x => x.Name == en.ResultTypeStr.Trim()).SingleOrDefault(); if (resultType == null) { errCount++; errorMsgStr = "成绩类型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //成绩类型 newSpecialtyCourse.ResultTypeID = resultType.Value; } } //处理方式 if (string.IsNullOrWhiteSpace(en.HandleModeStr)) { //默认为必修课 newSpecialtyCourse.HandleModeID = (int)CF_HandleMode.RequiredCourse; } else { var handleMode = handleModeList.Where(x => x.Name == en.HandleModeStr.Trim()).SingleOrDefault(); if (handleMode == null) { errCount++; errorMsgStr = "处理方式不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //处理方式 newSpecialtyCourse.HandleModeID = handleMode.Value; } } //授课方式 if (string.IsNullOrEmpty(en.TeachingModeIDListStr)) { newModeTypeList.Add((int)CF_TeachingMode.Theory); } else { //授课方式可为多个(可用顿号隔开) List list = en.TeachingModeIDListStr.Split('、').Where(x => !string.IsNullOrEmpty(x)) .Select(x => x.Trim()).Distinct().ToList(); foreach (var item in list) { var teachingMode = teachingModeList.Where(x => x.Name == item.Trim()).SingleOrDefault(); if (teachingMode == null) { errCount++; errorMsgStr = "授课方式(" + item.Trim() + ")不存在,请检查(存在多个授课方式时,可用顿号隔开)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); isListPass = false; break; } } if (isListPass) { newModeTypeList = teachingModeList.Where(x => list.Contains(x.Name)) .Select(x => x.Value.Value).ToList(); } else { isListPass = true; continue; } } //授课地点 if (string.IsNullOrEmpty(en.TeachingPlaceIDListStr)) { newPlaceList.Add((int)EMIS.ViewModel.EM_TeachingPlace.Multimedia); } else { //授课地点可为多个(可用顿号隔开) List list = en.TeachingPlaceIDListStr.Split('、').Where(x => !string.IsNullOrEmpty(x)) .Select(x => x.Trim()).Distinct().ToList(); foreach (var item in list) { var teachingPlace = teachingPlaceList.Where(x => x.Name == item.Trim()).SingleOrDefault(); if (teachingPlace == null) { errCount++; errorMsgStr = "授课地点(" + item.Trim() + ")不存在,请检查(存在多个授课地点时,可用顿号隔开)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); isListPass = false; break; } } if (isListPass) { newPlaceList = teachingPlaceList.Where(x => list.Contains(x.Name)) .Select(x => x.Value.Value).ToList(); } else { isListPass = true; continue; } } //是否启用(默认为是) newSpecialtyCourse.IsEnable = true; //备注 if (string.IsNullOrWhiteSpace(en.Remark)) { //不考虑 } else { newSpecialtyCourse.Remark = en.Remark; } ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉) //for (int j = i + 1; j < enlist.Count; j++) //{ // SpecialtyCourseView enA = enlist[j]; // //根据Excel表中的业务主键进行去重(专业信息ID、开课学期、课程信息ID唯一) // if (en.No == enA.No && en.Name == enA.Name) // { // //用于标识Excel表中的重复记录(由于是批量进行插入数据表) // } //} //数据表重复性验证(专业信息ID、开课学期、课程信息ID唯一) var specialtyCourseVerify = newSpecialtyCourseList.Where(x => x.SpecialtyID == newSpecialtyCourse.SpecialtyID && x.StarttermID == newSpecialtyCourse.StarttermID && x.CoursematerialID == newSpecialtyCourse.CoursematerialID).SingleOrDefault(); if (specialtyCourseVerify == null) { //新增 if (!newSpecialtyCourseInList.Any(x => x.SpecialtyID == newSpecialtyCourse.SpecialtyID && x.StarttermID == newSpecialtyCourse.StarttermID && x.CoursematerialID == newSpecialtyCourse.CoursematerialID)) { newSpecialtyCourse.SpecialtyCourseID = Guid.NewGuid(); SetNewStatus(newSpecialtyCourse); newSpecialtyCourseInList.Add(newSpecialtyCourse); newTeachingSetting.SpecialtyCourseID = newSpecialtyCourse.SpecialtyCourseID; newTeachingSetting.TheoryWeeklyNum = 0; newTeachingSetting.PracticeWeeklyNum = 0; newTeachingSetting.TrialWeeklyNum = 0; newTeachingSetting.WeeklyHours = 0; newTeachingSetting.WeeklyNum = 0; newTeachingSetting.StartWeeklyNum = 1; newTeachingSetting.EndWeeklyNum = 18; newTeachingSettingInList.Add(newTeachingSetting); if (newModeTypeList != null && newModeTypeList.Count() > 0) { foreach (var newModeTypeID in newModeTypeList) { var newTeachingModeType = new EM_TeachingModeType(); newTeachingModeType.TeachingModeTypeID = Guid.NewGuid(); newTeachingModeType.SpecialtyCourseID = newSpecialtyCourse.SpecialtyCourseID; newTeachingModeType.TeachingModeID = newModeTypeID; this.SetNewStatus(newTeachingModeType); newTeachingModeTypeInList.Add(newTeachingModeType); } } if (newPlaceList != null && newPlaceList.Count() > 0) { foreach (var newPlaceID in newPlaceList) { var newTeachingPlace = new EMIS.Entities.EM_TeachingPlace(); newTeachingPlace.TeachingPlaceID = Guid.NewGuid(); newTeachingPlace.SpecialtyCourseID = newSpecialtyCourse.SpecialtyCourseID; newTeachingPlace.TeachingPlace = newPlaceID; this.SetNewStatus(newTeachingPlace); newTeachingPlaceInList.Add(newTeachingPlace); } } inCount++; } else { //Excel表重复性验证 //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑) inCount++; } } else { //更新(Excel有重复时,以最后一条记录的更新为准) specialtyCourseVerify.CourseStructureID = newSpecialtyCourse.CourseStructureID; specialtyCourseVerify.CourseCategoryID = newSpecialtyCourse.CourseCategoryID; specialtyCourseVerify.CourseTypeID = newSpecialtyCourse.CourseTypeID; specialtyCourseVerify.CourseQualityID = newSpecialtyCourse.CourseQualityID; specialtyCourseVerify.DepartmentID = newSpecialtyCourse.DepartmentID; specialtyCourseVerify.IsSpecialtycore = newSpecialtyCourse.IsSpecialtycore; specialtyCourseVerify.IsCooperation = newSpecialtyCourse.IsCooperation; specialtyCourseVerify.IsRequired = newSpecialtyCourse.IsRequired; specialtyCourseVerify.IsElective = newSpecialtyCourse.IsElective; specialtyCourseVerify.IsNetworkCourse = newSpecialtyCourse.IsNetworkCourse; specialtyCourseVerify.IsMainCourse = newSpecialtyCourse.IsMainCourse; specialtyCourseVerify.IsNeedMaterial = newSpecialtyCourse.IsNeedMaterial; specialtyCourseVerify.CourseFineID = newSpecialtyCourse.CourseFineID; specialtyCourseVerify.PracticeTypeID = newSpecialtyCourse.PracticeTypeID; specialtyCourseVerify.TeachinglanguageID = newSpecialtyCourse.TeachinglanguageID; specialtyCourseVerify.ExaminationModeID = newSpecialtyCourse.ExaminationModeID; specialtyCourseVerify.ResultTypeID = newSpecialtyCourse.ResultTypeID; specialtyCourseVerify.HandleModeID = newSpecialtyCourse.HandleModeID; //specialtyCourseVerify.IsEnable = newSpecialtyCourse.IsEnable; specialtyCourseVerify.Remark = newSpecialtyCourse.Remark; SetModifyStatus(specialtyCourseVerify); newSpecialtyCourseUpList.Add(specialtyCourseVerify); if (specialtyCourseVerify.EM_SpecialtyCourseTeachingSetting == null) { if (newTeachingSettingInList.Any(x => x.SpecialtyCourseID == specialtyCourseVerify.SpecialtyCourseID)) { newTeachingSettingInList.RemoveAll(x => x.SpecialtyCourseID == specialtyCourseVerify.SpecialtyCourseID); } newTeachingSetting.SpecialtyCourseID = specialtyCourseVerify.SpecialtyCourseID; newTeachingSetting.TheoryWeeklyNum = 0; newTeachingSetting.PracticeWeeklyNum = 0; newTeachingSetting.TrialWeeklyNum = 0; newTeachingSetting.WeeklyHours = 0; newTeachingSetting.WeeklyNum = 0; newTeachingSetting.StartWeeklyNum = 1; newTeachingSetting.EndWeeklyNum = 16; newTeachingSettingInList.Add(newTeachingSetting); } else { specialtyCourseVerify.EM_SpecialtyCourseTeachingSetting.Credit = newTeachingSetting.Credit; specialtyCourseVerify.EM_SpecialtyCourseTeachingSetting.TheoryCourse = newTeachingSetting.TheoryCourse; specialtyCourseVerify.EM_SpecialtyCourseTeachingSetting.Practicehours = newTeachingSetting.Practicehours; specialtyCourseVerify.EM_SpecialtyCourseTeachingSetting.Trialhours = newTeachingSetting.Trialhours; newTeachingSettingUpList.Add(specialtyCourseVerify.EM_SpecialtyCourseTeachingSetting); } if (newModeTypeList != null && newModeTypeList.Count() > 0) { if (newTeachingModeTypeInList.Any(x => x.SpecialtyCourseID == specialtyCourseVerify.SpecialtyCourseID)) { newTeachingModeTypeInList.RemoveAll(x => x.SpecialtyCourseID == specialtyCourseVerify.SpecialtyCourseID); } specialtyCourseTMDelList.Add(specialtyCourseVerify.SpecialtyCourseID); foreach (var newModeTypeID in newModeTypeList) { var newTeachingModeType = new EM_TeachingModeType(); newTeachingModeType.TeachingModeTypeID = Guid.NewGuid(); newTeachingModeType.SpecialtyCourseID = specialtyCourseVerify.SpecialtyCourseID; newTeachingModeType.TeachingModeID = newModeTypeID; this.SetNewStatus(newTeachingModeType); newTeachingModeTypeInList.Add(newTeachingModeType); } } else { specialtyCourseTMDelList.Add(specialtyCourseVerify.SpecialtyCourseID); } if (newPlaceList != null && newPlaceList.Count() > 0) { if (newTeachingPlaceInList.Any(x => x.SpecialtyCourseID == specialtyCourseVerify.SpecialtyCourseID)) { newTeachingPlaceInList.RemoveAll(x => x.SpecialtyCourseID == specialtyCourseVerify.SpecialtyCourseID); } specialtyCourseTPDelList.Add(specialtyCourseVerify.SpecialtyCourseID); foreach (var newPlace in newPlaceList) { var newTeachingPlace = new EMIS.Entities.EM_TeachingPlace(); newTeachingPlace.TeachingPlaceID = Guid.NewGuid(); newTeachingPlace.SpecialtyCourseID = specialtyCourseVerify.SpecialtyCourseID; newTeachingPlace.TeachingPlace = newPlace; this.SetNewStatus(newTeachingPlace); newTeachingPlaceInList.Add(newTeachingPlace); } } else { specialtyCourseTPDelList.Add(specialtyCourseVerify.SpecialtyCourseID); } upCount++; } } 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(); } errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception) { throw; } } } }