using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Text.RegularExpressions; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using Bowin.Common.Utility; using Bowin.Common.DataTime; using EMIS.Entities; using EMIS.Utility; using EMIS.ViewModel; using EMIS.ViewModel.UniversityManage.TeacherManage; using EMIS.ViewModel.SystemManage.UserManage; using EMIS.ViewModel.CacheManage; using EMIS.DataLogic.UniversityManage.TeacherManage; namespace EMIS.CommonLogic.UniversityManage.TeacherManage { public class StaffServices : BaseServices, IStaffServices { public Lazy staffDAL { get; set; } public Lazy TimeHelper { get; set; } /// /// 查询教师信息View /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetStaffViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID, int? incumbencyState, int? titleID, int? isDualTeacher, int pageIndex, int pageSize) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expStaff = expStaff.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { expStaff = expStaff.And(x => x.DepartmentID == departmentID); } if (isPhoto.HasValue) { if (isPhoto.Value == (int)CF_GeneralExist.Have) { expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != ""); } if (isPhoto.Value == (int)CF_GeneralExist.No) { expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == ""); } } if (teacherTypeID.HasValue) { expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID); } if (incumbencyState.HasValue) { expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState); } if (titleID.HasValue) { expStaff = expStaff.And(x => x.TitleID == titleID); } if (isDualTeacher.HasValue) { if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes) { expStaff = expStaff.And(x => x.IsDualTeacher == true); } if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo) { expStaff = expStaff.And(x => x.IsDualTeacher != true); } } var query = staffDAL.Value.GetStaffViewQueryable(expStaff); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRange(query, x => x.UserID).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询教师信息List /// /// /// /// /// /// /// /// /// /// /// public IList GetStaffViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID, int? incumbencyState, int? titleID, int? isDualTeacher) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expStaff = expStaff.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { expStaff = expStaff.And(x => x.DepartmentID == departmentID); } if (isPhoto.HasValue) { if (isPhoto.Value == (int)CF_GeneralExist.Have) { expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != ""); } if (isPhoto.Value == (int)CF_GeneralExist.No) { expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == ""); } } if (teacherTypeID.HasValue) { expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID); } if (incumbencyState.HasValue) { expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState); } if (titleID.HasValue) { expStaff = expStaff.And(x => x.TitleID == titleID); } if (isDualTeacher.HasValue) { if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes) { expStaff = expStaff.And(x => x.IsDualTeacher == true); } if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo) { expStaff = expStaff.And(x => x.IsDualTeacher != true); } } var query = staffDAL.Value.GetStaffViewQueryable(expStaff); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRange(query, x => x.UserID).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode) .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList(); } /// /// 查询教师信息View /// /// /// /// /// /// /// /// /// public IGridResultSet GetStaffViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, string loginID, string name, int pageIndex, int pageSize) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expStaff = expStaff.And(x => x.CollegeID == collegeID); } if (!string.IsNullOrEmpty(loginID)) { expStaff = expStaff.And(x => x.Sys_User.LoginID.Contains(loginID)); } if (!string.IsNullOrEmpty(name)) { expStaff = expStaff.And(x => x.Sys_User.Name.Contains(name)); } var query = staffDAL.Value.GetStaffViewQueryable(expStaff); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length) .ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询教师信息List /// /// /// /// /// /// /// public IList GetStaffViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, string loginID, string name) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expStaff = expStaff.And(x => x.CollegeID == collegeID); } if (!string.IsNullOrEmpty(loginID)) { expStaff = expStaff.And(x => x.Sys_User.LoginID.Contains(loginID)); } if (!string.IsNullOrEmpty(name)) { expStaff = expStaff.And(x => x.Sys_User.Name.Contains(name)); } var query = staffDAL.Value.GetStaffViewQueryable(expStaff); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length) .ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList(); } /// /// 查询教师信息View(无数据范围) /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetStaffViewGridWithNoDataRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID, int? incumbencyState, int? titleID, int? isDualTeacher, int pageIndex, int pageSize) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expStaff = expStaff.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { expStaff = expStaff.And(x => x.DepartmentID == departmentID); } if (isPhoto.HasValue) { if (isPhoto.Value == (int)CF_GeneralExist.Have) { expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != ""); } if (isPhoto.Value == (int)CF_GeneralExist.No) { expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == ""); } } if (teacherTypeID.HasValue) { expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID); } if (incumbencyState.HasValue) { expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState); } if (titleID.HasValue) { expStaff = expStaff.And(x => x.TitleID == titleID); } if (isDualTeacher.HasValue) { if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes) { expStaff = expStaff.And(x => x.IsDualTeacher == true); } if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo) { expStaff = expStaff.And(x => x.IsDualTeacher != true); } } var query = staffDAL.Value.GetStaffViewQueryable(expStaff); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询教师信息List(无数据范围) /// /// /// /// /// /// /// /// /// /// /// public IList GetStaffViewListWithNoDataRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID, int? incumbencyState, int? titleID, int? isDualTeacher) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expStaff = expStaff.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { expStaff = expStaff.And(x => x.DepartmentID == departmentID); } if (isPhoto.HasValue) { if (isPhoto.Value == (int)CF_GeneralExist.Have) { expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != ""); } if (isPhoto.Value == (int)CF_GeneralExist.No) { expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == ""); } } if (teacherTypeID.HasValue) { expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID); } if (incumbencyState.HasValue) { expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState); } if (titleID.HasValue) { expStaff = expStaff.And(x => x.TitleID == titleID); } if (isDualTeacher.HasValue) { if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes) { expStaff = expStaff.And(x => x.IsDualTeacher == true); } if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo) { expStaff = expStaff.And(x => x.IsDualTeacher != true); } } var query = staffDAL.Value.GetStaffViewQueryable(expStaff); if (campusID.HasValue) { //校区 query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList(); } /// /// 查询教师信息StaffView(全部) /// /// /// /// /// public IGridResultSet GetAllStaffView(ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = staffDAL.Value.GetStaffViewQueryable(expStaff); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询教师信息List(全部) /// /// /// public IList GetAllStaffList(ConfiguretView configuretView) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = staffDAL.Value.GetStaffViewQueryable(expStaff); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList(); } /// /// 查询对应的教师信息StaffView(全部) /// /// public List GetListStaffView() { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = staffDAL.Value.GetStaffViewQueryable(expStaff); return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList(); } /// /// 查询对应的教师信息CF_Staff(全部) /// /// public List GetStaffList() { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = staffDAL.Value.staffRepository.GetList(expStaff); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.Sys_User.LoginID.Length).ThenBy(x => x.Sys_User.LoginID).ToList(); } /// /// 查询对应的教师信息CF_Staff /// /// /// public CF_Staff GetStaff(Guid? userID) { try { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStaff = expStaff.And(x => x.UserID == userID); var query = staffDAL.Value.staffRepository.GetList(expStaff, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffManageDepartment), (x => x.CF_StaffProfile), (x => x.Sys_User)).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的教师信息CF_StaffProfile /// /// /// public CF_StaffProfile GetStaffProfile(Guid? userID) { try { Expression> expStaffProfile = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStaffProfile = expStaffProfile.And(x => x.UserID == userID); var query = staffDAL.Value.staffProfileRepository.GetList(expStaffProfile).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的教师信息CF_Staff /// /// /// public CF_Staff GetStaff(Expression> exp) { try { return staffDAL.Value.staffRepository.GetSingle(exp); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的教师信息StaffView /// /// /// public StaffView GetStaffView(Guid? userID) { try { var query = staffDAL.Value.GetStaffViewQueryable(x => x.UserID == userID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的教师信息StaffView /// /// /// public StaffView GetStaffView(Expression> exp) { try { var query = staffDAL.Value.GetStaffViewQueryable(exp).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的教师信息List /// /// /// public List GetListStaffView(Guid? userID) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStaff = expStaff.And(x => x.UserID == userID); var query = staffDAL.Value.GetStaffViewQueryable(expStaff); return query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ToList(); } /// /// 编辑(新增、修改,业务主键:教职工号或证件号码) /// /// /// public void StaffEdit(StaffView staffView, string photoUrl) { try { var userVerify = staffDAL.Value.UserRepository.GetList(x => x.UserID != staffView.UserID && x.LoginID == staffView.StaffCode).SingleOrDefault(); if (userVerify == null) { if (!string.IsNullOrEmpty(staffView.CertificatesNum)) { var staffVerify = staffDAL.Value.staffRepository.GetList(x => x.UserID != staffView.UserID && x.CertificatesNum == staffView.CertificatesNum).SingleOrDefault(); if (staffVerify != null) { throw new Exception("已存在相同的证件号码(证件号码重复),请核查。"); } } var college = staffDAL.Value.CollegeRepository.GetList(x => x.CollegeID == staffView.CollegeID).SingleOrDefault(); if (staffView.DepartmentID.HasValue) { var department = staffDAL.Value.DepartmentRepository.GetList(x => x.DepartmentID == staffView.DepartmentID).SingleOrDefault(); if (department.CollegeID != staffView.CollegeID) { throw new Exception("所属教研室和" + RSL.Get("College") + "不匹配,请核查。"); } } var teacherInitPassword = staffDAL.Value.ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.TeacherInitPassword).SingleOrDefault(); var teacherRoleList = staffDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Teacher && x.RoleName.Contains("教师")).ToList(); List newUserInList = new List(); List newUserUpList = new List(); List newStaffInList = new List(); List newStaffUpList = new List(); List newStaffProfileInList = new List(); List newStaffProfileUpList = new List(); List newStaffManageCampusInList = new List(); List newStaffManageCollegeInList = new List(); List newStaffManageDepartmentInList = new List(); List CampusUserIDDelList = new List(); List CollegeUserIDDelList = new List(); List DepartmentUserIDDelList = new List(); if (staffView.UserID != Guid.Empty) { //表示修改 var staff = staffDAL.Value.staffRepository.GetList(x => x.UserID == staffView.UserID, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffManageDepartment), (x => x.CF_StaffProfile), (x => x.Sys_User)).SingleOrDefault(); if (staff == null) { throw new Exception("数据有误,请核查。"); } else { staff.Sys_User.LoginID = staffView.StaffCode.Trim(); staff.Sys_User.Name = staffView.Name.Trim(); this.SetModifyStatus(staff.Sys_User); newUserUpList.Add(staff.Sys_User); staff.StaffCode = staffView.StaffCode.Trim(); if (staff.CollegeID != staffView.CollegeID) { CampusUserIDDelList.Add(staffView.UserID); var staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = staffView.UserID; staffManageCampus.CampusID = college.CampusID; this.SetNewStatus(staffManageCampus); newStaffManageCampusInList.Add(staffManageCampus); CollegeUserIDDelList.Add(staffView.UserID); var staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = staffView.UserID; staffManageCollege.CollegeID = staffView.CollegeID; this.SetNewStatus(staffManageCollege); newStaffManageCollegeInList.Add(staffManageCollege); DepartmentUserIDDelList.Add(staffView.UserID); if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = staffView.UserID; staffManageDepartment.DepartmentID = staffView.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } } else { if (staff.CF_StaffManageCampus.Count() <= 0 || staff.CF_StaffManageCampus == null) { var staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = staffView.UserID; staffManageCampus.CampusID = college.CampusID; this.SetNewStatus(staffManageCampus); newStaffManageCampusInList.Add(staffManageCampus); } if (staff.CF_StaffManageCollege.Count() <= 0 || staff.CF_StaffManageCollege == null) { var staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = staffView.UserID; staffManageCollege.CollegeID = staffView.CollegeID; this.SetNewStatus(staffManageCollege); newStaffManageCollegeInList.Add(staffManageCollege); } if (staff.DepartmentID != staffView.DepartmentID) { DepartmentUserIDDelList.Add(staffView.UserID); if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = staffView.UserID; staffManageDepartment.DepartmentID = staffView.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } } else { if (staff.CF_StaffManageDepartment.Count() <= 0 || staff.CF_StaffManageDepartment == null) { if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = staffView.UserID; staffManageDepartment.DepartmentID = staffView.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } } } } staff.CollegeID = staffView.CollegeID; staff.DepartmentID = staffView.DepartmentID; staff.SexID = staffView.SexID; staff.BirthDate = staffView.BirthDate; staff.NationID = staffView.NationID; staff.PoliticsID = staffView.PoliticsID; staff.CertificatesType = staffView.CertificatesType; staff.CertificatesNum = staffView.CertificatesNum; staff.TeacherTypeID = staffView.TeacherTypeID; staff.IncumbencyState = staffView.IncumbencyState; staff.SituationID = staffView.SituationID; staff.TitleID = staffView.TitleID; staff.LiteracyLevelID = staffView.LiteracyLevelID; staff.LearnPositionID = staffView.LearnPositionID; staff.IsDualTeacher = staffView.IsDualTeacher; staff.PaymentLevelID = staffView.PaymentLevelID; staff.WorkDate = staffView.WorkDate; staff.ComeSchoolDate = staffView.ComeSchoolDate; if (!string.IsNullOrEmpty(photoUrl)) { staff.PhotoUrl = photoUrl; } staff.Profile = staffView.Profile; staff.Remark = staffView.Remark; this.SetModifyStatus(staff); newStaffUpList.Add(staff); if (staff.CF_StaffProfile == null) { var staffProfile = new CF_StaffProfile(); staffProfile.UserID = staff.UserID; staffProfile.UsedName = staffView.UsedName; staffProfile.Nationality = staffView.Nationality; staffProfile.Place = staffView.Place; staffProfile.Email = staffView.Email; staffProfile.ZIPCode = staffView.ZIPCode; staffProfile.WeChatNum = staffView.WeChatNum; staffProfile.QQ = staffView.QQ; staffProfile.Telephone = staffView.Telephone; staffProfile.OfficeTelephone = staffView.OfficeTelephone; staffProfile.HousePhone = staffView.HousePhone; staffProfile.Mobile = staffView.Mobile; staffProfile.Speciality = staffView.Speciality; staffProfile.HealthStateID = staffView.HealthStateID; staffProfile.ReligionID = staffView.ReligionID; staffProfile.Account = staffView.Account; staffProfile.Residence = staffView.Residence; staffProfile.HomeAddress = staffView.HomeAddress; staffProfile.Address = staffView.Address; staffProfile.NowAddress = staffView.NowAddress; this.SetNewStatus(staffProfile); newStaffProfileInList.Add(staffProfile); } else { staff.CF_StaffProfile.UsedName = staffView.UsedName; staff.CF_StaffProfile.Nationality = staffView.Nationality; staff.CF_StaffProfile.Place = staffView.Place; staff.CF_StaffProfile.Email = staffView.Email; staff.CF_StaffProfile.ZIPCode = staffView.ZIPCode; staff.CF_StaffProfile.WeChatNum = staffView.WeChatNum; staff.CF_StaffProfile.QQ = staffView.QQ; staff.CF_StaffProfile.Telephone = staffView.Telephone; staff.CF_StaffProfile.OfficeTelephone = staffView.OfficeTelephone; staff.CF_StaffProfile.HousePhone = staffView.HousePhone; staff.CF_StaffProfile.Mobile = staffView.Mobile; staff.CF_StaffProfile.Speciality = staffView.Speciality; staff.CF_StaffProfile.HealthStateID = staffView.HealthStateID; staff.CF_StaffProfile.ReligionID = staffView.ReligionID; staff.CF_StaffProfile.Account = staffView.Account; staff.CF_StaffProfile.Residence = staffView.Residence; staff.CF_StaffProfile.HomeAddress = staffView.HomeAddress; staff.CF_StaffProfile.Address = staffView.Address; staff.CF_StaffProfile.NowAddress = staffView.NowAddress; this.SetModifyStatus(staff.CF_StaffProfile); newStaffProfileUpList.Add(staff.CF_StaffProfile); } } } else { //表示新增 var newUser = new Sys_User(); newUser.UserID = Guid.NewGuid(); newUser.LoginID = staffView.StaffCode.Trim(); newUser.Name = staffView.Name.Trim(); if (teacherInitPassword == null) { newUser.Password = ("A" + staffView.StaffCode.Trim()).MD5(); } else { if (teacherInitPassword.Value != null) { newUser.Password = teacherInitPassword.Value; } else { newUser.Password = ("A" + staffView.StaffCode.Trim()).MD5(); } } this.SetNewStatus(newUser, (int)SYS_STATUS.USABLE); newUserInList.Add(newUser); newUser.Sys_Role = new HashSet(); if (teacherRoleList != null && teacherRoleList.Count() > 0) { teacherRoleList.ForEach(x => newUser.Sys_Role.Add(x)); } else { //对应角色为空时,默认为不分配用户角色 } var newStaff = new CF_Staff(); newStaff.UserID = newUser.UserID; newStaff.StaffCode = staffView.StaffCode.Trim(); newStaff.CollegeID = staffView.CollegeID; var staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = newStaff.UserID; staffManageCampus.CampusID = college.CampusID; this.SetNewStatus(staffManageCampus); newStaffManageCampusInList.Add(staffManageCampus); var staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = newStaff.UserID; staffManageCollege.CollegeID = staffView.CollegeID; this.SetNewStatus(staffManageCollege); newStaffManageCollegeInList.Add(staffManageCollege); newStaff.DepartmentID = staffView.DepartmentID; if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = newStaff.UserID; staffManageDepartment.DepartmentID = staffView.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } newStaff.SexID = staffView.SexID; newStaff.BirthDate = staffView.BirthDate; newStaff.NationID = staffView.NationID; newStaff.PoliticsID = staffView.PoliticsID; newStaff.CertificatesType = staffView.CertificatesType; newStaff.CertificatesNum = staffView.CertificatesNum; newStaff.TeacherTypeID = staffView.TeacherTypeID; newStaff.IncumbencyState = staffView.IncumbencyState; newStaff.SituationID = staffView.SituationID; newStaff.TitleID = staffView.TitleID; newStaff.LiteracyLevelID = staffView.LiteracyLevelID; newStaff.LearnPositionID = staffView.LearnPositionID; newStaff.IsDualTeacher = staffView.IsDualTeacher; newStaff.PaymentLevelID = staffView.PaymentLevelID; newStaff.WorkDate = staffView.WorkDate; newStaff.ComeSchoolDate = staffView.ComeSchoolDate; if (!string.IsNullOrEmpty(photoUrl)) { newStaff.PhotoUrl = photoUrl; } newStaff.Profile = staffView.Profile; newStaff.Remark = staffView.Remark; this.SetNewStatus(newStaff); newStaffInList.Add(newStaff); var newStaffProfile = new CF_StaffProfile(); newStaffProfile.UserID = newStaff.UserID; newStaffProfile.UsedName = staffView.UsedName; newStaffProfile.Nationality = staffView.Nationality; newStaffProfile.Place = staffView.Place; newStaffProfile.Email = staffView.Email; newStaffProfile.ZIPCode = staffView.ZIPCode; newStaffProfile.WeChatNum = staffView.WeChatNum; newStaffProfile.QQ = staffView.QQ; newStaffProfile.Telephone = staffView.Telephone; newStaffProfile.OfficeTelephone = staffView.OfficeTelephone; newStaffProfile.HousePhone = staffView.HousePhone; newStaffProfile.Mobile = staffView.Mobile; newStaffProfile.Speciality = staffView.Speciality; newStaffProfile.HealthStateID = staffView.HealthStateID; newStaffProfile.ReligionID = staffView.ReligionID; newStaffProfile.Account = staffView.Account; newStaffProfile.Residence = staffView.Residence; newStaffProfile.HomeAddress = staffView.HomeAddress; newStaffProfile.Address = staffView.Address; newStaffProfile.NowAddress = staffView.NowAddress; this.SetNewStatus(newStaffProfile); newStaffProfileInList.Add(newStaffProfile); } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => DepartmentUserIDDelList.Contains(x.UserID)); UnitOfWork.Delete(x => CollegeUserIDDelList.Contains(x.UserID)); UnitOfWork.Delete(x => CampusUserIDDelList.Contains(x.UserID)); UnitOfWork.BulkInsert(newUserInList); UnitOfWork.BulkInsert(newUserInList, (x => x.Sys_Role)); UnitOfWork.BulkInsert(newStaffInList); UnitOfWork.BulkInsert(newStaffProfileInList); UnitOfWork.BulkInsert(newStaffManageCampusInList); UnitOfWork.BulkInsert(newStaffManageCollegeInList); UnitOfWork.BulkInsert(newStaffManageDepartmentInList); if (newUserUpList != null && newUserUpList.Count() > 0) { UnitOfWork.BatchUpdate(newUserUpList); } if (newStaffUpList != null && newStaffUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStaffUpList); } if (newStaffProfileUpList != null && newStaffProfileUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStaffProfileUpList); } ts.Complete(); } } else { var staffVerify = staffDAL.Value.staffRepository.GetList(x => x.UserID != staffView.UserID, (x => x.Sys_User)).Where(x => x.Sys_User.LoginID == staffView.StaffCode.Trim()).SingleOrDefault(); if (staffVerify != null) { throw new Exception("已存在相同的教职工号(教职工号重复),请核查。"); } else { var studentVerify = staffDAL.Value.StudentRepository.GetList(x => x.UserID != staffView.UserID, (x => x.Sys_User)).Where(x => x.Sys_User.LoginID == staffView.StaffCode.Trim()).SingleOrDefault(); if (studentVerify != null) { throw new Exception("学生信息中已存在相同的用户(用户名重复),请核查。"); } else { throw new Exception("用户信息中已存在相同的用户(用户名重复),请核查。"); } } } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool StaffDelete(List userIDs) { try { 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 = staffDAL.Value.UserRepository.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(); return true; } catch (Exception) { throw; } } /// /// 验证 /// /// /// /// public bool GetVerification(Guid? collegeID, Guid? departmentID) { try { var college = staffDAL.Value.CollegeRepository.GetList(x => x.CollegeID == collegeID).SingleOrDefault(); if (departmentID.HasValue) { var department = staffDAL.Value.DepartmentRepository.GetList(x => x.DepartmentID == departmentID).SingleOrDefault(); if (department.CollegeID != collegeID) { return false; } } return true; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除照片(单个删除) /// /// public void DeletePhoto(Guid? userID) { try { var staff = staffDAL.Value.staffRepository.GetList(x => x.UserID == userID).SingleOrDefault(); if (staff != null) { if (!string.IsNullOrEmpty(staff.PhotoUrl)) { FileUploadHelper.DeleteFile(staff.PhotoUrl); staff.PhotoUrl = null; this.UnitOfWork.Commit(); } else { throw new Exception("对应的照片不存在。"); } } else { throw new Exception("对应的信息未保存,数据有误。"); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除照片(批量删除) /// /// /// public bool PicDelete(List userIDs) { try { List photoUrlList = new List(); List staffUpList = new List(); var staffList = staffDAL.Value.staffRepository.GetList(x => userIDs.Contains(x.UserID)).ToList(); foreach (var staff in staffList) { if (staff != null) { if (!string.IsNullOrEmpty(staff.PhotoUrl)) { photoUrlList.Add(staff.PhotoUrl); staff.PhotoUrl = null; staffUpList.Add(staff); } } } using (TransactionScope ts = new TransactionScope()) { foreach (var photoUrl in photoUrlList) { FileUploadHelper.DeleteFile(photoUrl); } if (staffUpList != null && staffUpList.Count() > 0) { UnitOfWork.BatchUpdate(staffUpList); } ts.Complete(); } return true; } catch (Exception) { throw; } } /// /// 查询教师对应的角色信息UserView /// /// /// /// /// /// /// /// /// public IGridResultSet GetRoleListViewGrid(ConfiguretView configuretView, Guid? userID, Guid? roleID, int? dataRange, int? roleStatus, int pageIndex, int pageSize) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStaff = expStaff.And(x => x.UserID == userID); var query = staffDAL.Value.GetStaffRoleViewQueryable(expStaff); if (roleID.HasValue) { query = query.Where(x => x.RoleID == roleID); } if (dataRange.HasValue) { query = query.Where(x => x.DataRange == dataRange); } if (roleStatus.HasValue) { query = query.Where(x => x.RoleStatus == roleStatus); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LoginID.Length).ThenBy(x => x.LoginID).ThenBy(x => x.RoleOrderNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询教师对应的角色信息List /// /// /// /// /// /// /// public IList GetRoleListViewList(ConfiguretView configuretView, Guid? userID, Guid? roleID, int? dataRange, int? roleStatus) { Expression> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStaff = expStaff.And(x => x.UserID == userID); var query = staffDAL.Value.GetStaffRoleViewQueryable(expStaff); if (roleID.HasValue) { query = query.Where(x => x.RoleID == roleID); } if (dataRange.HasValue) { query = query.Where(x => x.DataRange == dataRange); } if (roleStatus.HasValue) { query = query.Where(x => x.RoleStatus == roleStatus); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.LoginID.Length).ThenBy(x => x.LoginID).ThenBy(x => x.RoleOrderNo).ToList(); } /// /// 导入照片 /// /// /// public void StaffPicImport(IList photoPaths, string importPicType) { List staffUpList = new List(); var mapList = photoPaths.Select(s => new { PhotoName = Path.GetFileNameWithoutExtension(s).Trim(), PhotoPath = s, }).ToArray(); var photoNameList = mapList.Select(s => s.PhotoName).Distinct().ToArray(); var userList = new List(); var staffList = new List(); switch (importPicType) { case "StaffCode": userList = staffDAL.Value.UserRepository.GetList(x => photoNameList.Contains(x.LoginID), (x => x.CF_Staff)).ToList(); break; case "IDNumber": staffList = staffDAL.Value.staffRepository.GetList(x => photoNameList.Contains(x.CertificatesNum)).ToList(); break; } foreach (var map in mapList) { switch (importPicType) { case "StaffCode": var user = userList.FirstOrDefault(w => w.LoginID == map.PhotoName); if (user == null) { throw new Exception("导入照片中存在无法匹对信息(名称:" + map.PhotoName + "-教职工号)" + ",请检查。"); } else { if (user.CF_Staff == null) { throw new Exception("导入照片中存在无法匹对信息(名称:" + map.PhotoName + "-教职工号)" + ",请检查。"); } else { user.CF_Staff.PhotoUrl = map.PhotoPath; staffUpList.Add(user.CF_Staff); } } break; case "IDNumber": var staff = staffList.FirstOrDefault(w => w.CertificatesNum == map.PhotoName); if (staff == null) { throw new Exception("导入照片中存在无法匹对信息(名称:" + map.PhotoName + "-证件号码)" + ",请检查。"); } else { staff.PhotoUrl = map.PhotoPath; staffUpList.Add(staff); } break; } } if (staffUpList != null && staffUpList.Count() > 0) { UnitOfWork.BatchUpdate(staffUpList); } } /// /// Excel教师信息导入 /// /// /// /// /// /// /// public void StaffImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath) { try { StringBuilder errorMsg = new StringBuilder(); List errList = new List(); cellheader.Remove("ErrorMessage"); List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "未导入原因"); //对List集合进行有效性校验 if (enlist.Count() <= 0) { throw new Exception("Excel文件数据为空,请检查。"); } Regex reg = null; //正则表达式 DateTime result; //用于返回判断日期字段格式 inCount = 0; //导入个数 upCount = 0; //更新个数 errCount = 0; //失败个数 string errorMsgStr = ""; //错误信息 var teacherInitPassword = staffDAL.Value.ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.TeacherInitPassword).SingleOrDefault(); var teacherRoleList = staffDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Teacher && x.RoleName.Contains("教师")).ToList(); List newUserInList = new List(); List newUserUpList = new List(); List newStaffInList = new List(); List newStaffUpList = new List(); List newStaffProfileInList = new List(); List newStaffProfileUpList = new List(); List newStaffManageCampusInList = new List(); List newStaffManageCollegeInList = new List(); List newStaffManageDepartmentInList = new List(); List CampusUserIDDelList = new List(); List CollegeUserIDDelList = new List(); List DepartmentUserIDDelList = new List(); //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询) //用户信息 var userList = staffDAL.Value.UserRepository.GetList(x => true).ToList(); //教职工号 var staffCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.StaffCode)).Select(x => x.StaffCode.Trim()).ToList(); //对比后的newUserList var newUserList = userList.Where(x => staffCodeList.Contains(x.LoginID)).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 certificatesTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType).ToList(); //教师类型 var teacherTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeacherType).ToList(); //在职状态 var incumbencyStateList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_IncumbencyState).ToList(); //任课状况 var situationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Situation).ToList(); //职称 var titleList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Title).ToList(); //文化程度 var literacyLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevel).ToList(); //学位 var learnPositionList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition).ToList(); //是否 var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList(); //课酬级别 var paymentLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.TP_PaymentLevel).ToList(); //健康状况 var healthStateList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState).ToList(); //宗教信仰 var religionList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Religion).ToList(); //院系所信息 var collegeList = staffDAL.Value.CollegeRepository.GetList(x => true).ToList(); //院系所 var collegeNameList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeName)).Select(x => x.CollegeName.Trim()).ToList(); //对比后的newCollegeList var newCollegeList = collegeList.Where(x => collegeNameList.Contains(x.Name)).ToList(); //教研室信息 var departmentList = staffDAL.Value.DepartmentRepository.GetList(x => true).ToList(); //所属教研室 var departmentNameList = enlist.Where(x => !string.IsNullOrEmpty(x.DepartmentName)).Select(x => x.DepartmentName.Trim()).ToList(); //对比后的newDepartmentList var newDepartmentList = departmentList.Where(x => departmentNameList.Contains(x.Name)).ToList(); //证件号码 var certificatesNumList = enlist.Where(x => !string.IsNullOrEmpty(x.CertificatesNum)).Select(x => x.CertificatesNum.Trim()).ToList(); //教师信息 var staffList = staffDAL.Value.staffRepository.GetList(x => true, (x => x.CF_StaffManageDepartment), (x => x.CF_StaffManageCollege), (x => x.CF_StaffManageCampus), (x => x.CF_StaffProfile), (x => x.Sys_User)).ToList(); //对比后的certificatesNumStaffList var certificatesNumStaffList = staffList.Where(x => certificatesNumList.Contains(x.CertificatesNum)).ToList(); //对比后的newUserIDList var newUserIDList = newUserList.Select(x => x.UserID).ToList(); //对比后的newStaffList var newStaffList = staffList.Where(x => newUserIDList.Contains(x.UserID)).ToList(); //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等) for (int i = 0; i < enlist.Count; i++) { StaffView en = enlist[i]; //Excel表数据视图 Sys_User newUser = new Sys_User(); CF_Staff newStaff = new CF_Staff(); CF_StaffProfile newStaffProfile = new CF_StaffProfile(); //教职工号 if (string.IsNullOrWhiteSpace(en.StaffCode)) { 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.StaffCode.Trim())) { errCount++; errorMsgStr = "教职工号格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newUser.LoginID = en.StaffCode.Trim(); newStaff.StaffCode = en.StaffCode.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 { newStaffProfile.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 { newStaff.SexID = sex.Value; } } //出生日期 if (string.IsNullOrWhiteSpace(en.BirthDateStr)) { //暂不考虑 } 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 { newStaff.BirthDate = Convert.ToDateTime(en.BirthDateStr); } } //民族 if (string.IsNullOrWhiteSpace(en.NationStr)) { //暂不考虑 } 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 { newStaff.NationID = nation.Value; } } //政治面貌 if (string.IsNullOrWhiteSpace(en.PoliticsStr)) { //暂不考虑 } 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 { newStaff.PoliticsID = politics.Value; } } //院系所 if (string.IsNullOrWhiteSpace(en.CollegeName)) { errCount++; errorMsgStr = RSL.Get("College") + "不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var college = newCollegeList.Where(x => x.Name == en.CollegeName.Trim()).SingleOrDefault(); if (college == null) { errCount++; errorMsgStr = RSL.Get("College") + "不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.CollegeID = college.CollegeID; en.CampusID = college.CampusID; } } //所属教研室 if (string.IsNullOrWhiteSpace(en.DepartmentName)) { //暂不考虑 } else { var department = newDepartmentList.Where(x => x.Name == en.DepartmentName.Trim()).SingleOrDefault(); if (department == null) { errCount++; errorMsgStr = "所属教研室不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //判断院系所与所属教研室是否匹配 if (department.CollegeID != newStaff.CollegeID) { errCount++; errorMsgStr = "所属教研室和" + RSL.Get("College") + "不匹配,请核查。"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.DepartmentID = department.DepartmentID; } } } //证件类型 if (string.IsNullOrWhiteSpace(en.CertificatesTypeStr)) { //默认为身份证 newStaff.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 { newStaff.CertificatesType = certificatesType.Value; } } //证件号码 if (string.IsNullOrWhiteSpace(en.CertificatesNum)) { //暂不考虑 } else { if (string.IsNullOrWhiteSpace(en.CertificatesTypeStr)) { 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.CertificatesNum.Trim())) { errCount++; errorMsgStr = "证件号码格式不正确,请检查(数字或英文字母)"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.CertificatesNum = en.CertificatesNum.Trim(); } } } //教师类型 if (string.IsNullOrWhiteSpace(en.TeacherTypeStr)) { errCount++; errorMsgStr = "教师类型不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var teacherType = teacherTypeList.Where(x => x.Name == en.TeacherTypeStr.Trim()).SingleOrDefault(); if (teacherType == null) { errCount++; errorMsgStr = "教师类型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.TeacherTypeID = teacherType.Value; } } //在职状态 if (string.IsNullOrWhiteSpace(en.IncumbencyStateStr)) { errCount++; errorMsgStr = "在职状态不能为空"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { var incumbencyState = incumbencyStateList.Where(x => x.Name == en.IncumbencyStateStr.Trim()).SingleOrDefault(); if (incumbencyState == null) { errCount++; errorMsgStr = "在职状态不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.IncumbencyState = incumbencyState.Value; } } //任课状况 if (string.IsNullOrWhiteSpace(en.SituationStr)) { //暂不考虑 } else { var situation = situationList.Where(x => x.Name == en.SituationStr.Trim()).SingleOrDefault(); if (situation == null) { errCount++; errorMsgStr = "任课状况不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.SituationID = situation.Value; } } //职称 if (string.IsNullOrWhiteSpace(en.TitleStr)) { //暂不考虑 } else { var title = titleList.Where(x => x.Name == en.TitleStr.Trim()).SingleOrDefault(); if (title == null) { errCount++; errorMsgStr = "职称不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.TitleID = title.Value; } } //文化程度 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 { newStaff.LiteracyLevelID = literacyLevel.Value; } } //学位 if (string.IsNullOrWhiteSpace(en.LearnPositionStr)) { //暂不考虑 } else { var learnPosition = learnPositionList.Where(x => x.Name == en.LearnPositionStr.Trim()).SingleOrDefault(); if (learnPosition == null) { errCount++; errorMsgStr = "学位不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.LearnPositionID = learnPosition.Value; } } //是否双师型 if (string.IsNullOrWhiteSpace(en.IsDualTeacherStr)) { newStaff.IsDualTeacher = false; } else { var isDualTeacher = generalPurposeList.Where(x => x.Name == en.IsDualTeacherStr.Trim()).SingleOrDefault(); if (isDualTeacher == null) { errCount++; errorMsgStr = "是否双师型不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.IsDualTeacher = isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes ? true : false; } } //课酬级别 if (string.IsNullOrWhiteSpace(en.PaymentLevelStr)) { //暂不考虑 } else { var paymentLevel = paymentLevelList.Where(x => x.Name == en.PaymentLevelStr.Trim()).SingleOrDefault(); if (paymentLevel == null) { errCount++; errorMsgStr = "课酬级别不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.PaymentLevelID = paymentLevel.Value; } } //国籍 if (string.IsNullOrWhiteSpace(en.Nationality)) { //暂不考虑 } else { newStaffProfile.Nationality = en.Nationality.Trim(); } //籍贯 if (string.IsNullOrWhiteSpace(en.Place)) { //暂不考虑 } else { newStaffProfile.Place = en.Place.Trim(); } //参加工作年月 if (string.IsNullOrWhiteSpace(en.WorkDateStr)) { //暂不考虑 } else { if (!DateTime.TryParse(en.WorkDateStr, out result)) { errCount++; errorMsgStr = "参加工作年月格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.WorkDate = Convert.ToDateTime(en.WorkDateStr); } } //来校年月 if (string.IsNullOrWhiteSpace(en.ComeSchoolDateStr)) { //暂不考虑 } else { if (!DateTime.TryParse(en.ComeSchoolDateStr, out result)) { errCount++; errorMsgStr = "来校年月格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaff.ComeSchoolDate = Convert.ToDateTime(en.ComeSchoolDateStr); } } //电子邮箱 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 { newStaffProfile.Email = en.Email.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 { newStaffProfile.ZIPCode = en.ZIPCode.Trim(); } } //微信号 if (string.IsNullOrWhiteSpace(en.WeChatNum)) { //暂不考虑 } else { newStaffProfile.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 { newStaffProfile.QQ = en.QQ.Trim(); } } //家庭电话 if (string.IsNullOrWhiteSpace(en.Telephone)) { //暂不考虑 } else { newStaffProfile.Telephone = en.Telephone.Trim(); } //办公电话 if (string.IsNullOrWhiteSpace(en.OfficeTelephone)) { //暂不考虑 } else { newStaffProfile.OfficeTelephone = en.OfficeTelephone.Trim(); } //住宅电话 if (string.IsNullOrWhiteSpace(en.HousePhone)) { //暂不考虑 } else { newStaffProfile.HousePhone = en.HousePhone.Trim(); } //移动电话 if (string.IsNullOrWhiteSpace(en.Mobile)) { //暂不考虑 } else { newStaffProfile.Mobile = en.Mobile.Trim(); } //健康状况 if (string.IsNullOrWhiteSpace(en.HealthStateStr)) { newStaffProfile.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 { newStaffProfile.HealthStateID = healthState.Value; } } //宗教信仰 if (string.IsNullOrWhiteSpace(en.ReligionStr)) { //暂不考虑 } else { var religion = religionList.Where(x => x.Name == en.ReligionStr.Trim()).SingleOrDefault(); if (religion == null) { errCount++; errorMsgStr = "宗教信仰不存在,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaffProfile.ReligionID = religion.Value; } } //特长 if (string.IsNullOrWhiteSpace(en.Speciality)) { //暂不考虑 } else { newStaffProfile.Speciality = en.Speciality.Trim(); } //银行卡号 if (string.IsNullOrWhiteSpace(en.Account)) { //暂不考虑 } else { reg = new Regex(@"^[0-9]*$"); //正则表达式 if (!reg.IsMatch(en.Account.Trim())) { errCount++; errorMsgStr = "银行卡号格式不正确,请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { newStaffProfile.Account = en.Account.Trim(); } } //户口所在地 if (string.IsNullOrWhiteSpace(en.Residence)) { //暂不考虑 } else { newStaffProfile.Residence = en.Residence.Trim(); } //家庭住址 if (string.IsNullOrWhiteSpace(en.HomeAddress)) { //暂不考虑 } else { newStaffProfile.HomeAddress = en.HomeAddress.Trim(); } //通信地址 if (string.IsNullOrWhiteSpace(en.Address)) { //暂不考虑 } else { newStaffProfile.Address = en.Address.Trim(); } //现住地址 if (string.IsNullOrWhiteSpace(en.NowAddress)) { //暂不考虑 } else { newStaffProfile.NowAddress = en.NowAddress.Trim(); } //简介 if (string.IsNullOrWhiteSpace(en.Profile)) { //暂不考虑 } else { newStaff.Profile = en.Profile.Trim(); } //备注 if (string.IsNullOrWhiteSpace(en.Remark)) { //暂不考虑 } else { newStaff.Remark = en.Remark.Trim(); } ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉) //for (int j = i + 1; j < enlist.Count; j++) //{ // StaffView enA = enlist[j]; // //根据Excel表中的业务主键进行去重(教职工号或证件号码唯一) // if (en.StaffCode == enA.StaffCode && en.CertificatesNum == enA.CertificatesNum) // { // //用于标识Excel表中的重复记录(由于是批量进行插入数据表) // } //} //数据表重复性验证(教职工号或证件号码唯一) var userVerify = newUserList.Where(x => x.LoginID == newUser.LoginID).SingleOrDefault(); if (userVerify == null) { //判断证件号码 if (!string.IsNullOrEmpty(newStaff.CertificatesNum)) { if (!newStaffUpList.Any(x => x.CertificatesNum == newStaff.CertificatesNum)) { if (!newStaffInList.Any(x => x.CertificatesNum == newStaff.CertificatesNum)) { var certificatesNumVerify = certificatesNumStaffList.Where(x => x.CertificatesNum == newStaff.CertificatesNum).ToList(); if (certificatesNumVerify != null && certificatesNumVerify.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 (!newUserInList.Any(x => x.LoginID == newUser.LoginID)) { newUser.UserID = Guid.NewGuid(); if (teacherInitPassword == null) { newUser.Password = ("A" + newUser.LoginID.Trim()).MD5(); } else { if (teacherInitPassword.Value != null) { newUser.Password = teacherInitPassword.Value; } else { newUser.Password = ("A" + newUser.LoginID.Trim()).MD5(); } } this.SetNewStatus(newUser, (int)SYS_STATUS.USABLE); newUserInList.Add(newUser); newUser.Sys_Role = new HashSet(); if (teacherRoleList != null && teacherRoleList.Count() > 0) { teacherRoleList.ForEach(x => newUser.Sys_Role.Add(x)); } else { //对应角色为空时,默认为不分配用户角色 } newStaff.UserID = newUser.UserID; var staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = newUser.UserID; staffManageCampus.CampusID = en.CampusID; this.SetNewStatus(staffManageCampus); newStaffManageCampusInList.Add(staffManageCampus); var staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = newUser.UserID; staffManageCollege.CollegeID = newStaff.CollegeID; this.SetNewStatus(staffManageCollege); newStaffManageCollegeInList.Add(staffManageCollege); if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = newUser.UserID; staffManageDepartment.DepartmentID = newStaff.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } this.SetNewStatus(newStaff); newStaffInList.Add(newStaff); newStaffProfile.UserID = newStaff.UserID; this.SetNewStatus(newStaffProfile); newStaffProfileInList.Add(newStaffProfile); inCount++; } else { //Excel表重复性验证 //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中) errCount++; errorMsgStr = "教职工号重复(Excel中),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } } else { //更新(判断Excel有重复时,以最后一条记录更新为准) var staffVerify = newStaffList.Where(x => x.UserID == userVerify.UserID).SingleOrDefault(); if (staffVerify == null) { errCount++; errorMsgStr = "教职工号冲突(与其它帐号冲突),请检查"; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); continue; } else { //判断证件号码 if (!string.IsNullOrEmpty(newStaff.CertificatesNum)) { if (!newStaffInList.Any(x => x.CertificatesNum == newStaff.CertificatesNum)) { if (!newStaffUpList.Any(x => x.CertificatesNum == newStaff.CertificatesNum)) { var certificatesNumVerify = certificatesNumStaffList.Where(x => x.UserID != userVerify.UserID && x.CertificatesNum == newStaff.CertificatesNum).ToList(); if (certificatesNumVerify != null && certificatesNumVerify.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; } } staffVerify.Sys_User.LoginID = newUser.LoginID.Trim(); staffVerify.Sys_User.Name = newUser.Name.Trim(); this.SetModifyStatus(staffVerify.Sys_User); newUserUpList.Add(staffVerify.Sys_User); staffVerify.StaffCode = newUser.LoginID.Trim(); if (staffVerify.CollegeID != newStaff.CollegeID) { CampusUserIDDelList.Add(staffVerify.UserID); var staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = staffVerify.UserID; staffManageCampus.CampusID = en.CampusID; this.SetNewStatus(staffManageCampus); newStaffManageCampusInList.Add(staffManageCampus); CollegeUserIDDelList.Add(staffVerify.UserID); var staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = staffVerify.UserID; staffManageCollege.CollegeID = newStaff.CollegeID; this.SetNewStatus(staffManageCollege); newStaffManageCollegeInList.Add(staffManageCollege); DepartmentUserIDDelList.Add(staffVerify.UserID); if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = staffVerify.UserID; staffManageDepartment.DepartmentID = newStaff.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } } else { if (staffVerify.CF_StaffManageCampus.Count() <= 0 || staffVerify.CF_StaffManageCampus == null) { var staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = staffVerify.UserID; staffManageCampus.CampusID = en.CampusID; this.SetNewStatus(staffManageCampus); newStaffManageCampusInList.Add(staffManageCampus); } if (staffVerify.CF_StaffManageCollege.Count() <= 0 || staffVerify.CF_StaffManageCollege == null) { var staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = staffVerify.UserID; staffManageCollege.CollegeID = newStaff.CollegeID; this.SetNewStatus(staffManageCollege); newStaffManageCollegeInList.Add(staffManageCollege); } if (staffVerify.DepartmentID != newStaff.DepartmentID) { DepartmentUserIDDelList.Add(staffVerify.UserID); if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = staffVerify.UserID; staffManageDepartment.DepartmentID = newStaff.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } } else { if (staffVerify.CF_StaffManageDepartment.Count() <= 0 || staffVerify.CF_StaffManageDepartment == null) { if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty) { var staffManageDepartment = new CF_StaffManageDepartment(); staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid(); staffManageDepartment.UserID = staffVerify.UserID; staffManageDepartment.DepartmentID = newStaff.DepartmentID; this.SetNewStatus(staffManageDepartment); newStaffManageDepartmentInList.Add(staffManageDepartment); } } } } staffVerify.CollegeID = newStaff.CollegeID; staffVerify.DepartmentID = newStaff.DepartmentID; staffVerify.SexID = newStaff.SexID; staffVerify.BirthDate = newStaff.BirthDate; staffVerify.NationID = newStaff.NationID; staffVerify.PoliticsID = newStaff.PoliticsID; staffVerify.CertificatesType = newStaff.CertificatesType; staffVerify.CertificatesNum = newStaff.CertificatesNum; staffVerify.TeacherTypeID = newStaff.TeacherTypeID; staffVerify.IncumbencyState = newStaff.IncumbencyState; staffVerify.SituationID = newStaff.SituationID; staffVerify.TitleID = newStaff.TitleID; staffVerify.LiteracyLevelID = newStaff.LiteracyLevelID; staffVerify.LearnPositionID = newStaff.LearnPositionID; staffVerify.IsDualTeacher = newStaff.IsDualTeacher; staffVerify.PaymentLevelID = newStaff.PaymentLevelID; staffVerify.WorkDate = newStaff.WorkDate; staffVerify.ComeSchoolDate = newStaff.ComeSchoolDate; staffVerify.Profile = newStaff.Profile; staffVerify.Remark = newStaff.Remark; this.SetModifyStatus(staffVerify); newStaffUpList.Add(staffVerify); if (staffVerify.CF_StaffProfile == null) { var staffProfile = new CF_StaffProfile(); staffProfile.UserID = staffVerify.UserID; staffProfile.UsedName = newStaffProfile.UsedName; staffProfile.Nationality = newStaffProfile.Nationality; staffProfile.Place = newStaffProfile.Place; staffProfile.Email = newStaffProfile.Email; staffProfile.ZIPCode = newStaffProfile.ZIPCode; staffProfile.WeChatNum = newStaffProfile.WeChatNum; staffProfile.QQ = newStaffProfile.QQ; staffProfile.Telephone = newStaffProfile.Telephone; staffProfile.OfficeTelephone = newStaffProfile.OfficeTelephone; staffProfile.HousePhone = newStaffProfile.HousePhone; staffProfile.Mobile = newStaffProfile.Mobile; staffProfile.Speciality = newStaffProfile.Speciality; staffProfile.HealthStateID = newStaffProfile.HealthStateID; staffProfile.ReligionID = newStaffProfile.ReligionID; staffProfile.Account = newStaffProfile.Account; staffProfile.Residence = newStaffProfile.Residence; staffProfile.HomeAddress = newStaffProfile.HomeAddress; staffProfile.Address = newStaffProfile.Address; staffProfile.NowAddress = newStaffProfile.NowAddress; this.SetNewStatus(staffProfile); newStaffProfileInList.Add(staffProfile); } else { staffVerify.CF_StaffProfile.UsedName = newStaffProfile.UsedName; staffVerify.CF_StaffProfile.Nationality = newStaffProfile.Nationality; staffVerify.CF_StaffProfile.Place = newStaffProfile.Place; staffVerify.CF_StaffProfile.Email = newStaffProfile.Email; staffVerify.CF_StaffProfile.ZIPCode = newStaffProfile.ZIPCode; staffVerify.CF_StaffProfile.WeChatNum = newStaffProfile.WeChatNum; staffVerify.CF_StaffProfile.QQ = newStaffProfile.QQ; staffVerify.CF_StaffProfile.Telephone = newStaffProfile.Telephone; staffVerify.CF_StaffProfile.OfficeTelephone = newStaffProfile.OfficeTelephone; staffVerify.CF_StaffProfile.HousePhone = newStaffProfile.HousePhone; staffVerify.CF_StaffProfile.Mobile = newStaffProfile.Mobile; staffVerify.CF_StaffProfile.Speciality = newStaffProfile.Speciality; staffVerify.CF_StaffProfile.HealthStateID = newStaffProfile.HealthStateID; staffVerify.CF_StaffProfile.ReligionID = newStaffProfile.ReligionID; staffVerify.CF_StaffProfile.Account = newStaffProfile.Account; staffVerify.CF_StaffProfile.Residence = newStaffProfile.Residence; staffVerify.CF_StaffProfile.HomeAddress = newStaffProfile.HomeAddress; staffVerify.CF_StaffProfile.Address = newStaffProfile.Address; staffVerify.CF_StaffProfile.NowAddress = newStaffProfile.NowAddress; this.SetModifyStatus(staffVerify.CF_StaffProfile); newStaffProfileUpList.Add(staffVerify.CF_StaffProfile); } upCount++; } } } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => DepartmentUserIDDelList.Contains(x.UserID)); UnitOfWork.Delete(x => CollegeUserIDDelList.Contains(x.UserID)); UnitOfWork.Delete(x => CampusUserIDDelList.Contains(x.UserID)); UnitOfWork.BulkInsert(newUserInList); UnitOfWork.BulkInsert(newUserInList, (x => x.Sys_Role)); UnitOfWork.BulkInsert(newStaffInList); UnitOfWork.BulkInsert(newStaffProfileInList); UnitOfWork.BulkInsert(newStaffManageCampusInList); UnitOfWork.BulkInsert(newStaffManageCollegeInList); UnitOfWork.BulkInsert(newStaffManageDepartmentInList); if (newUserUpList != null && newUserUpList.Count() > 0) { UnitOfWork.BatchUpdate(newUserUpList); } if (newStaffUpList != null && newStaffUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStaffUpList); } if (newStaffProfileUpList != null && newStaffProfileUpList.Count() > 0) { UnitOfWork.BatchUpdate(newStaffProfileUpList); } ts.Complete(); } errdataList = errList.Distinct().ToList(); //错误列表List } catch (Exception) { throw; } } } }