private void DoCancel(Object obj) { if (MessageBox.Show("Данные не сохранены, завершить работу?", "Внимание", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { view.Close(); } }
public void RegisterView(ViewType viewType, IClosableView view, bool startClosed = true) { _views.Add(viewType, view); if (startClosed) { view.Close(); } }
public EditInstrumentViewModel(Instrument model, IDataClient client, IClosableView view, IDialogCoordinator dialogCoordinator) : base(model, new InstrumentValidator()) { _view = view; DialogCoordinator = dialogCoordinator; if (model.Sessions == null) { model.Sessions = new List <InstrumentSession>(); } if (model.Tags == null) { model.Tags = new List <Tag>(); } foreach (var session in model.Sessions) { Sessions.Add(new SessionViewModel(session)); } ContractMonths = new ObservableCollection <KeyValuePair <int, string> >(); //fill the continuous futures contrat month combobox for (int i = 1; i < 10; i++) { ContractMonths.Add(new KeyValuePair <int, string>(i, MyUtils.Ordinal(i) + " Contract")); } Load = ReactiveCommand.CreateFromTask(async _ => { var tags = client.GetTags(); var sessionTemplates = client.GetSessionTemplates(); var exchanges = client.GetExchanges(); var underlyingSymbols = client.GetUnderlyingSymbols(); var datasources = client.GetDatasources(); await Task.WhenAll(tags, sessionTemplates, exchanges, underlyingSymbols, datasources).ConfigureAwait(true); var responses = new ApiResponse[] { tags.Result, sessionTemplates.Result, exchanges.Result, underlyingSymbols.Result, datasources.Result }; if (await responses.DisplayErrors(this, DialogCoordinator).ConfigureAwait(true)) { return; } foreach (var tag in tags.Result.Result.Select(x => new CheckBoxTag(x, model.Tags.Contains(x)))) { AllTags.Add(tag); tag.PropertyChanged += Tag_PropertyChanged; } Exchanges.AddRange(exchanges.Result.Result); foreach (var template in sessionTemplates.Result.Result) { SessionTemplates.Add(template); } foreach (var us in underlyingSymbols.Result.Result) { UnderlyingSymbols.Add(us); } foreach (var ds in datasources.Result.Result) { Datasources.Add(ds); } }); //Sessions AddNewSession = ReactiveCommand.Create(() => AddSession()); RemoveSession = ReactiveCommand.Create <SessionViewModel>(ExecRemoveSession); //Save var saveCanExecute = this .WhenAnyValue(x => x.HasErrors) .Select(x => !x); Save = ReactiveCommand.CreateFromTask(async _ => { if (model.ID == null || model.ID <= 0) { //adding a new instrument return(await client.AddInstrument(model).ConfigureAwait(true)); } else { //updating an existing one return(await client.UpdateInstrument(model).ConfigureAwait(true)); } } , saveCanExecute); Save.Subscribe(async result => { var errors = await result.DisplayErrors(this, DialogCoordinator).ConfigureAwait(true); if (!errors) { AddedInstrument = result.Result; _view.Close(); } }); this.Validate(); }
public void Close() { _closableView.Close(); }