using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.Specialtyclass; using EMIS.ViewModel.Specialtyclass; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.Utility; using Bowin.Common.Linq; using EMIS.DataLogic.Common.CalendarManage; using System.Linq.Expressions; using EMIS.CommonLogic.Students; using EMIS.ViewModel.Students; using EMIS.CommonLogic.CalendarManage; using Bowin.Common.Utility; using System.Text.RegularExpressions; using EMIS.CommonLogic.TeacherManagement; namespace EMIS.CommonLogic.Specialtyclass { public class ClassmajorServices : BaseServices, IClassmajorServices { public ClassmajorDAL ClassmajorDAL { get; set; } public GrademajorDAL GrademajorDAL { get; set; } public Lazy SchoolYearServices { get; set; } public Lazy StaffServices { get; set; } /// /// 查询对应的班级信息View /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetClassmajorViewGrid(ConfiguretView configuretView, int? schoolAreaID, Guid? collegeID, int? schoolyearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? grademajorID, int? inSchoolStatus, int pageIndex, int pageSize) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (grademajorID.HasValue) { //年级专业 expClassmajor = expClassmajor.And(x => x.GrademajorID == grademajorID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetClassmajorViewQueryable(expClassmajor, expStudent); if (schoolAreaID.HasValue) { //校区 query = query.Where(x => x.SchoolAreaID == schoolAreaID); } if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 query = query.Where(x => x.SchoolyearID == schoolyearID); } 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 (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.GetQueryByAssistant(query, null, this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenByDescending(x => x.GrademajorCode.Length).ThenByDescending(x => x.GrademajorCode) .ThenByDescending(x => x.SchoolyearID).ThenBy(x => x.StandardID) .ThenBy(x => x.No.Length).ThenBy(x => x.No) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的班级信息View /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetInschoolClassmajorViewGrid(ConfiguretView configuretView, int? schoolAreaID, Guid? collegeID, int? schoolyearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? grademajorID, int pageIndex, int pageSize) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (grademajorID.HasValue) { //年级专业 expClassmajor = expClassmajor.And(x => x.GrademajorID == grademajorID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetClassmajorViewQueryable(expClassmajor, expStudent); if (schoolAreaID.HasValue) { //校区 query = query.Where(x => x.SchoolAreaID == schoolAreaID); } if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 query = query.Where(x => x.SchoolyearID == schoolyearID); } 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 (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.GetQueryByAssistant(query, null, query) .OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenByDescending(x => x.GrademajorCode.Length).ThenByDescending(x => x.GrademajorCode) .ThenByDescending(x => x.SchoolyearID).ThenBy(x => x.StandardID) .ThenBy(x => x.No.Length).ThenBy(x => x.No) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的班级信息List /// /// /// /// /// /// /// /// /// /// /// /// public IList GetClassmajorViewList(ConfiguretView configuretView, int? schoolAreaID, Guid? collegeID, int? schoolyearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? grademajorID, int? inSchoolStatus) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (grademajorID.HasValue) { //年级专业 expClassmajor = expClassmajor.And(x => x.GrademajorID == grademajorID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetClassmajorViewQueryable(expClassmajor, expStudent); if (schoolAreaID.HasValue) { //校区 query = query.Where(x => x.SchoolAreaID == schoolAreaID); } if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 query = query.Where(x => x.SchoolyearID == schoolyearID); } 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 (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.GetQueryByAssistant(query, null, this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenByDescending(x => x.GrademajorCode.Length).ThenByDescending(x => x.GrademajorCode) .ThenByDescending(x => x.SchoolyearID).ThenBy(x => x.StandardID) .ThenBy(x => x.No.Length).ThenBy(x => x.No) .ToList(); } /// /// 查询对应的班级信息View(带毕业学期) /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetClassmajorViewGridForGraduateReport(ConfiguretView configuretView, Guid? collegeID, int? standardID, int? schoolyearID, int? educationID, int? learningformID, string learnSystem, Guid? graduatingSemesterID, int pageIndex, int pageSize) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetClassmajorViewQueryable(expClassmajor); if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 query = query.Where(x => x.SchoolyearID == schoolyearID); } 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 (graduatingSemesterID.HasValue) { //毕业学期 query = query.Where(x => x.GraduatingSemesterID == graduatingSemesterID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByAssistant(query, null, this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenByDescending(x => x.GrademajorCode.Length).ThenByDescending(x => x.GrademajorCode) .ThenByDescending(x => x.SchoolyearID).ThenBy(x => x.StandardID) .ThenBy(x => x.No.Length).ThenBy(x => x.No) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的班级信息List(带毕业学期) /// /// /// /// /// /// /// /// /// /// public IList GetClassmajorViewGridForGraduateReport(ConfiguretView configuretView, Guid? collegeID, int? standardID, int? schoolyearID, int? educationID, int? learningformID, string learnSystem, Guid? graduatingSemesterID) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetClassmajorViewQueryable(expClassmajor); if (collegeID.HasValue) { //院系所 query = query.Where(x => x.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 query = query.Where(x => x.SchoolyearID == schoolyearID); } 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 (graduatingSemesterID.HasValue) { //毕业学期 query = query.Where(x => x.GraduatingSemesterID == graduatingSemesterID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByAssistant(query, null, this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenByDescending(x => x.GrademajorCode.Length).ThenByDescending(x => x.GrademajorCode) .ThenByDescending(x => x.SchoolyearID).ThenBy(x => x.StandardID) .ThenBy(x => x.No.Length).ThenBy(x => x.No) .ToList(); } /// /// 根据年级专业信息ID查询对应的班级信息List /// /// /// public List GetClassmajorList(Guid? grademajorID) { var query = ClassmajorDAL.ClassmajorRepository.GetList(x => x.GrademajorID == grademajorID); return query.OrderBy(x => x.No.Length).ThenBy(x => x.No) .ToList(); } /// /// 查询对应的班级信息List(无数据范围) /// /// /// /// /// public List GetClassmajorListWithoutRange(Guid? collegeID, int? schoolyearID, int? standardID) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { //院系所 expClassmajor = expClassmajor.And(x => x.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 expClassmajor = expClassmajor.And(x => x.CF_Grademajor.SchoolyearID == schoolyearID); } if (standardID.HasValue) { //专业ID(Value) expClassmajor = expClassmajor.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } var query = ClassmajorDAL.ClassmajorRepository.GetList(expClassmajor); return query.OrderBy(x => x.No.Length).ThenBy(x => x.No) .ToList(); } /// /// 查询对应的班级信息List(带数据范围) /// /// /// /// /// public List GetClassmajorList(Guid? collegeID, int? schoolyearID, int? standardID) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { //院系所 expClassmajor = expClassmajor.And(x => x.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (schoolyearID.HasValue) { //年级 expClassmajor = expClassmajor.And(x => x.CF_Grademajor.SchoolyearID == schoolyearID); } if (standardID.HasValue) { //专业ID(Value) expClassmajor = expClassmajor.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } var query = ClassmajorDAL.ClassmajorRepository.GetList(expClassmajor); return this.GetQueryByAssistant(query, null, this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.No.Length).ThenBy(x => x.No) .ToList(); } /// /// 查询对应的班级信息CF_Classmajor /// /// /// public CF_Classmajor GetClassmajorInfo(Guid? classmajorID) { try { var query = ClassmajorDAL.ClassmajorRepository.GetList(x => x.ClassmajorID == classmajorID); return query.SingleOrDefault(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的班级信息ClassmajorView /// /// /// public ClassmajorView GetClassmajorView(Guid? classmajorID) { try { var query = ClassmajorDAL.GetClassmajorViewQueryable(x => x.ClassmajorID == classmajorID); return query.SingleOrDefault(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改,业务主键:班级编号或班级名称唯一) /// /// public void ClassmajorEdit(ClassmajorView classmajorView) { try { //查询数据库进行验证 var classmajorVerification = ClassmajorDAL.ClassmajorRepository .GetList(x => x.ClassmajorID != classmajorView.ClassmajorID && (x.No == classmajorView.No || x.Name == classmajorView.Name)) .FirstOrDefault(); if (classmajorVerification == null) { //数据有误验证 if (classmajorView.ClassmajorID != Guid.Empty) { var classmajor = ClassmajorDAL.ClassmajorRepository .GetList(x => x.ClassmajorID == classmajorView.ClassmajorID, x => x.CF_Student) .SingleOrDefault(); if (classmajor == null) { throw new Exception("数据有误,请核查"); } else { //表示修改 classmajor.GrademajorID = classmajorView.GrademajorID; classmajor.No = classmajorView.No.Trim(); classmajor.Name = classmajorView.Name; classmajor.Abbreviation = classmajorView.Abbreviation; classmajor.EnglishName = classmajorView.EnglishName; classmajor.ClassNum = classmajorView.ClassNum; classmajor.UserID = classmajorView.UserID; classmajor.AssistantUserID = classmajorView.AssistantUserID; classmajor.Fixedclassroom = classmajorView.Fixedclassroom; classmajor.Remark = classmajorView.Remark; SetModifyStatus(classmajor); //计算对应学生的拟毕业时间 var grademajor = this.ClassmajorDAL.GrademajorRepository .GetSingle(x => x.GrademajorID == classmajor.GrademajorID); if (grademajor == null) { throw new Exception("年级专业有误,请重新选择。"); } else { if (grademajor.GraduatingSemesterID == null) { throw new Exception("年级专业信息中毕业学期有误,请核查。"); } } //这里应该用新的学年学期来算学生的拟毕业时间,原来的逻辑是用旧的…… var schoolyearView = SchoolYearServices.Value .GetSchoolYearView(grademajor.GraduatingSemesterID); if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringMonth == null) { throw new Exception("请先设置配置文件的预计毕业月份(春季入学)。"); } if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringDay == null) { throw new Exception("请先设置配置文件的预计毕业日期(春季入学)。"); } if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnMonth == null) { throw new Exception("请先设置配置文件的预计毕业月份(秋季入学)。"); } if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnDay == null) { throw new Exception("请先设置配置文件的预计毕业日期(秋季入学)。"); } List studentUpList = new List(); foreach (var item in classmajor.CF_Student) { item.PlanningGraduateDate = PlanningGraduateDateHelper .GetPlanningGraduateDate(schoolyearView.FirstWeek.Value); studentUpList.Add(item); } //事务提交 UnitOfWork.Commit(); //批量统一提交更新(预计毕业日期) if (studentUpList != null && studentUpList.Count() > 0) { UnitOfWork.BatchUpdate(studentUpList); } } } else { //表示新增 CF_Classmajor classmajor = new CF_Classmajor(); classmajor.ClassmajorID = Guid.NewGuid(); classmajor.GrademajorID = classmajorView.GrademajorID; classmajor.No = classmajorView.No.Trim(); classmajor.Name = classmajorView.Name; classmajor.Abbreviation = classmajorView.Abbreviation; classmajor.EnglishName = classmajorView.EnglishName; classmajor.ClassNum = classmajorView.ClassNum; classmajor.UserID = classmajorView.UserID; classmajor.AssistantUserID = classmajorView.AssistantUserID; classmajor.Fixedclassroom = classmajorView.Fixedclassroom; classmajor.Remark = classmajorView.Remark; SetNewStatus(classmajor); UnitOfWork.Add(classmajor); //事务提交 UnitOfWork.Commit(); } } else { throw new Exception("已存在相同的班级编号或班级名称,请核查"); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 批量新增 /// /// /// public string ClassmajorBatchAdd(ClassmajorView classmajorView) { try { List ClassmajorList = new List(); //获取源数据 var Grademajor = GrademajorDAL.GetGrademajorViwQueryable(x => x.SchoolyearID == classmajorView.BatchSchoolyearID); if (classmajorView.CollegeID != null) { Grademajor = Grademajor.Where(x => x.CollegeID == classmajorView.CollegeID); } if (classmajorView.StandardID != null && classmajorView.StandardID != -1) { Grademajor = Grademajor.Where(x => x.StandardID == classmajorView.StandardID); } //获取目标年级对应的年级专业 var GrademajorList = Grademajor.ToList(); //获取班级 var SourceClass = ClassmajorDAL.GetClassmajorViewQueryable(x => true); if (classmajorView.CollegeID != null) { SourceClass = SourceClass.Where(x => x.CollegeID == classmajorView.CollegeID); } if (classmajorView.StandardID != null && classmajorView.StandardID != -1) { SourceClass = SourceClass.Where(x => x.StandardID == classmajorView.StandardID); } if (classmajorView.SchoolyearID != null) { SourceClass = SourceClass.Where(x => x.SchoolyearID == classmajorView.SchoolyearID); } var SourceClassmajorList = SourceClass.ToList(); //获取目标年级中已存在数据 var BatchClass = ClassmajorDAL.GetClassmajorViewQueryable(x => true); if (classmajorView.CollegeID != null) { BatchClass = BatchClass.Where(x => x.CollegeID == classmajorView.CollegeID); } if (classmajorView.StandardID != null && classmajorView.StandardID != -1) { BatchClass = BatchClass.Where(x => x.StandardID == classmajorView.StandardID); } if (classmajorView.BatchSchoolyearID != null) { BatchClass = BatchClass.Where(x => x.SchoolyearID == classmajorView.BatchSchoolyearID); } var BatchClassmajorList = BatchClass.ToList(); //插入数据 foreach (var sc in SourceClassmajorList) { var Class = GrademajorList.Where(x => x.SchoolyearID == classmajorView.BatchSchoolyearID && x.StandardID == sc.StandardID && x.CollegeID == sc.CollegeID).FirstOrDefault(); if (Class != null) { CF_Classmajor classmajor = new CF_Classmajor(); string Schoolyear = sc.SchoolyearID.ToString(); string BatchSchoolyear = classmajorView.BatchSchoolyearID.Value.ToString(); //替换复制的年级专业代码 string No = sc.No.Trim().Replace(Schoolyear, BatchSchoolyear); //替换复制的年级专业名称 string Name = sc.Name.Trim().Replace(Schoolyear, BatchSchoolyear); //替换复制的年级专业简称 string Abbreviation = sc.Abbreviation.Trim().Replace(Schoolyear, BatchSchoolyear); classmajor.ClassmajorID = Guid.NewGuid(); classmajor.GrademajorID = Class.GrademajorID; classmajor.No = No; classmajor.Name = Name; classmajor.Abbreviation = Abbreviation; classmajor.EnglishName = classmajorView.EnglishName; classmajor.ClassNum = sc.ClassNum; classmajor.UserID = sc.UserID; classmajor.AssistantUserID = sc.AssistantUserID; classmajor.Fixedclassroom = sc.Fixedclassroom; classmajor.Remark = sc.Remark; SetNewStatus(classmajor); if (!classmajorView.IsOverwrite) { var batch = BatchClassmajorList.Where(x => x.No == No && x.SchoolyearID == classmajorView.BatchSchoolyearID && x.GrademajorID == Class.GrademajorID).FirstOrDefault(); if (batch == null) { ClassmajorList.Add(classmajor); } } else { var BatchClassmajorIDList = BatchClassmajorList.Select(x => x.ClassmajorID).ToList(); List ids = new List(); if (BatchClassmajorIDList.Count > 0) { foreach (var batch in BatchClassmajorIDList) { string BatchClassmajorID = batch.ToString(); Guid id = new Guid(BatchClassmajorID); ids.Add(id); } UnitOfWork.Remove(x => ids.Contains(x.ClassmajorID)); } ClassmajorList.Add(classmajor); } } } UnitOfWork.BulkInsert(ClassmajorList); UnitOfWork.Commit(); int DefeatedCount = SourceClassmajorList.Count() - ClassmajorList.Count(); int SuccessCount = SourceClassmajorList.Count() - DefeatedCount; int BatchClassmajorCount = BatchClassmajorList.Count(); var result = "一共处理了" + SourceClassmajorList.Count() + "条数据,其中成功" + SuccessCount + "条,失败0条"; if (DefeatedCount > 0 && BatchClassmajorCount == 0) { result = "一共处理了" + SourceClassmajorList.Count() + "条数据,其中成功" + SuccessCount + "条,失败" + DefeatedCount + "条,失败原因:没有对应的年级专业"; } if (DefeatedCount > 0 && BatchClassmajorCount > 0) { DefeatedCount = SourceClassmajorList.Count() - BatchClassmajorCount; SuccessCount = SourceClassmajorList.Count() - BatchClassmajorCount - DefeatedCount; result = "一共处理了" + SourceClassmajorList.Count() + "条数据,其中成功" + SuccessCount + " 条,有" + BatchClassmajorCount + "条数据已存在,失败" + DefeatedCount + "条,失败原因:没有对应的年级专业。"; } return result; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool ClassmajorDelete(IList classmajorIDList) { try { if (classmajorIDList.Count > 0) { UnitOfWork.Delete(x => classmajorIDList.Contains(x.ClassmajorID)); } return true; } catch (Exception) { throw; } } /// /// 查询班级信息对应的学生信息BaseStudentView /// /// /// /// /// /// /// public IGridResultSet GetBaseStudentViewGrid(ConfiguretView configuretView, Guid? classmajorID, int? inSchoolStatus, int pageIndex, int pageSize) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expClassmajor = expClassmajor.And(x => x.ClassmajorID == classmajorID); //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetBaseStudentViewQueryable(expClassmajor, expStudent); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LoginID) .ThenBy(x => x.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询班级信息对应的学生信息List /// /// /// /// /// public List GetBaseStudentViewList(ConfiguretView configuretView, Guid? classmajorID, int? inSchoolStatus) { //班级信息 Expression> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expClassmajor = expClassmajor.And(x => x.ClassmajorID == classmajorID); //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = ClassmajorDAL.GetBaseStudentViewQueryable(expClassmajor, expStudent); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LoginID) .ThenBy(x => x.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode) .ToList(); } /// /// 班级信息Excel导入 /// /// /// /// /// /// /// public void ClassmajorImport(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; //用于返回判断日期字段格式 inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 List newClassmajorInList = new List(); List newClassmajorUpList = new List(); //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询) //班级信息 var classmajorList = ClassmajorDAL.ClassmajorRepository.GetList(x => true).ToList(); //班级编号 var classmajorNoList = enlist.Where(x => !string.IsNullOrEmpty(x.No)).Select(x => x.No).ToList(); //班级名称 var classmajorNameList = enlist.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList(); //对比后的newClassmajorList var newClassmajorList = classmajorList .Where(x => classmajorNoList.Contains(x.No) || classmajorNameList.Contains(x.Name)).ToList(); //年级专业信息 var grademajorList = ClassmajorDAL.GrademajorRepository.GetList(x => true).ToList(); //年级专业编号 var grademajorCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.GrademajorCode)).Select(x => x.GrademajorCode).ToList(); //对比后的newGrademajorList var newGrademajorList = grademajorList.Where(x => grademajorCodeList.Contains(x.Code)).ToList(); //教职工信息 var staffViewList = StaffServices.Value.GetListStaffView(); //教职工姓名(暂时不考虑,教职工号不同,姓名相同的情况) var staffNameUList = enlist.Where(x => !string.IsNullOrEmpty(x.UserName)).Select(x => x.UserName).ToList(); var staffNameAList = enlist.Where(x => !string.IsNullOrEmpty(x.AssistantUserName)).Select(x => x.AssistantUserName).ToList(); //对比后的newStaffViewList var newStaffViewList = staffViewList .Where(x => staffNameUList.Contains(x.Name) || staffNameAList.Contains(x.Name)).ToList(); //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { ClassmajorView en = enlist[i]; //Excel表数据视图 CF_Classmajor newClassmajor = new CF_Classmajor(); //班级编号 if (string.IsNullOrEmpty(en.No)) { 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.No)) { errCount++; errorMsgStr = "班级编号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //班级编号 newClassmajor.No = en.No.Trim(); } } //班级名称 if (string.IsNullOrEmpty(en.Name)) { errCount++; errorMsgStr = "班级名称不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //班级名称 newClassmajor.Name = en.Name.Trim(); } //简称 if (string.IsNullOrEmpty(en.Abbreviation)) { //不考虑 } else { newClassmajor.Abbreviation = en.Abbreviation; } //英文名称 if (string.IsNullOrEmpty(en.EnglishName)) { //不考虑 } else { newClassmajor.EnglishName = en.EnglishName; } //年级专业编号 if (string.IsNullOrEmpty(en.GrademajorCode)) { 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.GrademajorCode)) { errCount++; errorMsgStr = "年级专业编号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var grademajor = newGrademajorList.Where(x => x.Code == en.GrademajorCode.Trim()) .SingleOrDefault(); if (grademajor == null) { errCount++; errorMsgStr = "年级专业编号不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //年级专业信息ID newClassmajor.GrademajorID = grademajor.GrademajorID; } } } //班序 if (string.IsNullOrEmpty(en.ClassNumStr)) { errCount++; errorMsgStr = "班序不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { reg = new Regex(@"^[1-9]\d*|0$"); //班序字段正则表达式() if (!reg.IsMatch(en.ClassNumStr)) { errCount++; errorMsgStr = "班序格式不正确,请检查(自然数)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //班序 newClassmajor.ClassNum = Convert.ToInt32(en.ClassNumStr); } } //班主任 if (string.IsNullOrEmpty(en.UserName)) { //不考虑 } else { var staffViewByU = newStaffViewList.Where(x => x.Name == en.UserName.Trim()) .FirstOrDefault(); if (staffViewByU == null) { ////暂不考虑 //errCount++; //errorMsgStr = "班主任不存在,请检查"; //en.ErrorMessage = errorMsgStr; //errList.Add(en); //errorMsg.AppendLine(errorMsgStr); //continue; } else { //班主任 newClassmajor.UserID = staffViewByU.UserID; } } //辅导员 if (string.IsNullOrEmpty(en.AssistantUserName)) { //不考虑 } else { var staffViewByA = newStaffViewList.Where(x => x.Name == en.AssistantUserName.Trim()) .FirstOrDefault(); if (staffViewByA == null) { ////暂不考虑 //errCount++; //errorMsgStr = "辅导员不存在,请检查"; //en.ErrorMessage = errorMsgStr; //errList.Add(en); //errorMsg.AppendLine(errorMsgStr); //continue; } else { //辅导员 newClassmajor.AssistantUserID = staffViewByA.UserID; } } //固定教室 if (string.IsNullOrEmpty(en.Fixedclassroom)) { //不考虑 } else { newClassmajor.Fixedclassroom = en.Fixedclassroom; } //备注 if (string.IsNullOrEmpty(en.Remark)) { //不考虑 } else { newClassmajor.Remark = en.Remark; } ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉) //for (int j = i + 1; j < enlist.Count; j++) //{ // NewClassmajorView enA = enlist[j]; // //根据Excel表中的业务主键进行去重(班级编号或班级名称唯一) // if (en.No == enA.No && en.Name == enA.Name) // { // //用于标识Excel表中的重复记录(由于是批量进行插入数据表) // } //} //数据表重复性验证(班级编号或班级名称唯一) var classmajorVerification = newClassmajorList .Where(x => x.No == newClassmajor.No || x.Name == newClassmajor.Name) .FirstOrDefault(); if (classmajorVerification == null) { //新增 if (!newClassmajorInList.Any(x => x.No == newClassmajor.No || x.Name == newClassmajor.Name)) { //CF_Classmajor表 newClassmajor.ClassmajorID = Guid.NewGuid(); SetNewStatus(newClassmajor); newClassmajorInList.Add(newClassmajor); inCount++; } else { //Excel表重复性验证 //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑) inCount++; } } else { //更新(Excel有重复时,以最后一条记录的更新为准) //注:暂时不更新对应的年级专业信息 //classmajorVerification.GrademajorID = newClassmajor.GrademajorID; classmajorVerification.Abbreviation = newClassmajor.Abbreviation; classmajorVerification.EnglishName = newClassmajor.EnglishName; classmajorVerification.ClassNum = newClassmajor.ClassNum; classmajorVerification.UserID = newClassmajor.UserID; classmajorVerification.AssistantUserID = newClassmajor.AssistantUserID; classmajorVerification.Fixedclassroom = newClassmajor.Fixedclassroom; classmajorVerification.Remark = newClassmajor.Remark; SetModifyStatus(classmajorVerification); newClassmajorUpList.Add(classmajorVerification); upCount++; } } UnitOfWork.BulkInsert(newClassmajorInList); //批量插入 //批量统一提交更新 if (newClassmajorUpList != null && newClassmajorUpList.Count() > 0) { UnitOfWork.BatchUpdate(newClassmajorUpList); } errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception ex) { //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题 throw new Exception(ex.Message); } } } }