using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.Repositories; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.SystemDAL; using EMIS.ViewModel.Students; using EMIS.ViewModel.SystemView; using EMIS.Utility; using EMIS.DataLogic.Common.AdministrativeOrgan; using EMIS.DataLogic.Common.Students; using EMIS.ViewModel; using System.Data; using EMIS.ViewModel.Cache; using System.IO; using System.Text.RegularExpressions; using Bowin.Common.Utility; using Bowin.Common.DataTime; using System.Globalization; using EMIS.CommonLogic.CalendarManage; using EMIS.Utility.FormValidate; using System.Web; using System.Transactions; using EMIS.DataLogic; using System.Data.OleDb; using EMIS.DataLogic.ExaminationApply; namespace EMIS.CommonLogic.Students { public class StudentsServices : BaseServices, IStudentsServices { public Lazy StudentsDAL { get; set; } public Lazy RoleDAL { get; set; } public Lazy InSchoolSettingRepository { get; set; } public Lazy StudentProfileRepository { get; set; } public Lazy StudentContactRepository { get; set; } public Lazy UserRepository { get; set; } public Lazy RecruitstudentsRepository { get; set; } public Lazy StudentAccountRepository { get; set; } public Lazy ClassmajorRepository { get; set; } public Lazy SchoolyearRepository { get; set; } public Lazy SchoolYearServices { get; set; } public ParameterDAL ParameterDAL { get; set; } public InSchoolStatusSettingDAL InSchoolStatusSettingDAL { get; set; } public DataRangeDAL DataRangeDAL { get; set; } public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; } public AnnouncementDAL AnnouncementDAL { get; set; } /// /// 查询列表 /// /// /// 校区ID /// 院系所ID /// 培养层次ID /// 学年 /// 招生专业ID /// 学习形式ID /// 班级ID /// 在校状态ID /// 是否有照片 /// 是否毕业学生 /// /// /// public Bowin.Common.Linq.Entity.IGridResultSet GetStudentUserViewList(ViewModel.ConfiguretView configuretView, int? campusID, Guid? collegeID, int? years, int? standardID, int? learningformID, Guid? classmajorID, int? IsGraduation, int? inSchoolStatusID, int? isPhotos, int? isDream, string planningGraduateDate, string LearnSystem,int? education,int? reportStatusID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> classexp = (x => true); Expression> gradeexp = (x => true); if (isPhotos.HasValue) { if (isPhotos.Value == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.PhotoUrl != null); } else { exp = exp.And(x => x.PhotoUrl == null); } } if (campusID.HasValue) gradeexp = gradeexp.And(x => x.SchoolAreaID == campusID); if (collegeID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID); if (years.HasValue) gradeexp = gradeexp.And(x => x.SchoolyearID == years); if (standardID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID); if (learningformID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID); if (classmajorID.HasValue) exp = exp.And(x => x.ClassmajorID == classmajorID); if (inSchoolStatusID.HasValue) exp = exp.And(x => x.InSchoolStatusID == inSchoolStatusID); if (IsGraduation.HasValue) { if (IsGraduation != (int)EMIS.ViewModel.CF_GeneralPurpose.IsYes) exp = exp.And(x => x.StudentStatus != (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation); else exp = exp.And(x => x.StudentStatus == (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation); } if(isDream.HasValue){ if(isDream.Value==(int)CF_GeneralPurpose.IsYes){ exp = exp.And(x => x.IsDreamProject != null); } else { exp=exp.And(x=>x.IsDreamProject==null); } } if (planningGraduateDate != "" && !String.IsNullOrEmpty(planningGraduateDate) && planningGraduateDate != "-1") { //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); //dtFormat.ShortDatePattern = "yyyyMMdd"; DateTime date = DateTime.ParseExact(planningGraduateDate, "yyyyMMdd", CultureInfo.CurrentCulture); //string datestr = date.ToString("u"); //dtFormat.ShortDatePattern = "yyyy-MM-dd"; //dtFormat.DateSeparator = "-"; //DateTime dates = Convert.ToDateTime(datestr, dtFormat); exp = exp.And(x => DateTime.Compare((DateTime)x.PlanningGraduateDate, date) == 0); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } var query = StudentsDAL.Value.GetStudentQueryable(exp, classexp, gradeexp); if (reportStatusID.HasValue) { query = query.Where(x => x.ReportStatusID == reportStatusID); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } public IList GetStudentViewList(ViewModel.ConfiguretView configuretView, int? campusID, Guid? collegeID, int? years, int? standardID, int? learningformID, Guid? classmajorID, int? IsGraduation, int? inSchoolStatusID, int? isPhotos, int? isDream, string planningGraduateDate, string LearnSystem, int? education, int? reportStatusID, List UserIDsIDList) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> classexp = (x => true); Expression> gradeexp = (x => true); if (UserIDsIDList != null) { exp = exp.And(x => UserIDsIDList.Contains(x.UserID)); } else { if (isPhotos.HasValue) { if (isPhotos.Value == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.PhotoUrl != null); } else { exp = exp.And(x => x.PhotoUrl == null); } } if (campusID.HasValue) gradeexp = gradeexp.And(x => x.SchoolAreaID == campusID); if (collegeID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID); if (years.HasValue) gradeexp = gradeexp.And(x => x.SchoolyearID == years); if (standardID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID); if (learningformID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID); if (classmajorID.HasValue) exp = exp.And(x => x.ClassmajorID == classmajorID); if (inSchoolStatusID.HasValue) exp = exp.And(x => x.InSchoolStatusID == inSchoolStatusID); if (IsGraduation.HasValue) { if (IsGraduation != (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation) exp = exp.And(x => x.StudentStatus != (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation); else exp = exp.And(x => x.StudentStatus == (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation); } if (isDream.HasValue) { if (isDream.Value == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.IsDreamProject != null); } else { exp = exp.And(x => x.IsDreamProject == null); } } if (planningGraduateDate != "" && !String.IsNullOrEmpty(planningGraduateDate) && planningGraduateDate != "-1") { //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); //dtFormat.ShortDatePattern = "yyyyMMdd"; DateTime date = DateTime.ParseExact(planningGraduateDate, "yyyyMMdd", CultureInfo.CurrentCulture); //string datestr = date.ToString("u"); //dtFormat.ShortDatePattern = "yyyy-MM-dd"; //dtFormat.DateSeparator = "-"; //DateTime dates = Convert.ToDateTime(datestr, dtFormat); exp = exp.And(x => DateTime.Compare((DateTime)x.PlanningGraduateDate, date) == 0); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } } var query = StudentsDAL.Value.GetStudentQueryable(exp, classexp, gradeexp); if (reportStatusID.HasValue) { query = query.Where(x => x.ReportStatusID == reportStatusID); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToList(); } /// /// 导出excel和dbf /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IList GetStudentExportList(ViewModel.ConfiguretView configuretView, int? campusID, Guid? collegeID, int? years, int? standardID, int? learningformID, Guid? classmajorID, int? IsGraduation, int? inSchoolStatusID, int? isPhotos, int? isDream, string planningGraduateDate, string LearnSystem, int? education, int? reportStatusID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> classexp = (x => true); Expression> gradeexp = (x => true); if (isPhotos.HasValue) { if (isPhotos.Value == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.PhotoUrl != null); } else { exp = exp.And(x => x.PhotoUrl == null); } } if (campusID.HasValue) gradeexp = gradeexp.And(x => x.SchoolAreaID == campusID); if (collegeID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID); if (years.HasValue) gradeexp = gradeexp.And(x => x.SchoolyearID == years); if (standardID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID); if (learningformID.HasValue) gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID); if (classmajorID.HasValue) exp = exp.And(x => x.ClassmajorID == classmajorID); if (inSchoolStatusID.HasValue) exp = exp.And(x => x.InSchoolStatusID == inSchoolStatusID); if (IsGraduation.HasValue) { if (IsGraduation != (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation) exp = exp.And(x => x.StudentStatus != (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation); else exp = exp.And(x => x.StudentStatus == (int)EMIS.ViewModel.CF_STUDENTSTATUS.Graduation); } if (isDream.HasValue) { if (isDream.Value == (int)CF_GeneralPurpose.IsYes) { exp = exp.And(x => x.IsDreamProject != null); } else { exp = exp.And(x => x.IsDreamProject == null); } } if (planningGraduateDate != "" && !String.IsNullOrEmpty(planningGraduateDate) && planningGraduateDate != "-1") { //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); //dtFormat.ShortDatePattern = "yyyyMMdd"; DateTime date = DateTime.ParseExact(planningGraduateDate, "yyyyMMdd", CultureInfo.CurrentCulture); //string datestr = date.ToString("u"); //dtFormat.ShortDatePattern = "yyyy-MM-dd"; //dtFormat.DateSeparator = "-"; //DateTime dates = Convert.ToDateTime(datestr, dtFormat); exp = exp.And(x => DateTime.Compare((DateTime)x.PlanningGraduateDate, date) == 0); } if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } var query = StudentsDAL.Value.GetStudentForExcel(exp, classexp, gradeexp); if (reportStatusID.HasValue) { query = query.Where(x => x.ReportStatusID == reportStatusID); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToList(); } /// /// 将数据表写入到DBF文件中 /// /// public void WriteToDbf(DataTable dt, List colList) { //连接字符串 string sConn = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + System.IO.Directory.GetCurrentDirectory() + "; " + "Extended Properties=dBASE IV;"; OleDbConnection conn = new OleDbConnection(sConn); conn.Open(); try { //如果存在同名文件则先删除 if (File.Exists(dt.TableName + ".dbf")) { File.Delete(dt.TableName + ".dbf"); } OleDbCommand cmd; //建立新表 StringBuilder sbCreate = new StringBuilder(); sbCreate.Append("CREATE TABLE " + dt.TableName + ".dbf ("); for (int i = 0; i < colList.Count; i++) { sbCreate.Append(colList[i]); sbCreate.Append(" char(25)"); if (i != colList.Count - 1) { sbCreate.Append(", "); } else { sbCreate.Append(')'); } } cmd = new OleDbCommand(sbCreate.ToString(), conn); cmd.ExecuteNonQuery(); //插入各行 StringBuilder sbInsert = new StringBuilder(); foreach (DataRow dr in dt.Rows) { sbInsert.Clear(); sbInsert.Append("INSERT INTO " + dt.TableName + ".dbf ("); for (int i = 0; i < colList.Count; i++) { sbInsert.Append(colList[i]); if (i != colList.Count - 1) { sbInsert.Append(", "); } } sbInsert.Append(") VALUES ("); for (int i = 0; i < dt.Columns.Count; i++) { sbInsert.Append("'" + dr[i].ToString() + "'"); if (i != dt.Columns.Count - 1) { sbInsert.Append(", "); } } sbInsert.Append(')'); cmd = new OleDbCommand(sbInsert.ToString(), conn); cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } conn.Close(); //var physicalPath = System.IO.Directory.GetCurrentDirectory() + "\\" + dt.TableName + ".dbf"; //FileInfo finfo = new FileInfo(physicalPath); //return finfo; } public IList GetStudentViewListByIDList(IList studentUserIDList) { return StudentsDAL.Value.GetStudentQueryable(x => studentUserIDList.Contains(x.UserID)).ToList(); } /// /// 获取可进行异动申请的学生。 /// /// public IGridResultSet GetAbleDifferentDynamicApplyStudentList(ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> filter = w => w.RecordStatus > (int)SYS_STATUS.UNUSABLE; //为何和学籍状态有关? //var studentStatus = new[] //{ // (int?)CF_STUDENTSTATUS.Whodid, // (int?)CF_STUDENTSTATUS.Thegraduation, // (int?)CF_STUDENTSTATUS.Graduation //}; //filter = filter.And(w => !studentStatus.Contains(w.StudentStatus)); //2016年10月13日14:53:40 //PS:异动申请,新增异动的时候,这个异动权限要放开。现在只有在校生能学籍异动,非在校生也能异动才行。【相当于权限放开,可以添加任何在校状态的学生】 // var inSchoolStatusIDs = InSchoolSettingRepository.Value.GetList(w => w.IsSelected == true).Select(s => s.InSchoolStatusID).ToArray(); //filter = filter.And(w => inSchoolStatusIDs.Contains(w.InSchoolStatusID)); var query = StudentsDAL.Value.GetStudentQueryable(filter); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } query = this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.LoginID); return query.ToGridResultSet(pageIndex, pageSize); } /// /// 查询用户ID /// /// /// public StudentsView GetStudentfileView(Guid? userId) { //查询条件 var query = StudentsDAL.Value.GetStudentQueryable(x => x.UserID == userId); //if (userId.HasValue) // query = query.Where(x => x.UserID == userId); return query.FirstOrDefault(); } /// /// 添加 /// /// public void Save(StudentsView studentfileView) { BaseStudentView tempView = StudentsDAL.Value.GetBaseStudentViewQueryable(x => x.Sys_User.UserID == studentfileView.UserID).FirstOrDefault(); var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.StudentInitPassword); var roleList = RoleDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student && x.CF_StudentRole.StudentType == studentfileView.StudentType,(x=>x.CF_StudentRole)).ToList(); 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 (studentfileView.GradeMajorID==null) { var GradeMajorID=ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == (Guid)studentfileView.ClassMajorID).Select(w => w.GrademajorID).FirstOrDefault(); studentfileView.GradeMajorID = (Guid)GradeMajorID; } //studentfileView.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate((Guid)studentfileView.GradeMajorID)); SaveOrUpdateInternal(studentfileView, tempView, parameter, roleList); this.UnitOfWork.Commit(); } public void StudentDelete(List userIDs) { try { var registrationList = ExaminationSubjectDAL.examinationRegistrationRepository.GetList(x => userIDs.Contains(x.UserID.Value)).ToList(); if (registrationList != null && registrationList.Count() > 0) { throw new Exception("要删除的学生中存在已报名的数据,无法删除"); } else { //List dbuserID = new List(); using (TransactionScope ts = new TransactionScope()) { var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => x.Sys_User.Any(y => userIDs.Contains(y.UserID)), (x => x.Sys_Role), (x => x.Sys_User)).ToList(); announcementList.ForEach(x => { x.Sys_User.RemoveWhere(y => userIDs.Contains(y.UserID)); }); UnitOfWork.Commit(); //UnitOfWork.BatchUpdate UnitOfWork.Remove(x => userIDs.Contains(x.UserID)); UnitOfWork.Remove(x => userIDs.Contains(x.UserID)); UnitOfWork.Remove(x => userIDs.Contains(x.UserID)); UnitOfWork.Remove(x => userIDs.Contains(x.UserID)); UnitOfWork.Remove(x => userIDs.Contains(x.UserID)); var userList = this.UserRepository.Value.GetList(x => userIDs.Contains(x.UserID), (x => x.Sys_Role)).ToList(); userList.ForEach(x => x.Sys_Role = new HashSet()); UnitOfWork.Remove(x => userIDs.Contains(x.UserID)); UnitOfWork.Commit(); ts.Complete(); } } } catch (Exception) { throw; } } /// /// 获取信息 /// /// 用户ID /// public Entities.Sys_User GetUser(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return UserRepository.Value.GetSingle(expression, (x => x.Sys_Role)); } /// /// 获取学生扩展表信息 /// /// 用户ID /// public Entities.CF_StudentProfile GetProfile(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return StudentProfileRepository.Value.GetSingle(expression); } /// /// 获取学生信息 /// /// 用户ID /// public Entities.CF_Student GetStudent(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return StudentsDAL.Value.StudentRepository.GetSingle(expression); } /// /// 高考招生表 /// /// 用户ID /// public Entities.CF_Recruitstudents GetRecruit(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return RecruitstudentsRepository.Value.GetSingle(expression); } /// /// 学生缴费表 /// /// 用户ID /// public Entities.CF_StudentAccount GetAccount(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return StudentAccountRepository.Value.GetSingle(expression); } /// /// 学生联系表 /// /// 用户ID /// public Entities.CF_StudentContact GetContact(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return StudentContactRepository.Value.GetSingle(expression); } /// /// 获取学生表列表信息 /// /// public Entities.CF_Student GetStudenter(Guid? userID) { //查询条件 Expression> expression = x => x.UserID == userID; return StudentsDAL.Value.StudentRepository.GetSingle(expression); } public CF_Student GetReplaceGraduateNo(string ReplaceGraduateNo,Guid? userID) { //查询条件 Expression> expression = x => x.ReplaceGraduateNo == ReplaceGraduateNo; expression=expression.And(x => x.UserID != userID); return StudentsDAL.Value.StudentRepository.GetSingle(expression); } public Entities.Sys_User GetUserByLoginID(Guid userid) { Expression> user = p => p.UserID == userid; return UserRepository.Value.GetSingle(user); } private void SaveOrUpdate(params StudentsView[] studentsViews) { var IDNumberList = studentsViews.Select(x => x.IDNumber.Trim().ToLower().Replace(")", ")").Replace("(", "(")).ToList(); var existsStudentViewList = StudentsDAL.Value.StudentRepository.GetList(x => IDNumberList.Contains(x.IDNumber.Trim().ToLower().Replace(")", ")").Replace("(", "(")) || IDNumberList.Contains(x.Sys_User.LoginID.Trim().ToLower().Replace(")", ")").Replace("(", "(")), (x => x.Sys_User.Sys_Role), (x => x.CF_StudentProfile), (x => x.CF_StudentContact), (x => x.CF_StudentAccount), (x => x.CF_Recruitstudents)).ToList(); var existsStudentList = existsStudentViewList.Select(x=>x.IDNumber.Trim().ToLower().Replace(")", ")").Replace("(", "(")).ToList(); var addStudentsViews = studentsViews.Where(x => !existsStudentList.Contains(x.IDNumber.Trim().ToLower().Replace(")", ")").Replace("(", "("))).ToList(); var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.StudentInitPassword); var roleList = RoleDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student, (x => x.CF_StudentRole)).ToList(); 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("请先设置配置文件的预计毕业日期(秋季入学)。"); SaveInternalForImport(addStudentsViews, null, parameter, roleList); UnitOfWork.Delete(existsStudentViewList.Select(x => x.Sys_User).ToList(), (x => x.Sys_Role)); foreach (var item in studentsViews) { var student = existsStudentViewList.FirstOrDefault(x => x.IDNumber == item.IDNumber); if (student != null) { UpdateInternalForImport(item, student, parameter, roleList); student.Sys_User.LoginID = item.IDNumber; } } UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.Sys_User).ToList()); UnitOfWork.BatchUpdate(existsStudentViewList); UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_StudentProfile).ToList()); UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_StudentContact).ToList()); UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_StudentAccount).ToList()); UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_Recruitstudents).ToList()); UnitOfWork.BulkInsert(existsStudentViewList.Select(x => x.Sys_User).ToList(), (x => x.Sys_Role)); //UnitOfWork.Commit(); } public DataTable Import(DataTable dataSource) { var errorSource = dataSource.Clone(); errorSource.Columns.Add("错误信息"); //添加错误并且排除必填字段为空的记录行 var errorList = AddErrorAndExceptEmptyDataRow(dataSource); //添加错误并且排除重复的记录行 errorList.AddRange(AddErrorAndExceptRepetitiveDataRow(dataSource)); //现改为可重复导入学生,并以学号关键字修改学生相关信息表,因此注释掉排除重复学号方法:邓智荣 //添加错误并且排除已存在的记录 //AddErrorAndExceptExistingDataRow(dataSource, errorSource); var views = MapToStudentsView(dataSource, errorList); errorList.ForEach(x => AddError(errorSource, x.Row, x.Error) ); if (errorSource.Rows.Count == 0) { SaveOrUpdate(views); } return errorSource; } public void GraduationPicImport(IList photoPaths) { var map = photoPaths .Select(s => new { IDNum = Path.GetFileNameWithoutExtension(s).Trim(), PhotoPath = s, }) .ToArray(); var idNums = map.Select(s => s.IDNum).Distinct().ToArray(); var studentList = StudentsDAL.Value.StudentRepository.GetList(w => idNums.Contains(w.IDNumber), (x => x.CF_StudentProfile)).ToList(); foreach (var idNum in idNums) { var student = studentList.FirstOrDefault(w => w.IDNumber == idNum); if (student == null) { throw new Exception("导入照片中存在无法匹对信息,请检查文件名是否正确。"); } } foreach (var m in map) { var student = studentList.FirstOrDefault(w => w.IDNumber == m.IDNum); if (student != null) { student.CF_StudentProfile.GraduationPictureUrl = m.PhotoPath; } } UnitOfWork.Commit(); } public virtual void PicImport(IList photoPaths) { var map = photoPaths .Select(s => new { IDNumber = Path.GetFileNameWithoutExtension(s).Trim(), PhotoPath = s, }) .ToArray(); var IDNumbers = map.Select(s => s.IDNumber).Distinct().ToArray(); var userIDList = StudentsDAL.Value.StudentRepository.Entities.Where(x => IDNumbers.Contains(x.IDNumber)).Select(x => x.UserID).ToList(); var users = UserRepository.Value.GetList(w => userIDList.Contains(w.UserID), i => i.CF_Student).ToList(); var idList = new List(); foreach (var idNumber in IDNumbers) { var user = users.FirstOrDefault(w => w.CF_Student.IDNumber.Equals(idNumber, StringComparison.OrdinalIgnoreCase)); if (user == null) { idList.Add(idNumber); } } if (idList.Count() > 0) { string idstr = ""; for (int i = 0; i < (idList.Count() > 5 ? 5 : idList.Count()); i++) { idstr += idList[i] + ","; } throw new Exception("导入照片中存在无法匹对信息,照片名字为:" + idstr.Remove(idstr.Length - 1) + "...,请检查系统是否存在对应学生。"); } foreach (var m in map) { var user = users.FirstOrDefault(w => w.CF_Student.IDNumber.Equals(m.IDNumber, StringComparison.InvariantCultureIgnoreCase)); if (user != null) { user.CF_Student.PhotoUrl = m.PhotoPath; } } UnitOfWork.Commit(); } private StudentsView[] MapToStudentsView(DataTable dataSource, List errorList) { var views = new List(); var classNames = dataSource.AsEnumerable().Select(s => s.Field("班级名称").Trim()).Distinct().ToArray(); var classes = ClassmajorRepository.Value.GetList(w => classNames.Contains(w.Name.Trim()), i => i.CF_Grademajor.CF_Schoolyear).ToArray(); var schoolYearCodes = dataSource.AsEnumerable().Select(s => s.Field("入学学年学期").Trim()).Distinct().ToArray(); var schoolYears = SchoolyearRepository.Value.GetList(w => schoolYearCodes.Contains(w.Code.Trim())).ToArray(); var dictionarySex = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex); var dictionaryCertificatesType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType); var dictionaryStudentStatus = IdNameExt.GetDictionaryItem(DictionaryItem.CF_STUDENTSTATUS); var dictionaryInschoolStatus = IdNameExt.GetDictionaryItem(DictionaryItem.CF_InschoolStatus); var dictionaryStudentType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_STUDENTTYPE); var dictionaryCultureModel = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CULTUREMODEL); var dictionaryExamineeType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EXAMINEETYPE); var dictionaryEntranceWay = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EntranceWay); var dictionaryFeatures = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Features); var dictionaryTerritorial = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Province); var dictionaryNation = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation); var dictionaryHealthy = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState); var dictionaryBloodGroup = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BLOODGROUP); var dictionaryPolitics = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics); var dictionaryIsDreamProject = IdNameExt.GetDictionaryItem(DictionaryItem.CF_YesOrNoStatus); DataTimeHelper dth = new DataTimeHelper(); string temp; string isDreamProject; foreach (DataRow dr in dataSource.Rows) { List errorMessageList = new List(); var view = new StudentsView(); view.LoginID = (dr.Field("学号") ?? "").Trim(); view.UserName = (dr.Field("姓名") ?? "").Trim(); view.Career = (dr.Field("在校经历") ?? "").Trim(); #region 性别 var sexField = dr.Field("性别"); if (!string.IsNullOrEmpty(sexField)) { var sex = dictionarySex.SingleOrDefault(w => w.Name.Trim() == sexField.Trim()); if (sex == null) { errorMessageList.Add("性别数据格式不正确"); //AddError(errorSource, dr, "性别数据格式不正确"); //continue; } else { view.Sex = sex.Value; } } #endregion #region 是否是圆梦计划 isDreamProject = (dr.Field("是否是圆梦计划")??"").Trim(); if (!string.IsNullOrEmpty(isDreamProject)) { var IsDreamProject = dictionaryIsDreamProject.SingleOrDefault(w => w.Name.Trim() == isDreamProject); if (IsDreamProject == null) { errorMessageList.Add("是否是圆梦计划数据格式不正确"); //AddError(errorSource, dr, "是否是圆梦计划数据格式不正确"); //continue; } else { view.IsDreamProject = IsDreamProject.Value == 0 ? false : true; } } #endregion #region 证件类型 var certificatesTypeField = dr.Field("证件类型"); if (!string.IsNullOrEmpty(certificatesTypeField)) { var certificatesType = dictionaryCertificatesType.SingleOrDefault(w => w.Name.Trim() == certificatesTypeField.Trim()); if (certificatesType == null) { errorMessageList.Add("证件类型数据格式不正确"); //AddError(errorSource, dr, "证件类型数据格式不正确"); //continue; } else { view.CertificatesType = certificatesType.Value; } } #endregion view.IDNumber = (dr.Field("证件号码") ?? "").Trim(); #region 班级名称 var classField = dr.Field("班级名称"); if (!string.IsNullOrEmpty(classField)) { var @class = classes.SingleOrDefault(w => w.Name.Trim() == classField.Trim()); if (@class == null) { errorMessageList.Add("班级名称不存在"); //AddError(errorSource, dr, "班级名称不存在"); //continue; } else { view.ClassMajorID = @class.ClassmajorID; //view.PlanningGraduateDate = PlanningGraduateDateHelper.GetPlanningGraduateDate(@class.CF_Grademajor.CF_Schoolyear.FirstWeek); //string PlanningGraduateDate = GetPlanningGraduate(@class.CF_Grademajor.GrademajorID); //view.PlanningGraduateDate = GetPlanningGraduate(@class.CF_Grademajor.GrademajorID);//设置预计毕业时间 } } #endregion #region 学籍状态 var studentStatusField = dr.Field("学籍状态"); if (!string.IsNullOrEmpty(studentStatusField)) { var studentStatus = dictionaryStudentStatus.SingleOrDefault(w => w.Name.Trim() == studentStatusField.Trim()); if (studentStatus == null) { errorMessageList.Add("学籍状态数据格式不正确"); //AddError(errorSource, dr, "学籍状态数据格式不正确"); //continue; } else { view.StudentStatus = studentStatus.Value; } } #endregion #region 在校状态 var inschoolStatusField = dr.Field("在校状态"); if (!string.IsNullOrEmpty(inschoolStatusField)) { var inschoolStatus = dictionaryInschoolStatus.SingleOrDefault(w => w.Name.Trim() == inschoolStatusField.Trim()); if (inschoolStatus == null) { errorMessageList.Add("在校状态数据格式不正确"); //AddError(errorSource, dr, "在校状态数据格式不正确"); //continue; } else { view.InSchoolStatusID = inschoolStatus.Value; } } #endregion #region 入学学年学期 var schoolYearField = dr.Field("入学学年学期"); if (!string.IsNullOrEmpty(schoolYearField)) { var schoolYear = schoolYears.SingleOrDefault(w => w.Code.Trim() == schoolYearField.Trim()); if (schoolYear == null) { errorMessageList.Add("入学学年学期不存在"); //AddError(errorSource, dr, "入学学年学期不存在"); //continue; } else { view.EnteringSchoolYearID = schoolYear.SchoolyearID; } } #endregion #region 学生类别 temp = (dr.Field("学生类别") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryStudentType.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("学生类别不存在"); //AddError(errorSource, dr, "学生类别不存在"); //continue; } else { view.StudentType = ent.Value; } } #endregion #region 培养方式 temp = (dr.Field("培养方式") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryCultureModel.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("培养方式不存在"); //AddError(errorSource, dr, "培养方式不存在"); //continue; } else { view.CultureModel = ent.Value; } } #endregion view.StudentCardNo = (dr.Field("学号") ?? "").Trim();//岭南报名系统学号存在学籍卡号字段 //(dr.Field("学籍卡编号") ?? "").Trim(); view.GraduateCardNo = (dr.Field("毕结业证书编号") ?? "").Trim(); view.ExamineeNum = (dr.Field("教育部考生号") ?? "").Trim(); #region 考生类别 temp = (dr.Field("考生类别") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryExamineeType.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("考生类别不存在"); //AddError(errorSource, dr, "考生类别不存在"); //continue; } else { view.ExamineeType = ent.Value; } } #endregion #region 入学日期 temp = (dr.Field("入学日期") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { DateTime dt; if (!DateTime.TryParseExact(temp, "yyyyMMdd", null, 0, out dt)) { if (!DateTime.TryParse(temp, out dt)) { errorMessageList.Add("入学日期数据格式不正确"); //AddError(errorSource, dr, "入学日期数据格式不正确"); //continue; } else { view.EntranceDate = dt; } } else { view.EntranceDate = dt; } } #endregion #region 入学方式 temp = (dr.Field("入学方式") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryEntranceWay.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("入学方式不存在"); //AddError(errorSource, dr, "入学方式不存在"); //continue; } else { view.EntranceWay = ent.Value; } } #endregion view.Placebirth = (dr.Field("出生地") ?? "").Trim(); #region 考生特征 temp = (dr.Field("考生特征") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryFeatures.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("考生特征不存在"); //AddError(errorSource, dr, "考生特征不存在"); //continue; } else { view.Features = ent.Value; } } #endregion #region 高考总分 temp = (dr.Field("高考总分") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { decimal d; if (!decimal.TryParse(temp, out d)) { errorMessageList.Add("高考总分数据格式不正确"); //AddError(errorSource, dr, "高考总分数据格式不正确"); //continue; } else { view.Score = d; } } #endregion #region 生源所属地 temp = (dr.Field("生源所属地") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryTerritorial.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("生源所属地不存在"); //AddError(errorSource, dr, "生源所属地不存在"); //continue; } else { view.Territorial = ent.Value; } } #endregion view.Area = (dr.Field("来源地区") ?? "").Trim(); view.UsedName = (dr.Field("曾用名") ?? "").Trim(); view.DirectorName = (dr.Field("导师姓名") ?? "").Trim(); #region 出生日期 temp = (dr.Field("出生日期") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { DateTime dt; if (!DateTime.TryParseExact(temp, "yyyyMMdd", null, 0, out dt)) { if (!DateTime.TryParse(temp, out dt)) { errorMessageList.Add("出生日期数据格式不正确"); //AddError(errorSource, dr, "出生日期数据格式不正确"); //continue; } else { view.BirthDate = dt; } } else { view.BirthDate = dt; } } #endregion view.Country = (dr.Field("国籍") ?? "").Trim(); // view.Politics = (dr.Field("政治面貌") ?? "").Trim(); #region 政治面貌 temp = (dr.Field("政治面貌") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var politics = dictionaryPolitics.SingleOrDefault(w => w.Name.Trim() == temp); if (politics == null) { errorMessageList.Add("政治面貌不存在"); //AddError(errorSource, dr, "政治面貌不存在"); //continue; } else { view.Politics = politics.Value; } } #endregion #region 民族 temp = (dr.Field("民族") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryNation.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("民族不存在"); //AddError(errorSource, dr, "民族不存在"); //continue; } else { view.Nation = ent.Value; } } #endregion view.Place = (dr.Field("籍贯") ?? "").Trim(); #region 健康状态 temp = (dr.Field("健康状态") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryHealthy.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("健康状态不存在"); //AddError(errorSource, dr, "健康状态不存在"); //continue; } else { view.Healthy = ent.Value; } } #endregion #region 血型 temp = (dr.Field("血型") ?? "").Trim(); if (!string.IsNullOrEmpty(temp)) { var ent = dictionaryBloodGroup.SingleOrDefault(w => w.Name.Trim() == temp); if (ent == null) { errorMessageList.Add("血型不存在"); //AddError(errorSource, dr, "血型不存在"); //continue; } else { view.BloodGroup = ent.Value; } } #endregion view.Specialty = (dr.Field("特长") ?? "").Trim(); view.Height = (dr.Field("身高") ?? "").Trim(); view.Weight = (dr.Field("体重") ?? "").Trim(); view.Remarks = (dr.Field("备注") ?? "").Trim(); view.CardNo = (dr.Field("银行卡号") ?? "").Trim(); view.BankName = (dr.Field("开户银行") ?? "").Trim(); view.Email = (dr.Field("电子邮件") ?? "").Trim(); view.QQ = (dr.Field("QQ") ?? "").Trim(); view.Mobile = (dr.Field("移动电话") ?? "").Trim(); view.Telephone = (dr.Field("固定电话") ?? "").Trim(); view.MicroMsgNo = (dr.Field("微信号") ?? "").Trim(); view.ZipCode = (dr.Field("邮编") ?? "").Trim(); view.Address = (dr.Field("通信地址") ?? "").Trim(); view.WorkUnit = (dr.Field("工作单位") ?? "").Trim(); view.HomeAddress = (dr.Field("家庭地址") ?? "").Trim(); view.Recipient = (dr.Field("收件人") ?? "").Trim(); view.Dormitory = (dr.Field("宿舍编号") ?? "").Trim(); if (errorMessageList.Count > 0) { if (errorList.Any(x => x.Row == dr)) { var errorRow = errorList.First(x => x.Row == dr); errorRow.Error += "," + string.Join(",", errorMessageList); } else { errorList.Add(new ImportErrorRowView { Row = dr, Error = string.Join(",", errorMessageList) }); } } else if (!errorList.Any(x => x.Row == dr)) { views.Add(view); } } return views.ToArray(); } private List AddErrorAndExceptEmptyDataRow(DataTable dataSource) { var dic = new Dictionary { {"学号","学号不能为空"}, {"姓名","姓名不能为空"}, {"性别","性别不能为空"}, {"证件类型","证件类型不能为空"}, {"证件号码","证件号码不能为空"}, {"班级名称","班级名称不能为空"}, {"学籍状态","学籍状态不能为空"}, {"在校状态","在校状态不能为空"}, {"入学学年学期","入学学年学期不能为空"}, }; var errorRowList = (from ds in dataSource.AsEnumerable() from pair in dic where string.IsNullOrEmpty(ds.Field(pair.Key)) group pair by ds into g select new ImportErrorRowView { Row = g.Key, Error = string.Join(",", g.Select(x => x.Value)) }) .ToList(); //foreach (var errorRow in errorRowList) //{ // AddError(errorSource, errorRow.Row, errorRow.Error); // dataSource.Rows.Remove(errorRow.Row); //} return errorRowList; //foreach (var pair in dic) //{ // var query = dataSource.AsEnumerable().Where(w => string.IsNullOrEmpty(w.Field(pair.Key))).ToArray(); // foreach (var dr in query) // { // AddError(errorSource, dr, pair.Value); // dataSource.Rows.Remove(dr); // } //} } private List AddErrorAndExceptExistingDataRow(DataTable dataSource) { var loginIDs = dataSource.AsEnumerable().Select(s => s.Field("学号")).ToArray(); var hasLoginIds = UserRepository.Value.GetList(w => loginIDs.Contains(w.LoginID)).Select(s => s.LoginID).ToArray(); var query = dataSource.AsEnumerable().Where(w => hasLoginIds.Contains(w.Field("学号"))) .Select(x => new ImportErrorRowView { Row = x, Error = "该学号已存在" }).ToList(); return query; //foreach (var dr in query) //{ // AddError(errorSource, dr, "该学号已存在"); // dataSource.Rows.Remove(dr); //} } private List AddErrorAndExceptRepetitiveDataRow(DataTable dataSource) { var query = dataSource.AsEnumerable() .GroupBy(key => key.Field("学号").ToLower().Replace(")", ")").Replace("(", "(")) .Where(w => w.Count() > 1 && !string.IsNullOrEmpty(w.Key)) .SelectMany(s => s) .Select(x => new ImportErrorRowView { Row = x, Error = "学号重复" }).ToList(); var idNumber = dataSource.AsEnumerable() .GroupBy(key => key.Field("证件号码").ToLower().Replace(")", ")").Replace("(", "(")) .Where(w => w.Count() > 1 && !string.IsNullOrEmpty(w.Key)) .SelectMany(s => s) .Select(x => new ImportErrorRowView { Row = x, Error = "证件号码重复" }).ToList(); //foreach (var dr in query) //{ // AddError(errorSource, dr, "学号重复"); // dataSource.Rows.Remove(dr); //} if (query.Count > 0) { return query; } if (idNumber.Count > 0) { return idNumber; } return query; } private void AddError(DataTable dtError, DataRow dataRow, string message) { var dr = dtError.NewRow(); if (dataRow != null) { dr.ItemArray = dataRow.ItemArray; } dr["错误信息"] = message; dtError.Rows.Add(dr); } private void SaveOrUpdateInternal(StudentsView studentfileView, BaseStudentView tempView, CF_Parameter parameter, IList roleList) { Sys_User user; CF_Student student; //获取学生信息 CF_StudentProfile studentProfile; CF_StudentContact studentContact; CF_StudentAccount studentAccount; CF_Recruitstudents recruitstudents; List StudentID = new List(); //以导入信息中的学号查找学生,当没有该学生时新增,否则修改学生信息 if (tempView == null) //studentfileView.UserID == Guid.Empty { if (!string.IsNullOrEmpty(studentfileView.IDNumber) && StudentsDAL.Value.StudentRepository.Entities.Any(x => x.IDNumber == studentfileView.IDNumber)) { throw new Exception("已存在相同证件号码的学生"); } if (!string.IsNullOrEmpty(studentfileView.StudentNo) && StudentsDAL.Value.StudentRepository.Entities.Any(x => x.StudentCardNo == studentfileView.StudentNo)) { throw new Exception("已存在相同学号的学生"); } user = new Sys_User(); user.UserID = Guid.NewGuid(); StudentID.Add(user.UserID); if (parameter == null) { //密码默认为6个8 user.Password = ("888888").MD5(); } else { if (parameter.Value != null) { user.Password = parameter.Value; } else { //密码默认为6个8 user.Password = ("888888").MD5(); } } user.CreateTime = DateTime.Now; UnitOfWork.Add(user); SetNewStatus(user); //添加学生表 student = new CF_Student(); student.UserID = user.UserID; student.CreateTime = DateTime.Now; UnitOfWork.Add(student); SetNewStatus(student); //学生扩展信息表 studentProfile = new CF_StudentProfile(); studentProfile.UserID = student.UserID; studentProfile.CreateTime = DateTime.Now; UnitOfWork.Add(studentProfile); SetNewStatus(studentProfile); studentContact = new CF_StudentContact(); studentContact.UserID = student.UserID; studentContact.CreateTime = DateTime.Now; UnitOfWork.Add(studentContact); SetNewStatus(studentContact); studentAccount = new CF_StudentAccount(); studentAccount.UserID = student.UserID; studentAccount.CreateTime = DateTime.Now; UnitOfWork.Add(studentAccount); SetNewStatus(studentAccount); recruitstudents = new CF_Recruitstudents(); recruitstudents.UserID = student.UserID; recruitstudents.CreateTime = DateTime.Now; UnitOfWork.Add(recruitstudents); SetNewStatus(recruitstudents); } else { user = GetUser(tempView.UserID); //studentfileView.UserID SetModifyStatus(user); student = GetStudent(tempView.UserID); //studentfileView.UserID SetModifyStatus(student); studentProfile = GetProfile(tempView.UserID); //studentfileView.UserID SetModifyStatus(studentProfile); studentContact = GetContact(tempView.UserID); //studentfileView.UserID SetModifyStatus(studentContact); studentAccount = GetAccount(tempView.UserID); //studentfileView.UserID SetModifyStatus(studentAccount); recruitstudents = GetRecruit(tempView.UserID); //studentfileView.UserID SetModifyStatus(recruitstudents); } user.LoginID = studentfileView.IDNumber;//岭南登录号用身份证号 if (!string.IsNullOrEmpty(studentfileView.UserName)) user.Name = studentfileView.UserName; if (studentfileView.ClassMajorID != null) student.ClassmajorID = studentfileView.ClassMajorID; if (studentfileView.Sex != null) student.Sex = (int)studentfileView.Sex; if (studentfileView.CertificatesType != null) student.CertificatesType = studentfileView.CertificatesType; if (!string.IsNullOrEmpty(studentfileView.IDNumber)) student.IDNumber = studentfileView.IDNumber; if (studentfileView.IsDreamProject) student.IsDreamProject = studentfileView.IsDreamProject; student.Career = studentfileView.Career; if (!string.IsNullOrEmpty(studentfileView.PhotoUrl)) { student.PhotoUrl = studentfileView.PhotoUrl; } student.PlanningGraduateDate = studentfileView.PlanningGraduateDate ?? studentfileView.PlanningGraduateDateStr; //if (student.PlanningGraduateDate == null) //{ // var GradeMajorID = ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == studentfileView.ClassMajorID).FirstOrDefault().GrademajorID; // student.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate(GradeMajorID.Value)); //} student.StudentCardNo = studentfileView.StudentNo; //毕、结业证书编号 student.GraduateCardNo = studentfileView.GraduateCardNo; student.CultureModel = studentfileView.CultureModel; if (studentfileView.StudentType != null) student.StudentType = studentfileView.StudentType; if (studentfileView.StudentStatus != null) student.StudentStatus = studentfileView.StudentStatus; if (studentfileView.InSchoolStatusID != null) student.InSchoolStatusID = studentfileView.InSchoolStatusID; if (studentfileView.ReplaceGraduateNo != null) student.ReplaceGraduateNo = studentfileView.ReplaceGraduateNo; user.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == student.StudentType).ToList(); roleList.ForEach(x => user.Sys_Role.Add(x)); if (!string.IsNullOrEmpty(studentfileView.GraduationPictureUrl)) { studentProfile.GraduationPictureUrl = studentfileView.GraduationPictureUrl; } studentProfile.UsedName = studentfileView.UsedName; studentProfile.DirectorName = studentfileView.DirectorName; studentProfile.BirthDate = studentfileView.BirthDate; studentProfile.Country = studentfileView.Country; if (studentfileView.Politics != null) studentProfile.Politics = studentfileView.Politics; studentProfile.Nation = studentfileView.Nation; studentProfile.Place = studentfileView.Place; studentProfile.Healthy = studentfileView.Healthy; studentProfile.BloodGroup = studentfileView.BloodGroup; //studentProfile.BornPlace = studentfileView.BornPlace; studentProfile.Specialty = studentfileView.Specialty; studentProfile.Height = studentfileView.Height; studentProfile.Weight = studentfileView.Weight; studentProfile.Remarks = studentfileView.Remarks; studentContact.Email = studentfileView.Email; studentContact.QQ = studentfileView.QQ; studentContact.Mobile = studentfileView.Mobile; studentContact.Telephone = studentfileView.Telephone; studentContact.MicroMsgNo = studentfileView.MicroMsgNo; studentContact.Zipcode = studentfileView.ZipCode; studentContact.Address = studentfileView.Address; studentContact.WorkUnit = studentfileView.WorkUnit; studentContact.HomeAddress = studentfileView.HomeAddress; studentContact.Recipient = studentfileView.Recipient; studentContact.Dormitory = studentfileView.Dormitory; studentAccount.CardNo = studentfileView.CardNo; studentAccount.BankName = studentfileView.BankName; recruitstudents.EntranceDate = studentfileView.EntranceDate; recruitstudents.EntranceWay = studentfileView.EntranceWay; recruitstudents.ExamineeNum = studentfileView.ExamineeNum; recruitstudents.PlaceBirth = studentfileView.Placebirth; recruitstudents.ExamineeType = studentfileView.ExamineeType; recruitstudents.Features = studentfileView.Features; recruitstudents.Score = studentfileView.Score; recruitstudents.Territorial = studentfileView.Territorial; recruitstudents.Area = studentfileView.Area; recruitstudents.EnteringSchoolYearID = studentfileView.EnteringSchoolYearID; UnitOfWork.Commit(); } /// /// 导入更新 /// /// /// /// /// private void UpdateInternalForImport(StudentsView studentfileView, CF_Student student, CF_Parameter parameter, IList roleList) { SetModifyStatus(student.Sys_User); SetModifyStatus(student); SetModifyStatus(student.CF_StudentProfile); SetModifyStatus(student.CF_StudentContact); SetModifyStatus(student.CF_StudentAccount); SetModifyStatus(student.CF_Recruitstudents); student.Sys_User.LoginID = studentfileView.IDNumber;//岭南LoginID为证件号码 if (!string.IsNullOrEmpty(studentfileView.UserName)) student.Sys_User.Name = studentfileView.UserName; if (studentfileView.ClassMajorID != null) student.ClassmajorID = student.ClassmajorID; if (studentfileView.Sex != null) student.Sex = (int)studentfileView.Sex; if (studentfileView.CertificatesType != null) student.CertificatesType = studentfileView.CertificatesType; if (!string.IsNullOrEmpty(studentfileView.IDNumber)) student.IDNumber = studentfileView.IDNumber; if (studentfileView.IsDreamProject) student.IsDreamProject = studentfileView.IsDreamProject; if (!string.IsNullOrEmpty(studentfileView.Career)) student.Career = studentfileView.Career; if (!string.IsNullOrEmpty(studentfileView.PhotoUrl)) { student.PhotoUrl = studentfileView.PhotoUrl; } student.PlanningGraduateDate = studentfileView.PlanningGraduateDate ?? studentfileView.PlanningGraduateDateStr; //if (student.PlanningGraduateDate == null) //{ // var GradeMajorID = ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == studentfileView.ClassMajorID).FirstOrDefault().GrademajorID; // student.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate(GradeMajorID.Value)); //} if (!string.IsNullOrEmpty(studentfileView.StudentCardNo)) student.StudentCardNo = studentfileView.StudentCardNo; //毕、结业证书编号 if (!string.IsNullOrEmpty(studentfileView.GraduateCardNo)) student.GraduateCardNo = studentfileView.GraduateCardNo; if (studentfileView.CultureModel != null) student.CultureModel = studentfileView.CultureModel; if (studentfileView.StudentType != null) student.StudentType = studentfileView.StudentType; if (studentfileView.StudentStatus != null) student.StudentStatus = studentfileView.StudentStatus; if (studentfileView.InSchoolStatusID != null) student.InSchoolStatusID = studentfileView.InSchoolStatusID; student.Sys_User.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == student.StudentType).ToList(); roleList.ForEach(x => student.Sys_User.Sys_Role.Add(x)); if (!string.IsNullOrEmpty(studentfileView.GraduationPictureUrl)) { student.CF_StudentProfile.GraduationPictureUrl = studentfileView.GraduationPictureUrl; } if (!string.IsNullOrEmpty(studentfileView.UsedName)) student.CF_StudentProfile.UsedName = studentfileView.UsedName; if (!string.IsNullOrEmpty(studentfileView.DirectorName)) student.CF_StudentProfile.DirectorName = studentfileView.DirectorName; if (studentfileView.BirthDate != null) student.CF_StudentProfile.BirthDate = studentfileView.BirthDate; if (!string.IsNullOrEmpty(studentfileView.Country)) student.CF_StudentProfile.Country = studentfileView.Country; if (studentfileView.Politics != null) student.CF_StudentProfile.Politics = studentfileView.Politics; if (studentfileView.Nation != null) student.CF_StudentProfile.Nation = studentfileView.Nation; if (!string.IsNullOrEmpty(studentfileView.Place)) student.CF_StudentProfile.Place = studentfileView.Place; if (studentfileView.Healthy != null) student.CF_StudentProfile.Healthy = studentfileView.Healthy; if (studentfileView.BloodGroup != null) student.CF_StudentProfile.BloodGroup = studentfileView.BloodGroup; //studentProfile.BornPlace = studentfileView.BornPlace; if (!string.IsNullOrEmpty(studentfileView.Specialty)) student.CF_StudentProfile.Specialty = studentfileView.Specialty; if (!string.IsNullOrEmpty(studentfileView.Height)) student.CF_StudentProfile.Height = studentfileView.Height; if (!string.IsNullOrEmpty(studentfileView.Weight)) student.CF_StudentProfile.Weight = studentfileView.Weight; if (!string.IsNullOrEmpty(studentfileView.Remarks)) student.CF_StudentProfile.Remarks = studentfileView.Remarks; if (!string.IsNullOrEmpty(studentfileView.Email)) student.CF_StudentContact.Email = studentfileView.Email; if (!string.IsNullOrEmpty(studentfileView.QQ)) student.CF_StudentContact.QQ = studentfileView.QQ; if (!string.IsNullOrEmpty(studentfileView.Mobile)) student.CF_StudentContact.Mobile = studentfileView.Mobile; if (!string.IsNullOrEmpty(studentfileView.Telephone)) student.CF_StudentContact.Telephone = studentfileView.Telephone; if (!string.IsNullOrEmpty(studentfileView.MicroMsgNo)) student.CF_StudentContact.MicroMsgNo = studentfileView.MicroMsgNo; if (!string.IsNullOrEmpty(studentfileView.ZipCode)) student.CF_StudentContact.Zipcode = studentfileView.ZipCode; if (!string.IsNullOrEmpty(studentfileView.Address)) student.CF_StudentContact.Address = studentfileView.Address; if (!string.IsNullOrEmpty(studentfileView.WorkUnit)) student.CF_StudentContact.WorkUnit = studentfileView.WorkUnit; if (!string.IsNullOrEmpty(studentfileView.HomeAddress)) student.CF_StudentContact.HomeAddress = studentfileView.HomeAddress; if (!string.IsNullOrEmpty(studentfileView.Recipient)) student.CF_StudentContact.Recipient = studentfileView.Recipient; if (!string.IsNullOrEmpty(studentfileView.Dormitory)) student.CF_StudentContact.Dormitory = studentfileView.Dormitory; if (!string.IsNullOrEmpty(studentfileView.CardNo)) student.CF_StudentAccount.CardNo = studentfileView.CardNo; if (!string.IsNullOrEmpty(studentfileView.BankName)) student.CF_StudentAccount.BankName = studentfileView.BankName; if (studentfileView.EntranceDate != null) student.CF_Recruitstudents.EntranceDate = studentfileView.EntranceDate; if (studentfileView.EntranceWay != null) student.CF_Recruitstudents.EntranceWay = studentfileView.EntranceWay; if (!string.IsNullOrEmpty(studentfileView.ExamineeNum)) student.CF_Recruitstudents.ExamineeNum = studentfileView.ExamineeNum; if (!string.IsNullOrEmpty(studentfileView.Placebirth)) student.CF_Recruitstudents.PlaceBirth = studentfileView.Placebirth; if (studentfileView.ExamineeType != null) student.CF_Recruitstudents.ExamineeType = studentfileView.ExamineeType; if (studentfileView.Features != null) student.CF_Recruitstudents.Features = studentfileView.Features; if (studentfileView.Score != null) student.CF_Recruitstudents.Score = studentfileView.Score; if (studentfileView.Territorial != null) student.CF_Recruitstudents.Territorial = studentfileView.Territorial; if (!string.IsNullOrEmpty(studentfileView.Area)) student.CF_Recruitstudents.Area = studentfileView.Area; if (studentfileView.EnteringSchoolYearID != null) student.CF_Recruitstudents.EnteringSchoolYearID = studentfileView.EnteringSchoolYearID; } /// /// 导入新增 /// /// /// /// /// private void SaveInternalForImport(List studentfileView, BaseStudentView tempView, CF_Parameter parameter, IList roleList) { List StudentID=new List(); List userList=new List(); List studentList=new List(); //获取学生信息 List studentProfileList = new List(); List studentContactList= new List(); List studentAccountList =new List(); List recruitstudentsList = new List(); for (int i = 0; i < studentfileView.Count(); i++) { var pwd=""; if (parameter == null) { pwd = ("888888").MD5(); } else { if (parameter.Value != null) { pwd = parameter.Value; } else { pwd = ("888888").MD5(); } } Sys_User user=new Sys_User(); int? tpye=null; user.LoginID=studentfileView[i].IDNumber;//岭南LoginID为证件号码 if (!string.IsNullOrEmpty(studentfileView[i].UserName)) user.Name = studentfileView[i].UserName; if (studentfileView[i].StudentType != null) tpye= studentfileView[i].StudentType; user.Sys_Role = new HashSet(); roleList = roleList.Where(x => x.CF_StudentRole.StudentType == tpye).ToList(); roleList.ForEach(x => user.Sys_Role.Add(x)); userList.Add(new Sys_User { UserID = Guid.NewGuid(), Password = pwd, CreateTime=DateTime.Now, LoginID = user.LoginID, Name = user.Name, RecordStatus=(int)SYS_STATUS.USABLE, Sys_Role=user.Sys_Role }); StudentID.Add(userList[i].UserID); CF_Student students =new CF_Student(); students.UserID=userList[i].UserID; if (studentfileView[i].ClassMajorID != null) students.ClassmajorID = studentfileView[i].ClassMajorID; if (studentfileView[i].Sex != null) students.Sex = (int)studentfileView[i].Sex; if (studentfileView[i].CertificatesType != null) students.CertificatesType = studentfileView[i].CertificatesType; if (!string.IsNullOrEmpty(studentfileView[i].IDNumber)) students.IDNumber = studentfileView[i].IDNumber; if (studentfileView[i].IsDreamProject) students.IsDreamProject = studentfileView[i].IsDreamProject; if (!string.IsNullOrEmpty(studentfileView[i].Career)) students.Career = studentfileView[i].Career; if (!string.IsNullOrEmpty(studentfileView[i].PhotoUrl)) { students.PhotoUrl = studentfileView[i].PhotoUrl; } students.PlanningGraduateDate = studentfileView[i].PlanningGraduateDate ?? studentfileView[i].PlanningGraduateDateStr; //if (students.PlanningGraduateDate == null) //{ // var GradeMajorID = ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == studentfileView[i].ClassMajorID).FirstOrDefault().GrademajorID; // students.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate(GradeMajorID.Value)); //} if (!string.IsNullOrEmpty(studentfileView[i].StudentCardNo)) students.StudentCardNo = studentfileView[i].StudentCardNo; //毕、结业证书编号 if (!string.IsNullOrEmpty(studentfileView[i].GraduateCardNo)) students.GraduateCardNo = studentfileView[i].GraduateCardNo; if (studentfileView[i].CultureModel != null) students.CultureModel = studentfileView[i].CultureModel; if (studentfileView[i].StudentType != null) students.StudentType = studentfileView[i].StudentType; if (studentfileView[i].StudentStatus != null) students.StudentStatus = studentfileView[i].StudentStatus; if (studentfileView[i].InSchoolStatusID != null) students.InSchoolStatusID = studentfileView[i].InSchoolStatusID; studentList.Add(new CF_Student { UserID = students.UserID, ClassmajorID = students.ClassmajorID, Sex = students.Sex, CertificatesType = students.CertificatesType, IDNumber = students.IDNumber, IsDreamProject = students.IsDreamProject, Career = students.Career, PhotoUrl = students.PhotoUrl, PlanningGraduateDate = students.PlanningGraduateDate, StudentCardNo = students.StudentCardNo, GraduateCardNo = students.GraduateCardNo, CultureModel = students.CultureModel, StudentType = students.StudentType, StudentStatus = students.StudentStatus, InSchoolStatusID = students.InSchoolStatusID, CreateTime = DateTime.Now, RecordStatus = (int)SYS_STATUS.USABLE }); CF_StudentProfile studentProfile = new CF_StudentProfile(); if (!string.IsNullOrEmpty(studentfileView[i].GraduationPictureUrl)) { studentProfile.GraduationPictureUrl = studentfileView[i].GraduationPictureUrl; } if (!string.IsNullOrEmpty(studentfileView[i].UsedName)) studentProfile.UsedName = studentfileView[i].UsedName; if (!string.IsNullOrEmpty(studentfileView[i].DirectorName)) studentProfile.DirectorName = studentfileView[i].DirectorName; if (studentfileView[i].BirthDate != null) studentProfile.BirthDate = studentfileView[i].BirthDate; if (!string.IsNullOrEmpty(studentfileView[i].Country)) studentProfile.Country = studentfileView[i].Country; if (studentfileView[i].Politics != null) studentProfile.Politics = studentfileView[i].Politics; if (studentfileView[i].Nation != null) studentProfile.Nation = studentfileView[i].Nation; if (!string.IsNullOrEmpty(studentfileView[i].Place)) studentProfile.Place = studentfileView[i].Place; if (studentfileView[i].Healthy != null) studentProfile.Healthy = studentfileView[i].Healthy; if (studentfileView[i].BloodGroup != null) studentProfile.BloodGroup = studentfileView[i].BloodGroup; //studentProfile.BornPlace = studentfileView.BornPlace; if (!string.IsNullOrEmpty(studentfileView[i].Specialty)) studentProfile.Specialty = studentfileView[i].Specialty; if (!string.IsNullOrEmpty(studentfileView[i].Height)) studentProfile.Height = studentfileView[i].Height; if (!string.IsNullOrEmpty(studentfileView[i].Weight)) studentProfile.Weight = studentfileView[i].Weight; if (!string.IsNullOrEmpty(studentfileView[i].Remarks)) studentProfile.Remarks = studentfileView[i].Remarks; studentProfileList.Add(new CF_StudentProfile { UserID = students.UserID, UsedName = studentProfile.UsedName, GraduationPictureUrl=studentProfile.GraduationPictureUrl, DirectorName=studentProfile.DirectorName, BirthDate=studentProfile.BirthDate, Country=studentProfile.Country, Politics=studentProfile.Politics, Nation=studentProfile.Nation, Place=studentProfile.Place, Healthy=studentProfile.Healthy, BloodGroup=studentProfile.BloodGroup, Specialty=studentProfile.Specialty, Height=studentProfile.Height, Weight=studentProfile.Weight, Remarks = studentProfile.Remarks, CreateTime = DateTime.Now, RecordStatus = (int)SYS_STATUS.USABLE }); CF_StudentContact studentContact = new CF_StudentContact(); if (!string.IsNullOrEmpty(studentfileView[i].Email)) studentContact.Email = studentfileView[i].Email; if (!string.IsNullOrEmpty(studentfileView[i].QQ)) studentContact.QQ = studentfileView[i].QQ; if (!string.IsNullOrEmpty(studentfileView[i].Mobile)) studentContact.Mobile = studentfileView[i].Mobile; if (!string.IsNullOrEmpty(studentfileView[i].Telephone)) studentContact.Telephone = studentfileView[i].Telephone; if (!string.IsNullOrEmpty(studentfileView[i].MicroMsgNo)) studentContact.MicroMsgNo = studentfileView[i].MicroMsgNo; if (!string.IsNullOrEmpty(studentfileView[i].ZipCode)) studentContact.Zipcode = studentfileView[i].ZipCode; if (!string.IsNullOrEmpty(studentfileView[i].Address)) studentContact.Address = studentfileView[i].Address; if (!string.IsNullOrEmpty(studentfileView[i].WorkUnit)) studentContact.WorkUnit = studentfileView[i].WorkUnit; if (!string.IsNullOrEmpty(studentfileView[i].HomeAddress)) studentContact.HomeAddress = studentfileView[i].HomeAddress; if (!string.IsNullOrEmpty(studentfileView[i].Recipient)) studentContact.Recipient = studentfileView[i].Recipient; if (!string.IsNullOrEmpty(studentfileView[i].Dormitory)) studentContact.Dormitory = studentfileView[i].Dormitory; studentContactList.Add(new CF_StudentContact { UserID = students.UserID, Email=studentContact.Email, QQ=studentContact.QQ, Mobile=studentContact.Mobile, Telephone=studentContact.Telephone, MicroMsgNo=studentContact.MicroMsgNo, Zipcode=studentContact.Zipcode, Address=studentContact.Address, WorkUnit=studentContact.WorkUnit, HomeAddress=studentContact.HomeAddress, Recipient=studentContact.Recipient, Dormitory=studentContact.Dormitory, CreateTime = DateTime.Now, RecordStatus = (int)SYS_STATUS.USABLE }); CF_StudentAccount studentAccount=new CF_StudentAccount(); if (!string.IsNullOrEmpty(studentfileView[i].CardNo)) studentAccount.CardNo = studentfileView[i].CardNo; if (!string.IsNullOrEmpty(studentfileView[i].BankName)) studentAccount.BankName = studentfileView[i].BankName; studentAccountList.Add(new CF_StudentAccount { UserID = students.UserID, CardNo=studentAccount.CardNo, BankName=studentAccount.BankName, CreateTime = DateTime.Now, RecordStatus = (int)SYS_STATUS.USABLE }); CF_Recruitstudents recruitstudents = new CF_Recruitstudents(); if (studentfileView[i].EntranceDate != null) recruitstudents.EntranceDate = studentfileView[i].EntranceDate; if (studentfileView[i].EntranceWay != null) recruitstudents.EntranceWay = studentfileView[i].EntranceWay; if (!string.IsNullOrEmpty(studentfileView[i].ExamineeNum)) recruitstudents.ExamineeNum = studentfileView[i].ExamineeNum; if (!string.IsNullOrEmpty(studentfileView[i].Placebirth)) recruitstudents.PlaceBirth = studentfileView[i].Placebirth; if (studentfileView[i].ExamineeType != null) recruitstudents.ExamineeType = studentfileView[i].ExamineeType; if (studentfileView[i].Features != null) recruitstudents.Features = studentfileView[i].Features; if (studentfileView[i].Score != null) recruitstudents.Score = studentfileView[i].Score; if (studentfileView[i].Territorial != null) recruitstudents.Territorial = studentfileView[i].Territorial; if (!string.IsNullOrEmpty(studentfileView[i].Area)) recruitstudents.Area = studentfileView[i].Area; if (studentfileView[i].EnteringSchoolYearID != null) recruitstudents.EnteringSchoolYearID = studentfileView[i].EnteringSchoolYearID; recruitstudentsList.Add(new CF_Recruitstudents { UserID = students.UserID, EntranceDate=recruitstudents.EntranceDate, EntranceWay=recruitstudents.EntranceWay, ExamineeNum=recruitstudents.ExamineeNum, PlaceBirth=recruitstudents.PlaceBirth, ExamineeType=recruitstudents.ExamineeType, Features=recruitstudents.Features, Score=recruitstudents.Score, Territorial=recruitstudents.Territorial, Area=recruitstudents.Area, EnteringSchoolYearID=recruitstudents.EnteringSchoolYearID, CreateTime = DateTime.Now, RecordStatus = (int)SYS_STATUS.USABLE }); } UnitOfWork.BulkInsert(userList); UnitOfWork.BulkInsert(userList, (x => x.Sys_Role)); UnitOfWork.BulkInsert(studentList); UnitOfWork.BulkInsert(studentProfileList); UnitOfWork.BulkInsert(studentContactList); UnitOfWork.BulkInsert(studentAccountList); UnitOfWork.BulkInsert(recruitstudentsList); } public IGridResultSet GetBaseStudentView(ViewModel.ConfiguretView configuretView, Guid? collegeID, Guid? grademajorID, Guid? classmajorID, Guid? userID, int pageIndex, int pageSize) { Expression> filter = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) filter = filter.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); if (grademajorID.HasValue) filter = filter.And(x => x.CF_Classmajor.GrademajorID == grademajorID); if (classmajorID.HasValue) filter = filter.And(x => x.ClassmajorID == classmajorID); if (userID.HasValue) { filter = filter.And(x => x.UserID == userID); } var query = StudentsDAL.Value.GetBaseStudentViewQueryable(filter); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query .OrderByDescending(x => x.LoginID.Length).ThenBy(x => x.LoginID) .ThenBy(x => x.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode) .ToGridResultSet(pageIndex, pageSize); } public DateTime? ReckonPlanningGraduateDate(Guid GrademajorID) { //由于LINQ不识别方法的系统的时间 ToDateTime(系统,字符串)的方法、将计算时间移至外围 StudentsView studentsEntity = StudentsDAL.Value.GetPlanningGraduateDate(GrademajorID); return studentsEntity.PlanningGraduateDate.Value.AddDays(studentsEntity.WeeksNum); } //private DateTime GetPlanningGraduate(DateTime firstWeek) //{ // if (firstWeek.Month >= 1 && firstWeek.Month <= 6) // { // return new DateTime(firstWeek.Year, 6, 30); // } // else // { // return new DateTime((firstWeek.Year + 1), 1, 31); // } //} public string GetPlanningGraduate(Guid GrademajorID) { var graduationSchoolyear = this.SchoolyearRepository.Value.GetSingle(x => x.CF_Grademajor.Any(w => w.GrademajorID == GrademajorID)); if (graduationSchoolyear != null) { var date = PlanningGraduateDateHelper.GetPlanningGraduateDate(graduationSchoolyear.FirstWeek); return date.ToString("yyyy-MM-dd"); } else { return null; } //return GetPlanningGraduate(graduationSchoolyear.FirstWeek).ToString("yyyy-MM-dd"); //StudentsView studentsEntity = StudentsDAL.Value.GetPlanningGraduate(GrademajorID); //int PlanningGraduate = (int)studentsEntity.Years; //try //{ // string SetPlanningGraduate; // if (studentsEntity.PlanningGraduateSchoolCode == (int)EMIS.ViewModel.CF_Schoolcode.Spring) // { // SetPlanningGraduate = studentsEntity.PlanningGraduateYear.ToString() + "-06-30"; // } // else if (studentsEntity.PlanningGraduateSchoolCode == (int)EMIS.ViewModel.CF_Schoolcode.Autumn) // { //因秋季是跨年,毕业年份需要+1年 // SetPlanningGraduate = (studentsEntity.PlanningGraduateYear + 1).ToString() + "-01-31"; // } // else // throw new Exception("学期设置有问题,请核查"); // return SetPlanningGraduate; //} //catch //{ // return ""; //} //预计毕业时间,原来逻辑有问题,默认值为2016-01-31+30个月也就是2018-07-31,当学制不为3或2.5时,返回2018-07-31+学制年数:邓智荣 //DateTime SetPlanningGraduate = Convert.ToDateTime("2016-01-31").AddMonths(30); //DateTime SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate.ToString() + "-06-30"); //if (studentsEntity.LearnSystem == 3) //{ // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-06-30"); // // SetPlanningGraduate.AddYears((int)studentsEntity.LearnSystem); //} //if (studentsEntity.LearnSystem == (Decimal)2.5) //{ // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-01-31"); // // SetPlanningGraduate.AddMonths((int)studentsEntity.LearnSystem * 12); //} ////原逻辑只有学制2.5和3的判断,现加上2和4 //if (studentsEntity.LearnSystem == 2 || studentsEntity.LearnSystem == 4) //{ // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-06-30"); //} //if (Convert.ToInt32(studentsEntity.LearnSystem) == studentsEntity.LearnSystem) //{ //2、3或4年制 // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-06-30"); //} //else //{ //2.5或3.5年制 // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-01-31"); //} //return SetPlanningGraduate.AddYears((int)studentsEntity.LearnSystem);//2.5 转int 2 } public IGridResultSet GetPlanningGraduateList() { Dictionary diction = new Dictionary(); //int key = 0; var query = StudentsDAL.Value.GetPlanningGraduateDictionary().Where(x => x.PlanningGraduateDate != null); List list = query.Select(x => x.PlanningGraduateDate).OrderBy(x => x.Value).ToList(); List stulist = query.OrderBy(x => x.PlanningGraduateDate).ToList(); List datestr = new List(); for (int i = 0; i < stulist.Count; i++) { stulist[i].PlanningGraduateStr = list[i].Value.ToString("yyyyMMdd"); } //List dictionList = query.Select(x => x.PlanningGraduateStr).ToList(); //foreach(DateTime date in dictionList) //{ // diction.Add(key, date); // key++; //} return stulist.AsQueryable().ToGridResultSet(); } public void ClearPhotoUrl(IList studentIDList) { this.UnitOfWork.Update((x => new CF_Student { PhotoUrl = null }), (x => studentIDList.Contains(x.UserID))); } public virtual int? GetDefaultLearnformForList() { return null; } public StudentsView GetStudentViewByLoginID(string loginID){ var student = StudentsDAL.Value.GetStudentQueryable(x => x.Sys_User.LoginID == loginID).FirstOrDefault(); return student; } public StudentsView GetStudentViewByIDNum(string idNum) { var student = StudentsDAL.Value.GetStudentQueryable(x => x.IDNumber == idNum).FirstOrDefault(); return student; } public int GetDataRange() { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var curUserID = curUser.UserID; if (curUser.IsStudent) { return 6; } var menuNo = HttpHelper.GetMenuNo(); if (string.IsNullOrEmpty(menuNo)) { menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU"); } SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo); switch (dataRange) { case SYS_DataRange.All: default: return (int)SYS_DataRange.All; case SYS_DataRange.Campus: return (int)SYS_DataRange.Campus; case SYS_DataRange.College: return (int)SYS_DataRange.College; case SYS_DataRange.Department: return (int)SYS_DataRange.Department; case SYS_DataRange.Teacher: return (int)SYS_DataRange.Teacher; case SYS_DataRange.Assistant: return (int)SYS_DataRange.Assistant; } } public IGridResultSet GetStudentOnlyInSchool(ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.InSchoolStatusID == (int)CF_InschoolStatus.InSchool); Expression> classexp = (x => true); Expression> gradeexp = (x => true); var query = StudentsDAL.Value.GetInSchoolStudentViewQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } return query.OrderBy(x => x.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } /// /// 查询列表 /// /// /// 校区ID /// 院系所ID /// 培养层次ID /// 学年 /// 招生专业ID /// 学习形式ID /// 班级ID /// 在校状态ID /// 是否有照片 /// 是否毕业学生 /// /// /// public IGridResultSet GetStudentUserViewList(ConfiguretView configuretView, int? campusID, Guid? collegeID, int? education, int? years, int? standardID, int? learningformID, int? classNum, int? studentStatusID, bool? isPhotos, bool? isOnlyGraduation, bool? isPreviousNotGraduated, int pageIndex, int pageSize) { var currentSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear(); var inschoolStatusList = InSchoolSettingRepository.Value.GetList(x => x.IsSelected == true) .Select(x => x.InSchoolStatusID).Distinct().ToList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && inschoolStatusList.Contains(x.InSchoolStatusID)); Expression> classexp = (x => true); Expression> gradeexp = (x => true); if (campusID.HasValue) { gradeexp = gradeexp.And(x => x.SchoolAreaID == campusID); } if (collegeID.HasValue) { gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID); } if (education.HasValue) { gradeexp = gradeexp.And(x => x.CF_Facultymajor.EducationID == education.Value); } if (years.HasValue) { gradeexp = gradeexp.And(x => x.SchoolyearID == years); } if (standardID.HasValue) { gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID); } if (learningformID.HasValue) { gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID); } if (classNum.HasValue) { classexp = classexp.And(x => x.ClassNum == classNum); } if (studentStatusID.HasValue) { exp = exp.And(x => x.StudentStatus == studentStatusID); } if (isPhotos.HasValue) { if (isPhotos.Value) { exp = exp.And(x => x.PhotoUrl != null); } else { exp = exp.And(x => x.PhotoUrl == null); } } if (isOnlyGraduation == true) { gradeexp = gradeexp.And(x => x.GraduatingSemesterID == currentSchoolyear.SchoolYearID); } if (isPreviousNotGraduated == true) { gradeexp = gradeexp.And(x => x.CF_Schoolyear.Value < currentSchoolyear.Value); exp = exp.And(x => x.StudentStatus == (int)CF_STUDENTSTATUS.Complete && x.InSchoolStatusID == (int)CF_InschoolStatus.Complete); } var query = StudentsDAL.Value.GetStudentQueryable(exp, classexp, gradeexp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize); } public RegistView GetRegistViewByUserID(Guid userID) { var registView = StudentsDAL.Value.GetRegustViewQueryable(x => x.UserID == userID).FirstOrDefault(); return registView; } public bool CheckNecessary(Guid userID) { var registView = this.GetRegistViewByUserID(userID); if (registView == null) { return false; } if (string.IsNullOrEmpty(registView.LoginID)) { return false; } if (!registView.CertificatesType.HasValue) { return false; } if (string.IsNullOrEmpty(registView.UserName)) { return false; } if (string.IsNullOrEmpty(registView.Mobile)) { return false; } if (string.IsNullOrEmpty(registView.Email)) { return false; } if (string.IsNullOrEmpty(registView.PhotoUrl)) { return false; } if (!registView.Sex.HasValue) { return false; } if (!registView.BirthDate.HasValue) { return false; } return true; } } }