using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Travel.Vendor; using System.Security.Permissions; using AssetTableAdapters; using DestinationTableAdapters; [PrincipalPermission(SecurityAction.Demand, Role = "Vendor")] [PrincipalPermission(SecurityAction.Demand, Role = "Admin")] public partial class partners_resort_Location : System.Web.UI.Page { Asset.AssetsRow asset; protected void Page_Load(object sender, EventArgs e) { // Highlight the current nav button HyperLink curBtn = Master.FindControl("LocationBtn") as HyperLink; curBtn.CssClass = "on"; if (!IsPostBack) { LoadDestinations(); LoadData(); } } private void LoadData() { asset = Session["Asset"] as Asset.AssetsRow; if (asset == null) Response.Redirect("~/Default.aspx"); AssetTitle.Text = asset.Title; //load the corresponding destination data DestinationsTableAdapter destinationAdapter = new DestinationsTableAdapter(); Destination.DestinationsRow curDestination = destinationAdapter.GetByDestinationId(asset.DestinationId)[0]; //load the corresponding asset data AssetDataTableAdapter assetDataAdapter = new AssetDataTableAdapter(); Asset.AssetDataRow curAssetData = assetDataAdapter.GetByAssetIdAndPublishLevel( (int)AssetPublishLevel.Preview, asset.AssetId )[0] ; //load the corresponding asset resort data AssetResortsTableAdapter assetResortsAdapter = new AssetResortsTableAdapter(); Asset.AssetResortsRow curAssetResorts = assetResortsAdapter.GetByAssetIdAndPublishLevel( (int)AssetPublishLevel.Preview, asset.AssetId)[0] ; Destinations.SelectedValue = asset.DestinationId.ToString(); if (curDestination.Title != "") { LoadSubDestinations(asset.DestinationId); LoadAirports(asset.DestinationId); } else { SubDestinations.Items.Insert(0, new ListItem("Please Select Destination First", string.Empty)); NearestAirport.Items.Insert(0, new ListItem("Please Select Destination First", string.Empty)); } SubDestinations.SelectedValue = asset.SubDestinationId.ToString(); Address1.Text = curAssetData.Address1; Address2.Text = curAssetData.Address2; Address3.Text = curAssetData.Address3; //DistanceToTown.SelectedValue = asset["DistanceToTown"]; //FreeAirportShuttleYes.Checked = asset["FreeAirportShuttle"] == null ? false : asset["FreeAirportShuttle"].Equals("Yes"); //FreeAirportShuttleNo.Checked = asset["FreeAirportShuttle"] == null ? true : asset["FreeAirportShuttle"].Equals("No"); if (curAssetResorts.HasFreeShuttle) FreeAirportShuttleYes.Checked = true; else FreeAirportShuttleNo.Checked = true; NearestAirport.SelectedValue = curAssetResorts.NearestAirportId.ToString(); //DistanceToAirport.SelectedValue = asset["DistanceToAirport"]; //OceanFrontYes.Checked = asset["OceanFront"] == null ? false : asset["OceanFront"].Equals("Yes"); //OceanFrontNo.Checked = asset["OceanFront"] == null ? true : asset["OceanFront"].Equals("No"); } private void SaveData() { asset = Session["Asset"] as Asset.AssetsRow; if (asset == null) Response.Redirect("~/Default.aspx"); AssetDataTableAdapter assetDataAdapter = new AssetDataTableAdapter(); Asset.AssetDataRow curAssetData = assetDataAdapter.GetByAssetIdAndPublishLevel( (int)AssetPublishLevel.Preview, asset.AssetId )[0] ; AssetResortsTableAdapter assetResortsAdapter = new AssetResortsTableAdapter(); Asset.AssetResortsRow curAssetResorts = assetResortsAdapter.GetByAssetIdAndPublishLevel( (int)AssetPublishLevel.Preview, asset.AssetId)[0] ; asset.DestinationId = Int32.Parse(Destinations.SelectedValue); asset.SubDestinationId = Int32.Parse(SubDestinations.SelectedValue); curAssetData.Address1 = Address1.Text.Trim(); curAssetData.Address2 = Address2.Text.Trim(); curAssetData.Address3 = Address3.Text.Trim(); //asset["DistanceToTown"] = DistanceToTown.SelectedValue; curAssetResorts.HasFreeShuttle = FreeAirportShuttleYes.Checked; curAssetResorts.NearestAirportId = Int32.Parse(NearestAirport.SelectedValue); //asset["DistanceToAirport"] = DistanceToAirport.SelectedValue; curAssetResorts.HasOceanFront = OceanFrontYes.Checked; assetResortsAdapter.Update(curAssetResorts); assetDataAdapter.Update(curAssetData); } protected void Update_Click(object sender, ImageClickEventArgs e) { SaveData(); } private void LoadDestinations() { DestinationsTableAdapter destinationAdapter = new DestinationsTableAdapter(); Destination.DestinationsDataTable allDestinations = destinationAdapter.GetAll(); Destinations.DataSource = allDestinations; Destinations.DataBind(); Destinations.Items.Insert(0, new ListItem("Select", string.Empty)); } private void LoadSubDestinations(int destinationID) { DestinationsTableAdapter destinationAdapter = new DestinationsTableAdapter(); Destination.DestinationsDataTable allDestinations = destinationAdapter.GetAll(); SubDestinations.Items.Clear(); // if (subDestinations.Count == 0) // SubDestinations.Items.Insert(0, new ListItem("N/A", string.Empty)); // else // { SubDestinations.DataSource = allDestinations; SubDestinations.DataBind(); SubDestinations.Items.Insert(0,new ListItem("N/A", string.Empty)); // } } private void LoadAirports(int destinationID) { NearestAirport.Items.Clear(); /* AirportCollection airports = Airport.FetchByDestinationID(destinationID); if (airports.Count == 0) NearestAirport.Items.Insert(0, new ListItem("N/A", string.Empty)); else { NearestAirport.DataSource = airports; NearestAirport.DataBind(); NearestAirport.Items.Insert(0, new ListItem("N/A", string.Empty)); } */ } protected void Destinations_SelectedIndexChanged(object sender, EventArgs e) { if (Destinations.SelectedValue.Equals(string.Empty)) { SubDestinations.Items.Clear(); NearestAirport.Items.Clear(); } else { LoadSubDestinations(Int32.Parse(Destinations.SelectedValue)); LoadAirports(Int32.Parse(Destinations.SelectedValue)); } } }