// Loads the current weather /// <summary> /// Loads the current weather. /// </summary> private async void LoadCurrentWeather() { mainWindow.LoadCurrentWeather(); try { currentWeather = await CurrentWeatherInfoProcessor.LoadCurrentWeather(ReturnCity()); } catch (Exception) { Console.WriteLine("Exception occurred"); } BitmapImage weatherImage = new BitmapImage(); weatherImage.BeginInit(); weatherImage.UriSource = new Uri("images/" + currentWeather.Weather[0].Icon.ToString() + ".png", UriKind.Relative); weatherImage.EndInit(); CurrentWeatherImage.Source = weatherImage; CurrentWeatherName.Text = currentWeather.Name; CurrentWeatherDescription.Text = currentWeather.Weather[0].Description.ToString(); CurrentTemperature.Text = "Temperature: " + NormalizationOperations.NormalizeTemperature(currentWeather.Main.Temp).ToString() + " °C"; CurrentFeelsLikeTemperature.Text = "Apparent temp: " + Math.Round((currentWeather.Main.Feels_like - 273.15), 2).ToString() + " °C"; CurrentHumidity.Text = "Humidity: " + currentWeather.Main.Humidity.ToString() + " %"; CurrentPressure.Text = "Pressure: " + currentWeather.Main.Pressure.ToString() + " hPa"; CurrentWindSpeed.Text = "Wind speed: " + currentWeather.Wind.Speed.ToString() + " m/s"; }
// Loads the current weather /// <summary> /// Loads the current weather /// </summary> public async void LoadCurrentWeather() { try { currentWeather = await CurrentWeatherInfoProcessor.LoadCurrentWeather(ReturnCity()); } catch (Exception) { Console.WriteLine("Exception occurred"); } if (isCurrentWeatherGood()) { BitmapImage weatherImage = new BitmapImage(); weatherImage.BeginInit(); weatherImage.UriSource = new Uri("images/" + currentWeather.Weather[0].Icon.ToString() + ".png", UriKind.Relative); weatherImage.EndInit(); CurrentWeatherImage.Source = weatherImage; CurrentWeather.Text = NormalizationOperations.NormalizeTemperature(currentWeather.Main.Temp).ToString() + "°C"; Current_data = DateTime.UtcNow.AddSeconds(currentWeather.Timezone); RefreshAllDayButtons(); ShowCurrentDay(); AddEventToStackPanel(); } else { CurrentWeather.Text = "API Error"; } }
// The WeatherWindow constructor /// <summary> /// The WeatherWindow constructor. /// </summary> /// <param name="weather">CurrentWeatherInfoModel object containing current weather information.</param> /// <param name="main">MainWindow object cotaining the reference to our main window.</param> public WeatherWindow(CurrentWeatherInfoModel weather, MainWindow main) { InitializeComponent(); currentWeather = weather; mainWindow = main; LoadCurrentWeather(); SetChartStyle(); LoadDayilyTemperatureChart(); }
// The metod save change information to the database /// <summary> /// The metod save change information to the database /// </summary> /// <param name="sender"> Contains a reference to the object that triggered the event </param> /// <param name="e"> Contains state information and event data associated with a routed event </param> private async void ButtonSave_Click(object sender, RoutedEventArgs e) { CurrentWeatherInfoModel currentWeather = await CurrentWeatherInfoProcessor.LoadCurrentWeather(EventLocalization.Text); if (currentWeather.Cod == "404") { AlertWindow alertWindow = new AlertWindow("No such city! Try Again!", "Input Error"); alertWindow.ShowDialog(); } else { DbLocalization.SaveLocalization(EventLocalization.Text); mainWindow.LoadCurrentCity(); mainWindow.LoadCurrentWeather(); } }