public StationModel(RegionModelSource region) : this() { this.NavigateRoot = region.NavigateRoot; this.Navigate = new AsyncCommand((obj) => { var vm = new ReadingInputScreenViewModel(region, this); BaseViewModel.Navigator.Navigate(Shared.Navigation.NavigationType.StationInput, vm); }); }
public StationListViewModel(RegionModelSource region, IEnumerable <StationModel> stations) { this.Crumbs.Add(new Shared.Controls.BreadcrumbItemModel("Areas", region.NavigateRoot)); this.Crumbs.Add(new Shared.Controls.BreadcrumbItemModel(region.Name, region.Navigate)); this.Stations = new ObservableCollection <StationModel>(); foreach (var station in stations) { this.Stations.Add(new StationModel(region) { Id = station.Id, Name = station.Name, ItemCount = station.Items.Count(), Items = station.Items }); } }
/// <summary> /// Initializes a new instance of the <see cref="ReadingInputScreenViewModel"/> class. /// Represents the full view model for the page. /// </summary> public ReadingInputScreenViewModel(RegionModelSource region, StationModel station) { var regionNav = new AsyncCommand((obj) => { Navigator.Navigate(Shared.Navigation.NavigationType.StationSelect); }); this.Save = new AsyncCommand((obj) => this.SaveInput(this.input), this.CanSave); this.station = station; this.Crumbs.Add(new BreadcrumbItemModel("Areas", region.NavigateRoot)); this.Crumbs.Add(new BreadcrumbItemModel(region.Name, region.Navigate)); this.Crumbs.Add(new BreadcrumbItemModel(station.Name, station.Navigate)); this.Input = new ReadingInputViewModel(this.Save, null); this.ListModel = new ReadingInputListViewModel(this); foreach (var item in station.Items) { if (item.StationId == station.Id) { var newMeter = new Meter(item.Meter, item) { Id = item.Id, Name = item.Name, MeterName = item.Meter }; var currentReading = ReadingManager.Find(item.Id); newMeter.LastReading = new ReadingInput(); newMeter.TwoReadingsAgo = new ReadingInput(); newMeter.ThreeReadingsAgo = new ReadingInput(); newMeter.FourReadingsAgo = new ReadingInput(); newMeter.ComparisonType = ComparisonTypeViewModel.Locate(item.Specification.ComparisonType); newMeter.TodaysReading = new ReadingInput() { MinimumValue = item.Specification.LowerBound, MaximumValue = item.Specification.UpperBound, UnitAbbreviation = item.Specification.UnitOfMeasure.Abbreviation, ValueBounds = newMeter.ComparisonType.AsEnum(), IsWithinSpec = false, }; if (!string.IsNullOrEmpty(currentReading.Value)) { bool boolVal = false; if (bool.TryParse(currentReading.Value, out boolVal)) { newMeter.TodaysReading.BooleanValue = boolVal; } else { //just a string value. newMeter.TodaysReading.StringValue = currentReading.Value; } newMeter.TodaysReading.IsWithinSpec = !currentReading.IsOutOfSpec; newMeter.IsComplete = true; } var count = item.PastFourReadings.Count(); if (count > 0) { newMeter.LastReading.StringValue = item.PastFourReadings.ElementAt(0).Value; newMeter.LastReading.IsWithinSpec = !item.PastFourReadings.ElementAt(0).IsOutOfSpec; newMeter.LastReading.Notes = item.PastFourReadings.ElementAt(0).Comments; } if (count > 1) { newMeter.TwoReadingsAgo.StringValue = item.PastFourReadings.ElementAt(1).Value; newMeter.TwoReadingsAgo.IsWithinSpec = !item.PastFourReadings.ElementAt(1).IsOutOfSpec; } if (count > 2) { newMeter.ThreeReadingsAgo.StringValue = item.PastFourReadings.ElementAt(2).Value; newMeter.ThreeReadingsAgo.IsWithinSpec = !item.PastFourReadings.ElementAt(2).IsOutOfSpec; } if (count > 3) { newMeter.FourReadingsAgo.StringValue = item.PastFourReadings.ElementAt(3).Value; newMeter.FourReadingsAgo.IsWithinSpec = !item.PastFourReadings.ElementAt(3).IsOutOfSpec; } this.ListModel.Meters.Add(newMeter); } } }