/// <summary> /// Refreshing the dataset /// </summary> public override void Refresh() { if (!DataValidation.CheckPrerequisites(CRUD.Load)) { return; } tblMeasuringDevice current = SelectedAnalyticalInstrument; int id = 0; try { if (SelectedAnalyticalInstrument != null) { id = SelectedAnalyticalInstrument.mdIdPk; } LoadData(); SelectedAnalyticalInstrument = AnalyticalInstruments.Where(p => p.mdIdPk == id).First(); } catch { try { LoadData(); SelectedAnalyticalInstrument = new tblMeasuringDevice(); } catch { ((ShellViewModel)IoC.Get <IShell>()).ShowError("An unexpeced error occured."); } } }
/// <summary> /// Go to the first dataset /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void First() { if (AnalyticalInstruments.Count != 0) { SelectedAnalyticalInstrument = AnalyticalInstruments.First(); } }
//Loading filtered data private async void LoadData() { if (!ServerInteractionHelper.IsNetworkAvailable() && !ServerInteractionHelper.TryAccessDatabase()) { AnalyticalInstruments = new BindableCollection <tblMeasuringDevice>(); SelectedAnalyticalInstrument = new tblMeasuringDevice(); return; } try { await Task.Run(() => { using (var db = new ApirsRepository <tblMeasuringDevice>()) { AnalyticalInstruments = new BindableCollection <tblMeasuringDevice>(db.GetModel().ToList()); } }); this.allAnalyticalInstruments = AnalyticalInstruments; if (AnalyticalInstruments.Count == 0) { SelectedAnalyticalInstrument = new tblMeasuringDevice(); } else if (AnalyticalInstruments.Count > 1) { SelectedAnalyticalInstrument = AnalyticalInstruments.First(); } else { SelectedAnalyticalInstrument = AnalyticalInstruments.First(); } } catch (Exception e) { AnalyticalInstruments = new BindableCollection <tblMeasuringDevice>(); this.allAnalyticalInstruments = AnalyticalInstruments; SelectedAnalyticalInstrument = new tblMeasuringDevice(); } }