using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.Utility; using EMIS.ViewModel; using EMIS.ViewModel.UniversityManage.AdministrativeOrgan; using EMIS.DataLogic.UniversityManage.AdministrativeOrgan; namespace EMIS.CommonLogic.UniversityManage.AdministrativeOrgan { public class CampusServices : BaseServices, ICampusServices { public CampusDAL CampusDAL { get; set; } /// /// 查询校区信息View /// /// /// /// /// public IGridResultSet GetCampusViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = CampusDAL.GetCampusViewQueryable(expCampus); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet(pageIndex, pageSize); } /// /// 查询校区信息List /// /// /// public IList GetCampusViewList(ConfiguretView configuretView) { Expression> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = CampusDAL.GetCampusViewQueryable(expCampus); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList(); } /// /// 查询全部校区信息CF_Campus /// /// public List GetCampusList() { Expression> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = CampusDAL.CampusRepository.GetList(expCampus); return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList(); } /// /// 查询全部校区信息CF_Campus(不考虑状态列) /// /// public List GetCampusListWithoutDataRange() { Expression> expCampus = (x => true); var query = CampusDAL.CampusRepository.GetList(expCampus); return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList(); } /// /// 查询对应的校区信息CampusView /// /// /// public CampusView GetCampusView(Guid? campusID) { try { var query = CampusDAL.GetCampusViewQueryable(x => x.CampusID == campusID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改,业务主键:校区代码或校区名称) /// /// public void CampusEdit(CampusView campusView) { try { //查询数据库进行验证 var campusVerify = CampusDAL.CampusRepository.GetList(x => x.CampusID != campusView.CampusID && (x.No == campusView.No || x.Name == campusView.Name)).FirstOrDefault(); if (campusVerify == null) { //数据有误验证 if (campusView.CampusID != Guid.Empty) { var campus = CampusDAL.CampusRepository.GetList(x => x.CampusID == campusView.CampusID, (x => x.CF_CampusProfile)).SingleOrDefault(); if (campus == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 campus.UniversityID = campusView.UniversityID; campus.No = campusView.No; campus.Name = campusView.Name; campus.SimpleName = campusView.SimpleName; campus.EnglishName = campusView.EnglishName; campus.Remark = campusView.Remark; SetModifyStatus(campusView); //校区信息扩展表 if (campus.CF_CampusProfile == null) { //新增 var newCampusProfile = new CF_CampusProfile(); newCampusProfile.CampusID = campusView.CampusID; newCampusProfile.Generalsuper = campusView.Generalsuper; newCampusProfile.Recruitstudents = campusView.Recruitstudents; newCampusProfile.Placesuper = campusView.Placesuper; newCampusProfile.Teachingsuper = campusView.Teachingsuper; newCampusProfile.Studentcharge = campusView.Studentcharge; newCampusProfile.ZIPCode = campusView.ZIPCode; newCampusProfile.Officephone = campusView.Officephone; newCampusProfile.FAX = campusView.FAX; newCampusProfile.Email = campusView.Email; newCampusProfile.Evolution = campusView.Evolution; SetNewStatus(newCampusProfile); UnitOfWork.Add(newCampusProfile); } else { //修改 campus.CF_CampusProfile.Generalsuper = campusView.Generalsuper; campus.CF_CampusProfile.Recruitstudents = campusView.Recruitstudents; campus.CF_CampusProfile.Placesuper = campusView.Placesuper; campus.CF_CampusProfile.Teachingsuper = campusView.Teachingsuper; campus.CF_CampusProfile.Studentcharge = campusView.Studentcharge; campus.CF_CampusProfile.ZIPCode = campusView.ZIPCode; campus.CF_CampusProfile.Officephone = campusView.Officephone; campus.CF_CampusProfile.FAX = campusView.FAX; campus.CF_CampusProfile.Email = campusView.Email; campus.CF_CampusProfile.Evolution = campusView.Evolution; SetModifyStatus(campus.CF_CampusProfile); } } } else { //表示新增(CF_Campus主表) CF_Campus campus = new CF_Campus(); campus.CampusID = Guid.NewGuid(); campus.UniversityID = campusView.UniversityID; campus.No = campusView.No; campus.Name = campusView.Name; campus.SimpleName = campusView.SimpleName; campus.EnglishName = campusView.EnglishName; campus.Remark = campusView.Remark; SetNewStatus(campus); UnitOfWork.Add(campus); //表示新增(CF_CampusProfile扩展表) CF_CampusProfile campusProfile = new CF_CampusProfile(); campusProfile.CampusID = campus.CampusID; campusProfile.Generalsuper = campusView.Generalsuper; campusProfile.Recruitstudents = campusView.Recruitstudents; campusProfile.Placesuper = campusView.Placesuper; campusProfile.Teachingsuper = campusView.Teachingsuper; campusProfile.Studentcharge = campusView.Studentcharge; campusProfile.ZIPCode = campusView.ZIPCode; campusProfile.Officephone = campusView.Officephone; campusProfile.FAX = campusView.FAX; campusProfile.Email = campusView.Email; campusProfile.Evolution = campusView.Evolution; SetNewStatus(campusProfile); UnitOfWork.Add(campusProfile); } } else { throw new Exception("已存在相同的" + RSL.Get("CampusCode") + "或" + RSL.Get("CampusName") + ",请核查。"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool CampusDelete(List campusIDList) { try { UnitOfWork.Remove(x => campusIDList.Contains(x.CampusID)); UnitOfWork.Remove(x => campusIDList.Contains(x.CampusID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 查询校区对应的院系所信息CollegeView /// /// /// /// /// /// /// public IGridResultSet GetCollegeListViewGrid(ConfiguretView configuretView, Guid? campusID, int? unitCategoryID, int pageIndex, int pageSize) { Expression> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expCampus = expCampus.And(x => x.CampusID == campusID); var query = CampusDAL.GetCollegeViewQueryable(expCampus); if (unitCategoryID.HasValue) { query = query.Where(x => x.UnitCategoryID == unitCategoryID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet(pageIndex, pageSize); } /// /// 查询校区对应的院系所信息List /// /// /// /// /// public IList GetCollegeListViewList(ConfiguretView configuretView, Guid? campusID, int? unitCategoryID) { Expression> expCampus = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expCampus = expCampus.And(x => x.CampusID == campusID); var query = CampusDAL.GetCollegeViewQueryable(expCampus); if (unitCategoryID.HasValue) { query = query.Where(x => x.UnitCategoryID == unitCategoryID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList(); } } }