private void CreateSendCommand() { SendCommand = new DelegateCommand( () => { if (!Validate()) { return; } Entity.Send(CurrentEmployee, fuelRepository); sendedNow = Entity.Status == FuelTransferDocumentStatuses.Sent; OnPropertyChanged(() => CanSave); }, () => { return(CurrentEmployee != null && Entity.Status == FuelTransferDocumentStatuses.New && Entity.Driver != null && Entity.Car != null && Entity.CashSubdivisionFrom != null && Entity.CashSubdivisionTo != null && Entity.TransferedLiters > 0); } ); SendCommand.CanExecuteChangedWith(Entity, x => x.Status, x => x.Driver, x => x.Car, x => x.CashSubdivisionFrom, x => x.CashSubdivisionTo, x => x.TransferedLiters ); SendCommand.CanExecuteChanged += (sender, e) => { OnPropertyChanged(() => CanSend); }; }
private void CreateAddWriteoffItemCommand() { AddWriteoffItemCommand = new DelegateCommand( () => { var fuelTypeJournalViewModel = new SimpleEntityJournalViewModel <FuelType, FuelTypeViewModel>(x => x.Name, () => new FuelTypeViewModel(EntityUoWBuilder.ForCreate(), unitOfWorkFactory, commonServices), (node) => new FuelTypeViewModel(EntityUoWBuilder.ForOpen(node.Id), unitOfWorkFactory, commonServices), QS.DomainModel.UoW.UnitOfWorkFactory.GetDefaultFactory, commonServices ); fuelTypeJournalViewModel.SetRestriction(() => { return(Restrictions.Not(Restrictions.In(Projections.Id(), Entity.ObservableFuelWriteoffDocumentItems.Select(x => x.FuelType.Id).ToArray()))); }); fuelTypeJournalViewModel.SelectionMode = JournalSelectionMode.Single; fuelTypeJournalViewModel.OnEntitySelectedResult += (sender, e) => { var node = e.SelectedNodes.FirstOrDefault(); if (node == null) { return; } Entity.AddNewWriteoffItem(UoW.GetById <FuelType>(node.Id)); }; TabParent.AddSlaveTab(this, fuelTypeJournalViewModel); }, () => CanEdit ); AddWriteoffItemCommand.CanExecuteChangedWith(this, x => CanEdit); }
private void CreateAddWriteoffItemCommand() { AddWriteoffItemCommand = new DelegateCommand( () => { var fuelTypeJournalViewModel = new SimpleEntityJournalViewModel <FuelType, FuelTypeViewModel>(x => x.Name, () => new FuelTypeViewModel(EntityUoWBuilder.ForCreate(), unitOfWorkFactory, commonServices), (node) => new FuelTypeViewModel(EntityUoWBuilder.ForOpen(node.Id), unitOfWorkFactory, commonServices), QS.DomainModel.UoW.UnitOfWorkFactory.GetDefaultFactory, commonServices ); fuelTypeJournalViewModel.SetRestriction(() => { return(Restrictions.Not(Restrictions.In(Projections.Id(), Entity.ObservableFuelWriteoffDocumentItems.Select(x => x.FuelType.Id).ToArray()))); }); fuelTypeJournalViewModel.SelectionMode = JournalSelectionMode.Single; fuelTypeJournalViewModel.OnEntitySelectedResult += (sender, e) => { var node = e.SelectedNodes.FirstOrDefault(); if (node == null) { return; } Entity.AddNewWriteoffItem(UoW.GetById <FuelType>(node.Id)); }; var fuelTypePermissionSet = commonServices.PermissionService.ValidateUserPermission(typeof(FuelType), commonServices.UserService.CurrentUserId); if (fuelTypePermissionSet.CanRead && !fuelTypePermissionSet.CanUpdate) { var viewAction = new JournalAction("Просмотр", (selected) => selected.Any(), (selected) => true, (selected) => { var tab = fuelTypeJournalViewModel.GetTabToOpen(typeof(FuelType), selected.First().GetId()); fuelTypeJournalViewModel.TabParent.AddTab(tab, fuelTypeJournalViewModel); } ); (fuelTypeJournalViewModel.NodeActions as IList <IJournalAction>)?.Add(viewAction); } TabParent.AddSlaveTab(this, fuelTypeJournalViewModel); }, () => CanEdit ); AddWriteoffItemCommand.CanExecuteChangedWith(this, x => CanEdit); }
private void CreateReceiveCommand() { ReceiveCommand = new DelegateCommand( () => { Entity.Receive(CurrentEmployee); receivedNow = Entity.Status == FuelTransferDocumentStatuses.Received; OnPropertyChanged(() => CanSave); }, () => { return(CurrentEmployee != null && Entity.Status == FuelTransferDocumentStatuses.Sent && availableSubdivisionsForUser.Contains(Entity.CashSubdivisionTo) && Entity.Id != 0); } ); ReceiveCommand.CanExecuteChangedWith(Entity, x => x.Status, x => x.Id ); ReceiveCommand.CanExecuteChanged += (sender, e) => { OnPropertyChanged(() => CanReceive); }; }
private void CreateCommands() { SendCommand = new DelegateCommand( () => { var valid = new QSValidator <CommonCashTransferDocument>(Entity, new Dictionary <object, object>()); if (valid.RunDlgIfNotValid()) { return; } Entity.Send(Cashier); }, () => { return(Cashier != null && Entity.Status == CashTransferDocumentStatuses.New && Entity.Driver != null && Entity.Car != null && Entity.CashSubdivisionFrom != null && Entity.CashSubdivisionTo != null && Entity.ExpenseCategory != null && Entity.IncomeCategory != null && Entity.TransferedSum > 0); } ); SendCommand.CanExecuteChangedWith(Entity, x => x.Status, x => x.Driver, x => x.Car, x => x.CashSubdivisionFrom, x => x.CashSubdivisionTo, x => x.TransferedSum, x => x.ExpenseCategory, x => x.IncomeCategory ); ReceiveCommand = new DelegateCommand( () => { Entity.Receive(Cashier); }, () => { return(Cashier != null && Entity.Status == CashTransferDocumentStatuses.Sent && availableSubdivisionsForUser.Contains(Entity.CashSubdivisionTo) && Entity.Id != 0); } ); ReceiveCommand.CanExecuteChangedWith(Entity, x => x.Status, x => x.Id ); PrintCommand = new DelegateCommand( () => { var reportInfo = new QS.Report.ReportInfo { Title = String.Format($"Документ перемещения №{Entity.Id} от {Entity.CreationDate:d}"), Identifier = "Documents.CommonCashTransfer", Parameters = new Dictionary <string, object> { { "transfer_document_id", Entity.Id } } }; var report = new QSReport.ReportViewDlg(reportInfo); View.TabParent.AddTab(report, View, false); }, () => Entity.Id != 0 ); }