public void AddWindGenerator(WindGenerator generator) { this.WindGenerators.Add(generator); context.WindGenerators.Add(generator); context.SaveChanges(); WindGenerators = new ObservableCollection <WindGenerator>(context.WindGenerators.AsEnumerable()); }
private void WindGenList_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedWindGen = vm.WindGenerators.Where(x => x.Id == vm.WindGenerators.ToList()[WindGenList.SelectedIndex].Id).FirstOrDefault(); if (selectedWindGen != null) { nameLbl.Content = selectedWindGen.Name; ratedPowerLbl.Content = selectedWindGen.RatedPower; ratedWindSpeedLbl.Content = selectedWindGen.RatedWindSpeed; minWindSpeedLbl.Content = selectedWindGen.MinWindSpeed; maxWindSpeedLbl.Content = selectedWindGen.MaxWindSpeed; if (selectedWindGen.Radius == 0) { selectedWindGen.Radius = Math.Sqrt((double)selectedWindGen.SweptArea / Math.PI); vm.Modify(selectedWindGen); } rotorLbl.Content = ((double)selectedWindGen.Radius).ToString("0.00"); if (selectedWindGen.SweptArea == 0) { selectedWindGen.SweptArea = Math.PI * selectedWindGen.Radius * selectedWindGen.Radius; vm.Modify(selectedWindGen); } sweptAreaLbl.Content = ((double)selectedWindGen.SweptArea).ToString("0.0"); heightLbl.Content = selectedWindGen.Height == null ? "N/A" : selectedWindGen.Height.ToString(); if (chartWindow != null) { chartWindow.GetPowerValues(); } priceLabel.Content = selectedWindGen.Price.ToString(); } }
public MainWindow() { InitializeComponent(); startDateDP.SelectedDate = startDate; this.DataContext = new ViewModel(); vm = this.DataContext as ViewModel; weather = new WeatherAPI(); weatherListDaily = new List <Weather>(); weatherListHourly = new List <Weather>(); firstWeatherToCompare = new List <Weather>(); secondWeatherToCompare = new List <Weather>(); WindGenList.SelectedIndex = 0; RefreshWindList(); selectedWindGen = vm.WindGenerators.Where(x => x.Id == vm.WindGenerators.ToList()[WindGenList.SelectedIndex].Id).FirstOrDefault(); }
private void Button_Click(object sender, RoutedEventArgs e) { CheckValues(); if (correct) { WindGenerator generator = new WindGenerator() { IsWorking = true, MaxWindSpeed = maxWindSpeed, MinWindSpeed = minWindSpeed, Name = name, Radius = rotorRadius, RatedPower = ratedPower, RatedWindSpeed = ratedWindSpeed, SweptArea = sweptArea, Height = height == 0 ? 10 : height, Price = price }; main.vm.AddWindGenerator(generator); main.RefreshWindList(); this.Close(); } }
internal void Modify(WindGenerator selected) { context.Entry(selected).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }