private void UpdateForm(Forecast forecast)
        {
            PlaatsTextBox.Text    = Plaatsnaam;
            IntervalTextBox.Text  = Interval.ToString();
            LocationLabel.Text    = Plaatsnaam;
            DescriptionLabel.Text = forecast.weather.First().description;
            WeatherIconPictureBox.ImageLocation = "http://openweathermap.org/img/w/" + forecast.weather.First().icon + ".png";
            TemperatuurLabel.Text      = BuildTemperatureString(forecast.main.temp);
            LuchtvochtigheidLabel.Text = String.Format("Luchtvochtigheid: {0}%", forecast.main.humidity);
            WindLabel.Text             = BuildWindString(forecast.wind.speed, forecast.wind.deg);
            DateTime LatestUpdate = forecast.datetime;

            LatestUpdateLabel.Text = String.Format("[Laatste update: {0}]", LatestUpdate);
            FillChart(WController.GetAvgTempPerDayByCity(City_Id));
            TempToolStripTextBox.Text = BuildContextMenuTemperature(CalculateTemperature(forecast.main.temp, MetricSystem), MetricSystem);
        }
Ejemplo n.º 2
0
        public void QueryWeatherApi(int City_Id, string Language)
        {
            string url = String.Format("https://api.openweathermap.org/data/2.5/weather?id={0}&lang={1}&appid={2}", City_Id, Language, APIKEY);

            try
            {
                WebClient client       = new WebClient();
                string    responseBody = client.DownloadString(url);

                using (JsonTextReader reader = new JsonTextReader(new StringReader(responseBody)))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    Forecast       forecast   = (Forecast)serializer.Deserialize(reader, typeof(Forecast));
                    WriteForecastToDatabase(forecast);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void GetLatestForecastFromDatabase(int MaxPK)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "GetForecastByMaxPK";

                        //Add input parameters
                        command.Parameters.AddWithValue("@MaxPK", MaxPK);

                        //Add output parameters
                        command.Parameters.AddWithValue("@Weather_Desc", null);
                        command.Parameters["@Weather_Desc"].DbType    = DbType.String;
                        command.Parameters["@Weather_Desc"].Direction = ParameterDirection.Output;
                        command.Parameters["@Weather_Desc"].Size      = 30;

                        command.Parameters.AddWithValue("@Weather_Icon", null);
                        command.Parameters["@Weather_Icon"].DbType    = DbType.String;
                        command.Parameters["@Weather_Icon"].Direction = ParameterDirection.Output;
                        command.Parameters["@Weather_Icon"].Size      = 3;

                        command.Parameters.AddWithValue("@Datetime", null);
                        command.Parameters["@Datetime"].DbType    = DbType.DateTime;
                        command.Parameters["@Datetime"].Direction = ParameterDirection.Output;

                        command.Parameters.AddWithValue("@Temp", null);
                        command.Parameters["@Temp"].DbType    = DbType.Double;
                        command.Parameters["@Temp"].Direction = ParameterDirection.Output;

                        command.Parameters.AddWithValue("@Humidity", null);
                        command.Parameters["@Humidity"].DbType    = DbType.Int32;
                        command.Parameters["@Humidity"].Direction = ParameterDirection.Output;

                        command.Parameters.AddWithValue("@Wind_Speed", null);
                        command.Parameters["@Wind_Speed"].DbType    = DbType.Double;
                        command.Parameters["@Wind_Speed"].Direction = ParameterDirection.Output;

                        command.Parameters.AddWithValue("@Wind_Deg", null);
                        command.Parameters["@Wind_Deg"].DbType    = DbType.Double;
                        command.Parameters["@Wind_Deg"].Direction = ParameterDirection.Output;

                        connection.Open();
                        command.ExecuteNonQuery();

                        forecast = new Forecast();

                        forecast.weather = new List <Weather> {
                            new Weather {
                                description = command.Parameters["@Weather_Desc"].Value.ToString(),
                                icon        = command.Parameters["@Weather_Icon"].Value.ToString()
                            }
                        };
                        forecast.datetime = DateTime.Parse(command.Parameters["@Datetime"].Value.ToString());
                        forecast.main     = new Main {
                            temp     = Double.Parse(command.Parameters["@Temp"].Value.ToString()),
                            humidity = Int32.Parse(command.Parameters["@Humidity"].Value.ToString())
                        };
                        forecast.wind = new Wind {
                            speed = Double.Parse(command.Parameters["@Wind_Speed"].Value.ToString()),
                            deg   = Double.Parse(command.Parameters["@Wind_Deg"].Value.ToString())
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }