using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using EMIS.DataLogic.Common.TeacherManagement; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.TeacherManagement; using EMIS.ViewModel; using EMIS.Entities; using Bowin.Common.Linq; using System.Linq.Expressions; using EMIS.CommonLogic.AdministrativeOrgan; using EMIS.Utility; using EMIS.CommonLogic.SystemServices; using Bowin.Common.Utility; using EMIS.ViewModel.Cache; using EMIS.DataLogic.Repositories; using Bowin.Common.DataTime; using EMIS.DataLogic.SystemDAL; namespace EMIS.CommonLogic.TeacherManagement { public class StaffServices : BaseServices, IStaffServices { public Lazy staffDAL { get; set; } public ParameterDAL ParameterDAL { get; set; } public Lazy collegeServices { get; set; } public Lazy userServices { get; set; } public CollegeRepository CollegeRepository { get; set; } public DepartmentRepository DepartmentRepository { get; set; } public Lazy TimeHelper { get; set; } public RoleDAL RoleDAL { get; set; } /// /// 查询教师列表 /// /// 查询条件实体 /// 校区ID /// 学院ID /// 教研室ID /// 是否显示照片 /// 页码 /// 显示码 /// public Bowin.Common.Linq.Entity.IGridResultSet GetStaffViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, Guid? userID, int pageIndex, int pageSize) { var query = staffDAL.Value.GetStaffViewQueryable(x => true); if (campusID.HasValue) query = query.Where(x => x.CampusID == campusID); if (collegeID.HasValue) query = query.Where(x => x.CollegeID == collegeID); if (userID.HasValue) query = query.Where(x => x.UserID == userID); if (departmentID.HasValue) query = query.Where(x => x.DepartmentID == departmentID); if (isPhoto > 0) query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != ""); if (isPhoto == 0) query = query.Where(x => x.PhotoUrl == null || x.PhotoUrl == ""); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } query = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode); try { return query .ToGridResultSet(pageIndex, pageSize); } catch (Exception ex) { throw ex; } } /// /// 查询教师列表 /// /// 查询条件实体 /// 校区ID /// 学院ID /// 教研室ID /// 是否显示照片 /// 页码 /// 显示码 /// public IGridResultSet GetStaffViewGridWithNoDataRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, Guid? userID, int pageIndex, int pageSize) { var query = staffDAL.Value.GetStaffViewQueryable(x => true); if (campusID.HasValue) query = query.Where(x => x.CampusID == campusID); if (collegeID.HasValue) query = query.Where(x => x.CollegeID == collegeID); if (userID.HasValue) query = query.Where(x => x.UserID == userID); if (departmentID.HasValue) query = query.Where(x => x.DepartmentID == departmentID); if (isPhoto > 0) query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != ""); if (isPhoto == 0) query = query.Where(x => x.PhotoUrl == null || x.PhotoUrl == ""); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo) .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode); try { return query .ToGridResultSet(pageIndex, pageSize); } catch (Exception ex) { throw ex; } } public Bowin.Common.Linq.Entity.IGridResultSet GetStaffViewGrid(Guid? campusID, Guid? collegeID, string loginID, string name, int pageIndex, int pageSize) { Expression> exp = (x => true); if (campusID.HasValue) exp = exp.And(x => x.CF_College.CampusID == campusID); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (!string.IsNullOrEmpty(loginID)) exp = exp.And(x => x.Sys_User.LoginID.Contains(loginID)); if (!string.IsNullOrEmpty(name)) exp = exp.And(x => x.Sys_User.Name.Contains(name)); var query = staffDAL.Value.GetStaffViewQueryable(exp); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询教师列表 /// /// 查询条件实体 /// 校区ID /// 学院ID /// 教研室ID /// 是否显示照片 /// public List GetStaffViewList(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto) { var query = staffDAL.Value.GetStaffViewQueryable(x => true); if (campusID.HasValue) query = query.Where(x => x.CampusID == campusID); if (collegeID.HasValue) query = query.Where(x => x.CollegeID == collegeID); if (departmentID.HasValue) query = query.Where(x => x.DepartmentID == departmentID); if (isPhoto > 0) query = query.Where(x => x.PhotoUrl != null && x.PhotoUrl != ""); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length) .ThenBy(x => x.CollegeNo).ThenBy(x => x.StaffCode.Length) .ThenBy(x => x.StaffCode).ToList(); } /// /// 获取全部教师列表详细信息 /// /// public List GetListStaffView() { var query = staffDAL.Value.GetStaffViewQueryable(x => true); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode) .ToList(); } /// /// 获取全部教师主表列表信息 /// /// public List GetStaffList() { return this.GetQueryByDataRangeByCollege(staffDAL.Value.staffRepository.Entities) .OrderBy(x => x.Sys_User.LoginID.Length).ThenBy(x => x.Sys_User.LoginID) .ToList(); } /// /// 获取教师主表信息 /// /// 用户ID /// public Entities.CF_Staff GetStaff(Guid? userID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.UserID == userID); return staffDAL.Value.staffRepository.GetSingle(expression, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffProfile), (x => x.Sys_User)); } /// /// 获取教师主表信息 /// /// Expression查询条件 /// public Entities.CF_Staff GetStaff(System.Linq.Expressions.Expression> exp) { return staffDAL.Value.staffRepository.GetSingle(exp); } /// /// 获取教师扩展表信息 /// /// 用户ID /// public Entities.CF_StaffProfile GetStaffProfile(Guid? userID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => true); if (userID.HasValue) expression = (x => x.UserID == userID); return staffDAL.Value.staffProfileRepository.GetSingle(expression); } /// /// 获取教师详细信息 /// /// 用户ID /// public ViewModel.TeacherManagement.StaffView GetStaffView(Guid? userID) { var query = staffDAL.Value.GetStaffViewQueryable(x => true); if (userID.HasValue) query = query.Where(x => x.UserID == userID); return query.FirstOrDefault(); } /// /// 获取教师详细信息 /// /// Expression查询条件 /// public ViewModel.TeacherManagement.StaffView GetStaffView(System.Linq.Expressions.Expression> exp) { var query = staffDAL.Value.GetStaffViewQueryable(exp); return query.FirstOrDefault(); } /// /// 添加 /// /// 主表实体 /// 扩展表实体 /// public void StaffAdd(StaffView staffView, string photoUrl) { try { Sys_User sys_user = new Sys_User(); CF_Staff staff = new CF_Staff(); CF_StaffProfile staffProfile = new CF_StaffProfile(); CF_Department department = new CF_Department(); CF_College college = collegeServices.Value.GetCollegeInfo(staffView.CollegeID); var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.TeacherInitPassword); if (staffView.UserID == null || staffView.UserID == Guid.Empty) { sys_user.UserID = Guid.NewGuid(); sys_user.LoginID = staffView.StaffCode; sys_user.Name = staffView.Name; if (parameter == null) { sys_user.Password = ("A" + staffView.StaffCode).MD5(); } else { if (parameter.Value != null) { sys_user.Password = parameter.Value; } else { sys_user.Password = ("A" + staffView.StaffCode).MD5(); } } //sys_user.Password = Const.USER_INIT_PASSWORD; SetNewStatus(sys_user); UnitOfWork.Add(sys_user); var role = RoleDAL.RoleRepository.GetSingle(x => x.RoleName.Contains("教师")); if (role != null) { sys_user.Sys_Role.Add(role); } staff.UserID = sys_user.UserID; staff.DepartmentID = staffView.DepartmentID; staff.CollegeID = staffView.CollegeID; staff.StaffCode = staffView.StaffCode; if (staffView.BirthDate == null) { staff.BirthDate = DateTime.Now; } else { staff.BirthDate = staffView.BirthDate; } staff.Sex = staffView.Sex; staff.TeacherType = staffView.TeacherType; staff.IncumbencyState = staffView.IncumbencyState; staff.CertificatesType = staffView.CertificatesType; staff.CertificatesNum = staffView.CertificatesNum; staff.Situation = staffView.Situation; staff.LiteracyLevels = staffView.LiteracyLevels; staff.DegreeState = staffView.DegreeState; staff.LearnPosition = staffView.LearnPosition; staff.Title = staffView.Title; staff.WorkDate = staffView.WorkDate; staff.ComeSchoolDate = staffView.ComeSchoolDate; staff.TeachingDate = staffView.TeachingDate; if (!string.IsNullOrEmpty(photoUrl)) { staff.PhotoUrl = photoUrl; } staff.Profile = staffView.Profile; staff.Remarks = staffView.Remarks; staff.PaymentLevelID = staffView.PaymentLevelID; staff.IsDualTeacher = staffView.IsDualTeacher; SetNewStatus(staff); UnitOfWork.Add(staff); staffProfile.UserID = sys_user.UserID; staffProfile.UsedName = staffView.UsedName; staffProfile.Nation = staffView.Nation; staffProfile.Place = staffView.Place; staffProfile.EducationCode = staffView.EducationCode; staffProfile.Telephone = staffView.Telephone; staffProfile.OfficeTelephone = staffView.OfficeTelephone; staffProfile.Mobile = staffView.Mobile; staffProfile.Email = staffView.Email; staffProfile.QQ = staffView.QQ; staffProfile.Nationality = staffView.Nationality; staffProfile.HealthState = staffView.HealthState; staffProfile.HousePhone = staffView.HousePhone; staffProfile.Address = staffView.Address; staffProfile.Postcode = staffView.Postcode; staffProfile.HomeAddress = staffView.HomeAddress; staffProfile.NowAddress = staffView.NowAddress; staffProfile.Residence = staffView.Residence; staffProfile.Speciality = staffView.Speciality; staffProfile.WeChatNum = staffView.WeChatNum; staffProfile.Religion = staffView.Religion; staffProfile.Account = staffView.Account; UnitOfWork.Add(staffProfile); CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = sys_user.UserID; staffManageCampus.CampusID = college.CampusID; this.SetNewStatus(staffManageCampus); this.UnitOfWork.Add(staffManageCampus); CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = sys_user.UserID; staffManageCollege.CollegeID = staff.CollegeID; this.SetNewStatus(staffManageCollege); this.UnitOfWork.Add(staffManageCollege); } else { sys_user = userServices.Value.GetUserByID(staffView.UserID); staff = GetStaff(staffView.UserID); staffProfile = staff.CF_StaffProfile; sys_user.Name = staffView.Name; sys_user.LoginID = staffView.StaffCode; SetModifyStatus(sys_user); var lastCollegeID = staff.CollegeID; staff.DepartmentID = staffView.DepartmentID; staff.CollegeID = staffView.CollegeID; staff.StaffCode = staffView.StaffCode; staff.BirthDate = staffView.BirthDate; staff.Sex = staffView.Sex; staff.TeacherType = staffView.TeacherType; staff.IncumbencyState = staffView.IncumbencyState; staff.CertificatesType = staffView.CertificatesType; staff.CertificatesNum = staffView.CertificatesNum; staff.Situation = staffView.Situation; staff.LiteracyLevels = staffView.LiteracyLevels; staff.DegreeState = staffView.DegreeState; staff.LearnPosition = staffView.LearnPosition; staff.Title = staffView.Title; staff.WorkDate = staffView.WorkDate; staff.ComeSchoolDate = staffView.ComeSchoolDate; staff.TeachingDate = staffView.TeachingDate; if (photoUrl != null) { staff.PhotoUrl = photoUrl; } staff.Profile = staffView.Profile; staff.Remarks = staffView.Remarks; staff.PaymentLevelID = staffView.PaymentLevelID; staff.IsDualTeacher = staffView.IsDualTeacher; SetModifyStatus(staff); if (lastCollegeID != college.CollegeID) { staff.CF_StaffManageCampus = new HashSet(); staff.CF_StaffManageCollege = new HashSet(); CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = sys_user.UserID; staffManageCampus.CampusID = college.CampusID; this.SetNewStatus(staffManageCampus); this.UnitOfWork.Add(staffManageCampus); CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = sys_user.UserID; staffManageCollege.CollegeID = staff.CollegeID; this.SetNewStatus(staffManageCollege); this.UnitOfWork.Add(staffManageCollege); } if (staffProfile == null) { staffProfile = new CF_StaffProfile(); UnitOfWork.Add(staffProfile); } staffProfile.UserID = staff.UserID; staffProfile.UsedName = staffView.UsedName; staffProfile.Nation = staffView.Nation; staffProfile.Place = staffView.Place; staffProfile.EducationCode = staffView.EducationCode; staffProfile.Telephone = staffView.Telephone; staffProfile.OfficeTelephone = staffView.OfficeTelephone; staffProfile.Mobile = staffView.Mobile; staffProfile.Email = staffView.Email; staffProfile.QQ = staffView.QQ; staffProfile.Nationality = staffView.Nationality; staffProfile.HealthState = staffView.HealthState; staffProfile.HousePhone = staffView.HousePhone; staffProfile.Address = staffView.Address; staffProfile.Postcode = staffView.Postcode; staffProfile.HomeAddress = staffView.HomeAddress; staffProfile.NowAddress = staffView.NowAddress; staffProfile.Residence = staffView.Residence; staffProfile.Speciality = staffView.Speciality; staffProfile.WeChatNum = staffView.WeChatNum; staffProfile.Religion = staffView.Religion; staffProfile.Account = staffView.Account; } UnitOfWork.Commit(); } catch (Exception) { throw; } } /// /// 删除 /// /// /// public bool StaffDelete(List userIDs) { try { var staffList = staffDAL.Value.staffRepository.GetList(x => userIDs.Contains(x.UserID), (x => x.CF_StaffProfile), (x => x.Sys_User.Sys_Role)).ToList(); var UserList=staffDAL.Value.UserRepository.GetList(x => userIDs.Contains(x.UserID)).ToList(); UnitOfWork.Delete(staffList); UnitOfWork.Delete( UserList, (x=>x.Sys_Role)); UnitOfWork.Delete(UserList); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 获取全部教师列表详细信息 /// /// public List GetListStaffView(Guid? userID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (userID.HasValue) expression = (x => x.UserID == userID); var query = staffDAL.Value.GetStaffViewQueryable(expression); return query.ToList(); } /// /// 获取全部教师不带数据范围 /// /// public Bowin.Common.Linq.Entity.IGridResultSet GetAllStaffView(ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize) { //查询条件 System.Linq.Expressions.Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = staffDAL.Value.GetStaffViewQueryable(expression); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ToGridResultSet(pageIndex, pageSize); } /// /// 教师信息验证 /// /// 教职工ID /// 代码 /// public string GetVerification(Guid? userID, string Code, Guid? CollegeID, Guid? DepartmentID) { if (!DepartmentRepository.Entities.Any(x => x.CollegeID == CollegeID && x.DepartmentID == DepartmentID) && DepartmentID != null) { return ("教研室和" + RSL.Get("College") + "不匹配。"); } Sys_User userNo = null; Sys_User userInfo = null; if (!string.IsNullOrEmpty(Code)) { userNo = userServices.Value.GetUserByLoginID(Code.Trim()); if (!string.IsNullOrEmpty(Code) && userID != Guid.Empty) { userInfo = GetStaff(userID).Sys_User; if (userNo == userInfo) return "成功。"; else { if (userNo != null) return "保存失败,教职工号已存在。"; } } else { if (userNo != null) return "保存失败,教职工号已存在。"; } } if (userID.HasValue && userID != Guid.Empty) { userInfo = GetStaff(userID).Sys_User; if (userInfo == null) return "保存失败,数据有误,请核查。"; } return "成功。"; } public void DeletePhoto(Guid userID) { var staff = this.GetStaff(userID); if (!string.IsNullOrEmpty(staff.PhotoUrl)) { FileUploadHelper.DeleteFile(staff.PhotoUrl); staff.PhotoUrl = null; this.UnitOfWork.Commit(); } } /// /// 教师信息导入 /// /// 导入的数据集合 /// 返回的操作失败集合 /// 操作成功记录条数 /// public virtual void StaffImport(out int OkCount, out List errdataList, out int successCount, string sourcePhysicalPath,string sourceWebPath,out string errorWebPath,out string Errinfo) { var excel = new NpoiExcelHelper(); #region 1.0 单元格抬头 Dictionary cellheader = new Dictionary { { "StaffCode", "教职工号" }, { "Name", "姓名" }, { "CollegeName", RSL.Get("College") },{ "TeachingDateStr", "从教年月" }, { "DepartmentName", "教研室" },{ "BirthDateStr", "出生日期" }, { "IncumbencyStateStr", "在职状态" },{ "TeacherTypeStr", "教师类型" }, { "SexStr", "性别" },{ "UsedName", "曾用名" },// { "Politics", "政治面貌" }, { "NationStr", "民族" },{ "Place", "籍贯" }, {"EducationCodeStr","学历"},{ "Telephone", "家庭电话" }, { "OfficeTelephone", "办公电话" },{ "Mobile", "移动电话" }, { "Email", "电子邮箱" },{ "QQ", "QQ" }, { "Nationality", "国籍" }, { "HealthStateStr", "健康状态" }, {"HousePhone","住宅电话"},{ "Address", "通信地址" }, { "Postcode", "邮政编码" }, { "HomeAddress", "家族住址" }, { "NowAddress", "现住地址" },{ "Residence", "户口所在地" }, { "ReligionStr", "宗教信仰" }, { "CertificatesTypeStr", "证件类型" }, { "CertificatesNum", "证件号码" },{ "SituationStr", "任课状况名称" }, { "LiteracyLevelsStr", "文化程度" }, { "DegreeStateStr", "学位状况" }, { "LearnPositionStr", "学位" },{ "TitleStr", "职称" }, { "PaymentLevelStr", "课酬级别" },{ "IsDualTeacherStr", "是否双师型教师" }, { "WorkDateStr", "参加工作年月" }, { "ComeSchoolDateStr", "来校年月" }, { "Speciality", "特长" },{ "WeChatNum", "微信号码" }, { "Profile", "简介" },{ "Remarks", "备注" } , { "ErrorMessage", "错误信息" } }; #endregion StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); DataTimeHelper dth = new DataTimeHelper(); #region 1.1解析文件,存放到一个List集合里 // 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要 List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "错误信息");//还原字典项 #endregion #region 1.2 将Excel数据写入数据库中 #region 1.2.1 对List集合进行有效性校验 if (enlist.Count() <= 0) { throw new Exception("请填写Excel模板信息数据。"); } #region 1.2.1.1检测必填项是否必填 for (int i = 0; i < enlist.Count; i++) { StaffView en = enlist[i]; string errorMsgStr = "第" + (i + 2) + "行数据检测异常:"; bool isHaveNoInputValue = false; // 是否含有未输入项 if (string.IsNullOrEmpty(en.StaffCode)) { errorMsgStr += "教职工号不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.BirthDateStr)) { errorMsgStr += "出生日期不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.Name)) { errorMsgStr += "姓名不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.CollegeName)) { errorMsgStr += RSL.Get("College") + "不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.SexStr)) { errorMsgStr += "性别不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.TeacherTypeStr)) { errorMsgStr += "教师类型不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.IncumbencyStateStr)) { errorMsgStr += "在职状态不能为空;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } DateTime BirthDate; if (!string.IsNullOrEmpty(en.BirthDateStr)) { if (!DateTime.TryParse(en.BirthDateStr, out BirthDate)) { errorMsgStr += "出生日期填写错误;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } if (!string.IsNullOrEmpty(en.TeachingDateStr)) { if (!DateTime.TryParse(en.TeachingDateStr, out BirthDate)) { errorMsgStr += "从教年月填写错误;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } if (!string.IsNullOrEmpty(en.ComeSchoolDateStr)) { if (!DateTime.TryParse(en.ComeSchoolDateStr, out BirthDate)) { errorMsgStr += "来校年月填写错误;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } if (!string.IsNullOrEmpty(en.WorkDateStr)) { if(!DateTime.TryParse(en.WorkDateStr,out BirthDate) ) { errorMsgStr += "参加工作年月填写错误;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #region 1.2.1.2 检测(数据唯一性、) #region 教研室 if (!string.IsNullOrEmpty(en.DepartmentName)) { if (!DepartmentRepository.Entities.Any(x => x.Name == en.DepartmentName.Trim())) { errorMsgStr += "教研室不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 在职状态 if (!string.IsNullOrEmpty(en.IncumbencyStateStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_IncumbencyState.ToString()) .Any(x => x.Name == en.IncumbencyStateStr.Trim())) { errorMsgStr += "在职状态不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 政治面貌 由于教职工表暂时没有政治面貌字段、先行屏蔽 //if (!string.IsNullOrEmpty(en.Politics)) //{ // if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics.ToString()) // .Any(x => x.Name == en.Politics.Trim())) // { // errorMsgStr += "政治面貌不存在;"; // en.ErrorMessage = errorMsgStr; // isHaveNoInputValue = true; // } //} #endregion #region 教师类型 if (!string.IsNullOrEmpty(en.TeacherTypeStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeacherType.ToString()) .Any(x => x.Name == en.TeacherTypeStr.Trim())) { errorMsgStr += "教师类型不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 性别 if (!string.IsNullOrEmpty(en.SexStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex.ToString()) .Any(x => x.Name == en.SexStr.Trim())) { errorMsgStr += "性别不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 民族 if (!string.IsNullOrEmpty(en.NationStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation.ToString()) .Any(x => x.Name == en.NationStr.Trim())) { errorMsgStr += "民族不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 学历 if (!string.IsNullOrEmpty(en.EducationCodeStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationCode.ToString()) .Any(x => x.Name == en.EducationCodeStr.Trim())) { errorMsgStr += "学历不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 健康状况 if (!string.IsNullOrEmpty(en.HealthStateStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState.ToString()) .Any(x => x.Name == en.HealthStateStr.Trim())) { errorMsgStr += "健康状况不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 宗教信仰 if (!string.IsNullOrEmpty(en.ReligionStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Religion.ToString()) .Any(x => x.Name == en.ReligionStr.Trim())) { errorMsgStr += "宗教信仰不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 证件类型 if (!string.IsNullOrEmpty(en.CertificatesTypeStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType.ToString()) .Any(x => x.Name == en.CertificatesTypeStr.Trim())) { errorMsgStr += "证件类型不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 任课状况 if (!string.IsNullOrEmpty(en.SituationStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Situation.ToString()) .Any(x => x.Name == en.SituationStr.Trim())) { errorMsgStr += "任课类型不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 文化程度 if (!string.IsNullOrEmpty(en.LiteracyLevelsStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevels.ToString()) .Any(x => x.Name == en.LiteracyLevelsStr.Trim())) { errorMsgStr += "文化程度不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 学位状况 if (!string.IsNullOrEmpty(en.DegreeStateStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_DegreeState.ToString()) .Any(x => x.Name == en.DegreeStateStr.Trim())) { errorMsgStr += "学位状态不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 学位 if (!string.IsNullOrEmpty(en.LearnPositionStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition.ToString()) .Any(x => x.Name == en.LearnPositionStr.Trim())) { errorMsgStr += "学位不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 学历 if (!string.IsNullOrEmpty(en.EducationCodeStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationCode.ToString()) .Any(x => x.Name == en.EducationCodeStr.Trim())) { errorMsgStr += "学历不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 职称 if (!string.IsNullOrEmpty(en.TitleStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_Title.ToString()) .Any(x => x.Name == en.TitleStr.Trim())) { errorMsgStr += "职称不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 课酬级别 if (!string.IsNullOrEmpty(en.PaymentLevelStr)) { if (!IdNameExt.GetDictionaryItem(DictionaryItem.TP_PaymentLevel.ToString()) .Any(x => x.Name == en.PaymentLevelStr.Trim())) { errorMsgStr += "课酬级别不存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 院系名称检查 if (!string.IsNullOrEmpty(en.CollegeName)) { if (CollegeRepository.GetList(x => x.Name == en.CollegeName.Trim()).FirstOrDefault() == null) { errorMsgStr += RSL.Get("College") + "填写不正确;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #region 教职工号检查 if (!string.IsNullOrEmpty(en.StaffCode)) { if (staffDAL.Value.staffRepository.GetList(x => x.StaffCode == en.StaffCode.Trim()).Count() > 0) { errorMsgStr += "教职工号已存在;"; en.ErrorMessage = errorMsgStr; isHaveNoInputValue = true; } } #endregion #endregion if (isHaveNoInputValue) // 若必填项有值未填 { en.IsExcelVaildateOK = false; en.ErrorMessage = errorMsgStr; errList.Add(en); errorMsg.AppendLine(errorMsgStr); } } #endregion // TODO:其他检测 #region 1.2.1.3 循环写入验证成功的数据 List staffList = new List(); List userList = new List(); List staffProfileList = new List(); List staffManageCampusList = new List(); List staffManageCollegeList = new List(); for (int i = 0; i < enlist.Count; i++) { StaffView enA = enlist[i]; if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证 { continue; } //for (int j = i + 1; j < enlist.Count; j++) //{ // StaffView enB = enlist[j]; // // 判断必填列是否全部重复 // if (enA.StaffCode == enB.StaffCode) // { // enA.IsExcelVaildateOK = false; // enB.IsExcelVaildateOK = false; // enA.ErrorMessage = "第" + (i + 2) + "行与第" + (j + 2) + "行的必填列重复了"; // errList.Add(enA); // } //} try { //先删除旧数据、重新创建新数据 Sys_User sys_user = new Sys_User(); CF_Staff staff = new CF_Staff(); CF_StaffProfile staffProfile = new CF_StaffProfile(); if (enA != null) //有数据开始组装数据 { sys_user.UserID = Guid.NewGuid(); sys_user.LoginID = enA.StaffCode.Trim(); sys_user.Name = enA.Name; sys_user.Password = Const.USER_INIT_PASSWORD; SetNewStatus(sys_user); userList.Add(sys_user); // UnitOfWork.Add(sys_user); staff.UserID = sys_user.UserID; if (!string.IsNullOrEmpty(enA.DepartmentName)) { CF_Department department = DepartmentRepository.GetList(x => x.Name == enA.DepartmentName.Trim()).FirstOrDefault(); if (department != null) { staff.DepartmentID = department.DepartmentID; } } CF_College college = CollegeRepository.GetList(x => x.Name == enA.CollegeName.Trim()).FirstOrDefault(); staff.CollegeID = college.CollegeID; staff.StaffCode = enA.StaffCode.Trim(); if (!string.IsNullOrEmpty(enA.BirthDateStr)) { if (dth.ToDateTimeValue(enA.BirthDateStr) != string.Empty) staff.BirthDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.BirthDateStr)); else staff.BirthDate = Convert.ToDateTime(enA.BirthDateStr); } if (!string.IsNullOrEmpty(enA.TeachingDateStr)) { if (dth.ToDateTimeValue(enA.TeachingDateStr) != string.Empty) staff.TeachingDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.TeachingDateStr)); else staff.TeachingDate = Convert.ToDateTime(enA.TeachingDateStr); } if (!string.IsNullOrEmpty(enA.ComeSchoolDateStr)) { if (dth.ToDateTimeValue(enA.ComeSchoolDateStr) != string.Empty) staff.ComeSchoolDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.ComeSchoolDateStr)); else staff.ComeSchoolDate = Convert.ToDateTime(enA.ComeSchoolDateStr); } if (!string.IsNullOrEmpty(enA.WorkDateStr)) { if (dth.ToDateTimeValue(enA.WorkDateStr) != string.Empty) staff.WorkDate = Convert.ToDateTime(dth.ToDateTimeValue(enA.WorkDateStr)); else staff.WorkDate = Convert.ToDateTime(enA.WorkDateStr); } if (!string.IsNullOrEmpty(enA.SexStr)) { staff.Sex = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex.ToString()) .Where(x => x.Name == enA.SexStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.TeacherTypeStr)) { staff.TeacherType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeacherType.ToString()) .Where(x => x.Name == enA.TeacherTypeStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.IncumbencyStateStr)) { staff.IncumbencyState = IdNameExt.GetDictionaryItem(DictionaryItem.CF_IncumbencyState.ToString()) .Where(x => x.Name == enA.IncumbencyStateStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.CertificatesTypeStr)) { staff.CertificatesType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType.ToString()) .Where(x => x.Name == enA.CertificatesTypeStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.LiteracyLevelsStr)) { staff.LiteracyLevels = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevels.ToString()) .Where(x => x.Name == enA.LiteracyLevelsStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.SituationStr)) { staff.Situation = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Situation.ToString()) .Where(x => x.Name == enA.SituationStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.DegreeStateStr)) { staff.DegreeState = IdNameExt.GetDictionaryItem(DictionaryItem.CF_DegreeState.ToString()) .Where(x => x.Name == enA.DegreeStateStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.LearnPositionStr)) { staff.LearnPosition = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition.ToString()) .Where(x => x.Name == enA.LearnPositionStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.TitleStr)) { staff.Title = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Title.ToString()) .Where(x => x.Name == enA.TitleStr.Trim()).FirstOrDefault().Value; } if (!string.IsNullOrEmpty(enA.PaymentLevelStr)) { staff.PaymentLevelID = IdNameExt.GetDictionaryItem(DictionaryItem.TP_PaymentLevel.ToString()) .Where(x => x.Name == enA.PaymentLevelStr.Trim()).FirstOrDefault().Value; } staff.IsDualTeacher = (enA.IsDualTeacherStr.Trim() == "是"); staff.CertificatesNum = enA.CertificatesNum; if (!string.IsNullOrEmpty(enA.PhotoUrl)) { staff.PhotoUrl = enA.PhotoUrl; } staff.Profile = enA.Profile; staff.Remarks = enA.Remarks; SetNewStatus(staff); staffList.Add(staff); // UnitOfWork.Add(staff); staffProfile.UserID = sys_user.UserID; staffProfile.UsedName = enA.UsedName; if (!string.IsNullOrEmpty(enA.NationStr)) { staffProfile.Nation = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation.ToString()) .Where(x => x.Name == enA.NationStr.Trim()).FirstOrDefault().Value; } // staffProfile.Nation = enA.Nation; staffProfile.Place = enA.Place; if (!string.IsNullOrEmpty(enA.EducationCodeStr)) { staffProfile.EducationCode = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EducationCode.ToString()) .Where(x => x.Name == enA.EducationCodeStr.Trim()).FirstOrDefault().Value; } // staffProfile.EducationCode = enA.EducationCode; staffProfile.Telephone = enA.Telephone; staffProfile.OfficeTelephone = enA.OfficeTelephone; staffProfile.Mobile = enA.Mobile; staffProfile.Email = enA.Email; staffProfile.QQ = enA.QQ; staffProfile.Nationality = enA.Nationality; if (!string.IsNullOrEmpty(enA.HealthStateStr)) { staffProfile.HealthState = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState.ToString()) .Where(x => x.Name == enA.HealthStateStr.Trim()).FirstOrDefault().Value; } //staffProfile.HealthState = enA.HealthState; staffProfile.HousePhone = enA.HousePhone; staffProfile.Address = enA.Address; staffProfile.Postcode = enA.Postcode; staffProfile.HomeAddress = enA.HomeAddress; staffProfile.NowAddress = enA.NowAddress; staffProfile.Residence = enA.Residence; staffProfile.Speciality = enA.Speciality; staffProfile.WeChatNum = enA.WeChatNum; if (!string.IsNullOrEmpty(enA.ReligionStr)) { staffProfile.Religion = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Religion.ToString()) .Where(x => x.Name == enA.ReligionStr.Trim()).FirstOrDefault().Value; } // staffProfile.Religion = enA.Religion; // UnitOfWork.Add(staffProfile); staffProfileList.Add(staffProfile); CF_StaffManageCampus staffManageCampus = new CF_StaffManageCampus(); staffManageCampus.StaffManageCampusID = Guid.NewGuid(); staffManageCampus.UserID = sys_user.UserID; staffManageCampus.CampusID = college.CampusID; this.SetNewStatus(staffManageCampus); staffManageCampusList.Add(staffManageCampus); // this.UnitOfWork.Add(staffManageCampus); CF_StaffManageCollege staffManageCollege = new CF_StaffManageCollege(); staffManageCollege.StaffManageCollegeID = Guid.NewGuid(); staffManageCollege.UserID = sys_user.UserID; staffManageCollege.CollegeID = staff.CollegeID; this.SetNewStatus(staffManageCollege); staffManageCollegeList.Add(staffManageCollege); // this.UnitOfWork.Add(staffManageCollege); } } catch (Exception) { throw; } } #endregion if (userList.Count() > 0) { userList.ForEach(w => { UnitOfWork.Delete(x => x.LoginID == w.LoginID);//插入前先删除一次 }); } #region 教师信息统一写入 UnitOfWork.BulkInsert(userList);//统一写入 UnitOfWork.BulkInsert(staffList);//统一写入 UnitOfWork.BulkInsert(staffProfileList);//统一写入 UnitOfWork.BulkInsert(staffManageCampusList);//统一写入 UnitOfWork.BulkInsert(staffManageCollegeList);//统一写入 #endregion #endregion #endregion #region 1.3 返回各项数据值 errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教师信息操作失败文件", sourceWebPath)); successCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数 errdataList = errList.Distinct().ToList(); OkCount = errList.Distinct().Count(); Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", successCount < 1 ? 0 : successCount, OkCount < 1 ? 0 : OkCount); #endregion } /// /// 教师自己信息保存 /// /// public void UpdateForSelf(StaffView staffView) { try { Sys_User sys_user = new Sys_User(); CF_Staff staff = new CF_Staff(); CF_StaffProfile staffProfile = new CF_StaffProfile(); //CF_Department department = new CF_Department(); //CF_College college = collegeServices.Value.GetCollegeInfo(staffView.CollegeID); //var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.TeacherInitPassword); sys_user = userServices.Value.GetUserByID(staffView.UserID); staff = GetStaff(staffView.UserID); staffProfile = staff.CF_StaffProfile; //sys_user.Name = staffView.Name; //sys_user.LoginID = staffView.StaffCode; SetModifyStatus(sys_user); staff.DepartmentID = staffView.DepartmentID; //staff.CollegeID = staffView.CollegeID; //staff.StaffCode = staffView.StaffCode; //staff.BirthDate = staffView.BirthDate; //staff.Sex = staffView.Sex; //staff.TeacherType = staffView.TeacherType; //staff.IncumbencyState = staffView.IncumbencyState; staff.CertificatesType = staffView.CertificatesType; staff.CertificatesNum = staffView.CertificatesNum; staff.Situation = staffView.Situation; staff.LiteracyLevels = staffView.LiteracyLevels; staff.DegreeState = staffView.DegreeState; staff.LearnPosition = staffView.LearnPosition; staff.WorkDate = staffView.WorkDate; staff.ComeSchoolDate = staffView.ComeSchoolDate; staff.TeachingDate = staffView.TeachingDate; staff.Profile = staffView.Profile; staff.Remarks = staffView.Remarks; SetModifyStatus(staff); if (staffProfile == null) { staffProfile = new CF_StaffProfile(); UnitOfWork.Add(staffProfile); } staffProfile.UserID = staff.UserID; staffProfile.UsedName = staffView.UsedName; staffProfile.Nation = staffView.Nation; staffProfile.Place = staffView.Place; staffProfile.EducationCode = staffView.EducationCode; staffProfile.Telephone = staffView.Telephone; staffProfile.OfficeTelephone = staffView.OfficeTelephone; staffProfile.Mobile = staffView.Mobile; staffProfile.Email = staffView.Email; staffProfile.QQ = staffView.QQ; staffProfile.Nationality = staffView.Nationality; staffProfile.HealthState = staffView.HealthState; staffProfile.HousePhone = staffView.HousePhone; staffProfile.Address = staffView.Address; staffProfile.Postcode = staffView.Postcode; staffProfile.HomeAddress = staffView.HomeAddress; staffProfile.NowAddress = staffView.NowAddress; staffProfile.Residence = staffView.Residence; staffProfile.Speciality = staffView.Speciality; staffProfile.WeChatNum = staffView.WeChatNum; staffProfile.Religion = staffView.Religion; staffProfile.Account = staffView.Account; UnitOfWork.Commit(); } catch (Exception) { throw; } } } }