예제 #1
0
        public void CampgroundReservationScreen(Park currentWorkingPark)
        {
            string campgroundSelectionPrompt = "\nPlease select a 'Campground' ID from the list (enter 0 to cancel)?";

            string campsiteSelectionPrompt = "\nPlease select a 'Campsite ID' from the list (enter 0 to cancel)?";

            string enterValidIDError = "Please make a valid 'Campsite ID' selection from the list.";

            string arrivalDatePrompt = "What is the arrival date? (MM/DD/YYYY):";

            string departureDatePrompt = "What is the departure date? (MM/DD/YYYY):";

            string negativeDateRangeError = "Departure date must be after arrival date. Please try again.\n";

            string noResultsInRangeError = "\nThere are no open campsites in the selected timeframe for that campground.\nTry an alternative date range.";

            string reservationNamePrompt = "What name should the reservation be made under?";

            string searchResult = $"Results Matching Your Search Criteria\n\n" + "Site #".PadRight(9) + "Max Occup.".PadRight(11) + "Accessible?".PadRight(12) + "RV Size".PadRight(12) + "Utility".PadRight(15) + "Cost\n";

            string reqFromDate;             //User desired arrival date

            string reqToDate;               //User desired departure date

            bool isFirstTry = true;         //Used to track first run through campground selection process


            IList <Campground> campgroundList   = DisplayCampgrounds(currentWorkingPark);
            List <int>         campgroundIdList = new List <int>();

            foreach (Campground campground in campgroundList)
            {
                campgroundIdList.Add(campground.Campground_id);
            }

            IList <Site> unreservedSites = new List <Site>();

            do
            {
                bool negativeDateRangeAttempted = false;

                if (!isFirstTry)
                {
                    Console.WriteLine(noResultsInRangeError);
                }

                int campgroundNum;          //Stores DB value for campgroundID

                do
                {
                    campgroundNum = CLIHelper.GetInteger(campgroundSelectionPrompt); //CLIHelper deals with incorrect inputs, do while just waits for proper input or exit condition

                    if (campgroundNum == 0)
                    {
                        return;
                    }
                } while (!campgroundIdList.Contains(campgroundNum));

                reqFromDate = CLIHelper.GetDateTime(arrivalDatePrompt); //Arrival date is necessarry and CLIHelper handles errors, so no loop necessary

                do
                {
                    if (negativeDateRangeAttempted)
                    {
                        Console.WriteLine(negativeDateRangeError);
                    }

                    reqToDate = CLIHelper.GetDateTime(departureDatePrompt);

                    negativeDateRangeAttempted = DateTime.Parse(reqToDate) <= DateTime.Parse(reqFromDate);
                } while (negativeDateRangeAttempted);

                /*----------------------------------------------------Advanced Search------------------------------------------------------*/
                bool advancedSearch = false;  //TODO Any way to move this to its own method?
                int  minOccupancy   = 0;
                bool accessible     = false;
                int  maxRvLength    = 0;
                bool utilities      = false;

                advancedSearch = CLIHelper.GetBool("Use Advanced Search (Y/N)?");

                if (advancedSearch)
                {
                    minOccupancy = CLIHelper.GetInteger("Minimum Occupancy (Enter 0 to skip):");
                    accessible   = CLIHelper.GetBool("Do you require accessibility features (Y/N)?");
                    maxRvLength  = CLIHelper.GetInteger("What is your RV size (Enter 0 to skip)?");
                    utilities    = CLIHelper.GetBool("Do you require a utility hookup (Y/N)?");
                }
                /*---------------------------------------------------End of Advanced Search-------------------------------------------------*/

                SiteDAL siteDal = new SiteDAL(DatabaseConnection);
                unreservedSites = siteDal.GetUnreservedCampsites(reqFromDate, reqToDate, campgroundNum, minOccupancy, accessible, maxRvLength, utilities);

                isFirstTry = false;
            } while (unreservedSites.Count == 0);

            int lengthOfStay = CLIHelper.GetLengthOfStay(reqFromDate, reqToDate);

            Console.Clear();
            Console.WriteLine(searchResult);

            foreach (Site site in unreservedSites)
            {
                Console.WriteLine(site.ToString(lengthOfStay, false));
            }

            ReservationDAL reservationDAL = new ReservationDAL(DatabaseConnection);

            while (true)
            {
                int campsiteChoice = CLIHelper.GetInteger(campsiteSelectionPrompt);

                if (campsiteChoice == 0)
                {
                    return;
                }

                foreach (Site site in unreservedSites)
                {
                    if (campsiteChoice == site.SiteID)
                    {
                        string reservationHeader = $"===================Reservation Confirmation==================\n";

                        string reservationName = CLIHelper.GetString(reservationNamePrompt);
                        int    reservationID   = reservationDAL.MakeReservation(reqFromDate, reqToDate, campsiteChoice, reservationName);

                        Console.Clear();
                        Console.SetCursorPosition((Console.WindowWidth - reservationHeader.Length) / 2, Console.CursorTop);
                        Console.WriteLine(reservationHeader);
                        Console.WriteLine($"\nThe reservation has been made and the confirmation id is {reservationID}.\nPress Enter to continue."); //Can't move this yet
                        Console.ReadLine();
                        return;
                    }
                }

                Console.WriteLine(enterValidIDError);
            }
        } //Used to view open reservations and make reservations in the scope of a campsite at a campground
        }//ViewCampgroundsLis

        private void CampgroundReservationSearchMenu(int park_Id)
        {
            bool returnToPreviousMenu = false;

            while (returnToPreviousMenu == false)
            {
                PrintHeader("Search for Campground Reservation");

                List <Campground> campgrounds = ParkCampgroundsList(park_Id);
                FlowerLine();
                Console.WriteLine();

                List <Site> reservationsAvailable = null;


                while (reservationsAvailable == null)
                {
                    int campground_Id = CLIHelper.GetInteger(@"Which campground (enter 0 to cancel)?");

                    if (campground_Id == 0)
                    {
                        returnToPreviousMenu = true;
                        return;
                    }
                    //check to see if they are selecting a campground that was listed....
                    else if (!campgrounds.Any(campground => campground.Campground_Id == campground_Id))
                    {
                        WarningMessageFormat("This Campground ID is not available please try again");
                        Console.ReadLine();
                    }
                    else
                    {
                        DateTime from_date = new DateTime();
                        DateTime to_date   = new DateTime();


                        while (from_date.Date >= to_date.Date || from_date.Date <= DateTime.Today)  // can not book in the past? (at least 1 day stay ie to date must be atleast 1 in the future of the from date
                        {
                            Console.WriteLine("Reservations must be booked for at least 1 day.");
                            from_date = CLIHelper.GetDateTime("What is the arrival date? (YYYY-MM-DD)");
                            to_date   = CLIHelper.GetDateTime("What is the departure date? (YYYY-MM-DD)");
                            FlowerLine();

                            if (from_date.Date >= to_date.Date)
                            {
                                WarningMessageFormat("Departure Date must be after Arrival Date!");
                            }

                            if (from_date.Date < DateTime.Today)
                            {
                                WarningMessageFormat("Unable to book for past dates!");
                            }


                            Console.WriteLine();
                        }



                        //datetime in rang and also now or greater than today for atleast one day
                        //if (from_date >= 1753-01-01 && from_date <= 9999-12-31)


                        Console.WriteLine("\nResults Matching Your Search Criteria\n");
                        reservationsAvailable = CampgroundReservationSearchResults(park_Id, campground_Id, from_date, to_date);

                        if (reservationsAvailable.Count > 0)
                        {
                            MakeReservationMenu(park_Id, from_date, to_date, reservationsAvailable);
                            FlowerLine();
                        }

                        else
                        {
                            NoSitesAvailable();
                            FlowerLine();
                        }
                    }
                }
            }
        }//ViewCampgroundsList
예제 #3
0
        public void RunCLI()
        {
            while (true)
            {
                string parkSelectPrompt = "====================== Select a Park for Further Details ======================\n";

                string validSelectionError = "Please make a valid selection from the menu. Press Enter to try again.";

                string quitPrompt = $"{Command_Quit}) Quit\n";

                string selectionPrompt = "Selection:";

                int commandIfNum;

                Console.Clear();
                Console.SetCursorPosition((Console.WindowWidth - parkSelectPrompt.Length) / 2, Console.CursorTop);
                Console.WriteLine(parkSelectPrompt);

                ParkDAL      parkDAL  = new ParkDAL(DatabaseConnection);
                IList <Park> parkList = new List <Park>();
                parkList = parkDAL.GetParkList();

                foreach (Park park in parkList)
                {
                    Console.WriteLine($"{park.ParkID}) {park.Name}");
                }
                Console.WriteLine(quitPrompt);

                string command = CLIHelper.GetString(selectionPrompt).ToUpper();

                if (command == Command_Quit)
                {
                    return;
                }
                else if (!int.TryParse(command, out commandIfNum))
                {
                    Console.WriteLine(validSelectionError);
                    Console.ReadLine();
                    continue;
                }
                else
                {
                    bool commandNumIsInParkList = false;
                    foreach (Park park in parkList)
                    {
                        if (park.ParkID == commandIfNum)
                        {
                            commandNumIsInParkList = true;
                            break;
                        }
                    }

                    if (commandNumIsInParkList)
                    {
                        ParkInfoScreen(commandIfNum);
                    }
                    else
                    {
                        Console.WriteLine(validSelectionError);
                        Console.ReadLine();
                    }
                }
            }
        }
예제 #4
0
        public void ParkWideAvailabilitySearch(int parkID)
        {
            string reqFromDate;

            string reqToDate;

            string reservationHeader = $"===================Reservation Confirmation==================\n";

            bool isFirstTry = true;

            IList <Campground> campgroundList = new List <Campground>();
            List <Site>        masterSiteList = new List <Site>();
            CampgroundDAL      campgroundDAL  = new CampgroundDAL(DatabaseConnection);

            campgroundList = campgroundDAL.GetCampgroundList(parkID);

            do
            {
                if (!isFirstTry)
                {
                    Console.WriteLine("\nThere are no open campsites in the selected timeframe for that park.\nTry an alternative date range.");
                }

                //TODO: consolidate getDateRange into CLI helper method that returns two string dates once validated

                reqFromDate = CLIHelper.GetDateTime("What is the arrival date? (MM/DD/YYYY):");

                bool negativeDateRangeAttempted = false;

                do
                {
                    if (negativeDateRangeAttempted)
                    {
                        Console.WriteLine("Departure date must be after arrival date. Please try again.\n");
                    }
                    reqToDate = CLIHelper.GetDateTime("What is the departure date? (MM/DD/YYYY):");

                    negativeDateRangeAttempted = DateTime.Parse(reqToDate) <= DateTime.Parse(reqFromDate);
                } while (negativeDateRangeAttempted);


                /*----------------------------------------------------Advanced Search------------------------------------------------------*/
                bool advancedSearch = false;
                int  minOccupancy   = 0;
                bool accessible     = false;
                int  maxRvLength    = 0;
                bool utilities      = false;

                advancedSearch = CLIHelper.GetBool("Use Advanced Search (Y/N)?");

                if (advancedSearch)
                {
                    minOccupancy = CLIHelper.GetInteger("Minimum Occupancy (Enter 0 to skip):");
                    accessible   = CLIHelper.GetBool("Do you require accessibility features (Y/N)?");
                    maxRvLength  = CLIHelper.GetInteger("What is your RV size (Enter 0 to skip)?");
                    utilities    = CLIHelper.GetBool("Do you require a utility hookup (Y/N)?");
                }
                /*---------------------------------------------------End of Advanced Search-------------------------------------------------*/


                foreach (Campground campground in campgroundList)
                {
                    IList <Site> campgroundSiteList = new List <Site>();
                    SiteDAL      siteDAL            = new SiteDAL(DatabaseConnection);

                    campgroundSiteList = siteDAL.GetUnreservedCampsites(reqFromDate, reqToDate, campground.Campground_id, minOccupancy, accessible, maxRvLength, utilities);

                    foreach (Site site in campgroundSiteList)
                    {
                        site.CampgroundName = campground.Name;
                    }
                    masterSiteList.AddRange(campgroundSiteList); //Uses the SQL query on all campgrounds in a park to return top 5 campsites in all campgrounds
                }

                isFirstTry = false;
            } while (masterSiteList.Count == 0);

            int lengthOfStay = CLIHelper.GetLengthOfStay(reqFromDate, reqToDate);

            Console.Clear();
            Console.WriteLine($"Results Matching Your Search Criteria\n\n" + "Campground".PadRight(22) + "Site #".PadRight(10) + "Max Occup.".PadRight(13) + "Accessible?".PadRight(12) + "RV Size".PadRight(12) + "Utility".PadRight(15) + "Cost\n");
            foreach (Site site in masterSiteList)
            {
                Console.WriteLine(site.ToString(lengthOfStay, true));
            }

            ReservationDAL reservationDAL = new ReservationDAL(DatabaseConnection);

            while (true)
            {
                int campsiteChoice = CLIHelper.GetInteger("\nPlease select your desired Site # from the list (enter 0 to cancel)?");
                if (campsiteChoice == 0)
                {
                    return;
                }

                foreach (Site site in masterSiteList)
                {
                    if (campsiteChoice == site.SiteID)
                    {
                        string reservationName = CLIHelper.GetString("What name should the reservation be made under?");
                        int    reservationID   = reservationDAL.MakeReservation(reqFromDate, reqToDate, campsiteChoice, reservationName);
                        Console.Clear();
                        Console.SetCursorPosition((Console.WindowWidth - reservationHeader.Length) / 2, Console.CursorTop);
                        Console.WriteLine(reservationHeader);
                        Console.WriteLine($"\nThe reservation has been made and the confirmation id is {reservationID}.\nPress Enter to continue.");
                        Console.ReadLine();
                        return;
                    }
                }

                Console.WriteLine("Please make a valid campsite ID selection from the list.");
            }
        } //Searches availability for every campground in a given park
예제 #5
0
        private void SearchReservations()
        {
            int campgroundIdNumber = CLIHelper.GetInteger("Please Select a Campground: ");


            newCampground.Campground_Id = campgroundIdNumber;
            DateTime StartDate     = new DateTime(2019, 5, 1);
            DateTime SeaWallClose  = new DateTime(2019, 9, 30);
            DateTime SchoodicClose = new DateTime(2019, 10, 31);
            DateTime UapcClose     = new DateTime(2019, 11, 30);



            if (campgroundId.Contains(newCampground.Campground_Id) == false)
            {
                Console.WriteLine();
                Console.WriteLine("Please select a valid campground.");
                Console.WriteLine();
                SearchReservations();
            }

            DateTime FromDate = CLIHelper.GetDateTime("What is the arrival date? YYYY-MM-DD");

            if (newCampground.Campground_Id == 2 || newCampground.Campground_Id == 3 || newCampground.Campground_Id == 7)
            {
                if (FromDate < StartDate && FromDate != StartDate)
                {
                    Console.WriteLine();
                    Console.WriteLine("The campground is closed.");
                    Console.WriteLine();
                    SearchReservations();
                }
            }

            DateTime ToDate = CLIHelper.GetDateTime("What is the depature date? YYYY-MM-DD");

            if (newCampground.Campground_Id == 2)
            {
                if (ToDate > SeaWallClose && ToDate != SeaWallClose)
                {
                    Console.WriteLine();
                    Console.WriteLine("The campground closes on September 30th.");
                    Console.WriteLine();
                    SearchReservations();
                }
            }
            if (newCampground.Campground_Id == 3)
            {
                if (ToDate > SchoodicClose && ToDate != SchoodicClose)
                {
                    Console.WriteLine();
                    Console.WriteLine("The campground closes on October 31st.");
                    Console.WriteLine();
                    SearchReservations();
                }
            }
            if (newCampground.Campground_Id == 7)
            {
                if (ToDate > SchoodicClose && ToDate != SchoodicClose)
                {
                    Console.WriteLine();
                    Console.WriteLine("The campground closes on November 30th.");
                    Console.WriteLine();
                    SearchReservations();
                }
            }



            Console.Clear();


            newCampground.Daily_Fee  = Convert.ToDecimal(campgroundDAO.GetDailyFee(newCampground.Campground_Id));
            newReservation.From_Date = FromDate;
            newReservation.To_Date   = ToDate;
            int numberOfDays = (ToDate - FromDate).Days;


            IList <Site> siteReservations = siteDAO.SearchReservations(newCampground.Campground_Id, FromDate, ToDate);



            if (siteReservations.Count > 0)
            {
                Console.WriteLine("Results Matching Your Search Criteria");
                Console.WriteLine();
                Console.WriteLine("SiteID".PadRight(11) + "Max Occupancy".PadRight(15) + "Is Accesible".PadRight(15) + "Max RV Length".PadRight(15) + "Utilities".PadRight(14) + "Total Cost".PadRight(15));
                foreach (Site detail in siteReservations)
                {
                    string accessible;

                    siteIdList.Add(detail.Site_Id);

                    if (detail.Accessible == true)
                    {
                        accessible = "Yes";
                        Console.WriteLine(detail.Site_Id.ToString().PadRight(11) + detail.Max_Occupancy.ToString().PadRight(15) + accessible.PadRight(15) + detail.Max_Rv_Length.ToString().PadRight(15) + Utilities[detail.Utilities].PadRight(15) + ("$" + (numberOfDays * newCampground.Daily_Fee).ToString("0.00").PadRight(20)));
                    }
                    else if (detail.Accessible == false)
                    {
                        accessible = "No";
                        Console.WriteLine(detail.Site_Id.ToString().PadRight(11) + detail.Max_Occupancy.ToString().PadRight(15) + accessible.PadRight(15) + detail.Max_Rv_Length.ToString().PadRight(15) + Utilities[detail.Utilities].PadRight(15) + "$" + (numberOfDays * newCampground.Daily_Fee).ToString("0.00").PadRight(20));
                    }
                }
                ReserveSiteMenu();
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("**** NO RESERVATIONS AVAILABLE ****");
            }
        }
        private void SearchForAvailableReservations(int ParkID)
        {
            string CampgroundChoice = CLIHelper.GetString("Which campground would you like?");
            string ArrivalDate      = CLIHelper.GetDate("What is the arrival date?");
            string DepartureDate    = CLIHelper.GetDate("What is the departure date?");

            // This needs to return a list of available sites (for each campground) for those dates.

            SiteDAL sdal = new SiteDAL(DatabaseConnection);

            List <Site> slist = sdal.ViewAvailReservations(CampgroundChoice, ArrivalDate, DepartureDate);



            if (slist.Count > 0)
            {
                CampgroundDAL cgdal = new CampgroundDAL(DatabaseConnection);

                double camgroundCost = cgdal.GetCampgroundCost(CampgroundChoice);

                Console.WriteLine("Available sites & details for your dates:");
                Console.WriteLine("Site ID" + " " + "Max Occupancy" + " " + "Accessible?" + " " + "Max RV Length" + " " + "Utilities" + " " + "Cost");

                foreach (Site item in slist)
                {
                    Console.Write("   " + item.site_id.ToString().PadRight(9) + " " + item.max_occupancy.ToString().PadRight(10) + " " + TrueFalse(item.accessible).ToString().PadRight(14) + " " + item.max_rv_length.ToString().PadRight(10) + " " + TrueFalse(item.utilities).ToString().PadRight(8) + " " + camgroundCost);
                    Console.WriteLine();
                }


                string siteChoiceToReserve = CLIHelper.GetString("Which site should be reserved (enter 0 to cancel)");

                if (siteChoiceToReserve == "0")
                {
                    return;
                }


                bool SiteIsInTheList = false;



                foreach (Site item in slist)
                {
                    if (item.site_id.ToString() == siteChoiceToReserve)
                    {
                        SiteIsInTheList = true;
                    }
                }

                if (!SiteIsInTheList)

                {
                    Console.WriteLine("Sorry, that Site ID isn't in our list!  Please start over.");
                    return;
                }



                string name = CLIHelper.GetString("What name should the reservation be made under?");
                MakeReservation(siteChoiceToReserve, name, ArrivalDate, DepartureDate);
            }
            else
            {
                Console.WriteLine("Sorry, no campsites are available. Please try again with different dates.");
                return;
            }
        }
        private void DisplayReservationMenu(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("Search for Campground Reservation");
                Console.WriteLine();
                Console.WriteLine(string.Format("{0, -4}{1, -20}{2, -20}{3, -20}{4, -20}", "", "Name", "Open", "Close", "Daily Fee"));
                DisplayCampgrounds(park);
                Console.WriteLine();
                int campgroundId = CLIHelper.GetInteger("Choose a campground ? (enter 0 to cancel)");

                if (campgroundId == 0)
                {
                    exit = true;
                }
                else
                {
                    while (!exit)
                    {
                        _arrivalDate = CLIHelper.GetDate("What is the arrival date? (MM/DD/YYYY)");
                        exit         = ValidateArrivalDate(_arrivalDate);
                    }

                    exit = false;

                    while (!exit)
                    {
                        _departureDate = CLIHelper.GetDate("What is the departure date? (MM/DD/YYYY)");
                        exit           = ValidateDepartureDate(_departureDate);
                    }

                    exit = false;
                    int     numDays   = (int)(_departureDate - _arrivalDate).TotalDays;
                    decimal totalCost = CalculateCost(campgroundId, numDays);
                    while (!exit)
                    {
                        Console.WriteLine();
                        Console.WriteLine(string.Format("{0, -10}{1, -22}{2, -20}{3, -20}{4, -20}{5, -20}", "Site No.", "Max Occup.", "Max RV Length", "Accessible?", "Utilities", "Cost"));
                        DisplayCampgroundSites(campgroundId, _arrivalDate, _departureDate);
                        Console.WriteLine();
                        int inputNum = CLIHelper.GetInteger("Which site should be reserved? (Enter 0 to cancel)");

                        if (inputNum == 0)
                        {
                            exit = true;
                        }

                        else
                        {
                            //if campgrounds are empty, return "No sites available for dates requested"

                            //Console.WriteLine("What name should the reservation be made under?");
                            //string resName = Console.ReadLine();
                            string resName    = CLIHelper.GetString("What name should the reservation be made under?");
                            int    confirmNum = _reservationDAL.BookReservation(inputNum, _arrivalDate, _departureDate, resName);
                            Console.WriteLine();
                            Console.WriteLine();
                            Console.WriteLine($"The reservation has been made and the confirmation number is {confirmNum}");
                            Console.ReadKey();
                            //writeline "press a key to return to menu"
                        }
                    }
                }
            }
        }
        private void DisplayParkInfo(Park selectedPark)
        {
            int dateRangeSelected = -1;
            int userInput         = 0;

            Console.WriteLine();
            Console.WriteLine("PARK INFORMATION SCREEN");
            Console.WriteLine();

            //access park info from database

            ParkDAL dal = new ParkDAL(DatabaseConnection);

            selectedPark = dal.DisplayParkInfo(selectedPark);

            Console.WriteLine(selectedPark.Name + " National Park");
            Console.WriteLine("State: " + selectedPark.State);
            Console.WriteLine("Established: " + selectedPark.EstablishYear);
            Console.WriteLine("Area: " + string.Format("{0:n0}", selectedPark.Area) + " sq km");
            Console.WriteLine("Annual Visitors: " + string.Format("{0:n0}", selectedPark.Vistors));
            Console.WriteLine();

            //word wrap for console display

            String[]      words  = selectedPark.Description.Split(' ');
            StringBuilder buffer = new StringBuilder();

            foreach (String word in words)
            {
                buffer.Append(word);

                if (buffer.Length >= Console.WindowWidth)
                {
                    String line = buffer.ToString().Substring(0, buffer.Length - word.Length);
                    Console.WriteLine(line);
                    buffer.Clear();
                    buffer.Append(word);
                }
                buffer.Append(" ");
            }
            Console.WriteLine(buffer.ToString());
            Console.WriteLine();
            Console.WriteLine("Select a Command:");
            Console.WriteLine("1) View Campgrounds in " + selectedPark.Name);
            Console.WriteLine("2) View Existing Reservations for the Next 30 Days");
            Console.WriteLine("3) Make a Reservation");
            Console.WriteLine("4) Return to Previous Screen");

            userInput = CLIHelper.GetInteger("");

            //user input implements corresponding method, default returns to ViewParksMenu()

            List <Campground> campgroundsInPark = new List <Campground>();

            switch (userInput)
            {
            case 1:
                ViewCampgrounds(selectedPark, campgroundsInPark);
                break;

            case 2:
                ViewUpcomingReservations(selectedPark);
                break;

            case 3:
                while (dateRangeSelected == -1)
                {
                    dateRangeSelected = ChooseCampground(selectedPark, campgroundsInPark, dateRangeSelected);
                }
                break;

            default:
                Console.WriteLine();
                break;
            }
        }
        private int SearchForAvailableSites(int inputCampgroundNumber, List <Campground> campgroundsInPark)
        {
            //determine index of selected campground in list, based on input

            Campground selectedCampground = campgroundsInPark[inputCampgroundNumber - 1];

            Console.WriteLine("Selected " + selectedCampground.Name + ".");
            Console.WriteLine();

            //user specifies dates

            DateTime userFromDate = new DateTime();
            DateTime userToDate   = new DateTime();

            userFromDate = CLIHelper.GetDateTime("What is the arrival date? (Please enter in \"yyyy-mm-dd\" format)");
            Console.WriteLine();
            userToDate = CLIHelper.GetDateTime("What is the departure date? (Please enter in \"yyyy-mm-dd\" format)");
            int fromMonth = userFromDate.Month;
            int toMonth   = userToDate.Month;

            //ensure the arrival date is before the departure date

            if (userFromDate > userToDate)
            {
                Console.WriteLine("Invalid input. Arrival date must come before departure date.");
                Console.WriteLine();
            }

            //ensure dates have not already passed
            else if (userFromDate < DateTime.Now || userToDate < DateTime.Now)
            {
                Console.WriteLine("Invalid input. Dates must be in the future.");
                Console.WriteLine();
            }

            //ensure the park is open during desired dates
            else if (fromMonth < selectedCampground.OpenFromMM || toMonth > selectedCampground.OpenToMM)
            {
                Console.WriteLine();
                Console.WriteLine("Sorry, the campground is not open during your specified date range.");
                Console.WriteLine();
                Console.WriteLine("Press 0 to cancel or enter to use alternate dates.");
                string userInput = Console.ReadLine();
                if (userInput == "0")
                {
                    return(0);
                }
            }

            //query database for list of *already booked* reservations that interfere with desired dates
            //assemble list of their site IDs to run against all site IDs in campground

            else
            {
                CampgroundDAL      dal = new CampgroundDAL(DatabaseConnection);
                List <Reservation> BookedReservations = dal.FindBookedReservations(selectedCampground, userFromDate, userToDate);
                List <int>         bookedSiteIds      = new List <int>();

                foreach (Reservation thisReservation in BookedReservations)
                {
                    bookedSiteIds.Add(thisReservation.SiteId);
                }

                //get list of available sites from method
                //if no sites are available, return to ViewParksMenu() by pressing 0...
                //or exit method and start ChooseCampground() again (while dateRangeSelected == -1)

                List <Site> availableSites = GetAvailableSites(selectedCampground, bookedSiteIds);

                if (availableSites.Count == 0)
                {
                    Console.WriteLine("No sites available for chosen date range. Press 0 to cancel or enter to use alternate dates.");
                    string userInput = Console.ReadLine();
                    if (userInput == "0")
                    {
                        return(0);
                    }
                }
                else
                {
                    DisplaySitesInfo(availableSites, userFromDate, userToDate, selectedCampground.DailyFee);
                    return(1);
                }
            }
            return(-1);
        }
        public void BookCampsite(int parkId)
        {
            try
            {
                campgroundID = CLIHelper.GetInteger("Please enter the desired campground(ID) or 0 to Cancel:");
                if (campgroundID == 0)
                {
                    Console.Clear();
                    throw new Exception();
                }
                while (campGroundDAO.IsValidCampground(parkId, campgroundID) == false)
                {
                    Console.WriteLine("Please enter a campground ID from the campgrounds displayed.");
                    campgroundID = CLIHelper.GetInteger("Please enter the desired campground(ID) or 0 to Cancel:");
                }


                startDate = CLIHelper.GetDateTime("Enter desired start date (MM-DD-YYYY):");
                endDate   = CLIHelper.GetDateTime("Enter desired end date (MM-DD-YYY):");

                while (startDate > endDate || startDate < DateTime.Now)
                {
                    Console.WriteLine("Date input invalid, please try again");
                    startDate = CLIHelper.GetDateTime("Enter desired start date (MM-DD-YYYY):");
                    endDate   = CLIHelper.GetDateTime("Enter desired end date (MM-DD-YYY):");
                }
                ////for testing
                //IList<Reservations> reservationsByCampground = reservationDAO.GetReservationByCampground(campgroundID);
                //for (int index = 0; index < reservationsByCampground.Count; index++)
                //{
                //    Console.WriteLine($"SiteBooked: {reservationsByCampground[index].SiteId} From: {reservationsByCampground[index].StartDate.ToString("yyyy/MM/dd")} to {reservationsByCampground[index].EndDate.ToString("yyyy/MM/dd")}");
                //}
                ////
                int  startMonth        = campGroundDAO.CampGroundMonthToReserve(startDate);
                bool betweenOpenMonths = campGroundDAO.BetweenOpenMonths(campgroundID, startMonth);

                if (betweenOpenMonths == true)
                {
                    decimal      stayCost       = reservationDAO.TotalStayCost(campgroundID);
                    IList <Site> availablesites = siteDAO.AvailableSites(campgroundID, startDate, endDate);

                    if (availablesites.Count == 0)
                    {
                        Console.WriteLine("There are no Available Sites for these dates.");
                        BookCampsite(parkId);
                    }
                    else
                    {
                        Console.Clear();
                        menuSpacer();
                        Console.WriteLine("Results matching your search criteria:");
                        foreach (Site site in availablesites)
                        {
                            Console.Write(site.ToString());
                            Console.WriteLine($"Cost: {stayCost:C2}");
                        }
                        reservationDAO.MakeReservation(startDate, endDate);
                    }
                }
                else
                {
                    Console.WriteLine("Park is closed at date of reservation");
                    Console.WriteLine("Press any key to return to main menu");
                    Console.ReadLine();
                }
            }
            catch (Exception er)
            {
            }
        }
예제 #11
0
        static void Main(string[] args)
        {
            // Sample Code to get a connection string from the
            // App.Config file
            // Use this so that you don't need to copy your connection string all over your code!
            while (true)
            {
                ParkReservationCLI parkReservationCLI = new ParkReservationCLI();

                //Goes to main menu where the user can select a park then outputs that selected park
                Park _userChoicePark = parkReservationCLI.GoToMainMenu();
                List <Campground> _userCampground = parkReservationDAL.GetCampgroundsInPark(_userChoicePark);

                bool loop = true;
                while (loop)
                {
                    parkReservationCLI.DisplayParkInfo(_userChoicePark);

                    int parkInfoSelection = CLIHelper.GetInteger(3);


                    switch (parkInfoSelection)
                    {
                    case 1:
                        Console.Clear();
                        //This calls the GetCampgroundsInPark method with the user selected park as the parameter
                        //Which returns a list for the DisplayParkCampgrounds method which prints that list to the screen
                        parkReservationCLI.DisplayParkCampgrounds(parkReservationDAL.GetCampgroundsInPark(_userChoicePark));
                        parkReservationCLI.DisplayParkCampgroundsCommand(parkReservationDAL.GetCampgroundsInPark(_userChoicePark));
                        int  selection = CLIHelper.GetInteger(2);
                        bool menuLoop  = true;
                        switch (selection)
                        {
                        case 1:
                            while (menuLoop)
                            {
                                Console.Clear();
                                parkReservationCLI.DisplayParkCampgrounds(_userCampground);
                                menuLoop = parkReservationCLI.DisplayReservationMenu();
                            }
                            break;

                        case 2:
                            break;
                        }
                        break;

                    case 2:
                        parkReservationCLI.DisplayParkCampgrounds(parkReservationDAL.GetCampgroundsInPark(_userChoicePark));

                        Console.ReadKey();
                        break;

                    case 3:
                        //This breaks off this method and returns to the main menu
                        loop = false;
                        break;
                    }
                }
            }
        }