protected void btnHazards_Click(object sender, EventArgs e) { string longi = longitude.Text; string lat = latitude.Text; if (longi != string.Empty && lat != string.Empty) { IClosestRestaurantAndNaturalHazardsService service = new ClosestRestaurantAndNaturalHazardsServiceClient(); decimal longitude1, latitude1; decimal.TryParse(longi, out longitude1); decimal.TryParse(lat, out latitude1); decimal count = service.NaturalHazardsService(latitude1, longitude1); if (count == -1) { Label2.Text = "Oops! It looks like the longitude and latitude pair \n " + "you provided were invalid, or belonged to a remote location \n" + " that Google Maps could not pinpoint. Please try again!"; } else { Label2.Text = count.ToString(); } } }
//BEGIN BEVERLY EMMONS' CODE protected void btnRestaurant_Click(object sender, EventArgs e) { IClosestRestaurantAndNaturalHazardsService service = new ClosestRestaurantAndNaturalHazardsServiceClient(); //get and validate input string address = restaurantStreet.Text; string city = restaurantcity.Text; string state = restaurantstate.Text; decimal travelDistance; decimal.TryParse(restaurantdistance.Text, out travelDistance); if (String.IsNullOrEmpty(address)) { Label1.Text = "Address field cannot be empty."; } else if (String.IsNullOrEmpty(city)) { Label1.Text = "City field cannot be empty."; } else if (String.IsNullOrEmpty(state)) { Label1.Text = "State field cannot be empty."; } else if (travelDistance <= 0) { Label1.Text = "Travel distance must be > 0."; } else if (travelDistance > 50000) { Label1.Text = "Travel distance must be < 50,000."; } else { string fullAddress = address + ", " + city + ", " + state; //call service IList <string> results = service.FindClosestRestaurants(fullAddress, travelDistance); //make result text to display if (results == null || results.Count == 0) { Label1.Text = "It looks like there were no results returned for the address and" + " travel distance you entered. You might want to \n try again."; } else { string resultsString = string.Empty; int countLimitor = 0; foreach (string result in results) { if (countLimitor == 20) { break; } resultsString += "<div>" + result + "</div>"; countLimitor++; } Label1.Text = resultsString; } } }