using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.MinorManage.MinorCourseManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.DataLogic.MinorManage.MinorCourseManage; using Bowin.Common.Utility; using EMIS.ViewModel.CacheManage; using EMIS.DataLogic.Common.Cultureplan; using EMIS.DataLogic.Repositories; using System.Text.RegularExpressions; using EMIS.DataLogic.MinorManage.MinorPlanManage; namespace EMIS.CommonLogic.MinorManage { public class MinorSpecialtyCourseServices : BaseServices, IMinorSpecialtyCourseServices { public MinorSpecialtyCourseDAL minorSpecialtyCourseDAL { get; set; } public Lazy CoursematerialDAL { get; set; } public MinorPlanApplyDAL MinorPlanApplyDAL { get; set; } public Lazy DepartmentRepository { get; set; } /// /// 查询所有辅修专业课程 /// /// 查询条件实体 /// 专业名称 /// 课程名称 /// 开课学年 /// 开课学期 /// 教研室 /// 是否启用 /// 页码 /// 显示条数 /// public IGridResultSet GetMinorSpecialtyCourseViewGrid(ConfiguretView configuretView, int? standardID, Guid? CoursematerialID, int? SchoolyearNumID, int? SchoolcodeID, Guid? DepartmentID, int? IsEnable, int pageIndex, int pageSize) { Expression> exp = (x => true); if (standardID.HasValue) exp = exp.And(x =>x.StandardID==standardID); if (CoursematerialID.HasValue) exp = exp.And(x => x.CoursematerialID == CoursematerialID); if (SchoolyearNumID.HasValue) exp = exp.And(x => x.SchoolyearNumID == SchoolyearNumID); if (SchoolcodeID.HasValue) exp = exp.And(x => x.SchoolcodeID == SchoolcodeID); if (DepartmentID.HasValue) exp = exp.And(x => x.DepartmentID == DepartmentID); if (IsEnable.HasValue) { bool Enable = true; if(IsEnable==0) { Enable = false; } exp = exp.And(x => x.IsEnable == Enable); } var query = minorSpecialtyCourseDAL.GetMinorSpecialtyCourseViewQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StandardID).OrderBy(x=>x.SchoolyearNumID) .OrderBy(x => x.SchoolcodeID).ToGridResultSet(pageIndex, pageSize); } /// /// 查询所有辅修专业课程 /// /// 查询条件实体 /// 专业名称 /// 课程名称 /// 开课学年 /// 开课学期 /// 教研室 /// 是否启用 /// 辅修课程ID /// public List GetMinorCourseViewList(ConfiguretView configuretView, int? standardID, Guid? CoursematerialID, int? SchoolyearNumID, int? SchoolcodeID, Guid? DepartmentID, int? IsEnable, List MinorCourseIDList) { Expression> exp = (x => true); if (MinorCourseIDList != null) exp = exp.And(x => MinorCourseIDList.Contains(x.MinorCourseID)); if (standardID.HasValue) exp = exp.And(x => x.StandardID == standardID); if (CoursematerialID.HasValue) exp = exp.And(x => x.CoursematerialID == CoursematerialID); if (SchoolyearNumID.HasValue) exp = exp.And(x => x.SchoolyearNumID == SchoolyearNumID); if (SchoolcodeID.HasValue) exp = exp.And(x => x.SchoolcodeID == SchoolcodeID); if (DepartmentID.HasValue) exp = exp.And(x => x.DepartmentID == DepartmentID); if (IsEnable.HasValue) { bool Enable = true; if (IsEnable == 0) { Enable = false; } exp = exp.And(x => x.IsEnable == Enable); } var query = minorSpecialtyCourseDAL.GetMinorSpecialtyCourseViewQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StandardID).OrderBy(x => x.SchoolyearNumID) .OrderBy(x => x.SchoolcodeID).ToList(); } /// /// 查询辅修课程信息 /// /// 辅修课程ID /// public MinorSpecialtyCourseView GetMinorSpecialtyCourseView(Guid? MinorCourseID) { Expression> exp = (x =>x.MinorCourseID==MinorCourseID); var MinorSpecialtyCourse = minorSpecialtyCourseDAL.GetMinorSpecialtyCourseViewQueryable(exp).FirstOrDefault(); return MinorSpecialtyCourse; } /// /// 根据专业课程获取授课方式 /// /// 辅修课程 /// public List GetTeachingModeType(Guid? MinorCourseID) { return minorSpecialtyCourseDAL.GetTeachingModeTypeQueryble(MinorCourseID); } /// /// 获取课程资料信息 /// /// 辅修课程 /// public Entities.EM_MinorCourse GetMinorSpecialtyCourse(Guid? MinorCourseID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.MinorCourseID == MinorCourseID); return minorSpecialtyCourseDAL.MinorCourseRepository.GetSingle(expression, (x => x.CF_Department),(x => x.EM_Coursematerial), (x => x.EM_MinorCourseTeachingSetting)); } /// /// 专业课程教学设置表 /// /// 辅修课程ID /// public EM_MinorCourseTeachingSetting GetSpecialtyCourseTeachingSetting(Guid? MinorCourseID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => true); expression = (x => x.MinorCourseID == MinorCourseID); return minorSpecialtyCourseDAL.MinorCourseTeachingSettingRepository.GetSingle(expression); } /// /// 根据专业课程获取授课地点 /// /// 辅修课程ID /// public List GetTeachingPlace(Guid? MinorCourseID) { return minorSpecialtyCourseDAL.GetTeachingPlaceQueryble(MinorCourseID); } public void MinorSpecialtyCourseAdd(MinorSpecialtyCourseView minorSpecialtyCourseView) { try { if (minorSpecialtyCourseDAL.MinorCourseRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.StandardID == minorSpecialtyCourseView.StandardID && x.CoursematerialID == minorSpecialtyCourseView.CoursematerialID && x.SchoolyearNumID == minorSpecialtyCourseView.SchoolyearNumID && x.SchoolcodeID == minorSpecialtyCourseView.SchoolcodeID &&x.MinorCourseID!=minorSpecialtyCourseView.MinorCourseID).Count() > 0) { throw new Exception("该标准专业课程已经存在,请重新输入!"); } EM_MinorCourse MinorCourse = null; EM_MinorCourseTeachingSetting MinorCourseTeachingSetting = null; if (minorSpecialtyCourseView.MinorCourseID == null || minorSpecialtyCourseView.MinorCourseID == Guid.Empty) { MinorCourse = new EM_MinorCourse(); MinorCourse.MinorCourseID = Guid.NewGuid(); MinorCourse.StandardID = minorSpecialtyCourseView.StandardID; MinorCourse.DepartmentID = minorSpecialtyCourseView.DepartmentID; MinorCourse.CoursematerialID = minorSpecialtyCourseView.CoursematerialID; MinorCourse.CourseStructureID = minorSpecialtyCourseView.CourseStructureID; MinorCourse.CourseCategoryID = minorSpecialtyCourseView.CourseCategoryID; MinorCourse.CourseTypeID = minorSpecialtyCourseView.CourseTypeID; MinorCourse.CourseQualityID = minorSpecialtyCourseView.CourseQualityID; MinorCourse.PracticeTypeID = minorSpecialtyCourseView.PracticeTypeID; MinorCourse.ExaminationModeID = minorSpecialtyCourseView.ExaminationModeID; MinorCourse.TeachinglanguageID = minorSpecialtyCourseView.TeachinglanguageID; MinorCourse.SchoolyearNumID = minorSpecialtyCourseView.SchoolyearNumID; MinorCourse.SchoolcodeID = minorSpecialtyCourseView.SchoolcodeID; MinorCourse.CourseFineID = minorSpecialtyCourseView.CourseFineID; MinorCourse.IsSpecialtycore = minorSpecialtyCourseView.IsSpecialtycore; MinorCourse.IsCooperation = minorSpecialtyCourseView.IsCooperation; MinorCourse.IsRequired = minorSpecialtyCourseView.IsRequired; MinorCourse.IsElective = minorSpecialtyCourseView.IsElective; MinorCourse.IsNetworkCourse = minorSpecialtyCourseView.IsNetworkCourse; MinorCourse.IsMainCourse = minorSpecialtyCourseView.IsMainCourse; MinorCourse.IsEnable = minorSpecialtyCourseView.IsEnable; MinorCourse.ResultTypeID = minorSpecialtyCourseView.ResultTypeID; MinorCourse.Remarks = minorSpecialtyCourseView.Remarks; SetNewStatus(MinorCourse); UnitOfWork.Add(MinorCourse); MinorCourseTeachingSetting = new EM_MinorCourseTeachingSetting(); MinorCourseTeachingSetting.MinorCourseID = MinorCourse.MinorCourseID; MinorCourseTeachingSetting.Credit = minorSpecialtyCourseView.Credit; MinorCourseTeachingSetting.TheoryCourse = minorSpecialtyCourseView.TheoryCourse; MinorCourseTeachingSetting.Practicehours = minorSpecialtyCourseView.Practicehours; MinorCourseTeachingSetting.Trialhours = minorSpecialtyCourseView.Trialhours; MinorCourseTeachingSetting.WeeklyNum = minorSpecialtyCourseView.WeeklyNum; MinorCourseTeachingSetting.TheoryWeeklyNum = minorSpecialtyCourseView.TheoryWeeklyNum; MinorCourseTeachingSetting.PracticeWeeklyNum = minorSpecialtyCourseView.PracticeWeeklyNum; MinorCourseTeachingSetting.TrialWeeklyNum = minorSpecialtyCourseView.TrialWeeklyNum; MinorCourseTeachingSetting.StartWeeklyNum = minorSpecialtyCourseView.StartWeeklyNum; MinorCourseTeachingSetting.EndWeeklyNum = minorSpecialtyCourseView.EndWeeklyNum; MinorCourseTeachingSetting.WeeklyHours = minorSpecialtyCourseView.WeeklyHours; UnitOfWork.Add(MinorCourseTeachingSetting); if (minorSpecialtyCourseView.TeachingModeID != null) { UnitOfWork.Delete(x => x.MinorCourseID == MinorCourse.MinorCourseID); foreach (var i in minorSpecialtyCourseView.TeachingModeID) { EM_MinorCourseTeachingModeType MinorCourseTeachingModeType = new EM_MinorCourseTeachingModeType(); MinorCourseTeachingModeType.MinorCourseTeachingModeTypeID = Guid.NewGuid(); MinorCourseTeachingModeType.MinorCourseID = MinorCourse.MinorCourseID; MinorCourseTeachingModeType.TeachingModeID = i; SetNewStatus(MinorCourseTeachingModeType); UnitOfWork.Add(MinorCourseTeachingModeType); } } if (minorSpecialtyCourseView.TeachingPlaceID != null) { UnitOfWork.Delete(x => x.MinorCourseID == MinorCourse.MinorCourseID); foreach (var i in minorSpecialtyCourseView.TeachingPlaceID) { EMIS.Entities.EM_MinorCourseTeachingPlace MinorCourseTeachingPlace = new EMIS.Entities.EM_MinorCourseTeachingPlace(); MinorCourseTeachingPlace.MinorCourseTeachingPlaceID = Guid.NewGuid(); MinorCourseTeachingPlace.MinorCourseID = MinorCourse.MinorCourseID; MinorCourseTeachingPlace.TeachingPlace = i; SetNewStatus(MinorCourseTeachingPlace); UnitOfWork.Add(MinorCourseTeachingPlace); } } } else { MinorCourse = GetMinorSpecialtyCourse(minorSpecialtyCourseView.MinorCourseID); MinorCourseTeachingSetting = GetSpecialtyCourseTeachingSetting(minorSpecialtyCourseView.MinorCourseID); MinorCourse.StandardID = minorSpecialtyCourseView.StandardID; MinorCourse.DepartmentID = minorSpecialtyCourseView.DepartmentID; MinorCourse.CoursematerialID = minorSpecialtyCourseView.CoursematerialID; MinorCourse.CourseStructureID = minorSpecialtyCourseView.CourseStructureID; MinorCourse.CourseCategoryID = minorSpecialtyCourseView.CourseCategoryID; MinorCourse.CourseTypeID = minorSpecialtyCourseView.CourseTypeID; MinorCourse.CourseQualityID = minorSpecialtyCourseView.CourseQualityID; MinorCourse.PracticeTypeID = minorSpecialtyCourseView.PracticeTypeID; MinorCourse.ExaminationModeID = minorSpecialtyCourseView.ExaminationModeID; MinorCourse.TeachinglanguageID = minorSpecialtyCourseView.TeachinglanguageID; MinorCourse.SchoolyearNumID = minorSpecialtyCourseView.SchoolyearNumID; MinorCourse.SchoolcodeID = minorSpecialtyCourseView.SchoolcodeID; MinorCourse.CourseFineID = minorSpecialtyCourseView.CourseFineID; MinorCourse.IsSpecialtycore = minorSpecialtyCourseView.IsSpecialtycore; MinorCourse.IsCooperation = minorSpecialtyCourseView.IsCooperation; MinorCourse.IsRequired = minorSpecialtyCourseView.IsRequired; MinorCourse.IsElective = minorSpecialtyCourseView.IsElective; MinorCourse.IsNetworkCourse = minorSpecialtyCourseView.IsNetworkCourse; MinorCourse.IsMainCourse = minorSpecialtyCourseView.IsMainCourse; MinorCourse.IsEnable = minorSpecialtyCourseView.IsEnable; MinorCourse.ResultTypeID = minorSpecialtyCourseView.ResultTypeID; MinorCourse.Remarks = minorSpecialtyCourseView.Remarks; SetModifyStatus(MinorCourse); MinorCourseTeachingSetting.Credit = minorSpecialtyCourseView.Credit; MinorCourseTeachingSetting.TheoryCourse = minorSpecialtyCourseView.TheoryCourse; MinorCourseTeachingSetting.Practicehours = minorSpecialtyCourseView.Practicehours; MinorCourseTeachingSetting.Trialhours = minorSpecialtyCourseView.Trialhours; MinorCourseTeachingSetting.WeeklyNum = minorSpecialtyCourseView.WeeklyNum; MinorCourseTeachingSetting.TheoryWeeklyNum = minorSpecialtyCourseView.TheoryWeeklyNum; MinorCourseTeachingSetting.PracticeWeeklyNum = minorSpecialtyCourseView.PracticeWeeklyNum; MinorCourseTeachingSetting.TrialWeeklyNum = minorSpecialtyCourseView.TrialWeeklyNum; MinorCourseTeachingSetting.StartWeeklyNum = minorSpecialtyCourseView.StartWeeklyNum; MinorCourseTeachingSetting.EndWeeklyNum = minorSpecialtyCourseView.EndWeeklyNum; MinorCourseTeachingSetting.WeeklyHours = minorSpecialtyCourseView.WeeklyHours; UnitOfWork.Update(MinorCourseTeachingSetting); if (minorSpecialtyCourseView.TeachingModeID != null) { UnitOfWork.Delete(x => x.MinorCourseID == MinorCourse.MinorCourseID); foreach (var i in minorSpecialtyCourseView.TeachingModeID) { EM_MinorCourseTeachingModeType MinorCourseTeachingModeType = new EM_MinorCourseTeachingModeType(); MinorCourseTeachingModeType.MinorCourseTeachingModeTypeID = Guid.NewGuid(); MinorCourseTeachingModeType.MinorCourseID = MinorCourse.MinorCourseID; MinorCourseTeachingModeType.TeachingModeID = i; SetNewStatus(MinorCourseTeachingModeType); UnitOfWork.Add(MinorCourseTeachingModeType); } } if (minorSpecialtyCourseView.TeachingPlaceID != null) { UnitOfWork.Delete(x => x.MinorCourseID == MinorCourse.MinorCourseID); foreach (var i in minorSpecialtyCourseView.TeachingPlaceID) { EMIS.Entities.EM_MinorCourseTeachingPlace MinorCourseTeachingPlace = new EMIS.Entities.EM_MinorCourseTeachingPlace(); MinorCourseTeachingPlace.MinorCourseTeachingPlaceID = Guid.NewGuid(); MinorCourseTeachingPlace.MinorCourseID = MinorCourse.MinorCourseID; MinorCourseTeachingPlace.TeachingPlace = i; SetNewStatus(MinorCourseTeachingPlace); UnitOfWork.Add(MinorCourseTeachingPlace); } } } UnitOfWork.Commit(); } catch (Exception) { throw; } } /// /// 删除 /// /// /// public bool MinorCourseDelete(List MinorCourseIDList) { try { var CourseIDList = minorSpecialtyCourseDAL.MinorCourseRepository.GetList(x => MinorCourseIDList.Contains(x.MinorCourseID)).Select(w=>w.CoursematerialID).ToList(); var useCourseList = MinorPlanApplyDAL.MinorPlanApplicationRepository.GetList(x => CourseIDList.Contains(x.CoursematerialID)).FirstOrDefault(); if (useCourseList!=null) { throw new Exception("删除失败,已存在关联数据,如不使用该课程,可修改是否启用字段。"); } if (MinorCourseIDList.Count > 0) { UnitOfWork.Delete(x => MinorCourseIDList.Contains(x.MinorCourseID)); UnitOfWork.Delete(x => MinorCourseIDList.Contains(x.MinorCourseID)); UnitOfWork.Delete(x => MinorCourseIDList.Contains(x.MinorCourseID)); UnitOfWork.Delete(x => MinorCourseIDList.Contains(x.MinorCourseID)); } return true; } catch (Exception) { throw; } } public void MinorSpecialtyCourseImport(Dictionary cellheader, out int OkCount, out List errdataList, out int ErrCount, string sourcePhysicalPath) { StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); #region 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要 // 1.1解析文件,存放到一个List集合里 List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "错误信息");//还原字典项 #endregion #region 读取数据库数据 //专业字典 var StandardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard.ToString()).ToList(); //课程 var CoursematerialList = CoursematerialDAL.Value.CoursematerialRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList(); //教研室 var DepartmentList = DepartmentRepository.Value.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList(); //授课年级字典 var SchoolyearNumList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_SchoolyearNum.ToString()).ToList(); //学期字典 var SchoolcodeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester.ToString()).ToList(); //课程类型字典 var CourseTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseType.ToString()).ToList(); //课程属性字典 var CourseCategoryList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseCategory.ToString()).ToList(); //课程性质字典 var CourseQualityList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseQuality.ToString()).ToList(); //课程结构字典 var CourseStructureList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseStructure.ToString()).ToList(); //实践类型字典 var PracticeTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.EM_PracticeType.ToString()).ToList(); //考试方式字典 var ExaminationModeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ExaminationMode.ToString()).ToList(); //通用是或否字典 var YesOrNoStatusList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_YesOrNoStatus.ToString()).ToList(); //精品课程字典 var CourseFineList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseFine.ToString()).ToList(); //授课语言字典 var TeachinglanguageList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Teachinglanguage.ToString()).ToList(); //授课方式字典 var TeachingModeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeachingMode.ToString()).ToList(); //授课地点字典 var TeachingPlaceList = IdNameExt.GetDictionaryItem(DictionaryItem.EM_TeachingPlace.ToString()).ToList(); //成绩类型字典 var ResultTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ResultType.ToString()).ToList(); //辅修课程List var MinorCourseList = minorSpecialtyCourseDAL.MinorCourseRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList(); #endregion #region 1.2 检验数据合格性 if (enlist.Count() <= 0) { throw new Exception("请填写Excel模板信息数据。"); } #region 验证 //Regex reg = new Regex(@"^[0-9]*$"); Regex reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); for (int i = 0; i < enlist.Count; i++) { MinorSpecialtyCourseView en = enlist[i]; string errorMsgStr = "第" + (i + 2) + "行数据检测异常:"; bool isHaveNoInputValue = false; // 是否含有未输入项 #region 专业代码 if (string.IsNullOrEmpty(en.SpecialtyCodeStr)) { errorMsgStr += "专业代码不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } #endregion #region 专业名称 if (string.IsNullOrEmpty(en.StandardNameStr)) { errorMsgStr += "专业名称不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.StandardNameStr) && !string.IsNullOrEmpty(en.SpecialtyCodeStr)) { var Standard = StandardList.Where(x => x.Name == en.StandardNameStr.Trim() && x.Code == en.SpecialtyCodeStr.Trim()).FirstOrDefault(); if (Standard == null) { errorMsgStr += "专业代码与专业名称不符;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 课程名称 if (string.IsNullOrEmpty(en.CourseCode)) { errorMsgStr += "课程代码不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.CourseCode)) { if (CoursematerialList.Where(x => x.CourseCode == en.CourseCode.Trim()).FirstOrDefault() == null) { errorMsgStr += "该课程代码不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 教研室 if (string.IsNullOrEmpty(en.DepartmentName)) { errorMsgStr += "教研室不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.DepartmentName)) { if (DepartmentList.Where(x => x.Name == en.DepartmentName.Trim()).FirstOrDefault() == null) { errorMsgStr += "教研室不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.DepartmentID = DepartmentList.Where(x => x.Name == en.DepartmentName.Trim()).FirstOrDefault().DepartmentID; } } #endregion #region 授课年级 if (string.IsNullOrEmpty(en.SchoolyearNumNameStr)) { errorMsgStr += "授课年级不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { if (SchoolyearNumList.Where(x => x.Name.Trim() == en.SchoolyearNumNameStr.Trim()).FirstOrDefault() == null) { errorMsgStr += "授课年级不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 学期 if (string.IsNullOrEmpty(en.SchoolcodeStr)) { errorMsgStr += "学期不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.SchoolcodeStr)) { if (SchoolcodeList.Where(x => x.Name == en.SchoolcodeStr).FirstOrDefault() == null) { errorMsgStr += "学期不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.SchoolcodeID = SchoolcodeList.Where(x => x.Name == en.SchoolcodeStr).FirstOrDefault().Value; } } #endregion #region 课程类型 if (string.IsNullOrEmpty(en.CourseTypeStr)) { errorMsgStr += "课程类型不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.CourseTypeStr)) { if (CourseTypeList.Where(x => x.Name == en.CourseTypeStr).FirstOrDefault() == null) { errorMsgStr += "课程类型不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.CourseTypeID = CourseTypeList.Where(x => x.Name == en.CourseTypeStr).FirstOrDefault().Value; } } #endregion #region 课程属性 if (string.IsNullOrEmpty(en.CourseCategoryNameStr)) { errorMsgStr += "课程属性不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.CourseCategoryNameStr)) { if (CourseCategoryList.Where(x => x.Name == en.CourseCategoryNameStr).FirstOrDefault() == null) { errorMsgStr += "课程属性不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.CourseCategoryID = CourseCategoryList.Where(x => x.Name == en.CourseCategoryNameStr).FirstOrDefault().Value; } } #endregion #region 课程性质 if (string.IsNullOrEmpty(en.CourseQualityNameStr)) { errorMsgStr += "课程性质不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.CourseQualityNameStr)) { if (CourseQualityList.Where(x => x.Name == en.CourseQualityNameStr).FirstOrDefault() == null) { errorMsgStr += "课程性质不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.CourseQualityID = CourseQualityList.Where(x => x.Name == en.CourseQualityNameStr).FirstOrDefault().Value; } } #endregion #region 课程结构 if (!string.IsNullOrEmpty(en.CourseStructureNameStr)) { if (CourseStructureList.Where(x => x.Name == en.CourseStructureNameStr).FirstOrDefault() == null) { errorMsgStr += "课程结构不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.CourseStructureID = CourseStructureList.Where(x => x.Name == en.CourseStructureNameStr).FirstOrDefault().Value; } } #endregion #region 学分 if (string.IsNullOrEmpty(en.CreditStr)) { errorMsgStr += "学分不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.CreditStr)) { if (!reg.IsMatch(en.CreditStr)) { errorMsgStr += "学分格式不正确;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.Credit = Convert.ToDecimal(en.CreditStr); } } #endregion #region 理论学时 if (string.IsNullOrEmpty(en.TheoryCourseStr)) { errorMsgStr += "理论学时不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.TheoryCourseStr)) { if (!reg.IsMatch(en.TheoryCourseStr)) { errorMsgStr += "理论学时格式不正确;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.TheoryCourse = Convert.ToInt32(en.TheoryCourseStr); } } #endregion #region 实践学时 if (string.IsNullOrEmpty(en.PracticehoursStr)) { errorMsgStr += "实践学时不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.PracticehoursStr)) { if (!reg.IsMatch(en.PracticehoursStr)) { errorMsgStr += "实践学时格式不正确;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.Practicehours = Convert.ToInt32(en.PracticehoursStr); } } #endregion #region 实验学时 if (string.IsNullOrEmpty(en.TrialhoursStr)) { errorMsgStr += "实验学时不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.TrialhoursStr)) { if (!reg.IsMatch(en.TrialhoursStr)) { errorMsgStr += "实验学时格式不正确;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.Trialhours = Convert.ToInt32(en.TrialhoursStr); } } #endregion #region 实践方式 if (!string.IsNullOrEmpty(en.PracticeTypeNameStr)) { if (PracticeTypeList.Where(x => x.Name == en.PracticeTypeNameStr).FirstOrDefault() == null) { errorMsgStr += "实践方式不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.PracticeTypeID = PracticeTypeList.Where(x => x.Name == en.PracticeTypeNameStr).FirstOrDefault().Value; } } #endregion #region 考试方式 if (string.IsNullOrEmpty(en.ExaminationModeNameStr)) { errorMsgStr += "考试方式不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.ExaminationModeNameStr)) { if (ExaminationModeList.Where(x => x.Name == en.ExaminationModeNameStr).FirstOrDefault() == null) { errorMsgStr += "考试方式不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.ExaminationModeID = ExaminationModeList.Where(x => x.Name == en.ExaminationModeNameStr).FirstOrDefault().Value; } } #endregion #region 成绩类型 if (string.IsNullOrEmpty(en.ResultTypeNameStr)) { errorMsgStr += "成绩类型不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.ResultTypeNameStr)) { if (ResultTypeList.Where(x => x.Name == en.ResultTypeNameStr).FirstOrDefault() == null) { errorMsgStr += "成绩类型不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.ResultTypeID = ResultTypeList.Where(x => x.Name == en.ResultTypeNameStr).FirstOrDefault().Value; } } #endregion #region 是否专业核心 if (!string.IsNullOrEmpty(en.IsSpecialtycoreName)) { //var t = typeof(MinorSpecialtyCourseView); //var pName = t.GetProperty(en.IsSpecialtycoreName); ////4.0或以上版本 //var displayName = pName.GetCustomAttributes(); if (YesOrNoStatusList.Where(x => x.Name == en.IsSpecialtycoreName).FirstOrDefault() == null) { errorMsgStr += "是否专业核心不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.IsSpecialtycore = en.IsSpecialtycoreName == "是" ? true : false; } } #endregion #region 是否校企开发 if (!string.IsNullOrEmpty(en.IsCooperationName)) { if (YesOrNoStatusList.Where(x => x.Name == en.IsCooperationName).FirstOrDefault() == null) { errorMsgStr += "是否校企开发不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.IsCooperation = en.IsCooperationName == "是" ? true : false; } } #endregion #region 是否课证融通 if (!string.IsNullOrEmpty(en.IsRequiredName)) { if (YesOrNoStatusList.Where(x => x.Name == en.IsRequiredName).FirstOrDefault() == null) { errorMsgStr += "是否课证融通不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.IsRequired = en.IsRequiredName == "是" ? true : false; } } #endregion #region 是否学位主干 if (!string.IsNullOrEmpty(en.IsMainCourseName)) { if (YesOrNoStatusList.Where(x => x.Name == en.IsMainCourseName).FirstOrDefault() == null) { errorMsgStr += "是否学位主干不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.IsMainCourse = en.IsMainCourseName == "是" ? true : false; } } #endregion #region 是否选修 if (!string.IsNullOrEmpty(en.IsElectiveName)) { if (YesOrNoStatusList.Where(x => x.Name == en.IsElectiveName).FirstOrDefault() == null) { errorMsgStr += "是否选修不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.IsElective = en.IsElectiveName == "是" ? true : false; } } #endregion #region 是否网络 if (!string.IsNullOrEmpty(en.IsNetworkCourseName)) { if (YesOrNoStatusList.Where(x => x.Name == en.IsNetworkCourseName).FirstOrDefault() == null) { errorMsgStr += "是否网络不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.IsNetworkCourse = en.IsNetworkCourseName == "是" ? true : false; } } #endregion #region 精品课程 if (!string.IsNullOrEmpty(en.CourseFineNameStr)) { if (CourseFineList.Where(x => x.Name == en.CourseFineNameStr).FirstOrDefault() == null) { errorMsgStr += "精品课程不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.CourseFineID = CourseFineList.Where(x => x.Name == en.CourseFineNameStr).FirstOrDefault().Value; } } #endregion #region 授课语言 if (!string.IsNullOrEmpty(en.TeachinglanguageNameStr)) { if (TeachinglanguageList.Where(x => x.Name == en.TeachinglanguageNameStr).FirstOrDefault() == null) { errorMsgStr += "授课语言不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { en.TeachinglanguageID = TeachinglanguageList.Where(x => x.Name == en.TeachinglanguageNameStr).FirstOrDefault().Value; } } #endregion #region 授课方式 if (string.IsNullOrEmpty(en.TeachingModeStr)) { errorMsgStr += "授课方式不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (!string.IsNullOrEmpty(en.TeachingModeStr)) { bool IsExists = true;//是否存在! string[] StrArry = null; if (en.TeachingModeStr.Contains(",")) { StrArry = en.TeachingModeStr.Split(','); } if (en.TeachingModeStr.Contains(",")) { StrArry = en.TeachingModeStr.Split(','); } if (en.TeachingModeStr.Contains(",") && en.TeachingModeStr.Contains(",")) { StrArry = new string[1]; StrArry[0] = en.TeachingModeStr.ToString(); } if (StrArry != null) { foreach (var Str in StrArry) { if (TeachingModeList.Where(x => x.Name == Str).FirstOrDefault() == null && !string.IsNullOrEmpty(Str)) { IsExists = false; } } } else { if (TeachingModeList.Where(x => x.Name == en.TeachingModeStr).FirstOrDefault() == null && !string.IsNullOrEmpty(en.TeachingModeStr)) { IsExists = false; } } if (!IsExists) { errorMsgStr += "授课方式不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { List TeachingModesList = new List(); if (StrArry != null) { foreach (var Str in StrArry) { if (!string.IsNullOrEmpty(Str)) { int? TeachingModeID = TeachingModeList.Where(x => x.Name == Str).FirstOrDefault().Value; TeachingModesList.Add((int)TeachingModeID); } } } else { if (!string.IsNullOrEmpty(en.TeachingModeStr)) { int? TeachingModeID = TeachingModeList.Where(x => x.Name == en.TeachingModeStr).FirstOrDefault().Value; TeachingModesList.Add((int)TeachingModeID); } } en.TeachingModeID = TeachingModesList.Distinct().ToList(); } } #endregion #region 授课地点 if (!string.IsNullOrEmpty(en.TeachingPlaceStr)) { string[] StrArry = null; if (en.TeachingPlaceStr.Contains(",")) { StrArry = en.TeachingPlaceStr.Split(','); } if (en.TeachingPlaceStr.Contains(",")) { StrArry = en.TeachingPlaceStr.Split(','); } if (en.TeachingPlaceStr.Contains(",") && en.TeachingPlaceStr.Contains(",")) { StrArry = new string[1]; StrArry[0] = en.TeachingPlaceStr.ToString(); } bool IsExists = true;//是否存在! if (StrArry != null) { foreach (var Str in StrArry) { if (TeachingPlaceList.Where(x => x.Name == Str).FirstOrDefault() == null && !string.IsNullOrEmpty(Str)) { IsExists = false; } } } else { if (TeachingPlaceList.Where(x => x.Name == en.TeachingPlaceStr).FirstOrDefault() == null && !string.IsNullOrEmpty(en.TeachingPlaceStr)) { IsExists = false; } } if (!IsExists) { errorMsgStr += "授课地点不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } else { List TeachingsPlaceList = new List(); if (StrArry != null) { foreach (var Str in StrArry) { if (!string.IsNullOrEmpty(Str)) { int? TeachingPlaceID = TeachingPlaceList.Where(x => x.Name == Str).FirstOrDefault().Value; TeachingsPlaceList.Add((int)TeachingPlaceID); } } } else { if (!string.IsNullOrEmpty(en.TeachingPlaceStr)) { int? TeachingPlaceID = TeachingPlaceList.Where(x => x.Name == en.TeachingPlaceStr).FirstOrDefault().Value; TeachingsPlaceList.Add((int)TeachingPlaceID); } } en.TeachingPlaceID = TeachingsPlaceList.Distinct().ToList(); } } #endregion //唯一值 专业信息+课程+开课学期 #region 唯一值 if (!isHaveNoInputValue) { int? standardID = StandardList.Where(x => x.Name == en.StandardNameStr.Trim() && x.Code == en.SpecialtyCodeStr.Trim()).FirstOrDefault().Value; //学期 int? schoolcodeID = SchoolcodeList.Where(x => x.Name == en.SchoolcodeStr).FirstOrDefault().Value; //开课年级 int? schoolyearNum = SchoolyearNumList.Where(x => x.Name == en.SchoolyearNumNameStr).FirstOrDefault().Value; //以开课年级+学期 得出对应的 开课学期 EM_Coursematerial CoursematerialEntity = CoursematerialList.Where(x => x.CourseCode == en.CourseCode.Trim()).FirstOrDefault(); if (CoursematerialEntity == null) { isHaveNoInputValue = true; } else { if (MinorCourseList.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.StandardID == standardID && x.CoursematerialID == CoursematerialEntity.CoursematerialID && x.SchoolyearNumID == schoolyearNum && x.SchoolcodeID == schoolcodeID).Count() > 0) { errorMsgStr += "该标准专业课程已经存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; // throw new Exception("该标准专业课程已经存在,请重新输入!"); } else { en.StandardID = standardID; en.CoursematerialID = CoursematerialEntity.CoursematerialID; en.SchoolcodeID = schoolcodeID; en.SchoolyearNumID = schoolyearNum; } } } if (isHaveNoInputValue) // 若必填项有值未填 { en.IsExcelVaildateOK = false; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); } } #endregion #endregion #region 插入数据 List MinorCourseLists = new List(); List MinorCourseTeachingSettingList = new List(); List MinorCourseTeachingPlaceList = new List(); List MinorCourseTeachingModeTypeList = new List(); for (int i = 0; i < enlist.Count; i++) { MinorSpecialtyCourseView enA = enlist[i]; if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证 { continue; } EM_MinorCourse MinorCourse = null; EM_MinorCourseTeachingSetting MinorCourseTeachingSetting = null; if (enA != null) { MinorCourse = new EM_MinorCourse(); MinorCourse.MinorCourseID = Guid.NewGuid(); MinorCourse.StandardID = enA.StandardID; MinorCourse.DepartmentID = enA.DepartmentID; MinorCourse.CoursematerialID = enA.CoursematerialID; MinorCourse.CourseStructureID = enA.CourseStructureID; MinorCourse.CourseCategoryID = enA.CourseCategoryID; MinorCourse.CourseTypeID = enA.CourseTypeID; MinorCourse.CourseQualityID = enA.CourseQualityID; MinorCourse.PracticeTypeID = enA.PracticeTypeID; MinorCourse.ExaminationModeID = enA.ExaminationModeID; MinorCourse.TeachinglanguageID = enA.TeachinglanguageID; MinorCourse.SchoolyearNumID = enA.SchoolyearNumID; MinorCourse.SchoolcodeID = enA.SchoolcodeID; MinorCourse.CourseFineID = enA.CourseFineID; MinorCourse.IsSpecialtycore = enA.IsSpecialtycore; MinorCourse.IsCooperation = enA.IsCooperation; MinorCourse.IsRequired = enA.IsRequired; MinorCourse.IsElective = enA.IsElective; MinorCourse.IsNetworkCourse = enA.IsNetworkCourse; MinorCourse.IsMainCourse = enA.IsMainCourse; MinorCourse.IsEnable = true;//默认启用 MinorCourse.ResultTypeID = enA.ResultTypeID; MinorCourse.Remarks = enA.Remarks; SetNewStatus(MinorCourse); MinorCourseLists.Add(MinorCourse); MinorCourseTeachingSetting = new EM_MinorCourseTeachingSetting(); MinorCourseTeachingSetting.MinorCourseID = MinorCourse.MinorCourseID; MinorCourseTeachingSetting.Credit = enA.Credit; MinorCourseTeachingSetting.TheoryCourse = enA.TheoryCourse; MinorCourseTeachingSetting.Practicehours = enA.Practicehours; MinorCourseTeachingSetting.Trialhours = enA.Trialhours; MinorCourseTeachingSetting.WeeklyNum = enA.WeeklyNum; MinorCourseTeachingSetting.TheoryWeeklyNum = enA.TheoryWeeklyNum; MinorCourseTeachingSetting.PracticeWeeklyNum = enA.PracticeWeeklyNum; MinorCourseTeachingSetting.TrialWeeklyNum = enA.TrialWeeklyNum; MinorCourseTeachingSetting.StartWeeklyNum = enA.StartWeeklyNum; MinorCourseTeachingSetting.EndWeeklyNum = enA.EndWeeklyNum; MinorCourseTeachingSetting.WeeklyHours = enA.WeeklyHours; MinorCourseTeachingSettingList.Add(MinorCourseTeachingSetting); if (enA.TeachingModeID != null) { foreach (var item in enA.TeachingModeID) { EM_MinorCourseTeachingModeType teachingModeType = new EM_MinorCourseTeachingModeType(); teachingModeType.MinorCourseTeachingModeTypeID = Guid.NewGuid(); teachingModeType.MinorCourseID = MinorCourse.MinorCourseID; teachingModeType.TeachingModeID = item; SetNewStatus(teachingModeType); MinorCourseTeachingModeTypeList.Add(teachingModeType); } } if (enA.TeachingPlaceID != null) { foreach (var item in enA.TeachingPlaceID) { EM_MinorCourseTeachingPlace teachingPlace = new EM_MinorCourseTeachingPlace(); teachingPlace.MinorCourseTeachingPlaceID = Guid.NewGuid(); teachingPlace.MinorCourseID = MinorCourse.MinorCourseID; teachingPlace.TeachingPlace = item; SetNewStatus(teachingPlace); MinorCourseTeachingPlaceList.Add(teachingPlace); } } } } #endregion #endregion #region 1.3 返回各项数据值 UnitOfWork.BulkInsert(MinorCourseLists);//统一写入 UnitOfWork.BulkInsert(MinorCourseTeachingSettingList);//统一写入 UnitOfWork.BulkInsert(MinorCourseTeachingPlaceList);//统一写入 UnitOfWork.BulkInsert(MinorCourseTeachingModeTypeList);//统一写入 OkCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数 errdataList = errList.Distinct().ToList(); ErrCount = errList.Distinct().Count(); #endregion } } }