Ejemplo n.º 1
0
        /// <summary>Load current weather all cities by profile from database</summary>
        private void LoadCurrentWeatherFromProfile()
        {
            if (citiesProfile != null)
            {
                citiesProfile.Clear();
            }
            else
            {
                citiesProfile = new Dictionary <int, WeatherResponse>();
            }

            tableWeatherInCities = SqliteDataAccess.GetTable("SELECT Weather.id_city, Name, State, Country, longitude, City.latitude, Temp, Feels_like, Pressure, Humidity, Wind_speed, Wind_deg, Clouds, Sunrise, Sunset, Timezone " +
                                                             "FROM Weather, City " +
                                                             "WHERE Weather.id_city = City.id_city AND EXISTS " +
                                                             "(SELECT id_city " +
                                                             "FROM WeatherProfile " +
                                                             $"WHERE id_user_profile = {profile} AND Weather.id_city = WeatherProfile.id_city)");

            for (int i = 0; i < tableWeatherInCities.Rows.Count; i++)
            {
                currentWeatherResp = new WeatherResponse(
                    Convert.ToInt32(tableWeatherInCities.Rows[i][0].ToString()),   // cityId
                    tableWeatherInCities.Rows[i][1].ToString(),                    // name
                    tableWeatherInCities.Rows[i][2].ToString(),                    //state
                    tableWeatherInCities.Rows[i][3].ToString(),                    // country
                    Convert.ToSingle(tableWeatherInCities.Rows[i][4].ToString()),  // longitude
                    Convert.ToSingle(tableWeatherInCities.Rows[i][5].ToString()),  // latitude
                    Convert.ToSingle(tableWeatherInCities.Rows[i][6].ToString()),  // temp
                    Convert.ToSingle(tableWeatherInCities.Rows[i][7].ToString()),  // feels_like
                    Convert.ToInt32(tableWeatherInCities.Rows[i][8].ToString()),   // pressure
                    Convert.ToInt32(tableWeatherInCities.Rows[i][9].ToString()),   // humidity
                    Convert.ToSingle(tableWeatherInCities.Rows[i][10].ToString()), // wind_speed
                    Convert.ToInt32(tableWeatherInCities.Rows[i][11].ToString()),  // wind_deg
                    Convert.ToInt32(tableWeatherInCities.Rows[i][12].ToString()),  // clouds
                    Convert.ToInt32(tableWeatherInCities.Rows[i][13].ToString()),  // sunrise
                    Convert.ToInt32(tableWeatherInCities.Rows[i][14].ToString()),  // sunset
                    Convert.ToInt32(tableWeatherInCities.Rows[i][15].ToString())   // timezone
                    );

                citiesProfile.Add(currentWeatherResp.id, currentWeatherResp); // (cityID, WeatherInCity)
            }
        }
Ejemplo n.º 2
0
        /// <summary>Show current weather by city id on the screen</summary>
        public void ShowCurrentWeather(int cityId)
        {
            long     utcSunriseDate = currentWeatherResp.sys.sunrise;
            long     utcSunsetDate  = currentWeatherResp.sys.sunset;
            DateTime start          = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime sunriseDate    = start.AddSeconds(utcSunriseDate).ToLocalTime();
            DateTime sunsetDate     = start.AddSeconds(utcSunsetDate).ToLocalTime();
            TimeSpan timezone       = new TimeSpan(0, 0, 0, currentWeatherResp.timezone);

            currentWeatherResp = citiesProfile[cityId];

            cityNameText.text   = currentWeatherResp.name;
            tempText.text       = currentWeatherResp.main.temp.ToString();
            feels_likeText.text = currentWeatherResp.main.feels_like.ToString();
            pressureText.text   = currentWeatherResp.main.pressure.ToString();
            humidityText.text   = currentWeatherResp.main.humidity.ToString();
            wind_speedText.text = currentWeatherResp.wind.speed.ToString();
            wind_degText.text   = currentWeatherResp.wind.deg.ToString();
            cloudsText.text     = currentWeatherResp.clouds.all.ToString();
            sunriseText.text    = sunriseDate.ToShortTimeString();
            sunsetText.text     = sunsetDate.ToShortTimeString();

            ShowWeatherForecast(cityId);
        }