public StockBalanceJournalViewModel(
            IUnitOfWorkFactory unitOfWorkFactory,
            IInteractiveService interactiveService,
            INavigationManager navigation,
            ILifetimeScope autofacScope,
            FeaturesService featuresService) : base(unitOfWorkFactory, interactiveService, navigation)
        {
            AutofacScope  = autofacScope;
            JournalFilter = Filter = AutofacScope.Resolve <StockBalanceFilterViewModel>(
                new TypedParameter(typeof(JournalViewModelBase), this));

            var dataLoader = new ThreadDataLoader <StockBalanceJournalNode>(unitOfWorkFactory);

            dataLoader.AddQuery(ItemsQuery);
            DataLoader = dataLoader;

            CreateNodeActions();

            UpdateOnChanges(typeof(WarehouseOperation), typeof(Nomenclature));
            TabName = "Остатки по складу " +
                      (featuresService.Available(WorkwearFeature.Warehouses) ? Filter.Warehouse?.Name : "");

            Filter.PropertyChanged                     += (sender, e) =>
                                                TabName = "Остатки по складу " +
                                                          (featuresService.Available(WorkwearFeature.Warehouses) ? Filter.Warehouse?.Name : "");
        }
        void CreateDocumentsActions()
        {
            var addAction = new JournalAction("Добавить",
                                              (selected) => true,
                                              (selected) => true,
                                              null,
                                              "Insert"
                                              );

            NodeActionsList.Add(addAction);
            foreach (StokDocumentType docType in Enum.GetValues(typeof(StokDocumentType)))
            {
                switch (docType)
                {
                case StokDocumentType.CollectiveExpense when !FeaturesService.Available(WorkwearFeature.CollectiveExpense):
                case StokDocumentType.TransferDoc when !FeaturesService.Available(WorkwearFeature.Warehouses):
                case StokDocumentType.Completion when !FeaturesService.Available(WorkwearFeature.Completion):
                    continue;

                default:
                {
                    var insertDocAction = new JournalAction(
                        docType.GetEnumTitle(),
                        (selected) => true,
                        (selected) => true,
                        (selected) => openStockDocumentsModel.CreateDocumentDialog(this, docType)
                        );
                    addAction.ChildActionsList.Add(insertDocAction);
                    break;
                }
                }
            }

            var editAction = new JournalAction("Изменить",
                                               (selected) => selected.Any(),
                                               (selected) => true,
                                               (selected) => selected.Cast <StockDocumentsJournalNode>().ToList()
                                               .ForEach(n => openStockDocumentsModel.EditDocumentDialog(this, n.DocTypeEnum, n.Id))
                                               );

            NodeActionsList.Add(editAction);

            if (SelectionMode == JournalSelectionMode.None)
            {
                RowActivatedAction = editAction;
            }

            var deleteAction = new JournalAction("Удалить",
                                                 (selected) => selected.Any(),
                                                 (selected) => true,
                                                 (selected) => DeleteEntities(selected.Cast <StockDocumentsJournalNode>().ToArray()),
                                                 "Delete"
                                                 );

            NodeActionsList.Add(deleteAction);
        }
 private void DisableFeatures()
 {
     if (!featureService.Available(WorkwearFeature.Warehouses))
     {
         table1.Visible = false;
     }
 }
Esempio n. 4
0
 private void DisableFeatures()
 {
     if (!featuresService.Available(WorkwearFeature.Warehouses))
     {
         label3.Visible = false;
         entityWarehouseIncome.Visible = false;
         if (Entity.Warehouse == null)
         {
             entityWarehouseIncome.ViewModel.Entity = Entity.Warehouse = new StockRepository()
                                                                         .GetDefaultWarehouse(UoW, featuresService, AutofacScope.Resolve <IUserService>().CurrentUserId);
         }
     }
 }
        /// <summary>
        /// Возвращается первый склад из БД, если версия программы с единственным складом.
        /// Возвращает склад по умолчанию, определенный в настройках пользователя, при создании различных документов и прочее.
        /// </summary>
        public virtual Warehouse GetDefaultWarehouse(IUnitOfWork uow, FeaturesService featureService, int idUser)
        {
            if (!featureService.Available(WorkwearFeature.Warehouses))
            {
                var warehous = uow.Session.Query <Warehouse>().FirstOrDefault();
                return(warehous);
            }

            UserSettings settings = uow.Session.QueryOver <UserSettings>()
                                    .Where(x => x.User.Id == idUser).SingleOrDefault <UserSettings>();

            if (settings?.DefaultWarehouse != null)
            {
                return(settings.DefaultWarehouse);
            }

            var warehouses = uow.GetAll <Warehouse>().Take(2).ToList();

            return(warehouses.Count == 1 ? warehouses.First() : null);
        }