public static List <ForecastWeather> getForecastWeatherByCityName(string cityName) { string urlString = Credentials.initialApiForcasteSearchByCity + "?q=" + cityName + "&appid=" + Credentials.apiKey; string jsonResponse = ApiUtilities.getJsonStringResponse(urlString); //decode json string respnse to list of forecaste weather data dynamic weatherData = JsonConvert.DeserializeObject(jsonResponse); List <dynamic> weatherDataList = JsonConvert.DeserializeObject <List <dynamic> >(JsonConvert.SerializeObject(weatherData.list)); Console.WriteLine("test : {0}", weatherDataList.Count); List <ForecastWeather> forecastWeatherDataList = new List <ForecastWeather>(); foreach (dynamic weatherDataListElement in weatherDataList) { forecastWeatherDataList.Add(new ForecastWeather(Convert.ToString(weatherDataListElement.main.temp), Convert.ToString(weatherDataListElement.weather[0].icon), Convert.ToString(weatherDataListElement.main.feels_like), Convert.ToString(weatherDataListElement.main.pressure), Convert.ToString(weatherDataListElement.main.humidity), Convert.ToString(weatherDataListElement.wind.speed), Convert.ToString(weatherDataListElement.wind.deg), Convert.ToString(weatherDataListElement.clouds.all), Convert.ToString(weatherDataListElement.dt_txt))); } return(forecastWeatherDataList); }
private void setForecasteWeatherData(string cityName) { List <ForecastWeather> forecastWeatherList = ApiUtilities.getForecastWeatherByCityName(cityName); //ListView ListView = new ListView(); //foreach (ForecastWeather forecastWeatherElement in forecastWeatherList) for (int i = 0; i < forecastWeatherList.Count; i++) { ForecastWeather forecastWeatherElement = forecastWeatherList[i]; Console.WriteLine("test : {0}", forecastWeatherElement.DateText); DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[i].Clone(); //row.Cells["ColumnDateText"].Value = forecastWeatherElement.DateText; row.Cells[0].Value = DisplayTextDataUtility.displayDateText(forecastWeatherElement.DateText); row.Cells[1].Value = DisplayTextDataUtility.displayTemp(forecastWeatherElement.Temp, true); //row.Cells[2].Value = DisplayTextDataUtility.displayFeelsLike(ApiUtilities.convertKelvenToCelcius(forecastWeatherElement.FeelsLike)); row.Cells[2].Value = DisplayTextDataUtility.displayFeelsLike(forecastWeatherElement.FeelsLike, true); row.Cells[3].Value = DisplayTextDataUtility.displayhumidity(forecastWeatherElement.Humidity, true); row.Cells[4].Value = DisplayTextDataUtility.displayPressure(forecastWeatherElement.Pressure, true); row.Cells[5].Value = DisplayTextDataUtility.displaywind(forecastWeatherElement.WindSpeed, forecastWeatherElement.WindDirection, true); row.Cells[6].Value = DisplayTextDataUtility.displayCloudCover(forecastWeatherElement.CloudCover, true); dataGridView1.Rows.Add(row); } }
public static string displayFeelsLike(string feelsLike, bool isGrid = false) { String text = "Feels Like : "; if (isGrid) { text = ""; } return(text + ApiUtilities.convertKelvenToCelcius(feelsLike) + "° C"); }
public static string displayTemp(string temp, bool isGrid = false) { String text = "Temperature : "; if (isGrid) { text = ""; } return(text + ApiUtilities.convertKelvenToCelcius(temp) + "° C"); }
private void setCurrentWeatherData(string cityName) { CurrentWeather currentWeather = ApiUtilities.getCurrentWeatherByCityName(cityName); labelDateTime.Text = DisplayTextDataUtility.displayCurrentDateText(); cityLable.Text = DisplayTextDataUtility.displayCity(currentWeather.CityName, currentWeather.Country); //tempLabel.Text = DisplayTextDataUtility.displayTemp(ApiUtilities.convertKelvenToCelcius(currentWeather.Temp)); tempLabel.Text = DisplayTextDataUtility.displayTemp(currentWeather.Temp); //feelsLikeLabel.Text = DisplayTextDataUtility.displayFeelsLike(ApiUtilities.convertKelvenToCelcius(currentWeather.FeelsLike)); feelsLikeLabel.Text = DisplayTextDataUtility.displayFeelsLike(currentWeather.FeelsLike); pressureLabel.Text = DisplayTextDataUtility.displayPressure(currentWeather.Pressure); humidityLabel.Text = DisplayTextDataUtility.displayhumidity(currentWeather.Humidity); windLabel.Text = DisplayTextDataUtility.displaywind(currentWeather.WindSpeed, currentWeather.WindDirection); cloudCoverLabel.Text = DisplayTextDataUtility.displayCloudCover(currentWeather.CloudCover); currentWeatherIconImage.ImageLocation = ApiUtilities.getImageUrl(currentWeather.ImageIcon); }
public static CurrentWeather getCurrentWeatherByCityName(string cityName) { string urlString = Credentials.initialApiSearchByCity + "?q=" + cityName + "&appid=" + Credentials.apiKey; string jsonResponse = ApiUtilities.getJsonStringResponse(urlString); dynamic weatherData = JsonConvert.DeserializeObject(jsonResponse); Console.WriteLine("test : {0}", weatherData.name); CurrentWeather currentWeather = new CurrentWeather(Convert.ToString(weatherData.main.temp), Convert.ToString(weatherData.name), Convert.ToString(weatherData.weather[0].icon), Convert.ToString(weatherData.main.feels_like), Convert.ToString(weatherData.main.pressure), Convert.ToString(weatherData.main.humidity), Convert.ToString(weatherData.wind.speed), Convert.ToString(weatherData.wind.deg), Convert.ToString(weatherData.clouds.all), Convert.ToString(weatherData.sys.country)); return(currentWeather); }