예제 #1
0
        internal void AddCity(string queryText)
        {
            var task = ThreadPool.RunAsync((work) =>
            {
                lock (lockable)
                {
                    newlist    = null;
                    var list   = SQLAction.GetAll();
                    var result = list.Find((x) =>
                    {
                        return(x.CountryCode == "CN" ? x.CityZh.Equals(queryText, StringComparison.OrdinalIgnoreCase) : x.CityEn.Equals(queryText, StringComparison.OrdinalIgnoreCase));
                    });
                    if (result != null)
                    {
                        if (Array.Exists(Cities.SavedCities, x =>
                        {
                            return(x.Id == result.Id);
                        }))
                        {
                            return;
                        }
                        else
                        {
                            newlist = new List <CitySettingsModel>();
                            newlist.AddRange(Cities.SavedCities);
                            newlist.Add(new CitySettingsModel(result));
                            Cities.Save(newlist.ToArray());
                        }
                    }
                }
            });

            task.Completed = new AsyncActionCompletedHandler(AddCityComplete);
        }
예제 #2
0
파일: Location.cs 프로젝트: soiOL/hello
        public static City GetNearsetLocation(Location source)
        {
            var   list = SQLAction.GetAll();
            float dis  = float.MaxValue;
            City  fi   = null;

            foreach (var item in list)
            {
                var cal = CalcDistance(item.Latitude, item.Longitude, source);
                if (dis > cal)
                {
                    dis = cal;
                    fi  = item;
                }
            }
            return(fi);
        }
예제 #3
0
        internal List <City> Search_TextChanged(string text)
        {
            var           searcharray = text.Split(' ');
            StringBuilder searchsb    = new StringBuilder(@".*");

            foreach (var search in searcharray)
            {
                searchsb.Append(search);
                searchsb.Append(@".*");
            }
            var pattern = searchsb.ToString();
            var list    = SQLAction.GetAll();

            return(list.FindAll((x) =>
            {
                return x.CountryCode == "CN" ? (Regex.IsMatch(x.CityZh, pattern, RegexOptions.IgnoreCase) || Regex.IsMatch(x.CityEn, pattern, RegexOptions.IgnoreCase)) : Regex.IsMatch(x.CityEn, pattern, RegexOptions.IgnoreCase);
            }));
        }