private async void GetWeatherFiveDays(Settings.Settings set) { string req = String.Format("http://api.openweathermap.org/data/2.5/forecast?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set)); WebRequest request = WebRequest.Create(req); request.Method = "POST"; request.ContentType = "application/x-www-urlencoded"; WebResponse response = await request.GetResponseAsync(); string answer = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { answer = await sr.ReadToEndAsync(); } } response.Close(); Weather.OpenWeatherFiveDays OWFD = JsonConvert.DeserializeObject <Weather.OpenWeatherFiveDays>(answer); Point p = this.Location; FiveDayWeather FDW = new FiveDayWeather(OWFD, set, answer, p); FDW.Owner = this; this.Hide(); FDW.Show(); }
private async void GetWeatherNow(Settings.Settings set) { // WebRequest request = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=Syktyvkar&lang=en&units=metric&APPID=284736d7aa6652238e2598fa8ce6dd15"); string req1 = String.Format("http://api.openweathermap.org/data/2.5/weather?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set)); string req2 = String.Format("http://api.openweathermap.org/data/2.5/forecast?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set)); WebRequest request = WebRequest.Create(req1); request.Method = "POST"; request.ContentType = "application/x-www-urlencoded"; try { WebResponse response = await request.GetResponseAsync(); string answer = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { answer = await sr.ReadToEndAsync(); } } response.Close(); Weather.OpenWeatherNow OWN = JsonConvert.DeserializeObject <Weather.OpenWeatherNow>(answer); request = WebRequest.Create(req2); response = await request.GetResponseAsync(); answer = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { answer = await sr.ReadToEndAsync(); } } response.Close(); Weather.OpenWeatherFiveDays OWFD = JsonConvert.DeserializeObject <Weather.OpenWeatherFiveDays>(answer); SetWeatherParams(OWN, OWFD, set); } catch { if (set.General.Language == "English") { SetWeatherParams("Сonnection problemю. No data", set); } else { SetWeatherParams("Проблемы с подключением. Нет данных", set); } } }
private int GetFirstTomorrow(Weather.OpenWeatherFiveDays OWFD) { string today = DateTime.Now.ToShortDateString(); for (int i = 0; i < OWFD.List.Length; i++) { if (OWFD.List[i].Date.ToShortDateString() == DateTime.Now.AddDays(1).ToShortDateString()) { return(i); } } return(0); }
public FiveDayWeather(Weather.OpenWeatherFiveDays OWFD, Settings.Settings set, string str, Point p) { InitializeComponent(); this.Location = p; Settings.SettingsHelper.GetWeatherParams(set, ref temp, ref wind, ref pressure); wind_label_1.Text += " " + wind; wind_label_2.Text += " " + wind; wind_label_3.Text += " " + wind; int start = GetFirstTomorrow(OWFD); //date if (set.General.Language == "English") { this.Text = "Next 3 days weather"; first_date_label.Text = String.Format("{0}, {1}", OWFD.List[start].Date.DayOfWeek.ToString().ToUpper(), OWFD.List[start].Date.ToString("d MMM yyyy", new CultureInfo("en-US"))); second_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 8].Date.DayOfWeek.ToString().ToUpper(), OWFD.List[start + 8].Date.ToString("d MMM yyyy", new CultureInfo("en-US"))); third_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 16].Date.DayOfWeek.ToString().ToUpper(), OWFD.List[start + 16].Date.ToString("d MMM yyyy", new CultureInfo("en-US"))); } else { this.Text = "Погода на следующие 3 дня"; first_date_label.Text = String.Format("{0}, {1}", OWFD.List[start].Date.ToString("dddd", new CultureInfo("ru-RU")).ToUpper(), OWFD.List[start].Date.ToString("d MMM yyyy", new CultureInfo("ru-RU"))); second_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 8].Date.ToString("dddd", new CultureInfo("ru-RU")).ToUpper(), OWFD.List[start + 8].Date.ToString("d MMM yyyy", new CultureInfo("ru-RU"))); third_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 16].Date.ToString("dddd", new CultureInfo("ru-RU")).ToUpper(), OWFD.List[start + 16].Date.ToString("d MMM yyyy", new CultureInfo("ru-RU"))); } //icon first_icon_n.Image = OWFD.List[start].Weather[0].IconPath; first_icon_m.Image = OWFD.List[start + 2].Weather[0].IconPath; first_icon_a.Image = OWFD.List[start + 4].Weather[0].IconPath; first_icon_e.Image = OWFD.List[start + 6].Weather[0].IconPath; second_icon_n.Image = OWFD.List[start + 8].Weather[0].IconPath; second_icon_m.Image = OWFD.List[start + 10].Weather[0].IconPath; second_icon_a.Image = OWFD.List[start + 12].Weather[0].IconPath; second_icon_e.Image = OWFD.List[start + 14].Weather[0].IconPath; third_icon_n.Image = OWFD.List[start + 16].Weather[0].IconPath; third_icon_m.Image = OWFD.List[start + 18].Weather[0].IconPath; third_icon_a.Image = OWFD.List[start + 20].Weather[0].IconPath; third_icon_e.Image = OWFD.List[start + 22].Weather[0].IconPath; //temp first_temp_n.Text = Math.Round(OWFD.List[start].Main.Temp, 0) + temp; first_temp_m.Text = Math.Round(OWFD.List[start + 2].Main.Temp, 0) + temp; first_temp_a.Text = Math.Round(OWFD.List[start + 4].Main.Temp, 0) + temp; first_temp_e.Text = Math.Round(OWFD.List[start + 6].Main.Temp, 0) + temp; second_temp_n.Text = Math.Round(OWFD.List[start + 8].Main.Temp, 0) + temp; second_temp_m.Text = Math.Round(OWFD.List[start + 10].Main.Temp, 0) + temp; second_temp_a.Text = Math.Round(OWFD.List[start + 12].Main.Temp, 0) + temp; second_temp_e.Text = Math.Round(OWFD.List[start + 14].Main.Temp, 0) + temp; third_temp_n.Text = Math.Round(OWFD.List[start + 16].Main.Temp, 0) + temp; third_temp_m.Text = Math.Round(OWFD.List[start + 18].Main.Temp, 0) + temp; third_temp_a.Text = Math.Round(OWFD.List[start + 20].Main.Temp, 0) + temp; third_temp_e.Text = Math.Round(OWFD.List[start + 22].Main.Temp, 0) + temp; //wind first_wind_n.Text = Math.Round(OWFD.List[start].Wind.Speed, 0).ToString(); first_wind_m.Text = Math.Round(OWFD.List[start + 2].Wind.Speed, 0).ToString(); first_wind_a.Text = Math.Round(OWFD.List[start + 4].Wind.Speed, 0).ToString(); first_wind_e.Text = Math.Round(OWFD.List[start + 6].Wind.Speed, 0).ToString(); second_wind_n.Text = Math.Round(OWFD.List[start + 8].Wind.Speed, 0).ToString(); second_wind_m.Text = Math.Round(OWFD.List[start + 10].Wind.Speed, 0).ToString(); second_wind_a.Text = Math.Round(OWFD.List[start + 12].Wind.Speed, 0).ToString(); second_wind_e.Text = Math.Round(OWFD.List[start + 14].Wind.Speed, 0).ToString(); third_wind_n.Text = Math.Round(OWFD.List[start + 16].Wind.Speed, 0).ToString(); third_wind_m.Text = Math.Round(OWFD.List[start + 18].Wind.Speed, 0).ToString(); third_wind_a.Text = Math.Round(OWFD.List[start + 20].Wind.Speed, 0).ToString(); third_wind_e.Text = Math.Round(OWFD.List[start + 22].Wind.Speed, 0).ToString(); //humidity first_humidity_n.Text = OWFD.List[start].Main.Humidity.ToString(); first_humidity_m.Text = OWFD.List[start + 2].Main.Humidity.ToString(); first_humidity_a.Text = OWFD.List[start + 4].Main.Humidity.ToString(); first_humidity_e.Text = OWFD.List[start + 6].Main.Humidity.ToString(); second_humidity_n.Text = OWFD.List[start + 8].Main.Humidity.ToString(); second_humidity_m.Text = OWFD.List[start + 10].Main.Humidity.ToString(); second_humidity_a.Text = OWFD.List[start + 12].Main.Humidity.ToString(); second_humidity_e.Text = OWFD.List[start + 14].Main.Humidity.ToString(); third_humidity_n.Text = OWFD.List[start + 16].Main.Humidity.ToString(); third_humidity_m.Text = OWFD.List[start + 18].Main.Humidity.ToString(); third_humidity_a.Text = OWFD.List[start + 20].Main.Humidity.ToString(); third_humidity_e.Text = OWFD.List[start + 22].Main.Humidity.ToString(); //cloudeness first_cloudiness_n.Text = OWFD.List[start].Clouds.All.ToString(); first_cloudiness_m.Text = OWFD.List[start + 2].Clouds.All.ToString(); first_cloudiness_a.Text = OWFD.List[start + 4].Clouds.All.ToString(); first_cloudiness_e.Text = OWFD.List[start + 6].Clouds.All.ToString(); second_cloudiness_n.Text = OWFD.List[start + 8].Clouds.All.ToString(); second_cloudiness_m.Text = OWFD.List[start + 10].Clouds.All.ToString(); second_cloudiness_a.Text = OWFD.List[start + 12].Clouds.All.ToString(); second_cloudiness_e.Text = OWFD.List[start + 14].Clouds.All.ToString(); third_cloudiness_n.Text = OWFD.List[start + 16].Clouds.All.ToString(); third_cloudiness_m.Text = OWFD.List[start + 18].Clouds.All.ToString(); third_cloudiness_a.Text = OWFD.List[start + 20].Clouds.All.ToString(); third_cloudiness_e.Text = OWFD.List[start + 22].Clouds.All.ToString(); }
private void SetWeatherParams(Weather.OpenWeatherNow OWN, Weather.OpenWeatherFiveDays OWFD, Settings.Settings set) { //OWN VALUES string tempValue = ""; string windValue = ""; string pressureValue = ""; Settings.SettingsHelper.GetWeatherParams(set, ref tempValue, ref windValue, ref pressureValue); if (set.General.Language == "English") { if (set.Weather.MinMaxTemp) { temp_label.Text = String.Format("{0}{3} (Min temp {1}{3}, Max temp {2}{3})", Math.Round(OWN.Main.Temp, 0), OWN.Main.TempMin, OWN.Main.TempMax, tempValue); } else { temp_label.Text = String.Format("{0}{1}", Math.Round(OWN.Main.Temp, 0), tempValue); } wind_label.Text = String.Format("{0}, speed: {1} {2}", OWN.Wind.DegStrEng, OWN.Wind.Speed, windValue); wind_label_1.Text = "Wind speed, " + windValue; dateNow_label.Text = DateTime.Now.ToString("d MMM yyyy", new CultureInfo("en-US")); } else { if (set.Weather.MinMaxTemp) { temp_label.Text = String.Format("{0}{3} (Мин. темп. {1}{3}, Макс. темп. {2}{3})", OWN.Main.Temp, OWN.Main.TempMin, OWN.Main.TempMax, tempValue); } else { temp_label.Text = String.Format("{0}{1}", OWN.Main.Temp, tempValue); } wind_label.Text = String.Format("{0}, скорость: {1} {2}", OWN.Wind.DegStrRu, OWN.Wind.Speed, windValue); wind_label_1.Text = "Скорость ветра, " + windValue; dateNow_label.Text = DateTime.Now.ToString("D", new CultureInfo("ru-RU")); } city_label.Text = OWN.Name; humidity_label.Text = OWN.Main.Humidity.ToString() + "%"; pressure_label.Text = String.Format("{0} {1}", Math.Round(OWN.Main.Pressure, 0), pressureValue); description_label.Text = FirstUpper(OWN.Weather[0].Description); icon_pictureBox.Image = OWN.Weather[0].IconPath; cloudiness_label.Text = OWN.Clouds.All + "%"; wind_pictureBox.Image = OWN.Wind.Img; sunrise_label.Text = OWN.Sys.SunriseLocal.ToString("t"); sunset_label.Text = OWN.Sys.SunsetLocal.ToString("t"); //OWFD VALUES //time time1_label.Text = OWFD.List[1].Date.ToString("t"); time2_label.Text = OWFD.List[2].Date.ToString("t"); time3_label.Text = OWFD.List[3].Date.ToString("t"); time4_label.Text = OWFD.List[4].Date.ToString("t"); time5_label.Text = OWFD.List[5].Date.ToString("t"); time6_label.Text = OWFD.List[6].Date.ToString("t"); //icons icon1.Image = OWFD.List[1].Weather[0].IconPath; icon2.Image = OWFD.List[2].Weather[0].IconPath; icon3.Image = OWFD.List[3].Weather[0].IconPath; icon4.Image = OWFD.List[4].Weather[0].IconPath; icon5.Image = OWFD.List[5].Weather[0].IconPath; icon6.Image = OWFD.List[6].Weather[0].IconPath; //temp temp1.Text = Math.Round(OWFD.List[1].Main.Temp, 0) + tempValue; temp2.Text = Math.Round(OWFD.List[2].Main.Temp, 0) + tempValue; temp3.Text = Math.Round(OWFD.List[3].Main.Temp, 0) + tempValue; temp4.Text = Math.Round(OWFD.List[4].Main.Temp, 0) + tempValue; temp5.Text = Math.Round(OWFD.List[5].Main.Temp, 0) + tempValue; temp6.Text = Math.Round(OWFD.List[6].Main.Temp, 0) + tempValue; //wind wind1.Text = Math.Round(OWFD.List[1].Wind.Speed, 0).ToString(); wind2.Text = Math.Round(OWFD.List[2].Wind.Speed, 0).ToString(); wind3.Text = Math.Round(OWFD.List[3].Wind.Speed, 0).ToString(); wind4.Text = Math.Round(OWFD.List[4].Wind.Speed, 0).ToString(); wind5.Text = Math.Round(OWFD.List[5].Wind.Speed, 0).ToString(); wind6.Text = Math.Round(OWFD.List[6].Wind.Speed, 0).ToString(); }