Exemplo n.º 1
0
        public void Update(DayWeather item)
        {
            string sql = string.Format("Update DayWeather Set " +
                                       "Day = '@Day', DayTemperature = '@DayTemperature', NightTemperature = '@NightTemperature', " +
                                       "IdImagePath = '@IdImagePath'");

            using (var cmd = new SqlCommand(sql, _connection))
            {
                cmd.Parameters.AddWithValue("@Id", item.Id);
                cmd.Parameters.AddWithValue("@Day", item.Day);
                cmd.Parameters.AddWithValue("@DayTemperature", item.DayTemperature);
                cmd.Parameters.AddWithValue("@NightTemperature", item.NightTemperature);
                _connection.Open();
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    throw new Exception("Update operation wasn`t successful." + ex.Message, ex);
                }
                finally
                {
                    _connection.Close();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fill day weather view with the weather data
        /// </summary>
        /// /// <param name="place">Place for which is forecast</param>
        async Task FillDayWeather(string place)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(WeatherData));
            string        xml;

            try
            {
                xml = await GetWeather(DayWeatherUrl, place, 9);
            }
            catch (HttpRequestException)
            {
                throw;
            }
            if (xml != null)
            {
                try
                {
                    TextReader  reader   = new StringReader(xml);
                    WeatherData forecast = (WeatherData)serializer.Deserialize(reader);
                    DayWeather.Update(forecast);
                    reader.Dispose();
                }
                catch (InvalidOperationException)
                {
                    throw;
                }
            }
        }
Exemplo n.º 3
0
        public void Create(DayWeather item)
        {
            string sql = string.Format("Insert Into DayWeather" +
                                       "(Id, Day, DayTemperature, NightTemperature, IdImagePath)" +
                                       "Values(@Id, @Day, @DayTemperature, @NightTemperature, @IdImagePath)");

            using (var cmd = new SqlCommand(sql, _connection))
            {
                cmd.Parameters.AddWithValue("@Id", item.Id);
                cmd.Parameters.AddWithValue("@Day", item.Day);
                cmd.Parameters.AddWithValue("@DayTemperature", item.DayTemperature);
                cmd.Parameters.AddWithValue("@NightTemperature", item.NightTemperature);
                cmd.Parameters.AddWithValue("@IdImagePath", item.IdImagePath);
                _connection.Open();
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    throw new Exception("Insert operation wasn`t successful." + ex.Message, ex);
                }
                finally
                {
                    _connection.Close();
                }
            }
        }
Exemplo n.º 4
0
 public Weather(CityInfomaition cityInfo, TodayWeather today, DayWeather tomorrow, DayWeather third, DayWeather fourth)
 {
     _cityInfo = cityInfo;
     _today    = today;
     _fourth   = fourth;
     _third    = third;
     _tomorrow = tomorrow;
 }
Exemplo n.º 5
0
 public Weather(CityInfomaition cityInfo, TodayWeather today, DayWeather tomorrow, DayWeather third, DayWeather fourth)
 {
     _cityInfo = cityInfo;
     _today = today;
     _fourth = fourth;
     _third = third;
     _tomorrow = tomorrow;
 }
        public void AddDayWeather(CustomWeather.DayWeather dayWeather)
        {
            var list = _imagePathRepository.GetList().ToList();
            int id   = list.First(x => x.Weather == dayWeather.Weather.ToString()).Id;
            var item = new DayWeather()
            {
                Id               = _dayWeatherRepository.GetList().ToList().Count + 1,
                Day              = dayWeather.Day,
                DayTemperature   = dayWeather.DayTemperature,
                NightTemperature = dayWeather.NightTemperature,
                IdImagePath      = id
            };

            _dayWeatherRepository.Create(item);
            _dayWeatherRepository.Save();
        }
Exemplo n.º 7
0
 public MainWindow()
 {
     InitializeComponent();
     Forecaster     = new Forecaster();
     CurrentWeather = new CurrentWeather();
     DayWeather     = new DayWeather();
     WeekWeather    = new WeekWeather();
     this.CurrentPage.DataContext      = CurrentWeather;
     this.WeekForecastPage.DataContext = DayWeather;
     CreateDayForecast();
     this.WeekForecastPage.DataContext = WeekWeather;
     CreateWeekForecast();
     FillWeatherPages("London");
     PlaceBox.Items.Add(new TextBlock()
     {
         Text = "London"
     });
 }
Exemplo n.º 8
0
 /// <summary>Sets the day weather for the currently selected day.</summary>
 /// <param name="dayWeather">The day weather.</param>
 private void SetDayWeather(DayWeather dayWeather)
 {
     IsToday = dayWeather.Day.ToString() == "Today" ? true : false;
     foreach (var item in SevenDayForecast)
     {
         if (item.Day == dayWeather.Day)
         {
             item.DayColor   = Color.GreenYellow;
             item.IsSelected = true;
         }
         else
         {
             item.DayColor   = Color.DarkGray;
             item.IsSelected = false;
         }
     }
     SelectedDayWeather = dayWeather;
 }
Exemplo n.º 9
0
        public void Delete(DayWeather item)
        {
            string sql = string.Format($"Delete from DayWeather where Id ='{item.Id}'");

            using (var cmd = new SqlCommand(sql, _connection))
            {
                _connection.Open();
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    throw new Exception("Delete operation wasn`t successful." + ex.Message, ex);
                }
                finally
                {
                    _connection.Close();
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// If exists- generates collection for user from day weather objects
        /// </summary>
        public void PopulateDayWeatherList()
        {
            if (daysObservableCollection != null)
            {
                daysObservableCollection.Clear();
                FirstDay = null;
            }

            if (!CreatedWeatherGetter.ErrorOccured)
            {
                try
                {
                    daysObservableCollection = new ObservableCollection <DayWeather>(CreatedWeatherGetter.PopulateDayWeatherList());
                    FirstDay = daysObservableCollection.FirstOrDefault();
                    daysObservableCollection.RemoveAt(0);
                }
                catch (Exception e)
                {
                    MessageBox.Show("VIEWMODEL: " + e.Message);
                }
            }
        }
Exemplo n.º 11
0
        public DayWeather Get(int id)
        {
            DayWeather record = null;

            string sql = string.Format("Select * FROM DayWeather where Id = @Id");

            using (var cmd = new SqlCommand(sql, _connection))
            {
                _connection.Open();
                try
                {
                    cmd.Parameters.AddWithValue("@Id", id);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            record = GetRecord(reader);
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                catch (SqlException ex)
                {
                    throw new Exception("Find operation wasn`t successful." + ex.Message, ex);
                }
                finally
                {
                    _connection.Close();
                }
            }

            return(record);
        }
Exemplo n.º 12
0
        public IList <DayWeather> GetWeatherByParkCode(string parkCode)
        {
            List <DayWeather> result = new List <DayWeather>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string sql = "select * from weather WHERE parkCode = @code " +
                                 "ORDER BY fiveDayForecastValue ASC";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@code", parkCode);         //add user input safely

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        DayWeather weather = new DayWeather();

                        weather.ParkCode             = Convert.ToString(reader["parkCode"]);
                        weather.FiveDayForecastValue = Convert.ToInt32(reader["fiveDayForecastValue"]);
                        weather.Low      = Convert.ToInt32(reader["low"]);
                        weather.High     = Convert.ToInt32(reader["high"]);
                        weather.Forecast = Convert.ToString(reader["forecast"]);

                        result.Add(weather);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            return(result);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Weather
 /// </summary>
 /// <param name="cityInfo"></param>
 /// <param name="today"></param>
 /// <param name="dayWeathers"></param>
 public Weather(CityInfomaition cityInfo, TodayWeather today, DayWeather[] dayWeathers)
 {
     _cityInfo = cityInfo;
     _today = today;
     _dayWeathers = dayWeathers;
 }