Ejemplo n.º 1
0
        //display the search results from the search term in the query string on statup
        protected void Page_Load(object sender, EventArgs e)
        {
            //get the search term form the querystring
            searchTerm = Request.QueryString["ST"];
            //check if the search term is empty
            if (searchTerm == null || searchTerm == "")
            {
                JumbotronSearchBox.ForeColor = System.Drawing.Color.Red;
                JumbotronSearchBox.Text      = "Enter A Search Term";
            }
            else
            {
                //creat a counter to keep track of the current row and result count
                int productCount    = 0;
                int serviceCount    = 0;
                int stylistRowCount = 0;
                bookingCount = 0;
                try
                {
                    //run the search function of the BLL to get the results and diplay them
                    Tuple <List <SP_ProductSearchByTerm>, List <SP_SearchStylistsBySearchTerm> > results = handler.UniversalSearch(searchTerm);
                    #region Products
                    //check if there are product result or not
                    if (results.Item1.Count != 0)
                    {
                        TableRow        newRow        = new TableRow();
                        TableHeaderCell newHeaderCell = new TableHeaderCell();

                        //create a loop to display each result

                        foreach (SP_ProductSearchByTerm result in results.Item1)
                        {
                            //check if it is a service or product
                            //service (Applecation / Service)
                            if (result.ProductType == 'S' || result.ProductType == 'A')
                            {
                                //Service
                                serviceCount++;
                                //check if it the first service and create a table header if it  is
                                if (serviceCount == 1)
                                {
                                    createServiceTableHeader();
                                }
                                // create a new row in the results table and set the height
                                newRow        = new TableRow();
                                newRow.Height = 50;
                                serviceSearchResults.Rows.Add(newRow);
                                //fill the row with the data from the product results object
                                TableCell newCell = new TableCell();
                                newCell.Text = "<a class='btn btn-default' href='/cheveux/services.aspx?ProductID=" + result.ProductID.ToString().Replace(" ", string.Empty) + "'>" +
                                               result.Name.ToString() + "</a>";
                                serviceSearchResults.Rows[serviceCount].Cells.Add(newCell);
                                newCell      = new TableCell();
                                newCell.Text = "<a class='btn btn-default' href='/cheveux/services.aspx?ProductID=" + result.ProductID.ToString().Replace(" ", string.Empty) + "'>" +
                                               result.ProductDescription.ToString() + "</a>";
                                serviceSearchResults.Rows[serviceCount].Cells.Add(newCell);
                                newCell      = new TableCell();
                                newCell.Text = "R " + result.Price;
                                serviceSearchResults.Rows[serviceCount].Cells.Add(newCell);
                            }
                            //products (Treatments)
                            else if (result.ProductType == 'T')
                            {
                                //Products
                                productCount++;
                                //check if it the first product and create a table header if it  is
                                if (productCount == 1)
                                {
                                    createProductTableHeader();
                                }
                                // create a new row in the results table and set the height
                                newRow        = new TableRow();
                                newRow.Height = 50;
                                ProductSearchResults.Rows.Add(newRow);
                                //fill the row with the data from the product results object
                                TableCell newCell = new TableCell();
                                newCell.Text = "<a class='btn btn-default' href='/cheveux/Products.aspx??ProductID=" + result.ProductID.ToString().Replace(" ", string.Empty) + "'>" +
                                               result.Name.ToString() + "</a>";
                                ProductSearchResults.Rows[productCount].Cells.Add(newCell);
                                newCell      = new TableCell();
                                newCell.Text = "<a class='btn btn-default' href='/cheveux/Products.aspx??ProductID=" + result.ProductID.ToString().Replace(" ", string.Empty) + "'>" +
                                               result.ProductDescription.ToString() + "</a>";
                                ProductSearchResults.Rows[productCount].Cells.Add(newCell);
                                newCell      = new TableCell();
                                newCell.Text = "R " + result.Price;
                                ProductSearchResults.Rows[productCount].Cells.Add(newCell);
                            }
                            //error
                            else
                            {
                                //Error
                                function.logAnError("Unknown Product Type found in search results");
                            }
                        }
                    }
                    #endregion

                    #region Stylist
                    //check if the are Stylist Results or not
                    if (results.Item2.Count != 0)
                    {
                        //create a new row in the results table and set the height
                        TableRow newRow = new TableRow();
                        newRow.Height = 50;
                        StylistSearchResults.Rows.Add(newRow);
                        //create a header row and set cell withs
                        TableHeaderCell newHeaderCell = new TableHeaderCell();
                        newHeaderCell.Width = 150;
                        StylistSearchResults.Rows[0].Cells.Add(newHeaderCell);
                        newHeaderCell       = new TableHeaderCell();
                        newHeaderCell.Text  = "Stylist Name";
                        newHeaderCell.Width = 750;
                        StylistSearchResults.Rows[0].Cells.Add(newHeaderCell);
                        newHeaderCell       = new TableHeaderCell();
                        newHeaderCell.Text  = "Stylist Specialization";
                        newHeaderCell.Width = 750;
                        StylistSearchResults.Rows[0].Cells.Add(newHeaderCell);;

                        //create a loop to display each result
                        foreach (SP_SearchStylistsBySearchTerm result in results.Item2)
                        {
                            stylistRowCount++;
                            // create a new row in the results table and set the height
                            newRow        = new TableRow();
                            newRow.Height = 50;
                            StylistSearchResults.Rows.Add(newRow);
                            //fill the row with the data from the results object
                            TableCell newCell = new TableCell();
                            newCell.Text = "<img src=" + result.StylistImage
                                           + " alt='" + result.StylistFName + " " + result.StylistLName +
                                           " Profile Image' width='75' height='75'/>";
                            StylistSearchResults.Rows[stylistRowCount].Cells.Add(newCell);
                            newCell      = new TableCell();
                            newCell.Text = "<a class='btn btn-default' href='Profile.aspx?Action=View&empID=" + result.StylistID.ToString().Replace(" ", string.Empty) + "'>" +
                                           result.StylistFName + " " + result.StylistLName + "</a>";
                            StylistSearchResults.Rows[stylistRowCount].Cells.Add(newCell);
                            newCell      = new TableCell();
                            newCell.Text = "<a class='btn btn-default' href='/cheveux/services.aspx?ProductID=" + handler.viewStylistSpecialisationAndBio(result.StylistID.ToString()).serviceID.ToString().Replace(" ", string.Empty) + "'>" +
                                           handler.viewStylistSpecialisationAndBio(result.StylistID.ToString()).serviceName.ToString() + "</a>";
                            StylistSearchResults.Rows[stylistRowCount].Cells.Add(newCell);
                        }
                    }
                    #endregion

                    #region Bookings
                    searchBookings(sender, e);
                    #endregion

                    #region count headings
                    //set the headings based on the search results
                    //products heading
                    if (bookingCount != 0)
                    {
                        //set the product search results heading
                        bookingResultLable.Text = "<h2> " + bookingCount + " Booking Search Results For '" + searchTerm + "' </h2>";
                        btnShowBoings.Visible   = true;
                    }
                    //products heading
                    if (productCount != 0)
                    {
                        //set the product search results heading
                        ProductResultsLable.Text = "<h2> " + productCount + " Product Search Results For '" + searchTerm + "' </h2>";
                        btnHideProducts.Visible  = true;
                    }
                    //service heading
                    if (serviceCount != 0)
                    {
                        //set the product search results heading
                        serviceResultsLable.Text = "<h2> " + serviceCount + " Service Search Results For '" + searchTerm + "' </h2>";
                        btnHideServices.Visible  = true;
                    }
                    //Stylist Heading
                    if (stylistRowCount != 0)
                    {
                        //set the stylist search results heading
                        StylistResultsLable.Text = "<h2> " + stylistRowCount + " Stylist Search Results For '" + searchTerm + "' </h2>";
                        btnHideStylists.Visible  = true;
                    }
                    //no results
                    if (stylistRowCount == 0 && serviceCount == 0 && productCount == 0 && bookingCount == 0)
                    {
                        bookingResultLable.Text = "<h2> 0 Search Results For '" + searchTerm + "' </h2>";
                    }
                }
                #endregion

                catch (Exception Err)
                {
                    function.logAnError(Err.ToString());
                    serviceResultsLable.Text = "An Error Occurred Getting Search Results From The Server, Try Again Later";
                }
            }
        }