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); }
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); }
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); })); }