private void dgrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 6) { if (!string.IsNullOrWhiteSpace(dgrid.CurrentCell.Value?.ToString())) { var townId = (Town)Enum.Parse(typeof(Town), dgrid.CurrentCell.Value?.ToString()); dgrid.CurrentRow.Cells[7].Value = PostalCodes.FirstOrDefault(x => x.Key == (int)townId).Value; } } if (!validateGrid(e.RowIndex)) { dgrid.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; return; } var addCommand = AddtoPersonCommand(e.RowIndex); dgrid.Rows[e.RowIndex].Cells[10].Value = addCommand.Age; if (addCommand.IsValid) { dgrid.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; EnableButtons(); } }
public ActionResult Zips(int qry) { PostalCodes pcs = new PostalCodes(); List<int> zipcodes = pcs.getZipcodes(qry); string jsonString = JsonHelper.JsonSerializer<List<int>>(zipcodes); Response.Write(jsonString); return null; }
public ActionResult Zip(int postalcode) { PostalCodes pcs = new PostalCodes(); PostalCode pc = pcs.getCityByZip(postalcode); string jsonString = JsonHelper.JsonSerializer<PostalCode>(pc); Response.Write(jsonString); return null; }
public ActionResult State(string state) { PostalCodes pcs = new PostalCodes(); List<string> cities = pcs.getCitiesByState(state); string jsonString = JsonHelper.JsonSerializer<List<string>>(cities); Response.Write(jsonString); return null; }
/// <summary> /// Picks a random zip code and city for the given state /// </summary> /// <param name="random"> </param> /// <param name="state"> </param> /// <param name="zip"> </param> /// <param name="town"> </param> protected virtual void GenerateCity(Random random, string state, out string zip, out string town) { var zipMatches = PostalCodes.Where(z => z.State.Equals(state, StringComparison.OrdinalIgnoreCase)).ToList(); var postalCode = zipMatches[random.Next(zipMatches.Count())]; zip = postalCode.Zip; town = postalCode.Town; }
public async Task <GeoLocationCity> PostalCodeToLocationAsync(int postalCode) { var tcs = new TaskCompletionSource <GeoLocationCity>(); var result = await TaskEx.Run <GeoLocationCity>(() => { var query = PostalCodes.Where(item => item.PostalCode == postalCode).FirstOrDefault(); if (query == null) { return(GeoLocationCity.UnkownCity()); } return(query); }); return(result); }
public async Task <GeoLocationCity> LocationToPostalCodeAsync(GeoCoordinate location) { var tcs = new TaskCompletionSource <GeoLocationCity>(); var result = await TaskEx.Run <GeoLocationCity>(() => { var query = PostalCodes .OrderBy(item => item.Location.GetDistanceTo(location)) .FirstOrDefault(); if (query == null) { return(GeoLocationCity.UnkownCity()); } return(query); }); return(result); }
public static PostalCodesCities GetPostalCodesCities(string countryCode) { List <PostalCodeData> postalCodeArray = new List <PostalCodeData>(); List <CityData> cityArray = new List <CityData>(); List <GeographyData> geographyArray = new List <GeographyData>(); PostalCodes codes = PostalCodes.ForCountry(countryCode); Country country = Country.FromCode(countryCode); int maxPostalCodeLength = 0; foreach (PostalCode code in codes) { PostalCodeData dataPoint = new PostalCodeData { Code = code.PostalCode, CityId = code.CityId }; if (code.PostalCode.Length > maxPostalCodeLength) { maxPostalCodeLength = code.PostalCode.Length; } postalCodeArray.Add(dataPoint); } Cities cities = Cities.ForCountry(countryCode); foreach (City city in cities) { CityData dataPoint = new CityData { Id = city.Identity, Name = city.Name, GeographyId = city.GeographyId }; cityArray.Add(dataPoint); } Geographies geographies = Country.FromCode(countryCode).Geography.ThisAndBelow(); foreach (Geography geography in geographies) { GeographyData dataPoint = new GeographyData { Id = geography.Identity, Name = geography.Name }; geographyArray.Add(dataPoint); } PostalCodesCities result = new PostalCodesCities { PostalCodes = postalCodeArray.ToArray(), CityNames = cityArray.ToArray(), Geographies = geographyArray.ToArray(), PostalCodeLength = country.PostalCodeLength, PostalCodeLengthCheck = maxPostalCodeLength }; return(result); }