private void ExecuteEditViewCommand(ReestrObject reestr) { _dialogNavigationService.ShowDialog <ReestrEditViewModel, Reestr>(reestr.BuildOut(), callback => { if (callback.IsSuccess) { var result = callback.Value; Task.Run(async() => { await _reestrDataService.UpdateReestr(result); }).ContinueWith(x => { if (x.Status == TaskStatus.RanToCompletion) { var r = ReestrsCollection.FirstOrDefault(z => z.Id == reestr.Id); r.ReestrState = result.ReestrState; r.Customer = result.Customer; r.CustomerId = result.CustomerId; r.Net = result.Net; r.Note = result.Note; } }); } }); }
public GroupedReestrViewModel(IReestrDataService reestrDataService) { FilterModel = new FilterModel(); _reestrDataService = reestrDataService; FilterCommad = ReactiveCommand.CreateFromTask(ExecuteFilterCommand); var canFilter = this.WhenAnyValue(x => x.FilterModel.SearchQuery, x => !string.IsNullOrWhiteSpace(x)); var reestrCount = this.WhenAnyValue(x => x.ReestrsCollection.Count); _reestrCount = reestrCount .Select(x => ReestrsCollection.Sum(z => z.BarrelsCount)) .ToProperty(this, x => x.ReestrCount); _netTotal = reestrCount .Select(x => ReestrsCollection.Sum(z => z.TotalNet)) .ToProperty(this, x => x.NetTotal); ExportExcelCommand = ReactiveCommand.Create(ExecuteExportExcelCommand); }
public ReestrViewModel(IReestrDataService reestrDataService, IDialogNavigationService dialogNavigationService) { FilterModel = new FilterModel(); _reestrDataService = reestrDataService; _dialogNavigationService = dialogNavigationService; FilterCommad = ReactiveCommand.CreateFromTask(ExecuteFilterCommand); var canFilter = this.WhenAnyValue(x => x.FilterModel.SearchQuery, x => !string.IsNullOrWhiteSpace(x)); var reestrCount = this.WhenAnyValue(x => x.ReestrsCollection.Count); _reestrCount = reestrCount .Select(x => x) .ToProperty(this, x => x.ReestrCount); _netTotal = reestrCount .Select(x => ReestrsCollection.Sum(z => z.Net)) .ToProperty(this, x => x.NetTotal); this.WhenAnyValue(x => x.SelectedBarrelType) .Skip(1) .SelectMany(FilterCollectionByBarrelType) .Subscribe(); FilterBySearchQueryCommand = ReactiveCommand.CreateFromTask(ExecuteFilterBySearchQueryCommand, canFilter); PrintCommand = ReactiveCommand.Create <Reestr>(ExecutePrintCommand); EditCommand = ReactiveCommand.Create <Reestr>(ExecuteEditCommand); ExportExcelCommand = ReactiveCommand.Create(ExecuteExportExcelCommand); }
public void FillCollection(IEnumerable <ReestrObject> reestrs) { if (ReestrsCollection == null) { ReestrsCollection = new ObservableCollection <ReestrObject>(reestrs); } else { ReestrsCollection.AddRange(reestrs); } }
private void InsertToCollection(ReestrObject reestr) { if (reestr != null) { ReestrsCollection.Add(reestr); _isValueDroppedToMinimum = false; ExecutePrintViewCommand(reestr); MessageBus.Current.SendMessage(new ReestredAddedEvent { Reestr = reestr }); } }
public void FillCombo() { string all = ""; _allBatches = ReestrsCollection.Select(x => x.BatchNumber).Distinct(); Batches = new ObservableCollection <string> { all }; Batches.AddRange(_allBatches); var materials = ReestrsCollection.Select(x => x.Recipe.ShortName).Distinct(); Materials = new ObservableCollection <string> { all }; Materials.AddRange(materials); // SelectedMaterial = Materials.FirstOrDefault(); // SelectedBatch = Batches.FirstOrDefault(); }
public ShellViewModel(IComPortProvider comPortProvider, IReestrSettingDataService reestrSettingDataService, IDialogNavigationService dialogNavigationService, IReestrDataService reestrDataService) { _comPortProvider = comPortProvider; _reestrSettingDataService = reestrSettingDataService; _dialogNavigationService = dialogNavigationService; _reestrDataService = reestrDataService; MaxProgressValue = 3; IsAutoMode = true; Task.Run(Initialize); var parsedValue = this.WhenAnyValue(x => x._comPortProvider.ComPortConnector.ParsedValue); parsedValue.Subscribe(ValueDropped); parsedValue.ObserveOnDispatcher() .Subscribe(x => Proggress(x)); Observable.Interval(TimeSpan.FromSeconds(1)) .ObserveOnDispatcher() .Subscribe(Progress2); parsedValue.Throttle(TimeSpan.FromSeconds(3)) .Where(x => IsAutoMode && _isValueDroppedToMinimum) .Where(ValidateParsedValue) .SelectMany(InsertToDataBase) .Catch((Func <Exception, IObservable <ReestrObject> >)HandleException) .Where(x => x != null) .Select(x => x) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(InsertToCollection); var reestrCount = this.WhenAnyValue(x => x.ReestrsCollection.Count); _reestrCount = reestrCount .Select(x => x) .ToProperty(this, x => x.ReestrCount); _netTotal = reestrCount .Select(x => ReestrsCollection.Sum(z => z.Net)) .ToProperty(this, x => x.NetTotal); _itemWeight = parsedValue.Select(x => x) .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, x => x.ItemWeigth); var canExecute = this .WhenAnyValue(x => x.IsAutoMode, isAutoMode => isAutoMode == false); Imitation = ReactiveCommand.CreateFromTask(ExecuteImitation); SaveCommand = ReactiveCommand.CreateFromTask(ExecuteSaveCommand, canExecute); SaveCommand .Catch((Func <Exception, IObservable <ReestrObject> >)HandleException) .Where(x => x != null) .Select(x => x) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(InsertToCollection); var canEditAndCanPrint = this .WhenAnyValue(x => x.SelectedReestr) .Select(x => x != null); EditCommand = ReactiveCommand.Create <ReestrObject>(ExecuteEditViewCommand, canEditAndCanPrint); PrintCommand = ReactiveCommand.Create <ReestrObject>(ExecutePrintViewCommand, canEditAndCanPrint); ExecuteOpenReestrSettingCommand(); }