private void metric_Unit_CBox_CheckedChanged(object sender, EventArgs e) { if (imp_Unit_CBox.Checked) { imp_Unit_CBox.Checked = false; } if (stand_Unit_CBox.Checked) { stand_Unit_CBox.Checked = false; } unitChoice = UnitChooser.Metric; }
public static async Task <XmlDocument> LoadWeather(int id, LangChooser lang, UnitChooser unit) { string apiKey = "1e98a6276b52c465746e1853aef68c90"; // my personal apiKey free and has a limit per day string langMode = "en"; string units = "standard"; XmlDocument myRestXML = new XmlDocument(); // language choice will set the language parameter if (lang == LangChooser.Hungarian) { langMode = "hu"; } else if (lang == LangChooser.German) { langMode = "de"; } else if (lang == LangChooser.English) { langMode = "en"; } // unit choice will set the unit parameter if (unit == UnitChooser.Imperial) { units = "imperial"; } else if (unit == UnitChooser.Metric) { units = "metric"; } else if (unit == UnitChooser.Standard) { units = "standard"; } string url = $"http://api.openweathermap.org/data/2.5/weather?id={ id }&mode=xml&lang={ langMode }&units={ units }&appid={ apiKey }"; using (HttpResponseMessage response = await Api_Helper.ApiClient.GetAsync(url)) { string streamString; if (response.IsSuccessStatusCode) { streamString = await response.Content.ReadAsStringAsync(); myRestXML.LoadXml(streamString); return(myRestXML); } else { throw new Exception(response.ReasonPhrase); } } }
private void btn_GO_Click(object sender, EventArgs e) { ValidateChildren(ValidationConstraints.Enabled); decimal lon = 0; decimal lat = 0; string id = ""; string name = ""; int searchType = 0; LangChooser lc = LangChooser.Hungarian; UnitChooser uc = UnitChooser.Standard; if (textBox_ID.Visible == true) { id = textBox_ID.Text; searchType = 1; } if (textBox_Coord_Lat.Visible == true) { lon = decimal.Parse(textBox_Coord_Long.Text); lat = decimal.Parse(textBox_Coord_Lat.Text); searchType = 2; } if (textBox_Name.Visible == true) { name = textBox_Name.Text; searchType = 3; } lc = languageChoice; uc = unitChoice; Result_Form f1 = new Result_Form(id, lon, lat, name, searchType, lc, uc); f1.Show(); }
public async void LoadWeatherData(string id, decimal lon, decimal lat, string city, int searchType, LangChooser lc, UnitChooser uc) { XmlDocument GotResponse = new XmlDocument(); if (searchType == 1) { GotResponse = await WeatherProcessor.LoadWeather(id, lc, uc); } if (searchType == 2) { GotResponse = await WeatherProcessor.LoadWeather(lat, lon, lc, uc); } if (searchType == 3) { GotResponse = await WeatherProcessor.LoadWeather(city, lc, uc); } if (GotResponse.LastChild != null) { foreach (XmlElement element in GotResponse.LastChild) { //LastChild is current the other oe is the format header //on this level we have 11 nodes if (element.Name == "city") { resultWeater.ID = int.Parse(element.GetAttribute("id")); resultWeater.Name = element.GetAttribute("name"); foreach (XmlElement item in element) // city has 4 childNodes - iterete through { if (item.Name == "coord") { resultWeater.Longitude = decimal.Parse(item.GetAttribute("lon")); resultWeater.Latitude = decimal.Parse(item.GetAttribute("lat")); } if (item.Name == "country") { resultWeater.CountrySign = item.InnerText; } if (item.Name == "sun") { resultWeater.SunRise = DateTime.Parse(item.GetAttribute("rise")); resultWeater.SunSet = DateTime.Parse(item.GetAttribute("set")); } } } if (element.Name == "temperature") { resultWeater.Temperature = decimal.Parse(element.GetAttribute("value")); resultWeater.TemperatureUnit = element.GetAttribute("unit"); } if (element.Name == "humidity") { resultWeater.Humidity = int.Parse(element.GetAttribute("value")); resultWeater.HumidityUnit = element.GetAttribute("unit"); } if (element.Name == "pressure") { resultWeater.Pressure = int.Parse(element.GetAttribute("value")); resultWeater.PressureUnit = element.GetAttribute("unit"); } if (element.Name == "wind") { foreach (XmlElement item in element) { if (item.Name == "speed") { resultWeater.WindSpeed = decimal.Parse(item.GetAttribute("value")); resultWeater.WindSpeedUnit = item.GetAttribute("unit"); } if (item.Name == "direction") { resultWeater.WindDirection = item.GetAttribute("name"); } } } if (element.Name == "clouds") { resultWeater.CloudName = element.GetAttribute("name"); } if (element.Name == "visibility") { resultWeater.Visibility = int.Parse(element.GetAttribute("value")); } if (element.Name == "lastupdate") { resultWeater.LastUpdate = DateTime.Parse(element.GetAttribute("value")); } } } else { MessageBox.Show("Nem található ilyen adat, a bezárást követően próblája újra", "Hiba", MessageBoxButtons.OK); this.Close(); } DisplayWeather(); }
public Result_Form(string id, decimal lon, decimal lat, string city, int searchType, LangChooser lc, UnitChooser uc) { InitializeComponent(); this.Paint += Result_Form_Paint; FillNameDayList(); GetCurrentExchangeRates(); DisplayNameDay(); LoadWeatherData(id, lon, lat, city, searchType, lc, uc); DisplayWeather(); mnbRateDataGridView.DataSource = Rates; dgwSaveExchange.DataSource = _controller.ExchangeManager.Exchanges; }