예제 #1
0
        private void UpdateAverage()
        {
            AverageWeather.Clear();

            int        id;
            DateTime   date;
            double     temperature;
            double     pressure;
            double     speedOfWind;
            double     windDirection;
            string     sky;
            bool       rainy;
            bool       snowy;
            WeatherDay weatherDay;

            for (int i = 0; i < OpenWeather.Count; i++)
            {
                id            = OpenWeather[i].Id;
                date          = OpenWeather[i].Date;
                temperature   = (OpenWeather[i].Temperature + Apixu[i].Temperature) / 2;
                pressure      = (OpenWeather[i].Pressure + Apixu[i].Pressure) / 2;
                speedOfWind   = (OpenWeather[i].SpeedOfWind + Apixu[i].SpeedOfWind) / 2;
                windDirection = (OpenWeather[i].WindDirection + Apixu[i].WindDirection) / 2;
                sky           = OpenWeather[i].Sky;
                rainy         = OpenWeather[i].Rainy || Apixu[i].Rainy;
                snowy         = OpenWeather[i].Snowy || Apixu[i].Snowy;
                weatherDay    = new WeatherDay(id, date, temperature, pressure, speedOfWind, windDirection, sky, rainy, snowy);
                AverageWeather.Add(weatherDay);
            }
        }
예제 #2
0
 private void UpdateWeather(object obj)
 {
     OpenWeather        = new List <WeatherDay>(db.GetWeatherDays("openweather"));
     SelectedWeatherDay = new WeatherDay(
         OpenWeather[0].Id,
         OpenWeather[0].Date,
         OpenWeather[0].Temperature,
         OpenWeather[0].Pressure,
         OpenWeather[0].WindDirection,
         OpenWeather[0].SpeedOfWind,
         OpenWeather[0].Sky,
         OpenWeather[0].Rainy,
         OpenWeather[0].Snowy);
     Apixu = new List <WeatherDay>(db.GetWeatherDays("apixu"));
     UpdateAverage();
 }
예제 #3
0
        public IEnumerable <WeatherDay> GetWeatherDays(string table)
        {
            string            txtQuery = $"SELECT * FROM {table}";
            List <WeatherDay> weather  = new List <WeatherDay>();

            using (SQLiteConnection c = new SQLiteConnection(ConnectionString))
            {
                c.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(txtQuery, c))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        if (rdr.HasRows)
                        {
                            int        id;
                            DateTime   date;
                            double     temperature;
                            double     pressure;
                            double     speedOfWind;
                            double     windDirection;
                            string     sky;
                            WeatherDay weatherDay;
                            bool       rainy;
                            bool       snowy;
                            while (rdr.Read())
                            {
                                id            = Convert.ToInt32(rdr["id"]);
                                date          = Convert.ToDateTime((string)rdr["date"]);
                                temperature   = (double)rdr["temperature"];
                                pressure      = (double)rdr["pressure"];
                                windDirection = (double)rdr["wind"];
                                speedOfWind   = (double)rdr["speedOfWind"];
                                sky           = (string)rdr["sky"];
                                rainy         = sky == "cdn.apixu.com/weather/64x64/day/302.png";
                                snowy         = temperature < 10.0 ? true : false;
                                weatherDay    = new WeatherDay(id, date, temperature, pressure, speedOfWind, windDirection, sky, rainy, snowy);
                                weather.Add(weatherDay);
                            }
                        }
                    }
                }
            }
            return(weather);
        }