private async void PopulateBtn_Click(object sender, RoutedEventArgs e) { string json = await WeatherConnection.LoadTimeZoneAsync(33, 113, 50); JObject data = JObject.Parse(json); var cities = from p in data["list"] select(string) p["name"]; var weathers = from p in data["list"] select(string) p["weather"][0]["description"]; var temperature = from p in data["list"] select(string) p["main"]["temp"]; int maxID = weatherDB.weather_table.Max(p => p.ID); for (int i = 0; i < cities.Count(); ++i) { weather_table temp = new weather_table() { ID = ++maxID, city = cities.ElementAt(i), weather_descr = weathers.ElementAt(i), temp = (int)float.Parse(temperature.ElementAt(i), CultureInfo.InvariantCulture.NumberFormat) }; weatherDB.weather_table.Add(temp); } weatherDB.SaveChanges(); weather_tableViewSource.View.Refresh(); }
public async void UpdateStatus(Object stateInfo) { if (current_dots == 3) { current_dots = 0; } else { current_dots++; } string json = await WeatherConnection.GetWroclawWeather(); JObject data = JObject.Parse(json); string dots = new string('.', current_dots); string tmp = "Pogoda we Wroclawiu:" + (string)data["weather"][0]["description"] + ", temperatura:" + (string)data["main"]["temp"] + "[K]" + dots; sender.UpdateProgressBlock(tmp); }
private async void GetTimeZone_Click(object sender, RoutedEventArgs e) { try { string json = await WeatherConnection.LoadTimeZoneAsync(Int32.Parse(lat.Text), Int32.Parse(lon.Text), 10); JObject data = JObject.Parse(json); var cities = from p in data["list"] select(string) p["name"]; var weathers = from p in data["list"] select(string) p["weather"][0]["description"]; viewBox.Text = ""; for (int i = 0; i < cities.Count(); ++i) { viewBox.Text += cities.ElementAt(i) + ":" + weathers.ElementAt(i) + "\n"; } } catch (Exception ex) { viewBox.Text = ex.Message; } }