protected IQueryOver <WarehouseOperation> ItemsQuery(IUnitOfWork uow) { StockMovmentsJournalNode resultAlias = null; WarehouseOperation warehouseOperationAlias = null; ExpenseItem expenseItemAlias = null; IncomeItem incomeItemAlias = null; TransferItem transferItemAlias = null; CollectiveExpenseItem collectiveExpenseItemAlias = null; WriteoffItem writeOffItemAlias = null; EmployeeCard employeeCardAlias = null; EmployeeIssueOperation employeeIssueOperationAlias = null; CompletionResultItem completionResultItemAlias = null; CompletionSourceItem completionSourceItemAlias = null; Nomenclature nomenclatureAlias = null; ItemsType itemTypesAlias = null; MeasurementUnits unitsAlias = null; Size sizeAlias = null; Size heightAlias = null; var queryStock = uow.Session.QueryOver(() => warehouseOperationAlias) .JoinAlias(() => warehouseOperationAlias.WearSize, () => sizeAlias, JoinType.LeftOuterJoin) .JoinAlias(() => warehouseOperationAlias.Height, () => heightAlias, JoinType.LeftOuterJoin); if (Filter.Warehouse != null) { queryStock.Where(x => x.ReceiptWarehouse == Filter.Warehouse || x.ExpenseWarehouse == Filter.Warehouse); } if (Filter.StartDate.HasValue) { queryStock.Where(x => x.OperationTime >= Filter.StartDate.Value); } if (Filter.EndDate.HasValue) { queryStock.Where(x => x.OperationTime < Filter.EndDate.Value.AddDays(1)); } if (Filter.StockPosition != null) { queryStock.Where(x => x.Nomenclature == Filter.StockPosition.Nomenclature); queryStock.Where(x => x.WearSize == Filter.StockPosition.WearSize); queryStock.Where(x => x.Height == Filter.StockPosition.Height); queryStock.Where(x => x.WearPercent == Filter.StockPosition.WearPercent); } if (Filter.Nomenclature != null) { queryStock.Where(x => x.Nomenclature == Filter.Nomenclature); } if (Filter.Size != null) { queryStock.Where(x => x.WearSize.Id == Filter.Size.Id); } if (Filter.Height != null) { queryStock.Where(x => x.Height.Id == Filter.Height.Id); } IProjection receiptProjection, expenseProjection; if (Filter.Warehouse != null) { receiptProjection = Projections.Conditional( Restrictions.Eq(Projections .Property <WarehouseOperation>(x => x.ReceiptWarehouse.Id), Filter.Warehouse.Id), Projections.Constant(true), Projections.Constant(false) ); expenseProjection = Projections.Conditional( Restrictions.Eq(Projections .Property <WarehouseOperation>(x => x.ExpenseWarehouse.Id), Filter.Warehouse.Id), Projections.Constant(true), Projections.Constant(false) ); switch (Filter.Direction) { case DirectionOfOperation.expense: queryStock.Where(x => x.ExpenseWarehouse.Id == Filter.Warehouse.Id); break; case DirectionOfOperation.receipt: queryStock.Where(x => x.ReceiptWarehouse.Id == Filter.Warehouse.Id); break; } } else { receiptProjection = Projections.Conditional( Restrictions.IsNotNull(Projections .Property <WarehouseOperation>(x => x.ReceiptWarehouse.Id)), Projections.Constant(true), Projections.Constant(false) ); expenseProjection = Projections.Conditional( Restrictions.IsNotNull(Projections .Property <WarehouseOperation>(x => x.ExpenseWarehouse.Id)), Projections.Constant(true), Projections.Constant(false) ); switch (Filter.Direction) { case DirectionOfOperation.expense: queryStock.Where(x => x.ReceiptWarehouse == null); break; case DirectionOfOperation.receipt: queryStock.Where(x => x.ExpenseWarehouse == null); break; } } queryStock .JoinAlias(() => warehouseOperationAlias.Nomenclature, () => nomenclatureAlias) .JoinAlias(() => nomenclatureAlias.Type, () => itemTypesAlias) .JoinAlias(() => itemTypesAlias.Units, () => unitsAlias) .JoinEntityAlias(() => expenseItemAlias, () => expenseItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => collectiveExpenseItemAlias, () => collectiveExpenseItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => incomeItemAlias, () => incomeItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => transferItemAlias, () => transferItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => writeOffItemAlias, () => writeOffItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => employeeIssueOperationAlias, () => employeeIssueOperationAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => employeeCardAlias, () => employeeIssueOperationAlias.Employee.Id == employeeCardAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => completionResultItemAlias, () => completionResultItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .JoinEntityAlias(() => completionSourceItemAlias, () => completionSourceItemAlias.WarehouseOperation.Id == warehouseOperationAlias.Id, JoinType.LeftOuterJoin) .Where(GetSearchCriterion( () => employeeCardAlias.FirstName, () => employeeCardAlias.LastName, () => employeeCardAlias.Patronymic )); if (Filter.CollapseOperationItems) { queryStock.SelectList(list => list .SelectGroup(() => warehouseOperationAlias.Nomenclature.Id) .Select(() => warehouseOperationAlias.OperationTime).WithAlias(() => resultAlias.OperationTime) .Select(() => unitsAlias.Name).WithAlias(() => resultAlias.UnitsName) .Select(receiptProjection).WithAlias(() => resultAlias.Receipt) .Select(expenseProjection).WithAlias(() => resultAlias.Expense) .SelectSum(() => warehouseOperationAlias.Amount).WithAlias(() => resultAlias.Amount) .Select(() => nomenclatureAlias.Name).WithAlias(() => resultAlias.NomenclatureName) .Select(() => employeeCardAlias.FirstName).WithAlias(() => resultAlias.EmployeeName) .Select(() => employeeCardAlias.LastName).WithAlias(() => resultAlias.EmployeeSurname) .Select(() => employeeCardAlias.Patronymic).WithAlias(() => resultAlias.EmployeePatronymic) //Ссылки .SelectGroup(() => expenseItemAlias.ExpenseDoc.Id).WithAlias(() => resultAlias.ExpenceId) .SelectGroup(() => collectiveExpenseItemAlias.Document.Id).WithAlias(() => resultAlias.CollectiveExpenseId) .SelectCount(() => employeeCardAlias.Id).WithAlias(() => resultAlias.NumberOfCollapsedRows) .SelectGroup(() => incomeItemAlias.Document.Id).WithAlias(() => resultAlias.IncomeId) .SelectGroup(() => transferItemAlias.Document.Id).WithAlias(() => resultAlias.TransferItemId) .SelectGroup(() => writeOffItemAlias.Document.Id).WithAlias(() => resultAlias.WriteoffId) .SelectGroup(() => completionResultItemAlias.Completion.Id).WithAlias(() => resultAlias.CompletionFromResultId) .SelectGroup(() => completionSourceItemAlias.Completion.Id).WithAlias(() => resultAlias.CompletionFromSourceId) .SelectGroup(() => sizeAlias.Name).WithAlias(() => resultAlias.WearSizeName) .SelectGroup(() => heightAlias.Name).WithAlias(() => resultAlias.HeightName) .SelectGroup(() => warehouseOperationAlias.WearPercent).WithAlias(() => resultAlias.WearPercent) ); } else { queryStock.SelectList(list => list .Select(() => warehouseOperationAlias.Id).WithAlias(() => resultAlias.Id) .Select(() => warehouseOperationAlias.OperationTime).WithAlias(() => resultAlias.OperationTime) .Select(() => unitsAlias.Name).WithAlias(() => resultAlias.UnitsName) .Select(receiptProjection).WithAlias(() => resultAlias.Receipt) .Select(expenseProjection).WithAlias(() => resultAlias.Expense) .Select(() => warehouseOperationAlias.Amount).WithAlias(() => resultAlias.Amount) .Select(() => nomenclatureAlias.Name).WithAlias(() => resultAlias.NomenclatureName) .Select(() => sizeAlias.Name).WithAlias(() => resultAlias.WearSizeName) .Select(() => heightAlias.Name).WithAlias(() => resultAlias.HeightName) .Select(() => warehouseOperationAlias.WearPercent).WithAlias(() => resultAlias.WearPercent) //Ссылки .Select(() => expenseItemAlias.Id).WithAlias(() => resultAlias.ExpenceItemId) .Select(() => expenseItemAlias.ExpenseDoc.Id).WithAlias(() => resultAlias.ExpenceId) .Select(() => collectiveExpenseItemAlias.Id).WithAlias(() => resultAlias.CollectiveExpenseItemId) .Select(() => collectiveExpenseItemAlias.Document.Id).WithAlias(() => resultAlias.CollectiveExpenseId) .Select(() => incomeItemAlias.Id).WithAlias(() => resultAlias.IncomeItemId) .Select(() => incomeItemAlias.Document.Id).WithAlias(() => resultAlias.IncomeId) .Select(() => transferItemAlias.Id).WithAlias(() => resultAlias.TransferId) .Select(() => transferItemAlias.Document.Id).WithAlias(() => resultAlias.TransferItemId) .Select(() => writeOffItemAlias.Id).WithAlias(() => resultAlias.WriteoffItemId) .Select(() => writeOffItemAlias.Document.Id).WithAlias(() => resultAlias.WriteoffId) .Select(() => employeeCardAlias.FirstName).WithAlias(() => resultAlias.EmployeeName) .Select(() => employeeCardAlias.LastName).WithAlias(() => resultAlias.EmployeeSurname) .Select(() => employeeCardAlias.Patronymic).WithAlias(() => resultAlias.EmployeePatronymic) .Select(() => completionResultItemAlias.Id).WithAlias(() => resultAlias.CompletionResultItemId) .Select(() => completionSourceItemAlias.Id).WithAlias(() => resultAlias.CompletionSourceItemId) .Select(() => completionSourceItemAlias.Completion.Id).WithAlias(() => resultAlias.CompletionFromSourceId) .Select(() => completionResultItemAlias.Completion.Id).WithAlias(() => resultAlias.CompletionFromResultId) ); } return(queryStock .OrderBy(x => x.OperationTime).Desc .ThenBy(x => x.Id).Asc .TransformUsing(Transformers.AliasToBean <StockMovmentsJournalNode>())); }
public void DelSourceItems(CompletionSourceItem item) { Entity.ObservableSourceItems.Remove(item); OnPropertyChanged(nameof(CanDelItemSource)); }