コード例 #1
0
 private void searchBox_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         this.cityToRefresh = searchBox.Text;
         setupTimer();
         bool   found         = false;
         string selected_city = searchBox.Text;
         for (int i = 0; i < Favourites.Count; i++)
         {
             if (selected_city == Favourites.ElementAt(i).name + "," + Favourites.ElementAt(i).country)
             {
                 this.favouriteYES.Visibility = Visibility.Visible;
                 this.favouriteNO.Visibility  = Visibility.Hidden;
                 found = true;
                 break;
             }
         }
         if (!found)
         {
             this.favouriteYES.Visibility = Visibility.Hidden;
             this.favouriteNO.Visibility  = Visibility.Visible;
         }
     }
     else
     {
         return;
     }
 }
コード例 #2
0
        private void favourite_Checked(object sender, RoutedEventArgs e)
        {
            this.favouriteNO.Visibility  = Visibility.Hidden;
            this.favouriteYES.Visibility = Visibility.Visible;

            if (product.city == null)
            {
                this.favouriteNO.Visibility  = Visibility.Visible;
                this.favouriteYES.Visibility = Visibility.Hidden;
                return;
            }
            bool exists = false;

            for (int i = 0; i < Favourites.Count; i++)
            {
                if (product.city.id == Favourites.ElementAt(i).id)
                {
                    exists = true;
                }
            }
            if (!exists)
            {
                Favourites.Add(new City(product.city.id, product.city.name, product.city.coord, product.city.country, product.city.population));
                favWin.listView.Items.Add(product.city.name + "," + product.city.country);
                SaveFavourites();
            }
        }
コード例 #3
0
        public void updateFavourite()
        {
            var value = IsFavourite;

            if (value)
            {
                bool exists = false;
                for (int i = 0; i < Favourites.Count; i++)
                {
                    if (CurrentCityId == Favourites.ElementAt(i).Id)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    Favourites.Add(new City(CurrentCityName, CurrentCityId));
                    SaveFavourites();
                }
            }
            else
            {
                for (int i = 0; i < Favourites.Count; i++)
                {
                    if (CurrentCityId == Favourites.ElementAt(i).Id)
                    {
                        Favourites.Remove(Favourites.ElementAt(i));
                        SaveFavourites();
                        break;
                    }
                }
            }
        }
コード例 #4
0
 public void updateIsFavourite()
 {
     for (int i = 0; i < Favourites.Count; i++)
     {
         if (CurrentCityId == Favourites.ElementAt(i).Id)
         {
             IsFavourite = true;
             return;
         }
     }
     IsFavourite = false;
     return;
 }
コード例 #5
0
 private void favourite_Unchecked(object sender, RoutedEventArgs e)
 {
     this.favouriteYES.Visibility = Visibility.Hidden;
     this.favouriteNO.Visibility  = Visibility.Visible;
     this.favouriteNO.Visibility  = Visibility.Visible;
     for (int i = 0; i < Favourites.Count; i++)
     {
         if (product.city.id == Favourites.ElementAt(i).id)
         {
             Favourites.Remove(Favourites.ElementAt(i));
             favWin.listView.Items.Remove(product.city.name + "," + product.city.country);
             SaveFavourites();
             break;
         }
     }
 }
コード例 #6
0
        private void ComboBox_DropDownClosed(object sender, EventArgs e)
        {
            this.cityToRefresh = searchBox.Text;
            setupTimer();
            if (cityToRefresh != "" && product != null)
            {
                AddToHistory(product.city);
            }

            string selected_city = null;
            bool   found         = false;

            try
            {
                selected_city = searchBox.SelectedValue.ToString();
            }
            catch
            {
                return;
            }

            for (int i = 0; i < Favourites.Count; i++)
            {
                if (selected_city == Favourites.ElementAt(i).name + "," + Favourites.ElementAt(i).country)
                {
                    this.favouriteYES.Visibility = Visibility.Visible;
                    this.favouriteNO.Visibility  = Visibility.Hidden;
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                this.favouriteYES.Visibility = Visibility.Hidden;
                this.favouriteNO.Visibility  = Visibility.Visible;
            }
        }