Esempio n. 1
0
        private void btnCheckForecast_Click(object sender, EventArgs e)
        {
            LocationQuery lq;

            //Prefer longitude x latitude
            if (this.latitudeTextbox.TextLength * longitudeTextBox.TextLength > 0)
            {
                lq = new LocationQuery(double.Parse(latitudeTextbox.Text), double.Parse(longitudeTextBox.Text));
            }
            else if (txtBoxCityName.TextLength > 0)
            {
                lq = new LocationQuery(txtBoxCityName.Text);
            }
            else
            {
                return;
            }

            WeatherQuery wq = new WeatherQuery(lq);

            lblHigh.Text     = $"High: {wq.tempHigh.ToString()} {wq.temperatureUnit}";
            lblLow.Text      = $"Low: {wq.tempLow.ToString()} {wq.temperatureUnit}";
            lblUrl.Text      = $"More Info";
            lblUrl.ForeColor = Color.Blue;
            urlMoreInfo      = wq.webLocation.ToString();
        }
Esempio n. 2
0
 public WeatherQuery(LocationQuery lq)
 {
     using (var webClient = new System.Net.WebClient())
         jsonData = JObject.Parse(webClient.DownloadString($"http://dataservice.accuweather.com/forecasts/v1/daily/1day/{lq.Key}?apikey={apiKeys.AccuWeatherAPIKey}&metric=true"));
     webLocation     = (string)jsonData["DailyForecasts"][0]["Link"];
     temperatureUnit = (string)jsonData["DailyForecasts"][0]["Temperature"]["Minimum"]["Unit"];
     tempLow         = double.Parse((string)jsonData["DailyForecasts"][0]["Temperature"]["Minimum"]["Value"]);
     tempHigh        = double.Parse((string)jsonData["DailyForecasts"][0]["Temperature"]["Maximum"]["Value"]);
 }