using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Transactions; using Bowin.Common.Utility; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.CacheManage; using EMIS.ViewModel.StudentManage.StudentProfile; namespace EMIS.ExtensionLogic.ServiceLogic.StudentManage { public class StudentServices : EMIS.CommonLogic.StudentManage.StudentProfile.StudentServices { /// /// 编辑(新增、修改,业务主键:学号或考生号唯一) /// 注:学号总位数问题(临沧农校) /// /// /// public override void StudentEdit(StudentView studentView, string photoUrl) { try { //查询相关Web.config配置 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("预计毕业日(秋季、下学期入学日)未配置,请检查。"); } if (EMIS.Utility.Const.LOCAL_SETTING_ENTRANCESEMESTERID == null) { throw new Exception("入学学期(春季、上学期、秋季、下学期)未配置,请检查。"); } var studentNoTotal = EMIS.Utility.Const.LOCAL_SETTING_LOGINIDTOTAL; if (studentNoTotal == null) { throw new Exception("学号总位数未配置,请检查。"); } if (!string.IsNullOrEmpty(studentView.StudentNo)) { if (studentView.StudentNo.Trim().Length > Convert.ToInt32(studentNoTotal)) { throw new Exception("输入的学号总位数有误,学号总位数应小于等于" + studentNoTotal + "位。"); } } else { throw new Exception("学号不能为空,请输入学号。"); } var userVerify = StudentDAL.Value.UserRepository.GetList(x => x.UserID != studentView.UserID && x.LoginID == studentView.StudentNo.Trim()).SingleOrDefault(); if (userVerify == null) { var newStudentVerify = StudentDAL.Value.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.Assigned && x.ExamineeNum != studentView.ExamineeNum && x.StudentNo == studentView.StudentNo.Trim()).SingleOrDefault(); if (newStudentVerify != null) { throw new Exception("录取名单中已存在相同的学号(学号重复),请核查。"); } if (!string.IsNullOrEmpty(studentView.ExamineeNum)) { var examineeNumVerify = StudentDAL.Value.RecruitstudentsRepository.GetList(x => x.UserID != studentView.UserID && x.ExamineeNum == studentView.ExamineeNum.Trim()).SingleOrDefault(); if (examineeNumVerify != null) { throw new Exception("已存在相同的考生号(考生号重复),请核查。"); } } if (!string.IsNullOrEmpty(studentView.StudentCardNo)) { var studentCardNoVerify = StudentDAL.Value.StudentRepository.GetList(x => x.UserID != studentView.UserID && x.StudentCardNo == studentView.StudentCardNo.Trim()).SingleOrDefault(); if (studentCardNoVerify != null) { throw new Exception("已存在相同的学籍卡编号(学籍卡编号重复),请核查。"); } } if (!string.IsNullOrEmpty(studentView.GraduateCardNo)) { var graduateCardNoVerify = StudentDAL.Value.StudentRepository.GetList(x => x.UserID != studentView.UserID && x.GraduateCardNo == studentView.GraduateCardNo.Trim()).SingleOrDefault(); if (graduateCardNoVerify != null) { throw new Exception("已存在相同的毕结业证书编号(毕结业证书编号重复),请核查。"); } } if (!string.IsNullOrEmpty(studentView.ReplaceGraduateNo)) { var replaceGraduateNoVerify = StudentDAL.Value.StudentRepository.GetList(x => x.UserID != studentView.UserID && x.ReplaceGraduateNo == studentView.ReplaceGraduateNo.Trim()).SingleOrDefault(); if (replaceGraduateNoVerify != null) { throw new Exception("已存在相同的补证编号(补证编号重复),请核查。"); } } var passwordParameter = StudentDAL.Value.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.StudentInitPassword); var roleList = StudentDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student, (x => x.CF_StudentRole)).ToList(); List newUserInList = new List(); List newUserUpList = new List(); List newStudentInList = new List(); List newStudentUpList = new List(); List newStudentProfileInList = new List(); List newStudentProfileUpList = new List(); List newStudentContactInList = new List(); List newStudentContactUpList = new List(); List newStudentAccountInList = new List(); List newStudentAccountUpList = new List(); List newRecruitstudentsInList = new List(); List newRecruitstudentsUpList = new List(); if (studentView.UserID != Guid.Empty) { //修改 var student = StudentDAL.Value.StudentRepository.GetList(x => x.UserID == studentView.UserID, (x => x.CF_StudentProfile), (x => x.CF_StudentContact), (x => x.CF_StudentAccount), (x => x.CF_Recruitstudents), (x => x.Sys_User)).SingleOrDefault(); if (student == null) { throw new Exception("数据有误,请核查。"); } else { student.Sys_User.LoginID = studentView.StudentNo.Trim(); student.Sys_User.Name = studentView.Name.Trim(); this.SetModifyStatus(student.Sys_User); newUserUpList.Add(student.Sys_User); student.ClassmajorID = studentView.ClassmajorID; student.SexID = studentView.SexID; student.BirthDate = studentView.BirthDate; student.NationID = studentView.NationID; student.PoliticsID = studentView.PoliticsID; student.CertificatesType = studentView.CertificatesType; student.IDNumber = studentView.IDNumber; student.StudentType = studentView.StudentType; student.Sys_User.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == studentView.StudentType).ToList(); if (roleList != null && roleList.Count > 0) { roleList.ForEach(x => student.Sys_User.Sys_Role.Add(x)); } else { //对应角色为空时,默认为不分配用户角色 } student.InSchoolStatusID = studentView.InSchoolStatusID; student.StudentStatus = studentView.StudentStatus; student.StudentCardNo = studentView.StudentCardNo; if (!string.IsNullOrEmpty(photoUrl)) { student.PhotoUrl = photoUrl; } if (studentView.PlanningGraduateDate.HasValue) { student.PlanningGraduateDate = studentView.PlanningGraduateDate; } if (studentView.GraduateDate.HasValue) { student.GraduateDate = studentView.GraduateDate; } student.GraduateCardNo = studentView.GraduateCardNo; student.ReplaceGraduateNo = studentView.ReplaceGraduateNo; student.DegreeStatus = studentView.DegreeStatus; //if (!string.IsNullOrEmpty(studentView.GraduationPictureUrl)) //{ // student.GraduationPictureUrl = studentView.GraduationPictureUrl; //} student.Career = studentView.Career; //student.IsPhotoComparison = studentView.IsPhotoComparison; //student.IsProofread = studentView.IsProofread; student.Remark = studentView.Remark; this.SetModifyStatus(student); newStudentUpList.Add(student); if (student.CF_StudentProfile == null) { var studentProfile = new CF_StudentProfile(); studentProfile.UserID = student.UserID; studentProfile.UsedName = studentView.UsedName; studentProfile.LiteracyLevelID = studentView.LiteracyLevelID; studentProfile.CultureModelID = studentView.CultureModelID; studentProfile.IsDreamProject = studentView.IsDreamProject; studentProfile.Country = studentView.Country; studentProfile.Place = studentView.Place; studentProfile.BornPlace = studentView.BornPlace; studentProfile.HealthStateID = studentView.HealthStateID; studentProfile.BloodGroup = studentView.BloodGroup; studentProfile.Specialty = studentView.Specialty; studentProfile.Height = studentView.Height; studentProfile.Weight = studentView.Weight; studentProfile.DirectorName = studentView.DirectorName; this.SetNewStatus(studentProfile); newStudentProfileInList.Add(studentProfile); } else { student.CF_StudentProfile.UsedName = studentView.UsedName; student.CF_StudentProfile.LiteracyLevelID = studentView.LiteracyLevelID; student.CF_StudentProfile.CultureModelID = studentView.CultureModelID; student.CF_StudentProfile.IsDreamProject = studentView.IsDreamProject; student.CF_StudentProfile.Country = studentView.Country; student.CF_StudentProfile.Place = studentView.Place; student.CF_StudentProfile.BornPlace = studentView.BornPlace; student.CF_StudentProfile.HealthStateID = studentView.HealthStateID; student.CF_StudentProfile.BloodGroup = studentView.BloodGroup; student.CF_StudentProfile.Specialty = studentView.Specialty; student.CF_StudentProfile.Height = studentView.Height; student.CF_StudentProfile.Weight = studentView.Weight; student.CF_StudentProfile.DirectorName = studentView.DirectorName; this.SetModifyStatus(student.CF_StudentProfile); newStudentProfileUpList.Add(student.CF_StudentProfile); } if (student.CF_StudentContact == null) { var studentContact = new CF_StudentContact(); studentContact.UserID = student.UserID; studentContact.Email = studentView.Email; studentContact.Telephone = studentView.Email; studentContact.Mobile = studentView.Email; studentContact.ZIPCode = studentView.ZIPCode; studentContact.WeChatNum = studentView.WeChatNum; studentContact.QQ = studentView.QQ; studentContact.HomeAddress = studentView.HomeAddress; studentContact.WorkUnit = studentView.WorkUnit; studentContact.Address = studentView.Address; studentContact.Recipient = studentView.Recipient; studentContact.Dormitory = studentView.Dormitory; this.SetNewStatus(studentContact); newStudentContactInList.Add(studentContact); } else { student.CF_StudentContact.Email = studentView.Email; student.CF_StudentContact.Telephone = studentView.Telephone; student.CF_StudentContact.Mobile = studentView.Mobile; student.CF_StudentContact.ZIPCode = studentView.ZIPCode; student.CF_StudentContact.WeChatNum = studentView.WeChatNum; student.CF_StudentContact.QQ = studentView.QQ; student.CF_StudentContact.HomeAddress = studentView.HomeAddress; student.CF_StudentContact.WorkUnit = studentView.WorkUnit; student.CF_StudentContact.Address = studentView.Address; student.CF_StudentContact.Recipient = studentView.Recipient; student.CF_StudentContact.Dormitory = studentView.Dormitory; this.SetModifyStatus(student.CF_StudentContact); newStudentContactUpList.Add(student.CF_StudentContact); } if (student.CF_StudentAccount == null) { var studentAccount = new CF_StudentAccount(); studentAccount.UserID = student.UserID; studentAccount.BankName = studentView.BankName; studentAccount.CardNo = studentView.CardNo; this.SetNewStatus(studentAccount); newStudentAccountInList.Add(studentAccount); } else { student.CF_StudentAccount.BankName = studentView.BankName; student.CF_StudentAccount.CardNo = studentView.CardNo; this.SetModifyStatus(student.CF_StudentAccount); newStudentAccountUpList.Add(student.CF_StudentAccount); } if (student.CF_Recruitstudents == null) { var recruitstudents = new CF_Recruitstudents(); recruitstudents.UserID = student.UserID; recruitstudents.ExamineeNum = studentView.ExamineeNum; recruitstudents.AdmissionTicketNo = studentView.AdmissionTicketNo; recruitstudents.ExamineeType = studentView.ExamineeType; recruitstudents.EnteringSchoolYearID = studentView.StartSchoolyearID; recruitstudents.EntranceDate = studentView.EntranceDate; recruitstudents.Score = studentView.Score; recruitstudents.EntranceWayID = studentView.EntranceWayID; recruitstudents.FeaturesID = studentView.FeaturesID; recruitstudents.TerritorialID = studentView.TerritorialID; recruitstudents.Area = studentView.Area; //if (!string.IsNullOrEmpty(studentView.RecruitPictureUrl)) //{ // recruitstudents.RecruitPictureUrl = studentView.RecruitPictureUrl; //} this.SetNewStatus(recruitstudents); newRecruitstudentsInList.Add(recruitstudents); } else { student.CF_Recruitstudents.ExamineeNum = studentView.ExamineeNum; student.CF_Recruitstudents.AdmissionTicketNo = studentView.AdmissionTicketNo; student.CF_Recruitstudents.ExamineeType = studentView.ExamineeType; student.CF_Recruitstudents.EnteringSchoolYearID = studentView.StartSchoolyearID; student.CF_Recruitstudents.EntranceDate = studentView.EntranceDate; student.CF_Recruitstudents.Score = studentView.Score; student.CF_Recruitstudents.EntranceWayID = studentView.EntranceWayID; student.CF_Recruitstudents.FeaturesID = studentView.FeaturesID; student.CF_Recruitstudents.TerritorialID = studentView.TerritorialID; student.CF_Recruitstudents.Area = studentView.Area; //if (!string.IsNullOrEmpty(studentView.RecruitPictureUrl)) //{ // student.CF_Recruitstudents.RecruitPictureUrl = studentView.RecruitPictureUrl; //} this.SetModifyStatus(student.CF_Recruitstudents); newRecruitstudentsUpList.Add(student.CF_Recruitstudents); } } } else { //新增 var newUser = new Sys_User(); newUser.UserID = Guid.NewGuid(); newUser.LoginID = studentView.StudentNo.Trim(); newUser.Name = studentView.Name.Trim(); if (passwordParameter == null) { newUser.Password = ("A" + studentView.StudentNo.Trim()).MD5(); } else { if (passwordParameter.Value != null) { newUser.Password = passwordParameter.Value; } else { newUser.Password = ("A" + studentView.StudentNo.Trim()).MD5(); } } this.SetNewStatus(newUser, (int)SYS_STATUS.USABLE); newUserInList.Add(newUser); newUser.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == studentView.StudentType).ToList(); if (roleList != null && roleList.Count > 0) { roleList.ForEach(x => newUser.Sys_Role.Add(x)); } else { //对应角色为空时,默认为不分配用户角色 } var newStudent = new CF_Student(); newStudent.UserID = newUser.UserID; newStudent.ClassmajorID = studentView.ClassmajorID; newStudent.SexID = studentView.SexID; newStudent.BirthDate = studentView.BirthDate; newStudent.NationID = studentView.NationID; newStudent.PoliticsID = studentView.PoliticsID; newStudent.CertificatesType = studentView.CertificatesType; newStudent.IDNumber = studentView.IDNumber; newStudent.StudentType = studentView.StudentType; newStudent.InSchoolStatusID = studentView.InSchoolStatusID; newStudent.StudentStatus = studentView.StudentStatus; newStudent.StudentCardNo = studentView.StudentCardNo; if (!string.IsNullOrEmpty(photoUrl)) { newStudent.PhotoUrl = photoUrl; } newStudent.PlanningGraduateDate = this.GetClassmajorPlanningGraduateDate(studentView.ClassmajorID); newStudent.GraduateDate = this.GetClassmajorGraduateDate(studentView.ClassmajorID); newStudent.GraduateCardNo = studentView.GraduateCardNo; newStudent.ReplaceGraduateNo = studentView.ReplaceGraduateNo; newStudent.DegreeStatus = studentView.DegreeStatus; //if (!string.IsNullOrEmpty(studentView.GraduationPictureUrl)) //{ // newStudent.GraduationPictureUrl = studentView.GraduationPictureUrl; //} newStudent.Career = studentView.Career; //newStudent.IsPhotoComparison = studentView.IsPhotoComparison; //newStudent.IsProofread = studentView.IsProofread; newStudent.Remark = studentView.Remark; this.SetNewStatus(newStudent); newStudentInList.Add(newStudent); var newStudentProfile = new CF_StudentProfile(); newStudentProfile.UserID = newStudent.UserID; newStudentProfile.UsedName = studentView.UsedName; newStudentProfile.LiteracyLevelID = studentView.LiteracyLevelID; newStudentProfile.CultureModelID = studentView.CultureModelID; newStudentProfile.IsDreamProject = studentView.IsDreamProject; newStudentProfile.Country = studentView.Country; newStudentProfile.Place = studentView.Place; newStudentProfile.BornPlace = studentView.BornPlace; newStudentProfile.HealthStateID = studentView.HealthStateID; newStudentProfile.BloodGroup = studentView.BloodGroup; newStudentProfile.Specialty = studentView.Specialty; newStudentProfile.Height = studentView.Height; newStudentProfile.Weight = studentView.Weight; newStudentProfile.DirectorName = studentView.DirectorName; this.SetNewStatus(newStudentProfile); newStudentProfileInList.Add(newStudentProfile); var newStudentContact = new CF_StudentContact(); newStudentContact.UserID = newStudent.UserID; newStudentContact.Email = studentView.Email; newStudentContact.Telephone = studentView.Telephone; newStudentContact.Mobile = studentView.Mobile; newStudentContact.ZIPCode = studentView.ZIPCode; newStudentContact.WeChatNum = studentView.WeChatNum; newStudentContact.QQ = studentView.QQ; newStudentContact.HomeAddress = studentView.HomeAddress; newStudentContact.WorkUnit = studentView.WorkUnit; newStudentContact.Address = studentView.Address; newStudentContact.Recipient = studentView.Recipient; newStudentContact.Dormitory = studentView.Dormitory; this.SetNewStatus(newStudentContact); newStudentContactInList.Add(newStudentContact); var newStudentAccount = new CF_StudentAccount(); newStudentAccount.UserID = newStudent.UserID; newStudentAccount.CardNo = studentView.CardNo; newStudentAccount.BankName = studentView.BankName; this.SetNewStatus(newStudentAccount); newStudentAccountInList.Add(newStudentAccount); var newRecruitstudents = new CF_Recruitstudents(); newRecruitstudents.UserID = newStudent.UserID; newRecruitstudents.ExamineeNum = studentView.ExamineeNum; newRecruitstudents.AdmissionTicketNo = studentView.AdmissionTicketNo; newRecruitstudents.ExamineeType = studentView.ExamineeType; newRecruitstudents.EnteringSchoolYearID = studentView.StartSchoolyearID; newRecruitstudents.EntranceDate = studentView.EntranceDate; newRecruitstudents.Score = studentView.Score; newRecruitstudents.EntranceWayID = studentView.EntranceWayID; newRecruitstudents.FeaturesID = studentView.FeaturesID; newRecruitstudents.TerritorialID = studentView.TerritorialID; newRecruitstudents.Area = studentView.Area; //if (!string.IsNullOrEmpty(studentView.RecruitPictureUrl)) //{ // newRecruitstudents.RecruitPictureUrl = studentView.RecruitPictureUrl; //} this.SetNewStatus(newRecruitstudents); newRecruitstudentsInList.Add(newRecruitstudents); } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.BulkInsert(newUserInList); UnitOfWork.BulkInsert(newUserInList, (x => x.Sys_Role)); UnitOfWork.BulkInsert(newStudentInList); UnitOfWork.BulkInsert(newStudentProfileInList); UnitOfWork.BulkInsert(newStudentContactInList); UnitOfWork.BulkInsert(newStudentAccountInList); UnitOfWork.BulkInsert(newRecruitstudentsInList); if (newUserUpList != null && newUserUpList.Count() > 0) { UnitOfWork.BatchUpdate(newUserUpList); UnitOfWork.Delete(newUserUpList, (x => x.Sys_Role)); UnitOfWork.BulkInsert(newUserUpList, (x => x.Sys_Role)); } if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } if (newStudentProfileUpList != null && newStudentProfileUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentProfileUpList); } if (newStudentContactUpList != null && newStudentContactUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentContactUpList); } if (newStudentAccountUpList != null && newStudentAccountUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentAccountUpList); } if (newRecruitstudentsUpList != null && newRecruitstudentsUpList.Count() > 0) { UnitOfWork.BatchUpdate(newRecruitstudentsUpList); } ts.Complete(); } } else { var studentVerify = StudentDAL.Value.StudentRepository.GetList(x => x.UserID != studentView.UserID, (x => x.Sys_User)).Where(x => x.Sys_User.LoginID == studentView.StudentNo.Trim()).SingleOrDefault(); if (studentVerify != null) { throw new Exception("已存在相同的学号(学号重复),请核查。"); } else { var staffVerify = StudentDAL.Value.StaffRepository.GetList(x => x.UserID != studentView.UserID, (x => x.Sys_User)).Where(x => x.Sys_User.LoginID == studentView.StudentNo.Trim()).SingleOrDefault(); if (staffVerify != null) { throw new Exception("教师信息中已存在相同的用户(用户名重复),请核查。"); } else { throw new Exception("用户信息中已存在相同的用户(用户名重复),请核查。"); } } } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 学生信息Excel导入 /// 注:学号总位数问题(临沧农校) /// /// /// /// /// /// /// public override void StudentImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { try { //查询相关Web.config配置 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("预计毕业日(秋季、下学期入学日)未配置,请检查。"); } if (EMIS.Utility.Const.LOCAL_SETTING_ENTRANCESEMESTERID == null) { throw new Exception("入学学期(春季、上学期、秋季、下学期)未配置,请检查。"); } var studentNoTotal = EMIS.Utility.Const.LOCAL_SETTING_LOGINIDTOTAL; if (studentNoTotal == null) { throw new Exception("学号总位数未配置,请检查。"); } 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 newUserInList = new List(); List newUserUpList = new List(); List newStudentInList = new List(); List newStudentUpList = new List(); List newStudentProfileInList = new List(); List newStudentProfileUpList = new List(); List newStudentContactInList = new List(); List newStudentContactUpList = new List(); List newStudentAccountInList = new List(); List newStudentAccountUpList = new List(); List newRecruitstudentsInList = new List(); List newRecruitstudentsUpList = new List(); var passwordParameter = StudentDAL.Value.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.StudentInitPassword); var roleList = StudentDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student, (x => x.CF_StudentRole)).ToList(); //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询) //性别 var sexList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex).ToList(); //民族 var nationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation).ToList(); //政治面貌 var politicsList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics).ToList(); //学生类别 var studentTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_STUDENTTYPE).ToList(); //证件类型 var certificatesTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType).ToList(); //在校状态 var inschoolStatusList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_InschoolStatus).ToList(); //学籍状态 var studentStatusList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_StudentStatus).ToList(); //文化程度 var literacyLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevel).ToList(); //培养方式 var cultureModelList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CULTUREMODEL).ToList(); //考生类别 var examineeTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EXAMINEETYPE).ToList(); //入学方式 var entranceWayList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EntranceWay).ToList(); //考生特征 var featuresList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Features).ToList(); //生源所属地 var territorialList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Province).ToList(); //健康状况 var healthStateList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState).ToList(); //血型 var bloodGroupList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BLOODGROUP).ToList(); //是否 var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList(); //有无 var generalExistList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralExist).ToList(); //班级编号 var classmajorNoList = enlist.Where(x => !string.IsNullOrEmpty(x.ClassmajorNo)).Select(x => x.ClassmajorNo.Trim()).ToList(); //对比后的newClassmajorList var newClassmajorList = StudentDAL.Value.ClassmajorRepository.GetList(x => classmajorNoList.Contains(x.No)).ToList(); //学籍卡编号 var studentCardNoList = enlist.Where(x => !string.IsNullOrEmpty(x.StudentCardNo)).Select(x => x.StudentCardNo.Trim()).ToList(); //对比后的newStudentCardNoList var newStudentCardNoList = StudentDAL.Value.StudentRepository.GetList(x => studentCardNoList.Contains(x.StudentCardNo)).ToList(); //毕结业证书编号 var graduateCardNoList = enlist.Where(x => !string.IsNullOrEmpty(x.GraduateCardNo)).Select(x => x.GraduateCardNo.Trim()).ToList(); //对比后的newGraduateCardNoList var newGraduateCardNoList = StudentDAL.Value.StudentRepository.GetList(x => graduateCardNoList.Contains(x.GraduateCardNo)).ToList(); //考生号 var examineeNumList = enlist.Where(x => !string.IsNullOrEmpty(x.ExamineeNum)).Select(x => x.ExamineeNum.Trim()).ToList(); //对比后的newExamineeNumList var newExamineeNumList = StudentDAL.Value.RecruitstudentsRepository.GetList(x => examineeNumList.Contains(x.ExamineeNum)).ToList(); //学号 var studentNoList = enlist.Where(x => !string.IsNullOrEmpty(x.StudentNo)).Select(x => x.StudentNo.Trim()).ToList(); //对比后的newNewStuList var newNewStuList = StudentDAL.Value.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.Assigned).Where(x => studentNoList.Contains(x.StudentNo)).ToList(); //对比后的newStudentList var newStudentList = StudentDAL.Value.StudentRepository.GetList(x => studentNoList.Contains(x.Sys_User.LoginID), (x => x.CF_StudentProfile), (x => x.CF_StudentContact), (x => x.CF_StudentAccount), (x => x.CF_Recruitstudents), (x => x.Sys_User)).ToList(); //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { StudentView en = enlist[i]; //Excel表数据视图 var newUser = new Sys_User(); var newStudent = new CF_Student(); var newStudentProfile = new CF_StudentProfile(); var newStudentContact = new CF_StudentContact(); var newStudentAccount = new CF_StudentAccount(); var newRecruitstudents = new CF_Recruitstudents(); //考生号 if (string.IsNullOrWhiteSpace(en.ExamineeNum)) { 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.ExamineeNum.Trim())) { errCount++; errorMsgStr = "考生号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.ExamineeNum = en.ExamineeNum.Trim(); } } //准考证号 if (string.IsNullOrWhiteSpace(en.AdmissionTicketNo)) { //暂不考虑 } else { reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母) if (!reg.IsMatch(en.AdmissionTicketNo.Trim())) { errCount++; errorMsgStr = "准考证号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.AdmissionTicketNo = en.AdmissionTicketNo.Trim(); } } //学号 if (string.IsNullOrWhiteSpace(en.StudentNo)) { 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.StudentNo.Trim())) { errCount++; errorMsgStr = "学号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { if (en.StudentNo.Trim().Length > Convert.ToInt32(studentNoTotal)) { errCount++; errorMsgStr = "学号总位数有误,学号总位数应小于等于" + studentNoTotal + "位。"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newUser.LoginID = en.StudentNo.Trim(); } } } //姓名 if (string.IsNullOrWhiteSpace(en.Name)) { errCount++; errorMsgStr = "姓名不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newUser.Name = en.Name.Trim(); } //曾用名 if (string.IsNullOrWhiteSpace(en.UsedName)) { //暂不考虑 } else { newStudentProfile.UsedName = en.UsedName.Trim(); } //性别 if (string.IsNullOrWhiteSpace(en.SexStr)) { errCount++; errorMsgStr = "性别不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var sex = sexList.Where(x => x.Name == en.SexStr.Trim()).SingleOrDefault(); if (sex == null) { errCount++; errorMsgStr = "性别不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.SexID = sex.Value; } } //出生日期 if (string.IsNullOrWhiteSpace(en.BirthDateStr)) { errCount++; errorMsgStr = "出生日期不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28 if (!DateTime.TryParse(en.BirthDateStr, out result)) { errCount++; errorMsgStr = "出生日期格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.BirthDate = Convert.ToDateTime(en.BirthDateStr); } } //民族 if (string.IsNullOrWhiteSpace(en.NationStr)) { errCount++; errorMsgStr = "民族不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var nation = nationList.Where(x => x.Name == en.NationStr.Trim()).SingleOrDefault(); if (nation == null) { errCount++; errorMsgStr = "民族不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.NationID = nation.Value; } } //政治面貌 if (string.IsNullOrWhiteSpace(en.PoliticsStr)) { errCount++; errorMsgStr = "政治面貌不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var politics = politicsList.Where(x => x.Name == en.PoliticsStr.Trim()).SingleOrDefault(); if (politics == null) { errCount++; errorMsgStr = "政治面貌不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.PoliticsID = politics.Value; } } //学生类别 if (string.IsNullOrWhiteSpace(en.StudentTypeStr)) { newStudent.StudentType = (int)CF_STUDENTTYPE.DefaultType; } else { var studentType = studentTypeList.Where(x => x.Name == en.StudentTypeStr.Trim()).SingleOrDefault(); if (studentType == null) { errCount++; errorMsgStr = "学生类别不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.StudentType = studentType.Value; } } //证件类型 if (string.IsNullOrWhiteSpace(en.CertificatesTypeStr)) { //默认为身份证 newStudent.CertificatesType = (int)CF_CertificatesType.IdCrad; } else { var certificatesType = certificatesTypeList.Where(x => x.Name == en.CertificatesTypeStr.Trim()).SingleOrDefault(); if (certificatesType == null) { errCount++; errorMsgStr = "证件类型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.CertificatesType = certificatesType.Value; } } //证件号码 if (string.IsNullOrWhiteSpace(en.IDNumber)) { 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.IDNumber.Trim())) //{ // errCount++; // errorMsgStr = "证件号码格式不正确,请检查(数字或英文字母)"; // en.ErrorMessage = errorMsgStr; // errList.Add(en); // errorMsg.AppendLine(errorMsgStr); // continue; //} //else //{ // newStudent.IDNumber = en.IDNumber.Trim(); //} newStudent.IDNumber = en.IDNumber.Trim(); } //在校状态 if (string.IsNullOrWhiteSpace(en.InSchoolStatusStr)) { errCount++; errorMsgStr = "在校状态不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var inSchoolStatus = inschoolStatusList.Where(x => x.Name == en.InSchoolStatusStr.Trim()).SingleOrDefault(); if (inSchoolStatus == null) { errCount++; errorMsgStr = "在校状态不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.InSchoolStatusID = inSchoolStatus.Value; } } //学籍状态 if (string.IsNullOrWhiteSpace(en.StudentStatusStr)) { errCount++; errorMsgStr = "学籍状态不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var studentStatus = studentStatusList.Where(x => x.Name == en.StudentStatusStr.Trim()).SingleOrDefault(); if (studentStatus == null) { errCount++; errorMsgStr = "学籍状态不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.StudentStatus = studentStatus.Value; } } //班级编号 if (string.IsNullOrWhiteSpace(en.ClassmajorNo)) { errCount++; errorMsgStr = "班级编号不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var classmajor = newClassmajorList.Where(x => x.No == en.ClassmajorNo.Trim()).SingleOrDefault(); if (classmajor == null) { errCount++; errorMsgStr = "班级编号不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //判断班级编号与班级名称(以班级编号为准) if (string.IsNullOrWhiteSpace(en.ClassmajorName)) { //暂不考虑 } else { //班级编号与班级名称不对应 if (classmajor.Name.Trim() != en.ClassmajorName.Trim()) { errCount++; errorMsgStr = "班级编号与班级名称不对应(以班级编号为准),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } newStudent.ClassmajorID = classmajor.ClassmajorID; newStudent.PlanningGraduateDate = this.GetClassmajorPlanningGraduateDate(classmajor.ClassmajorID); newStudent.GraduateDate = this.GetClassmajorGraduateDate(classmajor.ClassmajorID); } } //班级名称 if (string.IsNullOrWhiteSpace(en.ClassmajorName)) { //暂不考虑 } else { //暂不考虑 } //文化程度 if (string.IsNullOrWhiteSpace(en.LiteracyLevelStr)) { //暂不考虑 } else { var literacyLevel = literacyLevelList.Where(x => x.Name == en.LiteracyLevelStr.Trim()).SingleOrDefault(); if (literacyLevel == null) { errCount++; errorMsgStr = "文化程度不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.LiteracyLevelID = literacyLevel.Value; } } //培养方式 if (string.IsNullOrWhiteSpace(en.CultureModelStr)) { //暂不考虑 } else { var cultureModel = cultureModelList.Where(x => x.Name == en.CultureModelStr.Trim()).SingleOrDefault(); if (cultureModel == null) { errCount++; errorMsgStr = "培养方式不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.CultureModelID = cultureModel.Value; } } //考生类别 if (string.IsNullOrWhiteSpace(en.ExamineeTypeStr)) { //暂不考虑 } else { var examineeType = examineeTypeList.Where(x => x.Name == en.ExamineeTypeStr.Trim()).SingleOrDefault(); if (examineeType == null) { errCount++; errorMsgStr = "考生类别不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.ExamineeType = examineeType.Value; } } //入学日期 if (string.IsNullOrWhiteSpace(en.EntranceDateStr)) { //暂不考虑 } else { if (!DateTime.TryParse(en.EntranceDateStr, out result)) { errCount++; errorMsgStr = "入学日期格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.EntranceDate = Convert.ToDateTime(en.EntranceDateStr); } } //总分 if (string.IsNullOrWhiteSpace(en.ScoreStr)) { //暂不考虑 } else { reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //数字正则表达式 if (!reg.IsMatch(en.ScoreStr)) { errCount++; errorMsgStr = "总分格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.Score = Convert.ToDecimal(en.ScoreStr); } } //入学方式 if (string.IsNullOrWhiteSpace(en.EntranceWayStr)) { //暂不考虑 } else { var entranceWay = entranceWayList.Where(x => x.Name == en.EntranceWayStr.Trim()).SingleOrDefault(); if (entranceWay == null) { errCount++; errorMsgStr = "入学方式不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.EntranceWayID = entranceWay.Value; } } //考生特征 if (string.IsNullOrWhiteSpace(en.FeaturesStr)) { //暂不考虑 } else { var features = featuresList.Where(x => x.Name == en.FeaturesStr.Trim()).SingleOrDefault(); if (features == null) { errCount++; errorMsgStr = "考生特征不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.FeaturesID = features.Value; } } //生源所属地 if (string.IsNullOrWhiteSpace(en.TerritorialStr)) { //暂不考虑 } else { var territorial = territorialList.Where(x => x.Name == en.TerritorialStr.Trim()).SingleOrDefault(); if (territorial == null) { errCount++; errorMsgStr = "生源所属地不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newRecruitstudents.TerritorialID = territorial.Value; } } //来源地区 if (string.IsNullOrWhiteSpace(en.Area)) { //暂不考虑 } else { newRecruitstudents.Area = en.Area.Trim(); } //国籍 if (string.IsNullOrWhiteSpace(en.Country)) { //暂不考虑 } else { newStudentProfile.Country = en.Country.Trim(); } //籍贯 if (string.IsNullOrWhiteSpace(en.Place)) { //暂不考虑 } else { newStudentProfile.Place = en.Place.Trim(); } //出生地 if (string.IsNullOrWhiteSpace(en.BornPlace)) { //暂不考虑 } else { newStudentProfile.BornPlace = en.BornPlace.Trim(); } //电子邮箱 if (string.IsNullOrWhiteSpace(en.Email)) { //暂不考虑 } else { reg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); //正则表达式 if (!reg.IsMatch(en.Email.Trim())) { errCount++; errorMsgStr = "电子邮箱格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentContact.Email = en.Email.Trim(); } } //移动电话 if (string.IsNullOrWhiteSpace(en.Mobile)) { //暂不考虑 } else { newStudentContact.Mobile = en.Mobile.Trim(); } //家庭电话 if (string.IsNullOrWhiteSpace(en.Telephone)) { //暂不考虑 } else { newStudentContact.Telephone = en.Telephone.Trim(); } //邮政编码 if (string.IsNullOrWhiteSpace(en.ZIPCode)) { //暂不考虑 } else { reg = new Regex(@"[1-9]\d{5}(?!\d)"); //正则表达式 if (!reg.IsMatch(en.ZIPCode.Trim())) { errCount++; errorMsgStr = "邮政编码格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentContact.ZIPCode = en.ZIPCode.Trim(); } } //健康状况 if (string.IsNullOrWhiteSpace(en.HealthStateStr)) { newStudentProfile.HealthStateID = (int)CF_HealthState.Healthy; } else { var healthState = healthStateList.Where(x => x.Name == en.HealthStateStr.Trim()).SingleOrDefault(); if (healthState == null) { errCount++; errorMsgStr = "健康状况不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.HealthStateID = healthState.Value; } } //血型 if (string.IsNullOrWhiteSpace(en.BloodGroupStr)) { //暂不考虑 } else { var bloodGroup = bloodGroupList.Where(x => x.Name == en.BloodGroupStr.Trim()).SingleOrDefault(); if (bloodGroup == null) { errCount++; errorMsgStr = "血型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.BloodGroup = bloodGroup.Value; } } //特长 if (string.IsNullOrWhiteSpace(en.Specialty)) { //暂不考虑 } else { newStudentProfile.Specialty = en.Specialty.Trim(); } //身高(cm) if (string.IsNullOrWhiteSpace(en.Height)) { //暂不考虑 } else { reg = new Regex(@"^\d+(\.\d+)?$"); //正则表达式 if (!reg.IsMatch(en.Height.Trim())) { errCount++; errorMsgStr = "身高(cm)格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.Height = en.Height.Trim(); } } //体重(kg) if (string.IsNullOrWhiteSpace(en.Weight)) { //暂不考虑 } else { reg = new Regex(@"^\d+(\.\d+)?$"); //正则表达式 if (!reg.IsMatch(en.Weight.Trim())) { errCount++; errorMsgStr = "体重(cm)格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.Weight = en.Weight.Trim(); } } //微信号 if (string.IsNullOrWhiteSpace(en.WeChatNum)) { //暂不考虑 } else { newStudentContact.WeChatNum = en.WeChatNum.Trim(); } //QQ if (string.IsNullOrWhiteSpace(en.QQ)) { //暂不考虑 } else { reg = new Regex(@"[1-9][0-9]{4,}"); //正则表达式 if (!reg.IsMatch(en.QQ.Trim())) { errCount++; errorMsgStr = "QQ格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentContact.QQ = en.QQ.Trim(); } } //家庭住址 if (string.IsNullOrWhiteSpace(en.HomeAddress)) { //暂不考虑 } else { newStudentContact.HomeAddress = en.HomeAddress.Trim(); } //工作单位 if (string.IsNullOrWhiteSpace(en.WorkUnit)) { //暂不考虑 } else { newStudentContact.WorkUnit = en.WorkUnit.Trim(); } //通信地址 if (string.IsNullOrWhiteSpace(en.Address)) { //暂不考虑 } else { newStudentContact.Address = en.Address.Trim(); } //宿舍地址 if (string.IsNullOrWhiteSpace(en.Dormitory)) { //暂不考虑 } else { newStudentContact.Dormitory = en.Dormitory.Trim(); } //收件人 if (string.IsNullOrWhiteSpace(en.Recipient)) { //暂不考虑 } else { newStudentContact.Recipient = en.Recipient.Trim(); } //圆梦计划 if (string.IsNullOrWhiteSpace(en.IsDreamProjectStr)) { newStudentProfile.IsDreamProject = false; } else { var isDreamProject = generalPurposeList.Where(x => x.Name == en.IsDreamProjectStr.Trim()).SingleOrDefault(); if (isDreamProject == null) { errCount++; errorMsgStr = "是否圆梦计划不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentProfile.IsDreamProject = isDreamProject.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //导师姓名 if (string.IsNullOrWhiteSpace(en.DirectorName)) { //暂不考虑 } else { newStudentProfile.DirectorName = en.DirectorName.Trim(); } //开户银行 if (string.IsNullOrWhiteSpace(en.BankName)) { //暂不考虑 } else { newStudentAccount.BankName = en.BankName.Trim(); } //银行卡号 if (string.IsNullOrWhiteSpace(en.CardNo)) { //暂不考虑 } else { reg = new Regex(@"^[0-9]*$"); //正则表达式 if (!reg.IsMatch(en.CardNo.Trim())) { errCount++; errorMsgStr = "银行卡号格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudentAccount.CardNo = en.CardNo.Trim(); } } //学籍卡编号 if (string.IsNullOrWhiteSpace(en.StudentCardNo)) { //暂不考虑 } else { reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式 if (!reg.IsMatch(en.StudentCardNo.Trim())) { errCount++; errorMsgStr = "学籍卡编号格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.StudentCardNo = en.StudentCardNo.Trim(); } } //毕结业证书编号 if (string.IsNullOrWhiteSpace(en.GraduateCardNo)) { //暂不考虑 } else { reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式 if (!reg.IsMatch(en.GraduateCardNo.Trim())) { errCount++; errorMsgStr = "毕结业证书编号格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.GraduateCardNo = en.GraduateCardNo.Trim(); } } //学位有无 if (string.IsNullOrWhiteSpace(en.DegreeStatusStr)) { newStudent.DegreeStatus = false; } else { var degreeStatus = generalExistList.Where(x => x.Name == en.DegreeStatusStr.Trim()).SingleOrDefault(); if (degreeStatus == null) { errCount++; errorMsgStr = "学位有无不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStudent.DegreeStatus = degreeStatus.Value == (int)CF_GeneralExist.Have ? true : false; } } //在校经历 if (string.IsNullOrWhiteSpace(en.Career)) { //暂不考虑 } else { newStudent.Career = en.Career.Trim(); } //备注 if (string.IsNullOrWhiteSpace(en.Remark)) { //暂不考虑 } else { newStudent.Remark = en.Remark.Trim(); } ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉) //for (int j = i + 1; j < enlist.Count; j++) //{ // StudentView enA = enlist[j]; // //根据Excel表中的业务主键进行去重(学号或考生号唯一) // if (en.StudentNo == enA.StudentNo || en.ExamineeNum == enA.ExamineeNum) // { // //用于标识Excel表中的重复记录(由于是批量进行插入数据表) // } //} //数据表重复性验证(学号或考生号唯一) var userVerify = newStudentList.Select(x => x.Sys_User).Where(x => x.LoginID == newUser.LoginID).SingleOrDefault(); if (userVerify == null) { var newNewStuVerify = newNewStuList.Where(x => x.ExamineeNum != newRecruitstudents.ExamineeNum && x.StudentNo == newUser.LoginID).SingleOrDefault(); if (newNewStuVerify != null) { errCount++; errorMsgStr = "学号重复(录取名单中学号重复),请核查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } if (!newRecruitstudentsUpList.Any(x => x.ExamineeNum == newRecruitstudents.ExamineeNum)) { if (!newRecruitstudentsInList.Any(x => x.ExamineeNum == newRecruitstudents.ExamineeNum)) { var newExamineeNumVerify = newExamineeNumList.Where(x => x.ExamineeNum == newRecruitstudents.ExamineeNum).SingleOrDefault(); if (newExamineeNumVerify != null) { errCount++; errorMsgStr = "考生号重复,请核查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "考生号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "考生号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } if (!string.IsNullOrEmpty(newStudent.StudentCardNo)) { if (!newStudentUpList.Any(x => x.StudentCardNo == newStudent.StudentCardNo)) { if (!newStudentInList.Any(x => x.StudentCardNo == newStudent.StudentCardNo)) { var newStudentCardNoVerify = newStudentCardNoList.Where(x => x.StudentCardNo == newStudent.StudentCardNo).SingleOrDefault(); if (newStudentCardNoVerify != null) { errCount++; errorMsgStr = "学籍卡编号重复,请核查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "学籍卡编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "学籍卡编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } if (!string.IsNullOrEmpty(newStudent.GraduateCardNo)) { if (!newStudentUpList.Any(x => x.GraduateCardNo == newStudent.GraduateCardNo)) { if (!newStudentInList.Any(x => x.GraduateCardNo == newStudent.GraduateCardNo)) { var newGraduateCardNoVerify = newGraduateCardNoList.Where(x => x.GraduateCardNo == newStudent.GraduateCardNo).SingleOrDefault(); if (newGraduateCardNoVerify != null) { errCount++; errorMsgStr = "毕结业证书编号重复,请核查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "毕结业证书编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "毕结业证书编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } //新增 if (!newUserInList.Any(x => x.LoginID == newUser.LoginID)) { newUser.UserID = Guid.NewGuid(); if (passwordParameter == null) { newUser.Password = ("A" + newUser.LoginID.Trim()).MD5(); } else { if (passwordParameter.Value != null) { newUser.Password = passwordParameter.Value; } else { newUser.Password = ("A" + newUser.LoginID.Trim()).MD5(); } } this.SetNewStatus(newUser, (int)SYS_STATUS.USABLE); newUserInList.Add(newUser); newUser.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == newStudent.StudentType).ToList(); if (roleList != null && roleList.Count > 0) { roleList.ForEach(x => newUser.Sys_Role.Add(x)); } else { //对应角色为空时,默认为不分配用户角色 } newStudent.UserID = newUser.UserID; newStudent.IsPhotoComparison = false; newStudent.IsProofread = false; this.SetNewStatus(newStudent); newStudentInList.Add(newStudent); newStudentProfile.UserID = newStudent.UserID; this.SetNewStatus(newStudentProfile); newStudentProfileInList.Add(newStudentProfile); newStudentContact.UserID = newStudent.UserID; this.SetNewStatus(newStudentContact); newStudentContactInList.Add(newStudentContact); newStudentAccount.UserID = newStudent.UserID; this.SetNewStatus(newStudentAccount); newStudentAccountInList.Add(newStudentAccount); newRecruitstudents.UserID = newStudent.UserID; this.SetNewStatus(newRecruitstudents); newRecruitstudentsInList.Add(newRecruitstudents); inCount++; } else { //Excel表重复性验证 //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中) errCount++; errorMsgStr = "学号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { //更新(判断Excel有重复时,以最后一条记录更新为准) var studentVerify = newStudentList.Where(x => x.UserID == userVerify.UserID).SingleOrDefault(); if (studentVerify == null) { errCount++; errorMsgStr = "学号冲突(与其它帐号冲突),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var newNewStuVerify = newNewStuList.Where(x => x.ExamineeNum != newRecruitstudents.ExamineeNum && x.StudentNo == newUser.LoginID).SingleOrDefault(); if (newNewStuVerify != null) { errCount++; errorMsgStr = "学号重复(录取名单中学号重复),请核查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } if (!newRecruitstudentsInList.Any(x => x.ExamineeNum == newRecruitstudents.ExamineeNum)) { if (!newRecruitstudentsUpList.Any(x => x.ExamineeNum == newRecruitstudents.ExamineeNum)) { var newExamineeNumVerify = newExamineeNumList.Where(x => x.UserID != userVerify.UserID && x.ExamineeNum == newRecruitstudents.ExamineeNum).ToList(); if (newExamineeNumVerify != null && newExamineeNumVerify.Count() > 0) { errCount++; errorMsgStr = "考生号已存在(与其它学生冲突),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "考生号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "考生号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } if (!string.IsNullOrEmpty(newStudent.StudentCardNo)) { if (!newStudentInList.Any(x => x.StudentCardNo == newStudent.StudentCardNo)) { if (!newStudentUpList.Any(x => x.StudentCardNo == newStudent.StudentCardNo)) { var newStudentCardNoVerify = newStudentCardNoList.Where(x => x.UserID != userVerify.UserID && x.StudentCardNo == newStudent.StudentCardNo).ToList(); if (newStudentCardNoVerify != null && newStudentCardNoVerify.Count() > 0) { errCount++; errorMsgStr = "学籍卡编号已存在(与其它学生冲突),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "学籍卡编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "学籍卡编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } if (!string.IsNullOrEmpty(newStudent.GraduateCardNo)) { if (!newStudentInList.Any(x => x.GraduateCardNo == newStudent.GraduateCardNo)) { if (!newStudentUpList.Any(x => x.GraduateCardNo == newStudent.GraduateCardNo)) { var newGraduateCardNoVerify = newGraduateCardNoList.Where(x => x.UserID != userVerify.UserID && x.GraduateCardNo == newStudent.GraduateCardNo).ToList(); if (newGraduateCardNoVerify != null && newGraduateCardNoVerify.Count() > 0) { errCount++; errorMsgStr = "毕结业证书编号已存在(与其它学生冲突),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "毕结业证书编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { errCount++; errorMsgStr = "毕结业证书编号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } studentVerify.Sys_User.LoginID = newUser.LoginID.Trim(); studentVerify.Sys_User.Name = newUser.Name.Trim(); this.SetModifyStatus(studentVerify.Sys_User); newUserUpList.Add(studentVerify.Sys_User); studentVerify.SexID = newStudent.SexID; studentVerify.BirthDate = newStudent.BirthDate; studentVerify.NationID = newStudent.NationID; studentVerify.PoliticsID = newStudent.PoliticsID; studentVerify.CertificatesType = newStudent.CertificatesType; studentVerify.IDNumber = newStudent.IDNumber; studentVerify.StudentType = newStudent.StudentType; studentVerify.Sys_User.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == newStudent.StudentType).ToList(); if (roleList != null && roleList.Count > 0) { roleList.ForEach(x => studentVerify.Sys_User.Sys_Role.Add(x)); } else { //对应角色为空时,默认为不分配用户角色 } studentVerify.StudentCardNo = newStudent.StudentCardNo; studentVerify.GraduateCardNo = newStudent.GraduateCardNo; studentVerify.DegreeStatus = newStudent.DegreeStatus; studentVerify.Career = newStudent.Career; studentVerify.Remark = newStudent.Remark; this.SetModifyStatus(studentVerify); newStudentUpList.Add(studentVerify); if (studentVerify.CF_StudentProfile == null) { var studentProfile = new CF_StudentProfile(); studentProfile.UserID = studentVerify.UserID; studentProfile.UsedName = newStudentProfile.UsedName; studentProfile.LiteracyLevelID = newStudentProfile.LiteracyLevelID; studentProfile.CultureModelID = newStudentProfile.CultureModelID; studentProfile.IsDreamProject = newStudentProfile.IsDreamProject; studentProfile.Country = newStudentProfile.Country; studentProfile.Place = newStudentProfile.Place; studentProfile.BornPlace = newStudentProfile.BornPlace; studentProfile.HealthStateID = newStudentProfile.HealthStateID; studentProfile.BloodGroup = newStudentProfile.BloodGroup; studentProfile.Specialty = newStudentProfile.Specialty; studentProfile.Height = newStudentProfile.Height; studentProfile.Weight = newStudentProfile.Weight; studentProfile.DirectorName = newStudentProfile.DirectorName; this.SetNewStatus(studentProfile); newStudentProfileInList.Add(studentProfile); } else { studentVerify.CF_StudentProfile.UsedName = newStudentProfile.UsedName; studentVerify.CF_StudentProfile.LiteracyLevelID = newStudentProfile.LiteracyLevelID; studentVerify.CF_StudentProfile.CultureModelID = newStudentProfile.CultureModelID; studentVerify.CF_StudentProfile.IsDreamProject = newStudentProfile.IsDreamProject; studentVerify.CF_StudentProfile.Country = newStudentProfile.Country; studentVerify.CF_StudentProfile.Place = newStudentProfile.Place; studentVerify.CF_StudentProfile.BornPlace = newStudentProfile.BornPlace; studentVerify.CF_StudentProfile.HealthStateID = newStudentProfile.HealthStateID; studentVerify.CF_StudentProfile.BloodGroup = newStudentProfile.BloodGroup; studentVerify.CF_StudentProfile.Specialty = newStudentProfile.Specialty; studentVerify.CF_StudentProfile.Height = newStudentProfile.Height; studentVerify.CF_StudentProfile.Weight = newStudentProfile.Weight; studentVerify.CF_StudentProfile.DirectorName = newStudentProfile.DirectorName; this.SetModifyStatus(studentVerify.CF_StudentProfile); newStudentProfileUpList.Add(studentVerify.CF_StudentProfile); } if (studentVerify.CF_StudentContact == null) { var studentContact = new CF_StudentContact(); studentContact.UserID = studentVerify.UserID; studentContact.Email = newStudentContact.Email; studentContact.Telephone = newStudentContact.Email; studentContact.Mobile = newStudentContact.Email; studentContact.ZIPCode = newStudentContact.ZIPCode; studentContact.WeChatNum = newStudentContact.WeChatNum; studentContact.QQ = newStudentContact.QQ; studentContact.HomeAddress = newStudentContact.HomeAddress; studentContact.WorkUnit = newStudentContact.WorkUnit; studentContact.Address = newStudentContact.Address; studentContact.Recipient = newStudentContact.Recipient; studentContact.Dormitory = newStudentContact.Dormitory; this.SetNewStatus(studentContact); newStudentContactInList.Add(studentContact); } else { studentVerify.CF_StudentContact.Email = newStudentContact.Email; studentVerify.CF_StudentContact.Telephone = newStudentContact.Telephone; studentVerify.CF_StudentContact.Mobile = newStudentContact.Mobile; studentVerify.CF_StudentContact.ZIPCode = newStudentContact.ZIPCode; studentVerify.CF_StudentContact.WeChatNum = newStudentContact.WeChatNum; studentVerify.CF_StudentContact.QQ = newStudentContact.QQ; studentVerify.CF_StudentContact.HomeAddress = newStudentContact.HomeAddress; studentVerify.CF_StudentContact.WorkUnit = newStudentContact.WorkUnit; studentVerify.CF_StudentContact.Address = newStudentContact.Address; studentVerify.CF_StudentContact.Recipient = newStudentContact.Recipient; studentVerify.CF_StudentContact.Dormitory = newStudentContact.Dormitory; this.SetModifyStatus(studentVerify.CF_StudentContact); newStudentContactUpList.Add(studentVerify.CF_StudentContact); } if (studentVerify.CF_StudentAccount == null) { var studentAccount = new CF_StudentAccount(); studentAccount.UserID = studentVerify.UserID; studentAccount.BankName = newStudentAccount.BankName; studentAccount.CardNo = newStudentAccount.CardNo; this.SetNewStatus(studentAccount); newStudentAccountInList.Add(studentAccount); } else { studentVerify.CF_StudentAccount.BankName = newStudentAccount.BankName; studentVerify.CF_StudentAccount.CardNo = newStudentAccount.CardNo; this.SetModifyStatus(studentVerify.CF_StudentAccount); newStudentAccountUpList.Add(studentVerify.CF_StudentAccount); } if (studentVerify.CF_Recruitstudents == null) { var recruitstudents = new CF_Recruitstudents(); recruitstudents.UserID = studentVerify.UserID; recruitstudents.ExamineeNum = newRecruitstudents.ExamineeNum; recruitstudents.AdmissionTicketNo = newRecruitstudents.AdmissionTicketNo; recruitstudents.ExamineeType = newRecruitstudents.ExamineeType; recruitstudents.EntranceDate = newRecruitstudents.EntranceDate; recruitstudents.Score = newRecruitstudents.Score; recruitstudents.EntranceWayID = newRecruitstudents.EntranceWayID; recruitstudents.FeaturesID = newRecruitstudents.FeaturesID; recruitstudents.TerritorialID = newRecruitstudents.TerritorialID; recruitstudents.Area = newRecruitstudents.Area; this.SetNewStatus(recruitstudents); newRecruitstudentsInList.Add(recruitstudents); } else { studentVerify.CF_Recruitstudents.ExamineeNum = newRecruitstudents.ExamineeNum; studentVerify.CF_Recruitstudents.AdmissionTicketNo = newRecruitstudents.AdmissionTicketNo; studentVerify.CF_Recruitstudents.ExamineeType = newRecruitstudents.ExamineeType; studentVerify.CF_Recruitstudents.EntranceDate = newRecruitstudents.EntranceDate; studentVerify.CF_Recruitstudents.Score = newRecruitstudents.Score; studentVerify.CF_Recruitstudents.EntranceWayID = newRecruitstudents.EntranceWayID; studentVerify.CF_Recruitstudents.FeaturesID = newRecruitstudents.FeaturesID; studentVerify.CF_Recruitstudents.TerritorialID = newRecruitstudents.TerritorialID; studentVerify.CF_Recruitstudents.Area = newRecruitstudents.Area; this.SetModifyStatus(studentVerify.CF_Recruitstudents); newRecruitstudentsUpList.Add(studentVerify.CF_Recruitstudents); } upCount++; } } } TransactionOptions transactionOption = new TransactionOptions(); transactionOption.IsolationLevel = System.Transactions.IsolationLevel.Serializable; transactionOption.Timeout = new TimeSpan(0, 3, 0); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transactionOption)) { UnitOfWork.BulkInsert(newUserInList); UnitOfWork.BulkInsert(newUserInList, (x => x.Sys_Role)); UnitOfWork.BulkInsert(newStudentInList); UnitOfWork.BulkInsert(newStudentProfileInList); UnitOfWork.BulkInsert(newStudentContactInList); UnitOfWork.BulkInsert(newStudentAccountInList); UnitOfWork.BulkInsert(newRecruitstudentsInList); if (newUserUpList != null && newUserUpList.Count() > 0) { UnitOfWork.BatchUpdate(newUserUpList); } if (newStudentUpList != null && newStudentUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentUpList); } if (newStudentProfileUpList != null && newStudentProfileUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentProfileUpList); } if (newStudentContactUpList != null && newStudentContactUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentContactUpList); } if (newStudentAccountUpList != null && newStudentAccountUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStudentAccountUpList); } if (newRecruitstudentsUpList != null && newRecruitstudentsUpList.Count() > 0) { UnitOfWork.BatchUpdate(newRecruitstudentsUpList); } ts.Complete(); } errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception) { throw; } } } }