// (c) Donn Felker // http://blog.donnfelker.com/post/HOWTO-Build-a-Store-Locator-in-ASPNET.aspx // http://codeplex.com/StoreLocator // // DotNetNuke® - http://www.dotnetnuke.com // Copyright (c) 2002-2009 // by DotNetNuke Corporation // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and // to permit persons to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or substantial portions // of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System; using System.Web.UI; using System.Web.UI.WebControls; using DotNetNuke.Common; using DotNetNuke.Services.Exceptions; namespace AdefWebserver.Modules.StoreLocator { public partial class Edit : DotNetNuke.Entities.Modules.PortalModuleBase { protected void Page_Load(object sender, EventArgs e) { try { if ((Page.IsPostBack == false)) { if (GetGoogleAPIKey() == "") { lblError.Text = "Error: Must Set Google API Key in Module Settings"; } } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } } #region lnkBack_Click protected void lnkBack_Click(object sender, EventArgs e) { Response.Redirect(Globals.NavigateURL(), true); } #endregion #region LDSLocations_Selecting protected void LDSLocations_Selecting(object sender, LinqDataSourceSelectEventArgs e) { e.WhereParameters["ModuleId"] = ModuleId; } #endregion #region lvLocations_ItemInserting protected void lvLocations_ItemInserting(object sender, ListViewInsertEventArgs e) { ListView lvLocations = (ListView)sender; // Get the address values DropDownList dllStates = (DropDownList)lvLocations.InsertItem.FindControl("dllStates"); TextBox AddressTextBox = (TextBox)lvLocations.InsertItem.FindControl("AddressTextBox"); TextBox CityTextBox = (TextBox)lvLocations.InsertItem.FindControl("CityTextBox"); TextBox ZipTextBox = (TextBox)lvLocations.InsertItem.FindControl("ZipTextBox"); // Check for valid addrss if ( AddressTextBox.Text.Trim() == "" || CityTextBox.Text.Trim() == "" || ZipTextBox.Text.Trim() == "" ) { lblError.Text = "Must use a valid address."; lblError.Focus(); e.Cancel = true; return; } // Build address string strAddress = String.Format("{0}, {1}, {2} {3}", AddressTextBox.Text.Trim(), CityTextBox.Text.Trim(), dllStates.SelectedValue, ZipTextBox.Text.Trim()); // Geocode Address GoogleGeoCoder.Coordinate Coordinate = GoogleGeoCoder.Geocode.GetCoordinates(strAddress, GetGoogleAPIKey()); // Check for valid Geocode addrss if (Coordinate.Latitude == Convert.ToDecimal(0)) { lblError.Text = "Must use a valid address."; lblError.Focus(); e.Cancel = true; return; } // Set Latitude and Longitude double? dblLatitude = Convert.ToDouble(Coordinate.Latitude); double? dblLongitude = Convert.ToDouble(Coordinate.Longitude); e.Values["Latitude"] = dblLatitude; e.Values["Longitude"] = dblLongitude; // Set the State e.Values["State"] = dllStates.SelectedValue; // Set the ModuleId e.Values["ModuleID"] = ModuleId; } #endregion #region GetGoogleAPIKey string GetGoogleAPIKey() { string GoogleAPIKey = ""; if ((Settings["GoogleAPIKey"]) != null) { GoogleAPIKey = Convert.ToString(Settings["GoogleAPIKey"]); } return GoogleAPIKey; } #endregion } }
Buy DotNetNuke Modules from Snowcovered |
DotNetNuke™ is a registered trademark of DotNetNuke Corporation.