Beispiel #1
0
        protected void LoadLocationGeo(LocationGeo locationGeo)
        {
            HtmlGenericControl coordinate = new HtmlGenericControl("div");

            coordinate.Attributes["name"]     = "coord";
            coordinate.Attributes["data-lat"] = locationGeo.Latitude.ToString();
            coordinate.Attributes["data-lon"] = locationGeo.Longitude.ToString();

            LocationController locationController = new LocationController();

            try
            {
                Location x = locationController.GetLocations(locationGeo.ID);
                coordinate.Attributes["data-name"] = x.Name;
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                var msg = AppData.CreateAlert("Could not load Geo info for one of your destinations", "warning");
                err_Placeholder.Controls.Add(msg);
            }
            finally
            {
                locationController.Dispose();
            }

            coordsPlaceholder.Controls.Add(coordinate);
        }
Beispiel #2
0
        private void FindFlightsBtn_Click(object sender, EventArgs e, LocationGeo location, string origin, string destination, string departDate, string returnDate, string passengers)
        {
            //var sentObject = obj as IDictionary<string, Object>;

            string url = "https://www.orbitz.com/Flights-Search?trip=roundtrip&leg1=from:" +
                         origin +
                         ",to:" +
                         destination +
                         ",departure:" +
                         departDate +
                         "TANYT&leg2=from:" +
                         destination +
                         ",to:" +
                         origin +
                         ",departure:" +
                         returnDate +
                         "TANYT&" +
                         "passengers=adults:" +
                         passengers +
                         "&mode=search";

            string script = string.Format("window.open('{0}');", url);

            //Page.ClientScript.RegisterStartupScript(this.GetType(),
            //    "newPage" + UniqueID, script, true);

            //Use this if post back is via Ajax
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                                "newPage" + UniqueID, script, true);
        }
        //////////////////////////////////////////////////////////////////////////////////////////
        //
        public LocationGeo GetCoordinatesByLocationID(int id)
        {
            LocationGeo locationGeo = null;
            DataTable   dt          = null;

            dt = _locationRepository.GetCoordinatesByLocationID(id);

            if (dt != null)
            {
                if (dt.Rows.Count == 1)
                {
                    locationGeo = new LocationGeo();
                    locationGeo.AddRowElementsToLocationGeo(dt.Rows[0]);
                }
                else
                {
                    //record that 0 or more than 1 row was returned.
                }
            }

            return(locationGeo);
        }
Beispiel #4
0
        protected void LoadFavorites()
        {
            List <Favorite> FavoriteList = GetFavoriteList();
            List <Location> LocationList = new List <Location>();

            if (FavoriteList.Count != 0)
            {
                LocationController locationController = new LocationController();
                foreach (Favorite favorite in FavoriteList)
                {
                    try
                    {
                        Location x = locationController.GetLocations(favorite.LocationID);
                        LocationList.Add(x);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        continue;
                    }
                }
                locationController.Dispose();
            }
            else
            {
                Label noFavorites = new Label
                {
                    Text     = "You have no favorites.",
                    CssClass = "panel panel-danger",
                };
                loc_Placeholder.Controls.Add(noFavorites);
            }

            if (LocationList.Count != 0)
            {
                foreach (Location location in LocationList)
                {
                    LoadLocations(location);
                    LoadLocationModals(location);
                }

                LocationController locationController  = new LocationController();
                List <LocationGeo> LocationCoordinates = new List <LocationGeo>();

                foreach (Location location in LocationList)
                {
                    try
                    {
                        LocationGeo x = locationController.GetCoordinatesByLocationID(location.ID);
                        LocationCoordinates.Add(x);
                    }
                    catch (Exception ex)
                    {
                        // Error retrieving coordinates
                        logger.Error(ex.Message);
                    }
                }
                locationController.Dispose();

                if (LocationCoordinates.Count != 0)
                {
                    foreach (LocationGeo locationGeo in LocationCoordinates)
                    {
                        LoadLocationGeo(locationGeo);
                        LoadLocationFlightModals(locationGeo);
                    }
                }
            }
        }
Beispiel #5
0
        protected void LoadLocationFlightModals(LocationGeo location)
        {
            // Create a Bootstrap Modal to display full location information
            HtmlGenericControl Modal = new HtmlGenericControl("div")
            {
                ID = "flightsModal_" + location.ID
            };

            Modal.Attributes["class"] = "modal";
            HtmlGenericControl ModalDialog = new HtmlGenericControl("div");

            ModalDialog.Attributes["class"] = "modal-dialog";
            HtmlGenericControl ModalContent = new HtmlGenericControl("div");

            ModalContent.Attributes["class"] = "modal-content";
            HtmlGenericControl ModalHeader = new HtmlGenericControl("div");

            ModalHeader.Attributes["class"] = "modal-header";
            HtmlGenericControl ModalBody = new HtmlGenericControl("div");

            ModalBody.Attributes["class"] = "modal-body";
            HtmlGenericControl ModalFooter = new HtmlGenericControl("div");

            ModalFooter.Attributes["class"] = "modal-footer";

            // Add content to the Modal
            if (location != null)
            {
                HtmlButton ModalClose = new HtmlButton()
                {
                    InnerText = "x",
                };
                ModalClose.Attributes["class"]        = "close";
                ModalClose.Attributes["data-dismiss"] = "modal";
                // Create an UpdatePanel for modal close
                UpdatePanel ModalPanelClose = new UpdatePanel()
                {
                    ID = "flightsModal_PanelClose" + location.ID,
                };
                ModalPanelClose.Attributes["class"] = "close";
                // Add unload event to prevent exception with dynamically created UpdatePanels
                ModalPanelClose.Unload += (sender, EventArgs) => { UpdatePanel_Unload(sender, EventArgs); };
                // Add close button to update panel
                ModalPanelClose.ContentTemplateContainer.Controls.Add(ModalClose);
                // Add to modal header
                ModalHeader.Controls.Add(ModalPanelClose);

                HtmlGenericControl title = new HtmlGenericControl("div")
                {
                    ID = "flightTitle" + location.ID,
                };
                title.Attributes["class"] = "form-group";
                ModalBody.Controls.Add(title);

                HtmlGenericControl FlightInfo = new HtmlGenericControl("div");
                FlightInfo.Attributes["class"] = "form-group";

                TextBox txtOrigin = new TextBox()
                {
                    CssClass = "form-control",
                    ID       = "txtOrigin_" + location.ID,
                    Text     = "PHL",
                };
                Label lblOrigin = new Label()
                {
                    ID = "lblOrigin_" + location.ID,
                    AssociatedControlID = txtOrigin.UniqueID,
                    Text = "Departing Airport <small class='text-muted'>" +
                           "(3 character " +
                           "<a target='_blank' href='http://www.webflyer.com/travel/milemarker/lookup.shtml'>" +
                           "airport code" +
                           "</a>)</small>",
                };

                FlightInfo.Controls.Add(lblOrigin);
                FlightInfo.Controls.Add(txtOrigin);

                TextBox txtDestination = new TextBox()
                {
                    CssClass = "form-control",
                    ID       = "txtDestination_" + location.ID,
                    ReadOnly = true,
                    Text     = location.AirportCode
                };
                Label lblDestination = new Label()
                {
                    ID = "lblDestination_" + location.ID,
                    AssociatedControlID = txtDestination.UniqueID,
                    Text = "Arrival Airport"
                };
                FlightInfo.Controls.Add(lblDestination);
                FlightInfo.Controls.Add(txtDestination);

                TextBox txtPassengers = new TextBox()
                {
                    CssClass = "form-control",
                    ID       = "txtPassengers_" + location.ID,
                    Text     = "1"
                };
                Label lblPassengers = new Label()
                {
                    ID = "lblPassengers_" + location.ID,
                    AssociatedControlID = txtPassengers.UniqueID,
                    Text = "Number of Passengers"
                };
                FlightInfo.Controls.Add(lblPassengers);
                FlightInfo.Controls.Add(txtPassengers);

                UpdatePanel dates = new UpdatePanel()
                {
                    ID = "datesPanel_" + location.ID,
                };
                // Add unload event to prevent exception with dynamically created UpdatePanels
                dates.Unload += (sender, EventArgs) => { UpdatePanel_Unload(sender, EventArgs); };

                ////////////// DEPART DATE /////////////////
                TextBox txtDepartDate = new TextBox()
                {
                    CssClass = "form-control",
                    ID       = "txtDepartDate_" + location.ID,
                    Text     = DateTime.Now.ToString("MM/dd/yyyy"),
                };
                txtDepartDate.Attributes["disabled"] = "disabled";
                Calendar departDate = new Calendar();
                departDate.ID = "departDate_" + location.ID;
                departDate.SelectionChanged += (sender, EventArgs) => { DepartDate_SelectionChanged(sender, EventArgs, txtDepartDate); };
                Label lblDepartDate = new Label()
                {
                    ID = "lblDepartDate_" + location.ID,
                    AssociatedControlID = txtDepartDate.UniqueID,
                    Text = "Depart Date"
                };
                dates.ContentTemplateContainer.Controls.Add(lblDepartDate);
                dates.ContentTemplateContainer.Controls.Add(txtDepartDate);
                dates.ContentTemplateContainer.Controls.Add(departDate);

                ////////////// RETURN DATE /////////////////
                TextBox txtReturnDate = new TextBox()
                {
                    CssClass = "form-control",
                    ID       = "txtReturnDate_" + location.ID,
                    Text     = DateTime.Now.ToString("MM/dd/yyyy"),
                };
                txtReturnDate.Attributes["disabled"] = "disabled";
                Calendar returnDate = new Calendar();
                returnDate.ID = "returnDate_" + location.ID;
                returnDate.SelectionChanged += (sender, EventArgs) => { ReturnDate_SelectionChanged(sender, EventArgs, txtReturnDate); };
                Label lblReturnDate = new Label()
                {
                    ID = "lblReturnDate_" + location.ID,
                    AssociatedControlID = txtReturnDate.UniqueID,
                    Text = "Return Date"
                };
                dates.ContentTemplateContainer.Controls.Add(lblReturnDate);
                dates.ContentTemplateContainer.Controls.Add(txtReturnDate);
                dates.ContentTemplateContainer.Controls.Add(returnDate);

                FlightInfo.Controls.Add(dates);

                ModalBody.Controls.Add(FlightInfo);

                Button FindFlights = new Button()
                {
                    ID   = "btnFindFlights_" + location.ID,
                    Text = "Find Flights",
                };
                FindFlights.Attributes.Add("class", "btn btn-outline-success");

                ///////// CREATE DYNAMIC OBJECT TO SEND DATA TO EVENT HANDLER ///////////

                //Dictionary<string, object> properties = new Dictionary<string, object>
                //{
                //    { "Origin", txtOrigin.Text },
                //    { "Destination", txtDestination.Text },
                //    { "Passengers", txtPassengers.Text },
                //    { "DepartDate", txtDepartDate.Text },
                //    { "ReturnDate", txtReturnDate.Text }
                //};

                //dynamic dynObj = GetDynamicObject(properties);

                /////////////////////////////////////////////////////////////////////////

                // Set click event and pass flight query values from user
                FindFlights.Click += (sender, EventArgs) =>
                {
                    FindFlightsBtn_Click
                    (
                        sender, EventArgs, location,
                        txtOrigin.Text,
                        txtDestination.Text,
                        txtDepartDate.Text,
                        txtReturnDate.Text,
                        txtPassengers.Text
                    );
                };

                // Create an UpdatePanel to update Favorites without refreshing page
                UpdatePanel ModalPanelBtns = new UpdatePanel()
                {
                    ID = "flightsModal_PanelBtns" + location.ID
                };
                // Add unload event to prevent exception with dynamically created UpdatePanels
                ModalPanelBtns.Unload += (sender, EventArgs) => { UpdatePanel_Unload(sender, EventArgs); };
                // Add FindFlights button to update panel
                ModalPanelBtns.ContentTemplateContainer.Controls.Add(FindFlights);
                // Add buttons to footer
                ModalFooter.Controls.Add(ModalPanelBtns);

                // Construct Modal
                ModalContent.Controls.Add(ModalHeader);
                ModalContent.Controls.Add(ModalBody);
                ModalContent.Controls.Add(ModalFooter);
                ModalDialog.Controls.Add(ModalContent);
                Modal.Controls.Add(ModalDialog);

                // Add modal to placeholder
                loc_Placeholder.Controls.Add(Modal);
            }
        }