12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352 |
- 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> staffDAL { get; set; }
- public ParameterDAL ParameterDAL { get; set; }
- public Lazy<ICollegeServices> collegeServices { get; set; }
- public Lazy<IUserServices> userServices { get; set; }
- public CollegeRepository CollegeRepository { get; set; }
- public DepartmentRepository DepartmentRepository { get; set; }
- public Lazy<DataTimeHelper> TimeHelper { get; set; }
- public RoleDAL RoleDAL { get; set; }
- /// <summary>
- /// 查询教师列表
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="campusID">校区ID</param>
- /// <param name="collegeID">学院ID</param>
- /// <param name="DepartmentID">教研室ID</param>
- /// <param name="isPhoto">是否显示照片</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示码</param>
- /// <returns></returns>
- public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.TeacherManagement.StaffView> 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<StaffView>(pageIndex, pageSize);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 查询教师列表
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="campusID">校区ID</param>
- /// <param name="collegeID">学院ID</param>
- /// <param name="DepartmentID">教研室ID</param>
- /// <param name="isPhoto">是否显示照片</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示码</param>
- /// <returns></returns>
- public IGridResultSet<StaffView> 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<StaffView>(pageIndex, pageSize);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.TeacherManagement.StaffView> GetStaffViewGrid(Guid? campusID, Guid? collegeID, string loginID, string name, int pageIndex, int pageSize)
- {
- Expression<Func<CF_Staff, bool>> 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<StaffView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询教师列表
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="campusID">校区ID</param>
- /// <param name="collegeID">学院ID</param>
- /// <param name="DepartmentID">教研室ID</param>
- /// <param name="isPhoto">是否显示照片</param>
- /// <returns></returns>
- public List<ViewModel.TeacherManagement.StaffView> 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();
- }
- /// <summary>
- /// 获取全部教师列表详细信息
- /// </summary>
- /// <returns></returns>
- public List<ViewModel.TeacherManagement.StaffView> GetListStaffView()
- {
- var query = staffDAL.Value.GetStaffViewQueryable(x => true);
- return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode)
- .ToList();
- }
- /// <summary>
- /// 获取全部教师主表列表信息
- /// </summary>
- /// <returns></returns>
- public List<Entities.CF_Staff> GetStaffList()
- {
- return this.GetQueryByDataRangeByCollege(staffDAL.Value.staffRepository.Entities)
- .OrderBy(x => x.Sys_User.LoginID.Length).ThenBy(x => x.Sys_User.LoginID)
- .ToList();
- }
- /// <summary>
- /// 获取教师主表信息
- /// </summary>
- /// <param name="userID">用户ID</param>
- /// <returns></returns>
- public Entities.CF_Staff GetStaff(Guid? userID)
- {
- //查询条件
- System.Linq.Expressions.Expression<Func<CF_Staff, bool>> 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));
- }
- /// <summary>
- /// 获取教师主表信息
- /// </summary>
- /// <param name="userID">Expression查询条件</param>
- /// <returns></returns>
- public Entities.CF_Staff GetStaff(System.Linq.Expressions.Expression<Func<Entities.CF_Staff, bool>> exp)
- {
- return staffDAL.Value.staffRepository.GetSingle(exp);
- }
- /// <summary>
- /// 获取教师扩展表信息
- /// </summary>
- /// <param name="userID">用户ID</param>
- /// <returns></returns>
- public Entities.CF_StaffProfile GetStaffProfile(Guid? userID)
- {
- //查询条件
- System.Linq.Expressions.Expression<Func<CF_StaffProfile, bool>> expression = (x => true);
- if (userID.HasValue)
- expression = (x => x.UserID == userID);
- return staffDAL.Value.staffProfileRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取教师详细信息
- /// </summary>
- /// <param name="userID">用户ID</param>
- /// <returns></returns>
- 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();
- }
- /// <summary>
- /// 获取教师详细信息
- /// </summary>
- /// <param name="exp">Expression查询条件</param>
- /// <returns></returns>
- public ViewModel.TeacherManagement.StaffView GetStaffView(System.Linq.Expressions.Expression<Func<Entities.CF_Staff, bool>> exp)
- {
- var query = staffDAL.Value.GetStaffViewQueryable(exp);
- return query.FirstOrDefault();
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="staff">主表实体</param>
- /// <param name="staffProfile">扩展表实体</param>
- /// <returns></returns>
- 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<CF_StaffManageCampus>();
- staff.CF_StaffManageCollege = new HashSet<CF_StaffManageCollege>();
- 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;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="userIDs"></param>
- /// <returns></returns>
- public bool StaffDelete(List<Guid> 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;
- }
- }
- /// <summary>
- /// 获取全部教师列表详细信息
- /// </summary>
- /// <returns></returns>
- public List<StaffView> GetListStaffView(Guid? userID)
- {
- //查询条件
- System.Linq.Expressions.Expression<Func<CF_Staff, bool>> 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();
- }
- /// <summary>
- /// 获取全部教师不带数据范围
- /// </summary>
- /// <returns></returns>
- public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.TeacherManagement.StaffView> GetAllStaffView(ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- //查询条件
- System.Linq.Expressions.Expression<Func<CF_Staff, bool>> 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);
- }
- /// <summary>
- /// 教师信息验证
- /// </summary>
- /// <param name="userID">教职工ID</param>
- /// <param name="Code">代码</param>
- /// <returns></returns>
- 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();
- }
- }
- /// <summary>
- /// 教师信息导入
- /// </summary>
- /// <param name="dataList">导入的数据集合</param>
- /// <param name="errdataList">返回的操作失败集合</param>
- /// <param name="successCount">操作成功记录条数</param>
- /// <returns></returns>
- public virtual void StaffImport(out int OkCount, out List<StaffView> errdataList, out int successCount, string sourcePhysicalPath,string sourceWebPath,out string errorWebPath,out string Errinfo)
- {
- var excel = new NpoiExcelHelper();
- #region 1.0 单元格抬头
- Dictionary<string, string> cellheader = new Dictionary<string, string>
- {
- { "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<StaffView> errList = new List<StaffView>();
- DataTimeHelper dth = new DataTimeHelper();
- #region 1.1解析文件,存放到一个List集合里
- // 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
- List<StaffView> enlist =
- NpoiExcelHelper.ExcelToEntityList<StaffView>(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<CF_Staff> staffList = new List<CF_Staff>();
- List<Sys_User> userList = new List<Sys_User>();
- List<CF_StaffProfile> staffProfileList = new List<CF_StaffProfile>();
- List<CF_StaffManageCampus> staffManageCampusList = new List<CF_StaffManageCampus>();
- List<CF_StaffManageCollege> staffManageCollegeList = new List<CF_StaffManageCollege>();
- 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<Sys_User>(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
- }
- /// <summary>
- /// 教师自己信息保存
- /// </summary>
- /// <param name="staffView"></param>
- 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;
- }
- }
- }
- }
|