protected void cities_Click(object sender, EventArgs e) { statusbuttonclick.Text = ""; if (cityname.Text == "") { throw new InvalidOperationException("Please Enter a city name first !!!"); } else { citiespanel.Visible = true; cities.BackColor = System.Drawing.Color.Gray; Geocoder.SearchClient geocode = new Geocoder.SearchClient(); string code = geocode.GetGeocodeFromCityName(cityname.Text); string[] codes = code.Split(','); Search.ServiceClient service = new Search.ServiceClient(); String res = service.getNearByCities(codes[0], codes[1]); XmlDocument result = new XmlDocument(); try { result.LoadXml(res); } catch (XmlException exp) { throw new InvalidOperationException("Sorry, No results found!!"); } string output = ""; XmlNodeList citiesNode = result.SelectNodes("Cities/City"); Boolean first = true; foreach (XmlNode city in citiesNode) { string cityName = city["CityName"].InnerText; string state = city["State"].InnerText; string cityLatitude = city["Latitude"].InnerText; string cityLongitude = city["Longitude"].InnerText; string zipCode = city["ZipCode"].InnerText; string distance = city["Distance"].InnerText; if (first) { output += "<b>Current City:</b><br />"; output += cityName + ", " + state + "<br />"; output += " - " + "Zip Code: " + zipCode + "<br />"; output += " - " + "Geocodes: (" + cityLatitude + ", " + cityLongitude + " )<br />"; output += "<br /><b>Nearby Cities:</b><br />"; first = false; } else { output += cityName + ", " + state + "<br />"; output += " - " + "Distance: " + distance + "<br />"; output += " - " + "Zip Code: " + zipCode + "<br />"; output += " - " + "Geocodes: (" + cityLatitude + ", " + cityLongitude + " )<br />"; output += "<br />"; } } if (!first) { citiesResults.Text = output; } else { throw new InvalidOperationException("Something is not right."); } } }
protected void searchButton_Click(object sender, EventArgs e) { statusbuttonclick.Text = ""; if (cityname.Text == "") { throw new InvalidOperationException("Please Enter a city name first !!!"); } nearestpanel.Visible = true; Geocoder.SearchClient service = new Geocoder.SearchClient(); string code = service.GetGeocodeFromCityName(cityname.Text); string[] codes = code.Split(','); string query = storeType.SelectedItem.Value; if (query == "food" || query == "drinks" || query == "coffee" || query == "arts" || query == "outdoors") { string response = service.SearchFor(cityname.Text, query); XmlDocument result = new XmlDocument(); result.LoadXml(response); string output = ""; XmlNodeList venues = result.SelectNodes("results/venue"); foreach (XmlNode venue in venues) { string name = venue["name"].InnerText; string address = venue["address"].InnerText; string phone = venue["phone"].InnerText; string url = venue["url"].InnerText; string rating = venue["rating"].InnerText; string isOpen = venue["isOpen"].InnerText; output += name + "<br />"; output += " - Address: " + address; output += " - Phone: " + phone + "<br />"; output += " - URL: " + url + "<br />"; output += " - Rating: " + rating + "<br />"; output += " - Open: " + isOpen + "<br />"; output += "<br />"; } searchResults.Text = output; } else if (query == "gas_station" || query == "train_station" || query == "subway_station") { Search.ServiceClient searchService = new Search.ServiceClient(); string xmlResponse = searchService.getStationInfo(codes[0], codes[1], query); XmlDocument result = new XmlDocument(); result.LoadXml(xmlResponse); string queryResults = ""; XmlNodeList stationList = result.SelectNodes("results/station"); foreach (XmlNode station in stationList) { string name = station["name"].InnerText; string address = station["vicinity"].InnerText; queryResults += name + "<br />" + " - Address: " + address + "<br />"; } searchResults.Text = queryResults; } else if (query == "beauty_salon" || query == "spa" || query == "hair_care") { Search.ServiceClient searchService = new Search.ServiceClient(); string res = searchService.findBeautySalons(codes[0], codes[1], query); string[] places = res.Split('+'); string result = ""; foreach (string place in places) { if (!string.IsNullOrEmpty(place)) { string[] parameters = place.Split('|'); result += parameters[0] + "<br />"; result += " - Address: " + parameters[1] + "<br />"; if (parameters.Length == 3) { result += " - Open: " + parameters[2] + "<br />"; } result += "<br />"; } } searchResults.Text = result; } else if (query == "atm" || query == "bank") { ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client(); String[] returnedbankatm = sc.getNearestBankAtm(codes[0], codes[1], query); if (returnedbankatm == null) { throw new InvalidOperationException("Server Error !!!"); } else { TableRow row = new TableRow(); TableCell cell = new TableCell(); Label l1 = new Label(); l1.Text = "NAME"; cell.Controls.Add(l1); row.Cells.Add(cell); cell = new TableCell(); Label l2 = new Label(); l2.Text = "ADDRESS"; cell.Controls.Add(l2); row.Cells.Add(cell); bankatmtable.Rows.Add(row); for (int i = 0; i < returnedbankatm.Length; i++) { string[] res = returnedbankatm[i].Split('|'); row = new TableRow(); cell = new TableCell(); l1 = new Label(); l1.Text = res[0]; cell.Controls.Add(l1); row.Cells.Add(cell); cell = new TableCell(); l2 = new Label(); l2.Text = res[1]; cell.Controls.Add(l2); row.Cells.Add(cell); bankatmtable.Rows.Add(row); } } } else { string zipcode = service.GetZipCodeFromGeocode(codes[0], codes[1]); searchResults.Text = "<b>Address: </b>" + service.GetNearestStore(zipcode, storeName.Text); } }