internal static CityWeather GetWeather(string i_cityName) { CityWeather weather = new CityWeather(); string weburl = string.Format("https://samples.openweathermap.org/data/2.5/weather?q=" + i_cityName + "&mode=xml&appid=b6907d289e10d714a6e88b30761fae22"); var xml = new WebClient().DownloadString(new Uri(weburl)); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); string Temp = doc.DocumentElement.SelectSingleNode("temperature").Attributes["value"].Value; double temp = double.Parse(Temp) - 273.16; weather.m_Temperature = string.Format("{0:0.00}", temp); string Humidity = doc.DocumentElement.SelectSingleNode("humidity").Attributes["value"].Value; weather.m_humidity = Humidity; return(weather); }
private void listBox_Events_SelectedIndexChanged(object sender, EventArgs e) { if (listBox_Events.SelectedItem != null) { EventWithWeather selectedEvent = listBox_Events.SelectedItem as EventWithWeather; textBox_eventName.Text = m_Manager.GetEventName(selectedEvent); textBox_eventLocation.Text = m_Manager.GetEventCity(selectedEvent); textBox_eventDescription.Text = m_Manager.GetEventDescription(selectedEvent); textBox_eventDate.Text = m_Manager.GetEventTime(selectedEvent); pictureBox_event.LoadAsync(m_Manager.GetEventURLPicture(selectedEvent)); string cityName = textBox_eventLocation.Text; CityWeather cityWeather = selectedEvent.CityWeather; //m_Manager.GetWeather(cityName); textBox_Temp.Text = cityWeather.m_Temperature; textBox_humidity.Text = cityWeather.m_humidity; double temperature = double.Parse(textBox_Temp.Text); pictureBox_whether.ImageLocation = m_Manager.GetPathOfImageWeather(temperature); panel_eventDetails.Visible = true; } }
//public double temperature { get; private set; } public EventWithWeather(Event i_Event) { Name = i_Event.Name; Event = i_Event; CityWeather = Weather.GetWeather(Event.Place.Location.City); }