private void AddButton_Click(object sender, EventArgs e) { WeatherForecast.DayWeather dayWeather; try { dayWeather = new WeatherForecast.DayWeather() { Day = dateTimePicker1.Value, Weather = (WeatherForecast.Weather)weatherListBox.SelectedItem, DayTemperature = Convert.ToDouble(dayTempTextBox.Text), NightTemperature = Convert.ToDouble(nightTempTextBox.Text) }; _weatherService.AddDayWeather(dayWeather); } catch (Exception ex) { MessageBox.Show(MyStrings.AddException + ex.Message); return; } var args = new DayWeatherAddedEventArgs() { DayWeather = dayWeather }; OnDayWeatherAdded(args); MessageBox.Show(MyStrings.AddSuccess); }
private void SetWeather(DayWeather d) { if (d == null) { throw new DayWeatherException(MyStrings.UndefinedDayValue, new NullReferenceException()); } string path; try { path = resourcesPath.Find(resource => resource.Weather == d.Weather).Path; } catch (ImagePathException ex) { throw new DayWeatherException(MyStrings.UndefinedPathsList, ex); } try { weatherPictureBox.Image = Image.FromFile(path); } catch (DayWeatherException ex) { throw ex; } catch (System.Exception ex) { throw new DayWeatherException(MyStrings.ErrorLoadImage + path, ex); } }
private void SetDay(DayWeather day) { if (day == null) { throw new DayWeatherException(MyStrings.UndefinedDayValue, new NullReferenceException()); } dayTempLabel.Text = $"{MyStrings.Day}:{day.DayTemperature} C"; nightTempLabel.Text = $"{MyStrings.Night}:{day.NightTemperature} C"; SetWeather(day); }
public void AddDayWeather(CustomWeather.DayWeather dayWeather) { var list = _imagePathRepository.GetList().ToList(); int id = list.First(x => x.Weather == dayWeather.Weather.ToString()).Id; var item = new DayWeather() { Id = _dayWeatherRepository.GetList().ToList().Count + 1, Day = dayWeather.Day, DayTemperature = dayWeather.DayTemperature, NightTemperature = dayWeather.NightTemperature, IdImagePath = id }; _dayWeatherRepository.Create(item); _dayWeatherRepository.Save(); }