예제 #1
0
        /// <summary>Load weather forecast by city id from database</summary>
        private WeatherForecastResponse LoadWeatherForecastFromDBbyCityId(int cityId)
        {
            WeatherForecastResponse tempForecast = new WeatherForecastResponse();

            tempForecast.list = new List <WeatherForecastInfo>();
            WeatherForecastInfo tempForecastInfo;

            DataTable table = SqliteDataAccess.GetTable($"SELECT * FROM WeatherForecast WHERE city_id = {cityId}");

            for (int i = 0; i < table.Rows.Count; i++)
            {
                tempForecastInfo = new WeatherForecastInfo(
                    Convert.ToSingle(table.Rows[i][3]),
                    Convert.ToSingle(table.Rows[i][4]),
                    Convert.ToSingle(table.Rows[i][5]),
                    Convert.ToSingle(table.Rows[i][6]),
                    Convert.ToInt32(table.Rows[i][7]),
                    Convert.ToInt32(table.Rows[i][8]),
                    Convert.ToInt32(table.Rows[i][9]),
                    Convert.ToInt32(table.Rows[i][10]),
                    table.Rows[i][11].ToString(),
                    table.Rows[i][12].ToString(),
                    table.Rows[i][13].ToString(),
                    Convert.ToSingle(table.Rows[i][14]),
                    Convert.ToInt32(table.Rows[i][15]),
                    Convert.ToInt32(table.Rows[i][16]),
                    table.Rows[i][2].ToString()
                    );

                tempForecast.list.Add(tempForecastInfo);
            }
            return(tempForecast);
        }
예제 #2
0
        /// <summary>Show weather forecast by city id on the screen</summary>
        public void ShowWeatherForecast(int cityId)
        {
            weatherForecastResp = LoadWeatherForecastFromDBbyCityId(cityId);

            for (int i = 0; i < weatherCards.Length; i++)
            {
                weatherCards[i].ShowCard(weatherForecastResp.list[i]);
            }
        }
예제 #3
0
        /// <summary>Save weather forecast in database</summary>
        private void SaveWeatherForecastInDB(WeatherForecastResponse weather)
        {
            DeleteWeatherForecastFromDB(weather.city.id);

            SqliteDataAccess.ConnectTo();

            foreach (WeatherForecastInfo item in weather.list)
            {
                SqliteDataAccess.ExecuteQuery(
                    "INSERT INTO WeatherForecast(city_id, DateTime, Temp, Temp_feels_like, Temp_min, Temp_max, Pressure, Humidity, Sea_level, Grnd_level, Weather_main, Weather_description, Weather_icon, Wind_speed, Wind_deg, Clouds) " +
                    $"VALUES ({weather.city.id}, \"{item.dt_txt}\", '{item.main.temp}', '{item.main.feels_like}', '{item.main.temp_min}', '{item.main.temp_max}', {item.main.pressure}, {item.main.humidity}, {item.main.sea_level}, {item.main.grnd_level}, \"{item.weather[0].main}\", \"{item.weather[0].description}\", \"{item.weather[0].icon}\", '{item.wind.speed}', {item.wind.deg}, {item.clouds.all})");
            }
            SqliteDataAccess.Close();


            UpdateProfile(weather.city.id);
        }