using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.StudentStatistics; using EMIS.DataLogic.StudentManage.StudentStatistics; namespace EMIS.CommonLogic.StudentManage.StudentStatistics { public class InSchoolSettingServices : BaseServices, IInSchoolSettingServices { public InSchoolSettingDAL InSchoolSettingDAL { get; set; } /// /// 查询对应的在校设定信息InSchoolSettingView /// /// /// /// /// /// /// /// public IGridResultSet GetInSchoolSettingViewGrid(ConfiguretView configuretView, int? inSchoolStatusID, int? isSelected, int? isDisplayID, int pageIndex, int pageSize) { Expression> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name); Expression> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting); if (inSchoolStatusID.HasValue) { query = query.Where(x => x.InSchoolStatusID == inSchoolStatusID); } if (isSelected.HasValue) { if (isSelected == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsSelected == true); } if (isSelected == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsSelected != true); } } if (isDisplayID.HasValue) { if (isDisplayID == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsDisplay == true); } if (isDisplayID == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsDisplay != true); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.InSchoolStatusID).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的在校设定信息List /// /// /// /// /// /// public IList GetInSchoolSettingViewList(ConfiguretView configuretView, int? inSchoolStatusID, int? isSelected, int? isDisplayID) { Expression> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name); Expression> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting); if (inSchoolStatusID.HasValue) { query = query.Where(x => x.InSchoolStatusID == inSchoolStatusID); } if (isSelected.HasValue) { if (isSelected == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsSelected == true); } if (isSelected == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsSelected != true); } } if (isDisplayID.HasValue) { if (isDisplayID == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsDisplay == true); } if (isDisplayID == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsDisplay != true); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.InSchoolStatusID).ToList(); } /// /// 查询对应的在校设定中状态List /// /// /// public List GetInschoolStatusList(bool? isSelected) { Expression> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name); Expression> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var inSchoolSettingViewList = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting); var inSchoolStatusIDList = inSchoolSettingViewList.Where(x => x.IsSelected == isSelected).Select(x => x.InSchoolStatusID).ToList(); return inSchoolStatusIDList; } /// /// 查询对应的在校设定信息InSchoolSettingView(根据在校设定ID) /// /// /// public InSchoolSettingView GetInSchoolSettingView(Guid? inSchoolSettingID) { try { var inSchoolSettingView = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(x => x.InSchoolSettingID == inSchoolSettingID).SingleOrDefault(); return inSchoolSettingView; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 设置(新增、修改、删除) /// /// public void InSchoolSettingEdit(IEnumerable inSchoolSettingViewList) { try { var inSchoolSettingInList = new List(); var inSchoolSettingUpList = new List(); var inschoolStatusList = InSchoolSettingDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_InschoolStatus).Name).ToList(); var inschoolStatusIDList = inschoolStatusList.Select(x => x.Value).ToList(); var inSchoolSettingList = InSchoolSettingDAL.InSchoolSettingRepository.GetList(x => true); var inSchoolSettingIDDelList = inSchoolSettingList.Where(x => !inschoolStatusIDList.Contains(x.InSchoolStatusID)).Select(x => x.InSchoolSettingID).ToList(); foreach (var inSchoolSettingView in inSchoolSettingViewList) { if (inSchoolSettingView.InSchoolSettingID == null || inSchoolSettingView.InSchoolSettingID == Guid.Empty) { var inSchoolSetting = inSchoolSettingList.Where(x => x.InSchoolStatusID == inSchoolSettingView.InSchoolStatusID).SingleOrDefault(); if (inSchoolSetting != null) { inSchoolSettingIDDelList.Add(inSchoolSetting.InSchoolSettingID); } var newInSchoolSetting = new CF_InSchoolSetting(); newInSchoolSetting.InSchoolSettingID = Guid.NewGuid(); newInSchoolSetting.InSchoolStatusID = inSchoolSettingView.InSchoolStatusID; newInSchoolSetting.IsSelected = inSchoolSettingView.IsSelected == null ? false : inSchoolSettingView.IsSelected; SetNewStatus(newInSchoolSetting); inSchoolSettingInList.Add(newInSchoolSetting); } else { var inSchoolSetting = inSchoolSettingList.SingleOrDefault(x => x.InSchoolSettingID == inSchoolSettingView.InSchoolSettingID); inSchoolSetting.IsSelected = inSchoolSettingView.IsSelected == null ? false : inSchoolSettingView.IsSelected; SetModifyStatus(inSchoolSetting); inSchoolSettingUpList.Add(inSchoolSetting); } } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => inSchoolSettingIDDelList.Contains(x.InSchoolSettingID)); UnitOfWork.BulkInsert(inSchoolSettingInList); if (inSchoolSettingUpList != null && inSchoolSettingUpList.Count() > 0) { UnitOfWork.BatchUpdate(inSchoolSettingUpList); } ts.Complete(); } } catch (Exception ex) { throw new Exception(ex.Message); } } } }