Ejemplo n.º 1
0
 public string GetWikiPageId(string country, string city)
 {
     return(AllCities
            .Where(cityInfo => cityInfo.Name == city && cityInfo.Country == country)
            .Select(cityInfo => cityInfo.WikiPageId)
            .FirstOrDefault());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// get city name by city id
 /// </summary>
 /// <param name="vCityId">city id</param>
 /// <returns></returns>
 public static string GetCityName(string vCityId)
 {
     return(AllCities.
            Where(ci => ci.City != null && ci.City.ItemId.ToString() == vCityId).
            Select(ci => ci.City.ItemName).
            DefaultIfEmpty(string.Empty).
            FirstOrDefault());
 }
Ejemplo n.º 3
0
 private void autoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
 {
     if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
     {
         SearchSuggestion = AllCities.Where(x => x.City.StartsWith(sender.Text))
                            .Select(x => $"{x.City}({x.Prov})")
                            .ToList(); //上海(直辖市)
         autoSuggestBox.ItemsSource = SearchSuggestion;
     }
 }
Ejemplo n.º 4
0
 public bool IsRecognizedCity(string country, string city)
 {
     return(AllCities
            .Where(cityInfo =>
                   String.Compare(
                       cityInfo.Country,
                       country,
                       StringComparison.OrdinalIgnoreCase) == 0 &&
                   String.Compare(
                       cityInfo.Name,
                       city,
                       StringComparison.OrdinalIgnoreCase) == 0)
            .Count() > 0);
 }
Ejemplo n.º 5
0
 public string GetWeatherAreaCode(string country, string city)
 {
     return(AllCities
            .Where(cityInfo =>
                   String.Compare(
                       cityInfo.Country,
                       country,
                       StringComparison.OrdinalIgnoreCase) == 0 &&
                   String.Compare(
                       cityInfo.Name,
                       city,
                       StringComparison.OrdinalIgnoreCase) == 0)
            .Select(cityInfo => cityInfo.WeatherAreaCode)
            .FirstOrDefault());
 }
Ejemplo n.º 6
0
        public void PopulateCityCollection(string country, ICollection <string> cities)
        {
            if (cities == null)
            {
                throw new ArgumentNullException("\"cities\" argument must not be null");
            }

            var cityCollection = AllCities
                                 .Where(city => city.Country == country)
                                 .Select(city => city.Name);

            foreach (var city in cityCollection)
            {
                cities.Add(city);
            }
        }
Ejemplo n.º 7
0
        private void autoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            var resultList = AllCities.Where(x => $"{x.City}({x.Prov})".StartsWith(sender.Text)).ToList();

            SearchResult.Clear();
            if (resultList.Count == 1) //回车能够直接添加,而不需要再次点击listView
            {
                var resultCity = resultList[0];
                ParentPage.AddCity(resultCity);
            }
            else
            {
                foreach (var item in resultList)
                {
                    SearchResult.Add(item);
                }
            }
        }
Ejemplo n.º 8
0
 private void OnCityInputChange(object sender, TextChangedEventArgs e)
 {
     Cities = new ObservableCollection <City>(AllCities.Where(x => x.Name.ToLower().Contains(e.NewTextValue.ToLower())).ToList());
 }