using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Text.RegularExpressions; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using Bowin.Common.Utility; using EMIS.Entities; using EMIS.Utility; using EMIS.ViewModel; using EMIS.ViewModel.CacheManage; using EMIS.ViewModel.UniversityManage.SpecialtyClassManage; using EMIS.ViewModel.StudentManage.StudentProfile; using EMIS.DataLogic.UniversityManage.SpecialtyClassManage; using EMIS.CommonLogic.StudentManage.StudentStatistics; namespace EMIS.CommonLogic.UniversityManage.SpecialtyClassManage { public class FacultymajorServices : BaseServices, IFacultymajorServices { public FacultymajorDAL FacultymajorDAL { get; set; } public Lazy InSchoolSettingServices { get; set; } /// /// 查询院系专业信息View /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetFacultymajorViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? scienceclassID, int? inSchoolStatus, int pageIndex, int pageSize) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { //院系所 expFacultymajor = expFacultymajor.And(x => x.CollegeID == collegeID); } if (standardID.HasValue) { //专业ID(Value) expFacultymajor = expFacultymajor.And(x => x.StandardID == standardID); } if (educationID.HasValue) { //培养层次 expFacultymajor = expFacultymajor.And(x => x.EducationID == educationID); } if (learningformID.HasValue) { //学习形式 expFacultymajor = expFacultymajor.And(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); expFacultymajor = expFacultymajor.And(x => x.LearnSystem == LearnSystems); } if (scienceclassID.HasValue) { //专业科类 expFacultymajor = expFacultymajor.And(x => x.ScienceclassID == scienceclassID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = FacultymajorDAL.GetFacultymajorViewQueryable(expFacultymajor, expStudent); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //if (inSchoolStatus != null && inSchoolStatus > -1) //{ // //排除人数为0的信息 // query = query.Where(x => x.StudentCount > 0); //} //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID) .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet(pageIndex, pageSize); } /// /// 查询院系专业信息List /// /// /// /// /// /// /// /// /// /// /// public IList GetFacultymajorViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? scienceclassID, int? inSchoolStatus) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { //院系所 expFacultymajor = expFacultymajor.And(x => x.CollegeID == collegeID); } if (standardID.HasValue) { //专业ID(Value) expFacultymajor = expFacultymajor.And(x => x.StandardID == standardID); } if (educationID.HasValue) { //培养层次 expFacultymajor = expFacultymajor.And(x => x.EducationID == educationID); } if (learningformID.HasValue) { //学习形式 expFacultymajor = expFacultymajor.And(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); expFacultymajor = expFacultymajor.And(x => x.LearnSystem == LearnSystems); } if (scienceclassID.HasValue) { //专业科类 expFacultymajor = expFacultymajor.And(x => x.ScienceclassID == scienceclassID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = FacultymajorDAL.GetFacultymajorViewQueryable(expFacultymajor, expStudent); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //if (inSchoolStatus != null && inSchoolStatus > -1) //{ // //排除人数为0的信息 // query = query.Where(x => x.StudentCount > 0); //} //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID) .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList(); } /// /// 根据院系所ID查询对应的院系专业信息(带数据范围) /// /// /// public IList GetFacultymajorViewList(Guid? collegeID) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expFacultymajor = expFacultymajor.And(x => x.CollegeID == collegeID); } var query = FacultymajorDAL.GetFacultymajorViewQueryable(expFacultymajor); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList(); } /// /// 根据院系所ID、专业ID(Value)查询对应的院系专业信息 /// /// /// /// public List GetFacultymajorViewList(Guid? collegeID, int? standardID) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expFacultymajor = expFacultymajor.And(x => x.CollegeID == collegeID); } if (standardID.HasValue) { expFacultymajor = expFacultymajor.And(x => x.StandardID == standardID); } var query = FacultymajorDAL.GetFacultymajorViewQueryable(expFacultymajor); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList(); } /// /// 查询院系专业对应的专业信息SpecialtyView(去重) /// /// /// /// /// /// public IGridResultSet GetStandardViewGrid(ConfiguretView configuretView, Guid? collegeID, int? pageIndex, int? pageSize) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expFacultymajor = expFacultymajor.And(x => x.CollegeID == collegeID); } var query = FacultymajorDAL.GetStandardViewQueryable(expFacultymajor); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StandardName).ToGridResultSet(pageIndex, pageSize); } /// /// 查询院系专业对应的学制信息(去重) /// /// /// /// /// /// public IGridResultSet GetLearnSystemViewGrid(ConfiguretView configuretView, string learnSystem, int pageIndex, int pageSize) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = FacultymajorDAL.GetLearnSystemViewQueryable(expFacultymajor); if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } if (configuretView.ConditionValue != null && configuretView.ConditionValue != "") { var learn = Convert.ToDecimal(configuretView.ConditionValue); query = query.Where(x => x.LearnSystem == learn); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LearnSystem).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的院系专业信息CF_Facultymajor /// /// /// public CF_Facultymajor GetFacultymajorInfo(Guid? facultymajorID) { try { var query = FacultymajorDAL.FacultymajorRepository.GetList(x => x.FacultymajorID == facultymajorID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的院系专业信息CF_Facultymajor /// /// /// public CF_Facultymajor GetFacultymajorInfoByCode(string code) { try { var query = FacultymajorDAL.FacultymajorRepository.GetSingle(x => x.Code == code); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询全部院系专业信息FacultymajorView(无数据范围) /// /// public List GetFacultymajorList() { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = FacultymajorDAL.FacultymajorRepository.GetList(expFacultymajor).ToList(); return query.OrderBy(x => x.CollegeID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList(); } /// /// 查询对应的院系专业信息FacultymajorView /// /// /// public FacultymajorView GetFacultymajorView(Guid? facultymajorID) { try { var query = FacultymajorDAL.GetFacultymajorViewQueryable(x => x.FacultymajorID == facultymajorID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改,业务主键:院系所ID、院系专业编号、专业ID(Value)、培养层次、学习形式、学制唯一) /// /// public void FacultymajorEdit(FacultymajorView facultymajorView) { try { //查询对应的专业信息 var specialty = FacultymajorDAL.SpecialtyRepository.GetList(x => x.StandardID == facultymajorView.StandardID && x.EducationID == facultymajorView.EducationID && x.LearningformID == facultymajorView.LearningformID && x.LearnSystem == facultymajorView.LearnSystem).SingleOrDefault(); if (specialty == null) { throw new Exception("对应的专业信息不存在,请检查。"); } else { CF_Facultymajor facultymajor = new CF_Facultymajor(); var existsFacultymajor = FacultymajorDAL.FacultymajorRepository.GetSingle(x => x.FacultymajorID != facultymajorView.FacultymajorID && x.Code == facultymajorView.Code && x.CollegeID == facultymajorView.CollegeID && x.StandardID == facultymajorView.StandardID && x.LearnSystem == facultymajorView.LearnSystem && x.EducationID == facultymajorView.EducationID && x.LearningformID == facultymajorView.LearningformID); if (existsFacultymajor != null) { throw new Exception("院系专业编号、" + RSL.Get("College") + "、专业名称、学制、" + RSL.Get("EducationID") + "、学习形式已存在。"); } if (facultymajorView.FacultymajorID == null || facultymajorView.FacultymajorID == Guid.Empty) { //新增 facultymajor.FacultymajorID = Guid.NewGuid(); facultymajor.CollegeID = facultymajorView.CollegeID; facultymajor.Code = facultymajorView.Code.Trim(); facultymajor.Name = facultymajorView.Name; facultymajor.Abbreviation = facultymajorView.Abbreviation; facultymajor.EnglishName = facultymajorView.EnglishName; facultymajor.StandardID = facultymajorView.StandardID; facultymajor.EducationID = facultymajorView.EducationID; facultymajor.LearningformID = facultymajorView.LearningformID; facultymajor.LearnSystem = facultymajorView.LearnSystem; facultymajor.ScienceclassID = facultymajorView.ScienceclassID; facultymajor.LearningstyleID = facultymajorView.LearningstyleID; facultymajor.LearnPositionID = facultymajorView.LearnPositionID; facultymajor.TeacherIdentification = facultymajorView.TeacherIdentification; facultymajor.SetTime = facultymajorView.SetTime; facultymajor.Remark = facultymajorView.Remark; SetNewStatus(facultymajor); UnitOfWork.Add(facultymajor); } else { //修改 facultymajor = this.GetFacultymajorInfo(facultymajorView.FacultymajorID); facultymajor.CollegeID = facultymajorView.CollegeID; facultymajor.Code = facultymajorView.Code.Trim(); facultymajor.Name = facultymajorView.Name; facultymajor.Abbreviation = facultymajorView.Abbreviation; facultymajor.EnglishName = facultymajorView.EnglishName; facultymajor.StandardID = facultymajorView.StandardID; facultymajor.EducationID = facultymajorView.EducationID; facultymajor.LearningformID = facultymajorView.LearningformID; facultymajor.LearnSystem = facultymajorView.LearnSystem; facultymajor.ScienceclassID = facultymajorView.ScienceclassID; facultymajor.LearningstyleID = facultymajorView.LearningstyleID; facultymajor.LearnPositionID = facultymajorView.LearnPositionID; facultymajor.TeacherIdentification = facultymajorView.TeacherIdentification; facultymajor.SetTime = facultymajorView.SetTime; facultymajor.Remark = facultymajorView.Remark; SetModifyStatus(facultymajor); } } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool FacultymajorDelete(List facultymajorIDList) { try { UnitOfWork.Delete(x => facultymajorIDList.Contains(x.FacultymajorID)); return true; } catch (Exception) { throw; } } /// /// 查询院系专业对应的年级专业信息GrademajorView(带对应的在校状态学生人数) /// /// /// /// /// /// /// /// /// public IGridResultSet GetGrademajorViewGrid(ConfiguretView configuretView, Guid? facultymajorID, int? gradeID, int? semesterID, int? inSchoolStatus, int pageIndex, int pageSize) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expFacultymajor = expFacultymajor.And(x => x.FacultymajorID == facultymajorID); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = FacultymajorDAL.GetGrademajorViwQueryable(expFacultymajor, expStudent); if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (semesterID.HasValue) { query = query.Where(x => x.SemesterID == semesterID); } //if (inSchoolStatus != null && inSchoolStatus > -1) //{ // //排除人数为0的信息 // query = query.Where(x => x.StudentCount > 0); //} //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.GradeID).ThenBy(x => x.SemesterID) .ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet(pageIndex, pageSize); } /// /// 查询院系专业对应的年级专业信息List(带对应的在校状态学生人数) /// /// /// /// /// /// /// public IList GetGrademajorViewList(ConfiguretView configuretView, Guid? facultymajorID, int? gradeID, int? semesterID, int? inSchoolStatus) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expFacultymajor = expFacultymajor.And(x => x.FacultymajorID == facultymajorID); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = FacultymajorDAL.GetGrademajorViwQueryable(expFacultymajor, expStudent); if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (semesterID.HasValue) { query = query.Where(x => x.SemesterID == semesterID); } //if (inSchoolStatus != null && inSchoolStatus > -1) //{ // //排除人数为0的信息 // query = query.Where(x => x.StudentCount > 0); //} //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.GradeID).ThenBy(x => x.SemesterID) .ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList(); } /// /// 查询院系专业对应的学生信息BaseStudentView /// /// /// /// /// /// /// /// /// public IGridResultSet GetStudentBaseViewGrid(ConfiguretView configuretView, Guid? facultymajorID, int? gradeID, int? semesterID, int? inSchoolStatus, int pageIndex, int pageSize) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expFacultymajor = expFacultymajor.And(x => x.FacultymajorID == facultymajorID); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = FacultymajorDAL.GetStudentBaseViewQueryable(expFacultymajor, expStudent); if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (semesterID.HasValue) { query = query.Where(x => x.SemesterID == semesterID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LoginID).ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询院系专业对应的学生信息List /// /// /// /// /// /// /// public IList GetStudentBaseViewList(ConfiguretView configuretView, Guid? facultymajorID, int? gradeID, int? semesterID, int? inSchoolStatus) { Expression> expFacultymajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expFacultymajor = expFacultymajor.And(x => x.FacultymajorID == facultymajorID); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = FacultymajorDAL.GetStudentBaseViewQueryable(expFacultymajor, expStudent); if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (semesterID.HasValue) { query = query.Where(x => x.SemesterID == semesterID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LoginID).ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ToList(); } /// /// 院系专业信息Excel导入 /// /// /// /// /// /// /// public void FacultymajorImport(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(); cellheader.Remove("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; //用于返回判断日期字段格式 inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 List newFacultymajorInList = new List(); List newFacultymajorUpList = new List(); //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询) //院系所信息 var collegeList = FacultymajorDAL.CollegeRepository.GetList(x => true).ToList(); //院系所代码 var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeCode)).Select(x => x.CollegeCode).ToList(); //对比后的newCollegeList var newCollegeList = collegeList.Where(x => collegeNoList.Contains(x.No)).ToList(); //专业代码、专业名称、专业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 scienceclassList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Scienceclass).ToList(); //学习方式 var learningstyleList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningstyle).ToList(); //授予学位 var learnPositionList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition).ToList(); //院系专业 var facultymajorList = FacultymajorDAL.FacultymajorRepository.GetList(x => true).ToList(); //院系所代码 var facultymajorCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList(); //对比后的newFacultymajorList(暂时只对比院系专业编号) var newFacultymajorList = facultymajorList.Where(x => facultymajorCodeList.Contains(x.Code)).ToList(); //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { FacultymajorView en = enlist[i]; //Excel表数据视图 CF_Facultymajor newFacultymajor = new CF_Facultymajor(); //院系专业编号 if (string.IsNullOrEmpty(en.Code)) { 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.Code)) { errCount++; errorMsgStr = "院系专业编号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //院系专业编号 newFacultymajor.Code = en.Code.Trim(); } } //院系专业名称 if (string.IsNullOrEmpty(en.Name)) { errCount++; errorMsgStr = "院系专业名称不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //院系专业名称 newFacultymajor.Name = en.Name.Trim(); } //简称 if (string.IsNullOrEmpty(en.Abbreviation)) { //不考虑 } else { newFacultymajor.Abbreviation = en.Abbreviation; } //英文名称 if (string.IsNullOrEmpty(en.EnglishName)) { //不考虑 } else { newFacultymajor.EnglishName = en.EnglishName; } //院系所代码 if (string.IsNullOrEmpty(en.CollegeCode)) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母) if (!reg.IsMatch(en.CollegeCode)) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var college = newCollegeList.Where(x => x.No == en.CollegeCode.Trim()).SingleOrDefault(); if (college == null) { errCount++; errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //院系所信息ID newFacultymajor.CollegeID = college.CollegeID; } } } //专业代码 if (string.IsNullOrEmpty(en.StandardCodeStr)) { errCount++; errorMsgStr = "专业代码不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var standardCode = standardList.Where(x => x.Code == en.StandardCodeStr.Trim()).FirstOrDefault(); if (standardCode == null) { errCount++; errorMsgStr = "专业代码不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业代码 } } //专业名称 if (string.IsNullOrEmpty(en.StandardNameStr)) { errCount++; errorMsgStr = "专业名称不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var standardName = standardList.Where(x => x.Name == en.StandardNameStr.Trim()).FirstOrDefault(); if (standardName == null) { errCount++; errorMsgStr = "专业名称不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业名称 } } //专业代码与专业名称查询专业ID(Value) if (string.IsNullOrEmpty(en.StandardCodeStr) || string.IsNullOrEmpty(en.StandardNameStr)) { errCount++; errorMsgStr = "专业代码或专业名称不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var standardID = standardList.Where(x => x.Code == en.StandardCodeStr.Trim() && x.Name == en.StandardNameStr.Trim()).SingleOrDefault(); if (standardID == null) { errCount++; errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业ID(Value) newFacultymajor.StandardID = standardID.Value; } } //培养层次 if (string.IsNullOrEmpty(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 { //培养层次 newFacultymajor.EducationID = education.Value; } } //学习形式 if (string.IsNullOrEmpty(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 { //学习形式 newFacultymajor.LearningformID = learningForm.Value; } } //学制 if (string.IsNullOrEmpty(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)) { errCount++; errorMsgStr = "学制格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //学制 newFacultymajor.LearnSystem = Convert.ToDecimal(en.LearnSystemStr); } } //专业科类 if (string.IsNullOrEmpty(en.ScienceclassStr)) { //不考虑 } else { var scienceclass = scienceclassList.Where(x => x.Name == en.ScienceclassStr.Trim()).SingleOrDefault(); if (scienceclass == null) { errCount++; errorMsgStr = "专业科类不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //专业科类 newFacultymajor.ScienceclassID = scienceclass.Value; } } //学习方式 if (string.IsNullOrEmpty(en.LearningstyleStr)) { //不考虑 } else { var learningstyle = learningstyleList.Where(x => x.Name == en.LearningstyleStr.Trim()).SingleOrDefault(); if (learningstyle == null) { errCount++; errorMsgStr = "学习方式不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //学习方式 newFacultymajor.LearningstyleID = learningstyle.Value; } } //授予学位 if (string.IsNullOrEmpty(en.LearnPositionStr)) { //不考虑 } else { var learnPosition = learnPositionList.Where(x => x.Name == en.LearnPositionStr.Trim()).SingleOrDefault(); if (learnPosition == null) { errCount++; errorMsgStr = "授予学位不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //授予学位 newFacultymajor.LearnPositionID = learnPosition.Value; } } //师范标识 if (string.IsNullOrEmpty(en.TeacherIdentification)) { //不考虑 } else { newFacultymajor.TeacherIdentification = en.TeacherIdentification; } //设置时间 if (string.IsNullOrEmpty(en.SetTimeStr)) { //不考虑 } else { //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28 if (!DateTime.TryParse(en.SetTimeStr, out result)) { errCount++; errorMsgStr = "创建年月格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //设置时间 newFacultymajor.SetTime = Convert.ToDateTime(en.SetTimeStr); } } //备注 if (string.IsNullOrEmpty(en.Remark)) { //不考虑 } else { newFacultymajor.Remark = en.Remark; } ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉) //for (int j = i + 1; j < enlist.Count; j++) //{ // NewFacultymajorView enA = enlist[j]; // //根据Excel表中的业务主键进行去重(院系所ID、院系专业编号、专业ID(Value)、培养层次、学习形式、学制唯一) // if (en.No == enA.No && en.Name == enA.Name) // { // //用于标识Excel表中的重复记录(由于是批量进行插入数据表) // } //} //数据表重复性验证(院系所ID、院系专业编号、专业ID(Value)、培养层次、学习形式、学制唯一) var facultymajorVerify = newFacultymajorList.Where(x => x.CollegeID == newFacultymajor.CollegeID && x.Code == newFacultymajor.Code && x.StandardID == newFacultymajor.StandardID && x.EducationID == newFacultymajor.EducationID && x.LearningformID == newFacultymajor.LearningformID && x.LearnSystem == newFacultymajor.LearnSystem).SingleOrDefault(); if (facultymajorVerify == null) { //新增 if (!newFacultymajorInList.Any(x => x.CollegeID == newFacultymajor.CollegeID && x.Code == newFacultymajor.Code && x.StandardID == newFacultymajor.StandardID && x.EducationID == newFacultymajor.EducationID && x.LearningformID == newFacultymajor.LearningformID && x.LearnSystem == newFacultymajor.LearnSystem)) { newFacultymajor.FacultymajorID = Guid.NewGuid(); SetNewStatus(newFacultymajor); newFacultymajorInList.Add(newFacultymajor); inCount++; } else { //Excel表重复性验证 //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑) inCount++; } } else { //更新(Excel有重复时,以最后一条记录的更新为准) facultymajorVerify.Abbreviation = newFacultymajor.Abbreviation; facultymajorVerify.EnglishName = newFacultymajor.EnglishName; facultymajorVerify.ScienceclassID = newFacultymajor.ScienceclassID; facultymajorVerify.LearningstyleID = newFacultymajor.LearningstyleID; facultymajorVerify.LearnPositionID = newFacultymajor.LearnPositionID; facultymajorVerify.TeacherIdentification = newFacultymajor.TeacherIdentification; facultymajorVerify.SetTime = newFacultymajor.SetTime; facultymajorVerify.Remark = newFacultymajor.Remark; SetModifyStatus(facultymajorVerify); newFacultymajorUpList.Add(facultymajorVerify); upCount++; } } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.BulkInsert(newFacultymajorInList); //批量统一提交更新 if (newFacultymajorUpList != null && newFacultymajorUpList.Count() > 0) { UnitOfWork.BatchUpdate(newFacultymajorUpList); } ts.Complete(); } errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception) { throw; } } } }