/// <summary> /// Добавить в запрос условие соответсвующее полю "До даты" /// </summary> private void GetLogicStateCriteria(ChangeOwnerWaybillLogicState logicState, WaybillDateType dateType, DateTime?priorToDate, ref ICriteria <ChangeOwnerWaybill> crit) { if (dateType != WaybillDateType.Date) { return; } switch (logicState) { case ChangeOwnerWaybillLogicState.All: break; case ChangeOwnerWaybillLogicState.ExceptNotAccepted: crit.Where(x => x.AcceptanceDate <= priorToDate); break; case ChangeOwnerWaybillLogicState.NotAccepted: crit.Where(x => x.AcceptanceDate > priorToDate || x.AcceptanceDate == null); break; case ChangeOwnerWaybillLogicState.Accepted: crit.Where(x => x.AcceptanceDate <= priorToDate); break; default: throw new Exception("Непредусмотренный статус накладной."); } }
/// <summary> /// Получение списка накладных по МХ, кураторам в диапозоне дат /// </summary> /// <param name="logicState">Статус накладной</param> /// <param name="storageIdList">Список кодов МХ</param> /// <param name="storageSubQuery">Подзапрос на видимые МХ</param> /// <param name="curatorIdList">Список кодов кураторов</param> /// <param name="curatorSubQuery">Подзапрос на видимых кураторов</param> /// <param name="startDate">Начало интервала</param> /// <param name="endDate">Конец интервала</param> /// <param name="changeOwnerWaybillSubQuery">Подзапрос на видимые приходы</param> /// <param name="pageNumber">Номер страницы. Первая страница имеет номар 1.</param> /// <param name="dateType">Тип даты</param> /// <param name="priorToDate">Параметр "До даты"</param> /// <returns>Список приходных накладных</returns> public IEnumerable <ChangeOwnerWaybill> GetList(ChangeOwnerWaybillLogicState logicState, ISubCriteria <ChangeOwnerWaybill> changeOwnerWaybillSubQuery, IEnumerable <short> storageIdList, ISubCriteria <Storage> storageSubQuery, IEnumerable <int> curatorIdList, ISubCriteria <User> curatorSubQuery, DateTime startDate, DateTime endDate, int pageNumber, WaybillDateType dateType, DateTime?priorToDate) { var crit = Query <ChangeOwnerWaybill>(); GetDateTypeCriteria(startDate, endDate, dateType, ref crit); GetLogicStateCriteria(logicState, dateType, priorToDate, ref crit); crit.PropertyIn(x => x.Id, changeOwnerWaybillSubQuery) .PropertyIn(x => x.Storage.Id, storageSubQuery) .PropertyIn(x => x.Curator.Id, curatorSubQuery) .OrderByAsc(x => x.Id); if (dateType != WaybillDateType.Date) { var stateList = GetStateListForChangeOwnerWaybill(logicState); crit.OneOf(x => x.State, stateList); } if (storageIdList != null) { crit.OneOf(x => x.Storage.Id, storageIdList); } if (curatorIdList != null) { crit.OneOf(x => x.Curator.Id, curatorIdList); } return(crit.SetFirstResult(100 * (pageNumber - 1)).SetMaxResults(100).ToList <ChangeOwnerWaybill>()); }
/// <summary> /// Получение списка накладных /// </summary> /// <param name="logicState">Статус накладной</param> /// <param name="storageIdList">Список кодов мест хранения</param> /// <param name="storagePermission">Право, которым определяются доступные места хранения</param> /// <param name="curatorIdList">Список кодов кураторов</param> /// <param name="curatorPermission">Право, которым определяются доступные пользователи</param> /// <param name="startDate">Начальная дата</param> /// <param name="endDate">Конечная дата</param> /// <param name="pageNumber">Номер страницы, первая 1.</param> /// <param name="dateType">Тип даты</param> /// <param name="priorToDate">Параметр "До даты"</param> /// <param name="user">Пользователь</param> /// <returns>Список накладных</returns> public IEnumerable <ChangeOwnerWaybill> GetList(ChangeOwnerWaybillLogicState logicState, IEnumerable <short> storageIdList, Permission storagePermission, IEnumerable <int> curatorIdList, Permission curatorPermission, DateTime startDate, DateTime endDate, int pageNumber, WaybillDateType dateType, DateTime?priorToDate, User user) { ISubCriteria <Storage> storageSubQuery = null; ISubCriteria <User> curatorSubQuery = null; ISubCriteria <ChangeOwnerWaybill> changeOwnerWaybillSubQuery = null; switch (user.GetPermissionDistributionType(storagePermission)) { case PermissionDistributionType.All: storageSubQuery = storageRepository.GetStorageSubQueryByAllPermission(); break; case PermissionDistributionType.Teams: storageSubQuery = storageRepository.GetStorageSubQueryByTeamPermission(user.Id); break; case PermissionDistributionType.None: return(new List <ChangeOwnerWaybill>()); } switch (user.GetPermissionDistributionType(curatorPermission)) { case PermissionDistributionType.All: curatorSubQuery = userRepository.GetUserSubQueryByAllPermission(); break; case PermissionDistributionType.Teams: curatorSubQuery = userRepository.GetUserSubQueryByTeamPermission(user.Id); break; case PermissionDistributionType.None: return(new List <ChangeOwnerWaybill>()); } switch (user.GetPermissionDistributionType(Permission.ChangeOwnerWaybill_List_Details)) { case PermissionDistributionType.All: changeOwnerWaybillSubQuery = changeOwnerWaybillRepository.GetChangeOwnerWaybillSubQueryByAllPermission(); break; case PermissionDistributionType.Teams: changeOwnerWaybillSubQuery = changeOwnerWaybillRepository.GetChangeOwnerWaybillSubQueryByTeamPermission(user.Id); break; case PermissionDistributionType.Personal: changeOwnerWaybillSubQuery = changeOwnerWaybillRepository.GetChangeOwnerWaybillSubQueryByPersonalPermission(user.Id); break; case PermissionDistributionType.None: return(new List <ChangeOwnerWaybill>()); } return(changeOwnerWaybillRepository.GetList(logicState, changeOwnerWaybillSubQuery, storageIdList, storageSubQuery, curatorIdList, curatorSubQuery, startDate, endDate, pageNumber, dateType, priorToDate)); }
/// <summary> /// Получение параметров фильтрации для подгрузки накладных смены собственника /// </summary> private IEnumerable <ChangeOwnerWaybillState> GetStateListForChangeOwnerWaybill(ChangeOwnerWaybillLogicState state) { var result = new List <ChangeOwnerWaybillState>(); switch (state) { case ChangeOwnerWaybillLogicState.All: result.Add(ChangeOwnerWaybillState.ArticlePending); result.Add(ChangeOwnerWaybillState.ConflictsInArticle); result.Add(ChangeOwnerWaybillState.Draft); result.Add(ChangeOwnerWaybillState.ReadyToAccept); result.Add(ChangeOwnerWaybillState.OwnerChanged); result.Add(ChangeOwnerWaybillState.ReadyToChangeOwner); break; case ChangeOwnerWaybillLogicState.ExceptNotAccepted: result.Add(ChangeOwnerWaybillState.ArticlePending); result.Add(ChangeOwnerWaybillState.ConflictsInArticle); result.Add(ChangeOwnerWaybillState.OwnerChanged); result.Add(ChangeOwnerWaybillState.ReadyToChangeOwner); break; case ChangeOwnerWaybillLogicState.NotAccepted: result.Add(ChangeOwnerWaybillState.Draft); result.Add(ChangeOwnerWaybillState.ReadyToAccept); break; case ChangeOwnerWaybillLogicState.Accepted: result.Add(ChangeOwnerWaybillState.ArticlePending); result.Add(ChangeOwnerWaybillState.ConflictsInArticle); result.Add(ChangeOwnerWaybillState.OwnerChanged); result.Add(ChangeOwnerWaybillState.ReadyToChangeOwner); break; } return(result); }