예제 #1
0
        /// <summary>
        /// In the makeAreservation method we again use the cli helper to take in user input.
        /// It calls the MakeReservation method from the ReservationSqlDAL class and uses it in a list
        /// We created variables of type string in and dateTime to store the user input then we called the reservation class
        /// from the models folder and assigned the user input to the variables in the reservation class which are get; set; properties
        /// We then call the list in a  if statement again and if count of items in list is > 0 we then print out the response with the
        /// reservation id confirming their reservation has been created.
        /// </summary>
        private void MakeAreservation()
        {
            string   name      = CLIHelper.GetString("Please enter the reservation name: ");
            int      site_id   = CLIHelper.GetInteger("Please enter the site number: ");
            DateTime startDate = CLIHelper.GetDateTime("Please enter the arrival date(YYYY/MM/DD): ");
            DateTime endDate   = CLIHelper.GetDateTime("Please enter the departure date(YYYY/MM/DD): ");


            Reservation newRes = new Reservation()
            {
                Name       = name,
                SiteID     = site_id,
                FromDate   = startDate,
                ToDate     = endDate,
                CreateDate = DateTime.Now
            };

            ReservationSqlDAL  dal     = new ReservationSqlDAL(DatabaseConnection);
            List <Reservation> confirm = dal.MakeReservation(newRes);

            if (confirm.Count > 0)
            {
                Console.WriteLine();
                Console.WriteLine("The reservation has been made and the confirmation ID is: " + confirm[0].ReservationId);
            }
            else
            {
                Console.WriteLine("DID NOT MAKE RESERVATION");
            }
        }
        private void SearchReservations(Park userParkChoice)
        {
            ViewCampgrounds(userParkChoice);
            int      userChoiceCampgroundID = CLIHelper.GetInteger("Enter the desired campground ID: ");
            DateTime userChoiceStartDate    = CLIHelper.GetDateTime("Enter the desired start date: (YYYY/MM/DD) ");
            DateTime userChoiceEndDate      = CLIHelper.GetDateTime("Enter the desired end date: (YYYY/MM/DD) ");

            ReservationSQLDAL dal            = new ReservationSQLDAL(DatabaseConnection);
            List <Site>       availableSites = dal.SearchForAvailableReservations(userChoiceCampgroundID, userChoiceStartDate, userChoiceEndDate);

            CampgroundSQLDAL cgDal            = new CampgroundSQLDAL(userChoiceCampgroundID, DatabaseConnection);
            decimal          totalCampingCost = cgDal.GetCampgroundDailyRate();
            int totalDays = Convert.ToInt32((userChoiceEndDate - userChoiceStartDate).TotalDays);

            if (availableSites.Count > 0)
            {
                Console.WriteLine("Showing First Five Available Sites:");
                Console.WriteLine("Site No.     Max Occupancy    Accessible?    Max RV Length    Utilites?   Total Cost");
                foreach (Site site in availableSites)
                {
                    Console.WriteLine("#" + site.SiteNumber + "  " + site.MaxOccupancy + "   " + site.IsAccessible + "   " + site.MaxRVLength + "   " + site.HasUtilities + "   " + (totalCampingCost * totalDays).ToString("C2"));
                }
            }
            else
            {
                Console.WriteLine("**** NO RESULTS ****");
            }
        }
예제 #3
0
        /// <summary>
        /// SearchCampSites method calls the GetSites method from the SiteSqlDAL and pass it to a list which we then call in the if statement
        /// and if count > 0 we then print out the appropriate response and we again use the foreach loop to print out the results from the
        /// database. we also use the CLIhelper again to take in the user input.
        /// </summary>
        private void SearchCampSites()
        {
            int      campgroundId = CLIHelper.GetInteger("Which campground (enter 0 to cancel)? ");
            DateTime startDate    = CLIHelper.GetDateTime("What is the arrival date? (YYYY/MM/DD): ");
            DateTime endDate      = CLIHelper.GetDateTime("What is the departure date? (YYYY/MM/DD): ");

            //double totalDays = (endDate - startDate).TotalDays;

            SiteSqlDAL  dal      = new SiteSqlDAL(DatabaseConnection);
            List <Site> allSites = dal.GetSites(campgroundId, startDate, endDate);

            if (allSites.Count > 0)
            {
                Console.WriteLine();
                Console.WriteLine("Site Number".PadRight(14) + "Max Occupancy".PadRight(15) + "Accessible".PadRight(15) + "Max RV Length".PadRight(17) + "Utilities".PadRight(16) + "Cost".PadRight(15));
                Console.WriteLine();

                allSites.ForEach(theseSites =>
                {
                    Console.WriteLine(theseSites);
                });
            }
            else
            {
                Console.WriteLine("There was an error with your inputs...");
            }
        }
        private void Reservation(int campgroundId)
        {
            DateTime arrivalInput = CLIHelper.GetDateTime("What is your desired arrival date?(MM/DD/YYYY)");
            DateTime fromDate     = Convert.ToDateTime(arrivalInput);

            DateTime departureInput = CLIHelper.GetDateTime("When would you like to leave?(MM/DD/YYYY)");
            DateTime toDate         = Convert.ToDateTime(departureInput);

            Console.WriteLine("Showing available sites ");

            SiteSqlDAL  sal          = new SiteSqlDAL(connectionString);
            List <Site> allCampSites = sal.CampsiteAvailability(campgroundId, fromDate, toDate);

            if (allCampSites.Count() <= 0)
            {
                Console.WriteLine("No available camp sites! Please make a new selection.");
                return;
            }
            else
            {
                foreach (Site s in allCampSites)
                {
                    Console.WriteLine();
                    Console.WriteLine("SiteId " + s.SiteID);
                    Console.WriteLine("Campground_Id " + s.CampgroundID);
                    Console.WriteLine("SiteNumber " + s.SiteNumber);
                    Console.WriteLine("MaxOccupancy " + s.MaxOccupancy);
                    Console.WriteLine("Handicap Accessible " + s.Accessible);
                    Console.WriteLine("MaxRvLength " + s.MaxRvLength);
                    Console.WriteLine("Utilities are available " + s.Utilities);
                }

                ReservationSqlDAL ral = new ReservationSqlDAL(connectionString);

                campgroundPrice = (ral.CostOfCampground(campgroundId) * (toDate.DayOfYear - fromDate.DayOfYear));

                Console.WriteLine("The total fee for these sites are: " + campgroundPrice.ToString("C"));
                Console.WriteLine();

                int campSiteInput = CLIHelper.GetInteger("What Camp site are you booking for?");
                Console.WriteLine();

                string nameInput = CLIHelper.GetString("What name should the reservation be under?");
                Console.WriteLine();

                DateTime createDate = DateTime.Now;
                int      wasReservationSuccessful = ral.MakeReservations(campSiteInput, nameInput, fromDate, toDate, createDate);

                if (wasReservationSuccessful > 0)
                {
                    Console.WriteLine("Success!");

                    Console.WriteLine("Here is your conformation ID: " + wasReservationSuccessful);
                }
                else
                {
                    Console.WriteLine("Sorry but that site is alreaday booked. Please try again.");
                }
            }
        }
        public Reservation SearchDateAvailabilityByCampground()
        {
            string      campground  = CLIHelper.GetString("Please enter campground name: ");
            DateTime    startDate   = CLIHelper.GetDateTime("Please enter a start date: ");
            DateTime    endDate     = CLIHelper.GetDateTime("Please enter an end date: ");
            Reservation reservation = new Reservation()
            {
                CampgroundName = campground,
                FromDate       = startDate,
                ToDate         = endDate
            };

            CampgroundSqlDAL dal      = new CampgroundSqlDAL();
            List <Site>      siteList = dal.SearchDateAvailabilityByCampground(reservation);

            if (siteList.Count < 1)
            {
                Console.WriteLine("No available sites for this date range.");
                return(null);
            }
            else
            {
                siteList.ForEach(site => Console.WriteLine(site));
            }

            return(reservation);
        }
예제 #6
0
        private void FindAvailableCampSites()
        {
            int campground_id = CLIHelper.GetInteger("Please Select Campground ID");

            Console.WriteLine();
            DateTime startDate = CLIHelper.GetDateTime("Please Select Start of Stay (yyyy-mm-dd)");

            Console.WriteLine();
            DateTime endDate = CLIHelper.GetDateTime("Please Select Date of Depature (yyyy-mm-dd)");

            SiteDal     dal = new SiteDal(connectionString);
            List <Site> sites;

            bool avail = dal.IsSiteAvailable(campground_id, startDate, endDate);

            if (!avail)
            {
                Tools.ColorfulWriteLine("No availablity please try different dates or Campground", ConsoleColor.Red);
            }
            else if (avail)
            {
                sites = dal.GetTop5(campground_id, startDate, endDate);
                foreach (Site s in sites)
                {
                    Console.WriteLine();
                    Tools.ColorfulWriteLine($"National Site ID".PadRight(20) + "Campground Site Number".PadRight(30) + "Max Occupancy".PadRight(25) + "Total Days".PadRight(20) + "Total Cost", ConsoleColor.Yellow);
                    Console.WriteLine($"{s.site_id}".PadRight(20) + $"{s.site_number}".PadRight(30) + $"{s.max_occupancy}".PadRight(30) + $"{s.totalDays}".PadRight(20) + $"${s.totalCost}");
                }
            }
        }
예제 #7
0
        private void CheckAvailableSpaces()
        {
            int resSpaceId = CLIHelper.GetInteger("Please enter the ID of the venue you would like to reserve:");

            Console.WriteLine();

            DateTime startDates = CLIHelper.GetDateTime("When do you need the space from ? (MM/DD/YYYY)");

            Console.WriteLine();
            DateTime endDates = CLIHelper.GetDateTime("When do you need the space until ? (MM/DD/YYYY)");

            Console.WriteLine();


            List <Space> spaces = spaceDAL.CheckAvailableSpaces(resSpaceId, startDates, endDates);

            if (spaces.Count > 0)
            {
                Console.WriteLine("The following spaces are available based on your needs: ");
                Console.WriteLine();
                Console.WriteLine(String.Format("{0, -10} {1, -25} {2, -15} {3, -15}", "Space #", "Name", "Daily Rate", "Max. Occupancy"));
                foreach (Space space in spaces)
                {
                    Console.WriteLine(String.Format("{0, -10} {1, -25} {2, -15} {3, -15}", space.id, space.name, space.dailyRate, space.maxOccupancy));
                }
            }
            else
            {
                Console.WriteLine("**** NO RESULTS ****");
            }
        }
        private void GetCampgroundAvailability(Dictionary <int, Campground> campgrounds)
        {
            CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL();
            int  campground       = CLIHelper.GetInteger("Which Campground (enter 0 to cancel):");
            bool returnToPrevious = campground == int.Parse(command_Cancel);

            //Return to previous screen if user enters 0
            if (returnToPrevious)
            {
                return;
            }

            while (!campgrounds.ContainsKey(campground))
            {
                campground = campground = CLIHelper.GetInteger("Invalid choice. Please pick a campground Site number from available list:");
            }
            ;

            bool stillBooking = false;

            do
            {
                DateTime startDate = CLIHelper.GetDateTime("Enter start date (YYYY/MM/DD):");
                DateTime endDate   = CLIHelper.GetDateTime("Enter end date (YYYY/MM/DD):");

                var availableSites = campgroundDAL.GetCampgroundAvailability(campgrounds[campground].Name, startDate, endDate);

                if (availableSites.Count > 0)
                {
                    List <int> availableSiteNumbers = new List <int>();

                    int totalReservDays = (int)(endDate - startDate).TotalDays;

                    Console.Clear();
                    Console.WriteLine("Results Matching Your Search Criteria");
                    Console.WriteLine(String.Format("").PadRight(30, '='));
                    Console.WriteLine("{0,3}{1,12}{2,13}{3,14}{4,9}{5,10}{6,7}", "Campground", "Site No.", "Max Occup.", "Accessible?", "RV Len", "Utility", "Cost");
                    foreach (var site in availableSites)
                    {
                        double cost = campgrounds[campground].Daily_Fee * totalReservDays;
                        availableSiteNumbers.Add(site.SiteNumber);

                        Console.WriteLine(campgrounds[campground].Name.PadRight(17) + site.SiteNumber.ToString().PadRight(12) + site.MaxOccupancy.ToString().PadRight(13) +
                                          site.WheelchairAccess.PadRight(11) + site.MaxRVLength.PadRight(10) + site.UtilityHookups.PadRight(9) + cost);
                    }

                    bool reservationSuccessful = BookReservation(availableSiteNumbers, startDate, endDate);
                    if (reservationSuccessful)
                    {
                        stillBooking = false;
                    }
                }
                else
                {
                    Console.WriteLine("Sorry, there are no sites available in the specified date range.");
                    stillBooking = CLIHelper.GetBoolFromYesOrNo("Would you like to enter another date range?");
                }
            } while (stillBooking);
        }
        /// <summary>
        /// Gets the reservation info from the user
        /// </summary>
        /// <param name="reservation">This is the object to add reservation info to. It already has campsite id populated.</param>
        /// <returns>The passed in reservation info with extra fields populated</returns>
        private ReservationInfo GetReservationInfo(ReservationInfo reservation)
        {
            bool validSelection = false;

            while (!validSelection)
            {
                reservation.FromDate = CLIHelper.GetDateTime("What is the arrival date  (mm/dd/yyyy)?");
                if (reservation.FromDate < DateTime.Now)
                {
                    Console.WriteLine("The arrival date cannot be earlier than today.");
                    var isTryAgain = CLIHelper.GetString(Message_ReEnterArrivalDate);
                    if (isTryAgain.ToLower() == "n")
                    {
                        throw new ExitException();
                    }
                }
                else
                {
                    validSelection = true;
                }
            }

            validSelection = false;
            while (!validSelection)
            {
                reservation.ToDate = CLIHelper.GetDateTime("What is the departure date (mm/dd/yyyy)?");
                if (reservation.ToDate < reservation.FromDate)
                {
                    Console.WriteLine("The departure date cannot be earlier than the arrival date.");
                    var isTryAgain = CLIHelper.GetString(Message_ReEnterDepartureDate);
                    if (isTryAgain.ToLower() == "n")
                    {
                        throw new ExitException();
                    }
                }
                else if ((reservation.ToDate - reservation.FromDate).Days <= 0)
                {
                    Console.WriteLine("The reservation length must be at least 1 day or more.");
                    var isTryAgain = CLIHelper.GetString(Message_ReEnterDepartureDate);
                    if (isTryAgain.ToLower() == "n")
                    {
                        throw new ExitException();
                    }
                }
                else
                {
                    validSelection = true;
                }
            }

            reservation.Occupancy    = CLIHelper.GetInteger("What are your occupancy requirements (1-55)?", 1, 55);
            reservation.IsAccessible = CLIHelper.GetBool("Do you need handicap accessiblity (true/false)?");
            reservation.HasUtilities = CLIHelper.GetBool("Do you need utilities (true/false)?");
            reservation.RvLength     = CLIHelper.GetInteger("What is your minimum RV length requirements (0-35)?", 0, 35);

            return(reservation);
        }
        private void SearchForSite()
        {
            Console.Clear(); //clears the screen and displays the campground options
            Console.WriteLine();
            Console.WriteLine("**Please note, if your reservation date is during the park off-season, campgrounds will be unavailable to book**");
            GetCampGrounds();
            Console.WriteLine();

            //searches to book reservation
            tempCampId = CLIHelper.GetInteger("Which campground would you like to reserve? (enter C to cancel and go back to park listing)");

            arriveDate = CLIHelper.GetDateTime("What is the arrival date? __/__/____");
            departDate = CLIHelper.GetDateTime("What is the departure date? __/__/____");

            SiteDAL dal = new SiteDAL(DatabaseConnection);

            IList <CampSite> campSites = dal.SearchForSiteTotalAmt(tempParkId, tempCampId, arriveDate, departDate);

            Console.WriteLine();
            Console.WriteLine(("Site No.").PadRight(15) + ("Max Occup.").PadRight(30) + ("Accessible?").PadRight(15) + ("Max RV Length").PadRight(15) + ("Utility").PadRight(15) + ("Fee").PadRight(15));
            if (campSites.Count > 0)
            {
                foreach (CampSite site in campSites)
                {
                    Console.WriteLine((site.SiteNumber.ToString()).PadRight(15) + (site.MaxOccupancy.ToString()).PadRight(30) + (site.Accessible.ToString()).PadRight(15) + (site.MaxRVLength.ToString()).PadRight(15) + (site.Utilities.ToString()).PadRight(15) + "$" + (site.Fee.ToString()).PadRight(15));
                }
                BookReservation();
            }
            else
            {
                Console.WriteLine("**** NO SPOTS OPEN TO RESERVE ****");
                Console.WriteLine("Press Y to go back to park options" + Environment.NewLine + "Press N to Exit");
                string choice = Console.ReadLine();
                switch (choice.ToLower())
                {
                case "y":
                    DisplayParkOptions();
                    break;

                case "n":
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Please Choose a valid option.");
                    break;
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Searched for sites and enter in dates you want to stay.
        /// </summary>
        private void SearchReservationRun()
        {
            Console.WriteLine("Search for Available Campground Sites");
            int campgroundId = CLIHelper.GetInteger("Which campground (enter 0 to cancel)?:");

            if (campgroundId == 0)
            {
                Console.Clear();
                return;
            }

            else
            {
                //campgroundId = choice;

                DateTime arrivalDate   = CLIHelper.GetDateTime("What is the arrival date? (MM/DD/YYYY): ");
                DateTime departureDate = CLIHelper.GetDateTime("What is the departure date? (MM/DD/YYYY): ");

                IList <CampSite> campSites = campSiteDAO.SearchReservationRun(campgroundId, arrivalDate, departureDate);

                if (campSites.Count == 0)
                {
                    Console.Clear();
                    Console.WriteLine("There are no available campsites for those dates, Please try again.");
                    return;
                }

                else
                {
                    CampGround campGround = campGroundDAO.ViewCampground(campgroundId);

                    decimal cost = campGround.DailyFee * (decimal)(departureDate - arrivalDate).TotalDays;

                    Console.WriteLine();
                    Console.WriteLine("Site NO.  MAX OCCUPANCY  ACCESSIBLE   MAX RV LENGTH    UTILITY  COST");
                    Console.WriteLine();

                    foreach (CampSite campSite in campSites)
                    {
                        Console.WriteLine($"#{campSite.SiteId}\t\t{campSite.MaxOccupancy}\t{campSite.IsAccessible}\t\t{campSite.MaxRvLength}\t\t{campSite.HasUtilties}\t{cost:C2}"); //todo: add daily fee
                    }

                    Console.WriteLine("");
                    CreateReservation(arrivalDate, departureDate);
                }
            }
        }
예제 #12
0
        private void MakeReservation()
        {
            int resSpaceId = CLIHelper.GetInteger("Please enter the ID of the space you would like to reserve:");

            Console.WriteLine();
            DateTime startDates = CLIHelper.GetDateTime("When do you need the space from ? (MM/DD/YYYY)");

            Console.WriteLine();
            DateTime endDates = CLIHelper.GetDateTime("When do you need the space until ? (MM/DD/YYYY)");

            Console.WriteLine();
            int numOfPeople = CLIHelper.GetInteger("How many people will be in attendance? ");

            Console.WriteLine();
            string reserved_for = CLIHelper.GetString("Please enter the name of person or group reserving the space: ");

            Console.WriteLine();
            Console.WriteLine();
            Reservation newRes = new Reservation
            {
                spaceId     = resSpaceId,
                startDate   = startDates,
                endDate     = endDates,
                reservedFor = reserved_for
            };
            int dal = reservationDAL.MakeReservation(resSpaceId, startDates, endDates, reserved_for);

            if (dal > 0)
            {
                Space space = spaceDAL.GetASpaceName(resSpaceId);
                Venue venue = venueDAL.GetVenueNameGivenSpaceId(resSpaceId);
                Console.WriteLine(String.Format("{0, -15}", "Thanks for submitting your reservation! The details for your event are listed below: "));
                Console.WriteLine();
                Console.WriteLine("Confirmation #: " + RandomString(resSpaceId));
                Console.WriteLine("Venue: " + venue.name);
                Console.WriteLine("Space: " + space.name);
                Console.WriteLine("Reserved For: " + reserved_for);
                Console.WriteLine("Attendees: " + numOfPeople);
                Console.WriteLine("Arrival Date: " + Convert.ToDateTime(startDates));
                Console.WriteLine("Departure Date: " + Convert.ToDateTime(endDates));
                Console.WriteLine("Total Cost: $" + space.dailyRate);
            }
            else
            {
                Console.WriteLine("*** DID NOT CREATE ***");
            }
        }
예제 #13
0
        private void CheckAvailability()
        {
            GetAllCampgrounds();

            int      campgroundId = CLIHelper.GetInteger("Please select which Campground Id you would like to check the availability of : ");
            DateTime startDate    = CLIHelper.GetDateTime("When would you like start your reservation?");
            DateTime endDate      = CLIHelper.GetDateTime("When would you like end your reservation?");

            CampgroundDAL cdal = new CampgroundDAL(DatabaseConnection);
            Campground    reservedCampground = cdal.GetCampground(campgroundId);

            if (startDate.Month < reservedCampground.OpenFromMM)
            {
                Console.WriteLine("The campground is not open yet.");
                return;
            }
            if (endDate.Month > reservedCampground.OpenToMM)
            {
                Console.WriteLine("The campground is closed for the year.");
                return;
            }


            Console.WriteLine();

            SiteDAL     sdal = new SiteDAL(DatabaseConnection);
            List <Site> site = sdal.GetAvailableCampsites(campgroundId, startDate, endDate);

            PrintSites(site);

            Console.ReadLine();
            string input = CLIHelper.GetString(" Would you Like to confirm your reservation?").ToLower();

            if (input == "yes" || input == "y")
            {
                HelpMakeReservation(campgroundId, startDate, endDate);
            }
            else
            {
                Console.WriteLine("Returning to Main Menu");
                Console.ReadLine();
            }
        }
        /// <summary>
        /// Gets arrival and departure dates from user
        /// </summary>
        /// <param name="fromMonth">Minimum month allowed for reservations at campground</param>
        /// <param name="toMonth">Maximum month allowed for reservations at campground</param>
        /// <param name="type">Whether the date is arrival or departure</param>
        /// <param name="minimumDate">Minimum date allowed for reservation</param>
        /// <returns>The arrival or departure date</returns>
        private DateTime GetDate(int fromMonth, int toMonth, string type, DateTime minimumDate)
        {
            DateTime date      = DateTime.Now;
            bool     validDate = false;

            while (!validDate)
            {
                date = CLIHelper.GetDateTime("What is the " + type + " date? ");

                if (date > minimumDate)
                {
                    if (date.Year == DateTime.Now.Year)
                    {
                        if (date.Month >= fromMonth && date.Month <= toMonth)
                        {
                            validDate = true;
                        }
                        else
                        {
                            Console.WriteLine("The campground is not open for reservations during the month entered. Please try again.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Reservations are only being accepted for the current year. Please try again.");
                    }
                }
                else
                {
                    if (type == "arrival")
                    {
                        Console.WriteLine("The arrival date must be later than today's date. Please try again.");
                    }
                    else
                    {
                        Console.WriteLine("The departure date must be later than the arrival date. Please try again.");
                    }
                }
            }

            return(date);
        }
예제 #15
0
        private void PromptForReservationInfo(int selectedPark)
        {
            IList <Campground> availableCampgrounds = campgroundDAO.GetCampgroundsFromPark(selectedPark);

            int      desiredCampground;
            DateTime arrivalDate;
            DateTime departureDate;

            while (true)
            {
                desiredCampground = CLIHelper.GetInteger("Which campground? Enter 0 to cancel");
                if (desiredCampground == 0)
                {
                    Console.Clear();
                    CampgroundMenu(selectedPark);
                }
                else if (desiredCampground <= availableCampgrounds.Count())
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid Entry. Please select a campground from the list.");
                }
            }
            while (true)
            {
                arrivalDate   = CLIHelper.GetDateTime("What day do you plan on arriving? Please enter in yyyy-mm-dd format.");
                departureDate = CLIHelper.GetDateTime("What day do you plan on leaving? Please enter in yyyy-mm-dd format.");
                if (arrivalDate > departureDate)
                {
                    Console.WriteLine();
                    Console.WriteLine("Your arrival date must be before your departure date. Please try again.");
                }
                else
                {
                    break;
                }
            }
            SiteMenu(selectedPark, desiredCampground, arrivalDate, departureDate);
        }
예제 #16
0
        public void SearchReservationMenu()
        {
            Console.Write("Which campground (enter 0 to cancel)? ");
            string campgroundInput = Console.ReadLine();

            userCampChoice = campgroundInput;
            if (campgroundInput != "0")
            {
                DateTime arrivalTime    = CLIHelper.GetDateTime("What Is the Arrival Date?(mm-dd-yyyy) ");
                string   arrivalInput   = arrivalTime.Date.ToShortDateString();
                DateTime departTime     = CLIHelper.GetDateTime("What is the Departure Date?(mm-dd-yyyy) ");
                string   departureInput = departTime.Date.ToShortDateString();
                TimeSpan diff           = (departTime - arrivalTime);
                reservedDays = diff.Days;
                AvailableSites(campgroundInput, arrivalInput, departureInput);
            }
            else if (campgroundInput == "0")
            {
                Console.Clear();
            }
        }
        private void GetParkWideAvailability(string parkName)
        {
            CampgroundSqlDAL             campgroundDAL = new CampgroundSqlDAL();
            Dictionary <int, Campground> campgrounds   = campgroundDAL.GetAllCampgroundsInPark(parkName);

            Console.Clear();
            DateTime startDate = CLIHelper.GetDateTime("What is the arrival date (YYYY/MM/DD)?:");
            DateTime endDate   = CLIHelper.GetDateTime("What is the departure date (YYYY/MM/DD)?:");

            List <Site> availableSites = campgroundDAL.GetParkAvailability(parkName, startDate, endDate);

            if (availableSites.Count > 0)
            {
                Console.Clear();
                Console.WriteLine("Results Matching Your Search Criteria");
                Console.WriteLine("{0,13}{1,12}{2,13}{3,14}{4,9}{5,10}{6,7}", "Campground", "Site No.", "Max Occup.", "Accessible?", "RV Len", "Utility", "Cost");
                List <int> availableSiteNumbers = new List <int>();

                int totalReservDays = (int)(endDate - startDate).TotalDays;

                foreach (var site in availableSites)
                {
                    Campground campground = campgrounds.Where(i => i.Value.CampgroundId == site.CampgroundID).First().Value;
                    availableSiteNumbers.Add(site.SiteNumber);
                    double cost = totalReservDays * campground.Daily_Fee;

                    Console.WriteLine(campground.Name.PadRight(13) + site.SiteNumber.ToString().PadRight(12) + site.MaxOccupancy.ToString().PadRight(13) +
                                      site.WheelchairAccess.PadRight(19) + site.MaxRVLength.PadRight(9) + site.UtilityHookups.PadRight(10) + cost);
                }

                BookReservation(availableSiteNumbers, startDate, endDate);
            }
            else
            {
                Console.WriteLine("Sorry, there are no sites available in the specified date range.");
                bool stillBooking = CLIHelper.GetBoolFromYesOrNo("Would you like to enter another date range?");
            }
        }
예제 #18
0
        public void BookReservation()
        {
            string   name           = CLIHelper.GetString("Please enter first and last name:");
            string   campgroundName = CLIHelper.GetString("Please enter the campground name:");
            int      siteNumber     = CLIHelper.GetInteger("Please enter the site number: ");
            int      numberCampers  = CLIHelper.GetInteger("Please enter the number of campers:");
            DateTime startDate      = CLIHelper.GetDateTime("Please enter a start date:");
            DateTime endDate        = CLIHelper.GetDateTime("Please enter an end date:");
            int      reservationID  = 0;

            Reservation r = new Reservation()
            {
                Name           = name,
                FromDate       = startDate,
                ToDate         = endDate,
                SiteNumber     = siteNumber,
                NumberCampers  = numberCampers,
                CampgroundName = campgroundName
            };
            ReservationSqlDAL dal = new ReservationSqlDAL();

            try
            {
                reservationID = dal.BookReservation(r);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            if (reservationID > 0)
            {
                Console.WriteLine($"Your reservation was successfully created. Reservation id: {reservationID}");
            }
            else
            {
                Console.WriteLine("Request unsuccessful. Reservation NOT created.");
            }
        }
예제 #19
0
        private void CheckReservation()
        {
            int     siteID  = CLIHelper.GetInteger("Please Select your Camp Site:");
            SiteDal siteDal = new SiteDal(connectionString);
            Site    site    = siteDal.GetSite(siteID);

            if (site == null)
            {
                Console.WriteLine("That site does not exist.");
                return;
            }

            CampgroundDAL campDal = new CampgroundDAL(connectionString);
            Campground    c       = campDal.GetCampgroundById(site.campground_id);

            string   name       = CLIHelper.GetString("Please enter reservation Name:");
            DateTime fromDate   = CLIHelper.GetDateTime("Please select arrival date (yyyy-mm-dd):");
            DateTime toDate     = CLIHelper.GetDateTime("Please select depature date(yyyy-mm-dd):");
            DateTime createDate = DateTime.Now;

            Console.WriteLine();

            if (c.OpenFromMM > fromDate.Month || c.OpenToMM < toDate.Month)
            {
                Tools.ColorfulWriteLine("Sorry the camp is closed during that time frame. Please try again", ConsoleColor.Red);
            }
            else
            {
                ReservationDAL dal = new ReservationDAL(connectionString);
                dal.MakeReservation(siteID, name, fromDate, toDate, createDate);
                Reservation r = dal.GetReservationNumber(siteID, name, fromDate, toDate);

                Console.WriteLine("Success, your reservation confirmation is below!");
                Tools.ColorfulWriteLine("Confirmation ID".PadRight(20) + "Name".PadRight(35) + "Arrival Date".PadRight(10) + "Depature Date".PadRight(15) + "Creation Date", ConsoleColor.Green);
                Console.WriteLine($"{r.reservationId})".PadRight(20) + $"{r.name}".PadRight(35) + $"{r.fromDate}".PadRight(10) + $"{r.toDate}".PadRight(15) + $"{r.createDate}");
            }
        }
        /// <summary>
        /// Runs menu to give user a choice of campgrounds from the choosen park.
        /// </summary>
        /// <param name="parkName"></param>
        /// <param name="parkId"></param>
        public void RunCampGroundCLI(string parkName, int parkId)
        {
            List <string> Wrap(string text, int margin)
            {
                int start = 0, end;
                var lines = new List <string>();

                text = Regex.Replace(text, @"\s", " ").Trim();

                while ((end = start + margin) < text.Length)
                {
                    while (text[end] != ' ' && end > start)
                    {
                        end -= 1;
                    }

                    if (end == start)
                    {
                        end = start + margin;
                    }

                    lines.Add(text.Substring(start, end - start));
                    start = end + 1;
                }

                if (start < text.Length)
                {
                    lines.Add(text.Substring(start));
                }

                return(lines);
            }

            IList <Park> parks = parksDAO.GetAllParks();

            foreach (Park park in parks)
            {
                List <string> decript = Wrap(park.Description, 155);
                foreach (string dp in decript)
                {
                    Console.WriteLine($"         {dp}");
                }
                Console.WriteLine();

                userParkId = parkId;
                IList <Park> pa = parksDAO.GetAllParks();
                parkName = "";
                string parkDecript = "";
                foreach (Park name in pa)
                {
                    if (name.ParkId == userParkId)
                    {
                        parkName    = name.Name;
                        parkDecript = name.Description;
                    }
                }
                Console.Clear();
                PrintHeader();
                Console.WriteLine();
                Console.WriteLine($"                                                                         {parkName}", Color.Yellow);
                Console.WriteLine("__________________________________________________________________________________________________________________________________________________________________________", Color.DimGray);
                Console.WriteLine();
                foreach (string dp in decript)
                {
                    Console.WriteLine($"         {dp}", Color.DarkKhaki);
                }
                Console.WriteLine();
                Console.WriteLine("__________________________________________________________________________________________________________________________________________________________________________", Color.DimGray);

                GetCampGroundList();
                PrintCampGroundChoices();

                while (true)
                {
                    string             userChoice  = Console.ReadLine();
                    IList <Campground> campgrounds = campgroundDAO.Search(userParkId);
                    foreach (Campground campground in campgrounds)
                    {
                        string cgIdString = campground.CampgroundId.ToString();
                        if (userChoice == cgIdString)
                        {
                            Console.WriteLine();
                            DateTime fromDate = CLIHelper.GetDateTime("Please Enter Arrival Date(YYYY-MM-DD): ");
                            DateTime toDate   = CLIHelper.GetDateTime("Please Enter Departure Date (YYYY-MM-DD): ");
                            SiteCLI  siteCLI  = new SiteCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
                            siteCLI.RunSiteCLI(parkName, parkId, campground.CampgroundId, campground.Name, campground.DailyFee, fromDate, toDate);
                        }
                        else
                        {
                            switch (userChoice.ToLower())
                            {
                            case "p":
                                Console.Clear();
                                ParkCLI parkCLI = new ParkCLI(parksDAO, campgroundDAO, siteDAO, reservationDAO);
                                parkCLI.RunParkCLI();
                                break;

                            default:
                                Console.WriteLine("The command provided was not a valid command, please try again.", Color.Red);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #21
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
        private void SearchForReservationInterface(Campground selectedCamp)
        {
            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("What is the arrival date? ");
                DateTime arrivalDate = CLIHelper.GetDateTime("Enter in year-month-day format.");

                Console.WriteLine("What is the departure date?");
                DateTime depatureDate = CLIHelper.GetDateTime("Enter in year-month-day format.");

                SiteDAO dao = new SiteDAO(_connectionString);
                try
                {
                    IList <Site> sites = dao.GetTop5Sites(selectedCamp, arrivalDate, depatureDate);



                    if (sites.Count > 0)
                    {
                        Console.Clear();

                        Console.WriteLine($"Results Matching Your Search Criteria");
                        Console.WriteLine("Site No.".PadRight(15) + "Max Occup.".PadRight(15) +
                                          "Accessible?".PadRight(15) + "Max RV Length".PadRight(15) +
                                          "Utility".PadRight(15) + "Cost");

                        Dictionary <int, Site> siteDict = new Dictionary <int, Site>();
                        int siteCount = 0;


                        foreach (Site s in sites)
                        {
                            Console.WriteLine($"{++siteCount}) " +
                                              $"{s.SiteNumber.ToString().PadRight(15)}" +
                                              $"{s.MaxOccupancy.ToString().PadRight(15)}" +
                                              $"{s.AccessibleString.PadRight(15)}" +
                                              $"{s.MaxRVString.PadRight(15)}" +
                                              $"{s.UtilitiesString.PadRight(15)}" +
                                              $"{selectedCamp.DailyFee.ToString("C")}");


                            siteDict.Add(siteCount, s);
                        }
                        Console.WriteLine();
                        int selection = CLIHelper.GetSingleInteger("Which site should be reserved(enter 0 to cancel) ", 0, sites.Count);
                        Console.WriteLine();

                        if (selection == 0)
                        {
                            exit = true;
                        }
                        else
                        {
                            //ReservationDAO  = new ReservationDAO(_connectionString);
                            string name = CLIHelper.GetString("What name should the reservation be made under? ");
                            MakeReservationInterface(siteDict[selection], name, arrivalDate, depatureDate);
                            exit = true;
                        }
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("****** NO RESULTS ******");
                        Console.WriteLine("");
                        Console.ReadKey();
                        exit = true;
                    }
                }
                catch
                {
                    Console.Clear();
                    Console.WriteLine("Something went wrong with the Dates you entered... try again.");
                }
            }
        }
예제 #23
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
        public void MakeReservation(int parkID, int campgroundID)
        {
            bool        searchAgain    = false;
            SiteDAL     siteDAL        = new SiteDAL(connectionString);
            List <Site> availableSites = new List <Site>();
            DateTime    fromDate;
            DateTime    toDate;

            do
            {
                searchAgain = false;
                fromDate    = CLIHelper.GetDateTime("What is the arrival date: ");
                int numberOfAttempts = 0;
                do
                {
                    if (numberOfAttempts > 0)
                    {
                        Console.WriteLine("Departure date cannot be before/equal to arrival date.");
                    }
                    toDate = CLIHelper.GetDateTime("What is the departure date: ");
                    numberOfAttempts++;
                } while (toDate.CompareTo(fromDate) <= 0);

                Console.WriteLine();
                Console.WriteLine("".PadRight(4) + "Campground".PadRight(35) + "Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(15) + "RV Len".PadRight(10) + "Utilities".PadRight(11) + "Cost");

                if (campgroundID == 0)
                {
                    availableSites = siteDAL.GetAvailableSitesPark(parkID, toDate, fromDate);
                }
                else
                {
                    availableSites = siteDAL.GetAvailableSitesCampground(campgroundID, toDate, fromDate);
                }

                if (availableSites.Count == 0)
                {
                    Console.WriteLine("There are no available sites.");
                    string askSearchAgain = CLIHelper.GetString("Do you wish to search again? ");

                    switch (askSearchAgain.ToLower())
                    {
                    case "y":
                        searchAgain = true;
                        break;

                    default:
                        Console.WriteLine("Thank you, you will be returned to the Park Selection screen.  Press enter to continue...");
                        Console.ReadLine();
                        return;
                    }
                }
            } while (searchAgain);

            TimeSpan interval = toDate.Date.Subtract(fromDate);
            int      numDays  = 1 + interval.Days;
            int      index    = 1;

            foreach (Site s in availableSites)
            {
                Console.WriteLine(index.ToString().PadRight(4) + s.ToString(numDays));
                index++;
            }
            ;

            int  siteToBook       = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel): ");
            bool invalidSelection = false;

            do
            {
                if (siteToBook == 0)
                {
                    invalidSelection = false;
                    Console.WriteLine("Thank you, you will be returned to the Park Selection screen.  Press enter to continue...");
                    Console.ReadLine();
                }
                else if (siteToBook > 0 && siteToBook < index)
                {
                    ReservationDAL reservationDAL = new ReservationDAL(connectionString);
                    string         nameToBook     = CLIHelper.GetString("What name should the reservation be made under? ");
                    int            confirm        = reservationDAL.CreateReservation(availableSites[siteToBook - 1].SiteID, nameToBook, fromDate, toDate);
                    Console.WriteLine($"\nThe reservation has been made and the confirmation id is {confirm}.");
                    Console.WriteLine("Press enter to continue...");
                    Console.ReadLine();
                    invalidSelection = false;
                }
                else
                {
                    siteToBook       = CLIHelper.GetInteger("Please enter a valid selection: ");
                    invalidSelection = true;
                }
            } while (invalidSelection);
            return;
        }
예제 #25
0
        public void RunCLI()
        {
            int userInput;
            int subMenuInput;

            Console.WriteLine();
            List <Park> parks = PrintAllParks();

            Console.WriteLine();
            Console.WriteLine("Please enter the number of the park you would like to visit.");
            userInput = cliHelper.GetInteger();
            int      campgroundInput;
            DateTime arrivalDate;
            DateTime departureDate;

            while (userInput < 0 || userInput > parks.Count)
            {
                Console.WriteLine("Invalid input. Please try again.");
                userInput = cliHelper.GetInteger();
            }

            if (userInput == 0)
            {
                Environment.Exit(0);
            }

            PrintParkDetails(parks[userInput - 1]);

            subMenuInput = PrintCampgroundMenu();
            bool goBack = false;

            while (goBack == false)
            {
                switch (subMenuInput)
                {
                case 0:
                    subMenuInput = PrintCampgroundMenu();
                    break;

                case 1:
                    List <Campground> campgrounds = PrintAllCampgrounds(parks[userInput - 1].ParkId);
                    Console.WriteLine("Select a command");
                    Console.WriteLine("1) Search for Available Reservation");
                    Console.WriteLine("2) Return to Previous Screen");
                    int input = cliHelper.GetInteger();
                    if (input == 1)
                    {
                        subMenuInput = 2;
                    }
                    else if (input == 2)
                    {
                        subMenuInput = 0;
                    }
                    break;

                case 2:
                    bool reservationsAvailable = false;
                    while (reservationsAvailable == false)
                    {
                        campgrounds = PrintAllCampgrounds(parks[userInput - 1].ParkId);
                        Console.WriteLine("Which campground (enter 0 to cancel)? ");

                        campgroundInput = cliHelper.GetInteger();
                        if (campgroundInput == 0)
                        {
                            RunCLI();
                        }
                        while (campgroundInput < 0 || !campgrounds.Exists(c => c.CampgroundId == campgroundInput))
                        {
                            Console.WriteLine("Invalid option. Please try again.");
                            campgroundInput = cliHelper.GetInteger();
                        }
                        if (campgroundInput == 0)
                        {
                            reservationsAvailable = true;
                            subMenuInput          = 0;
                            break;
                        }
                        Console.WriteLine();
                        Console.WriteLine("What is the arrival date? ");
                        arrivalDate = cliHelper.GetDateTime();
                        Console.WriteLine();
                        Console.WriteLine("What is the departure date? ");
                        departureDate = cliHelper.GetDateTime();
                        List <AvailableReservations> reservations = PrintReservations(parks[userInput - 1].ParkId, campgroundInput, arrivalDate, departureDate);
                        reservationsAvailable = reservations.Count > 0;
                        if (reservationsAvailable)
                        {
                            MakeReservation(arrivalDate, departureDate, reservations);
                            RunCLI();
                        }
                    }
                    break;

                case 3:
                    ReservationDAL     reservationDAL = new ReservationDAL();
                    List <Reservation> nextThirty     = reservationDAL.ReservationsNextThirtyDays(parks[userInput - 1].ParkId);
                    Console.Clear();
                    Console.WriteLine("ID".PadRight(5) + "Site".PadRight(8) + "Name".PadRight(30) + "Start Date".PadRight(25) + "End Date".PadRight(25) + "Date Reserved");
                    foreach (Reservation reservation in nextThirty)
                    {
                        Console.WriteLine(reservation.ReservationId.ToString().PadRight(5) + reservation.SiteId.ToString().PadRight(8) + reservation.Name.PadRight(30) +
                                          reservation.FromDate.ToString("MMMM").PadRight(25) + reservation.ToDate.ToString("MMMM").PadRight(25) + reservation.CreateDate.ToString());
                    }
                    Console.WriteLine();
                    subMenuInput = 0;
                    break;

                case 4:
                    Console.WriteLine();
                    RunCLI();
                    break;
                }
            }
        }
        }//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
예제 #27
0
        private void PrintReservationSearchPrompt(Park selectedPark)
        {
            IList <Campground> campgrounds = campgroundDAO.GetCampgrounds(selectedPark.ParkId);

            Console.Clear();
            Console.WriteLine("Search for Campground Reservation");
            Console.WriteLine();

            Console.WriteLine($"        Name                             Open           Close         Daily Fee");

            foreach (Campground campground in campgrounds)
            {
                Console.WriteLine($"#{campground.CampgroundId,-5}{campground.Name,-35}{campground.FromMonth,-15}{campground.ToMonth,-15}{$"{campground.DailyFee:C2}",-10}");
            }
            Console.WriteLine();
            int campgroundId = CLIHelper.GetInteger(" Which Campground (enter 0 to cancel)?:");

            if (campgroundId == 0)
            {
                return;
            }

            bool isValidCampground = false;

            foreach (Campground campground in campgrounds)
            {
                if (campgroundId == campground.CampgroundId)
                {
                    isValidCampground = true;
                }
            }

            if (!isValidCampground)
            {
                Console.WriteLine("Please enter a valid campground id..");
                Console.ReadLine();
                PrintReservationSearchPrompt(selectedPark);
            }

            DateTime arrival   = CLIHelper.GetDateTime("What is the arrival date? (as mm/dd/yyyy):");
            DateTime departure = CLIHelper.GetDateTime("What is the departure date? (as mm/dd/yyyy):");

            Console.WriteLine();

            if (departure < arrival)
            {
                Console.WriteLine("The departure date must be after the arrival date");
                Console.ReadLine();
                PrintReservationSearchPrompt(selectedPark);
                return;
            }

            TimeSpan dateRange = departure.Date - arrival.Date;

            int     daysOfStay = dateRange.Days;
            decimal dailyFee   = 0;

            IList <Site> sites = siteDAO.GetAvailableSites(campgroundId, arrival, departure);

            foreach (Campground campground in campgrounds)
            {
                if (campground.CampgroundId == campgroundId)
                {
                    dailyFee = campground.DailyFee;
                }
            }

            decimal costOfTotalStay = dailyFee * daysOfStay;

            Console.WriteLine("Results Matching Your Search Criteria");
            Console.WriteLine($"{"Site No.",-10}{"Max Occup.", -12}{"Accessible?",-12}{"Max RV Length",-14}{"Utility",-10}{"Cost",-8}");

            foreach (Site site in sites)
            {
                string rvLength   = "N/A";
                string accessible = "No";
                string utility    = "N/A";

                if (site.Utilities == true)
                {
                    utility = "Yes";
                }

                if (site.Accessible == true)
                {
                    accessible = "Yes";
                }

                if (site.MaxRVLength != 0)
                {
                    rvLength = site.MaxRVLength.ToString();
                }
                Console.WriteLine($"{site.SiteId,-10}{site.MaxOccupancy,-12}{accessible,-12}{rvLength,-14}{utility,-10}{$"{costOfTotalStay:C2}",-8}");
            }
            Console.WriteLine();
            int siteId = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?");

            if (siteId == 0)
            {
                return;
            }

            bool isValidSite = false;

            foreach (Site site in sites)
            {
                if (siteId == site.SiteId)
                {
                    isValidSite = true;
                }
            }

            if (!isValidSite)
            {
                Console.WriteLine("Please enter a valid site id..");
                Console.ReadLine();
                PrintReservationSearchPrompt(selectedPark);
            }

            string name = CLIHelper.GetString("What name should the reservation be made under?");

            Console.WriteLine();

            Reservation reservation = new Reservation
            {
                SiteId     = siteId,
                Name       = name,
                FromDate   = arrival,
                ToDate     = departure,
                CreateDate = DateTime.Now,
            };

            reservationDAO.BookReservation(reservation);
            Console.WriteLine("Thanks for booking your reservation, press enter to return to main menu");
            Console.ReadLine();
        }
        public void SearchForAvailableReservationScreen(Park park)
        {
            SiteSqlDal        siteSqlDal        = new SiteSqlDal(DatabaseConnection);
            CampgroundSqlDal  campgroundSqlDal  = new CampgroundSqlDal(DatabaseConnection);
            ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection);
            List <Campground> campgrounds       = campgroundSqlDal.GetAllCampgroundsFromPark(park.Id);

            //Search for valid campground
            bool done = false;

            while (!done)
            {
                Console.Clear();
                Console.WriteLine("Search for Campground Reservation: ");
                PrintAllCampgroundInfoInPark(park);

                int userInputCampgroundId = CLIHelper.GetInteger("\nWhich Campground number (Enter 0 to cancel)?");
                if (userInputCampgroundId == 0)
                {
                    Console.WriteLine("Cancelled! Press any key to continue.");
                    Console.ReadKey();
                    return;
                }

                if (GetCampgroundById(userInputCampgroundId, campgrounds) == null)
                {
                    Console.WriteLine("Not a valid campground! Press any key to continue.");
                    Console.ReadKey();
                    return;
                }

                //Once valid campground has been chosen --> Get good dates for query
                DateTime    checkIn  = CLIHelper.GetDateTime("Check-in date: ");
                DateTime    checkOut = CLIHelper.GetDateTime("Check-out date: ");
                List <Site> availableSitesFromCampgrounds = new List <Site>();
                bool        gotDates = false;
                bool        showReservationPrompt = false;
                while (!gotDates)
                {
                    availableSitesFromCampgrounds = siteSqlDal.GetAvailableSitesFromCampground(userInputCampgroundId, checkIn, checkOut);
                    if (checkOut.CompareTo(checkIn) <= 0)
                    {
                        Console.WriteLine("Cannot check-out earlier or same day as check-in.  Press any key to continue");
                        Console.ReadKey();
                        showReservationPrompt = false;
                        gotDates = true;
                        //could allow user a choice to return or enter new dates
                    }
                    else if (availableSitesFromCampgrounds.Count < 1)
                    {
                        string dateReset = CLIHelper.GetString("\nThere are no available sites. \nWould you like to enter an alternate date range?\n\tYes or No?").ToLower();
                        if (dateReset == "yes" || dateReset == "y")
                        {
                            Console.WriteLine();
                            checkIn  = CLIHelper.GetDateTime("Check-in date: ");
                            checkOut = CLIHelper.GetDateTime("Check-out date: ");
                            gotDates = false;
                        }
                        else if (dateReset == "no" || dateReset == "n")
                        {
                            gotDates = true;
                        }
                        else
                        {
                            Console.WriteLine("Invalid input. Try again");
                            gotDates = false;
                        }
                    }
                    else
                    {
                        showReservationPrompt = true;
                        gotDates = true;
                    }
                }
                if (showReservationPrompt)
                {
                    int daysReserved = checkOut.Subtract(checkIn).Days;
                    Console.WriteLine("Site Id".PadRight(10) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(20) + "Utility".PadRight(15) + "Cost\n");
                    foreach (Site site in availableSitesFromCampgrounds)
                    {
                        Console.WriteLine(site.GetPrintString(daysReserved, GetCampgroundById(userInputCampgroundId, campgrounds).DailyFee));
                    }
                    Console.WriteLine();

                    MakeReservationPrompts(checkIn, checkOut, availableSitesFromCampgrounds);
                    done = true;
                }
            }
        }
예제 #29
0
        /// <summary>
        /// Preforms a search for campsites available to be reserved
        /// </summary>
        /// <param name="currentPark">The park to find a reservation in.</param>
        /// <param name="fromWholePark">Option to search through all campgrounds in the specified Park.</param>
        private void SearchForReservation(Park currentPark, bool fromWholePark)
        {
            Console.Clear();

            //Initialize working variables
            List <Campground> campgrounds = campDAL.GetCampgrounds(currentPark);
            List <Site>       sites       = new List <Site>();
            DateTime          startDate   = DateTime.MinValue;
            DateTime          endDate     = DateTime.MinValue;
            int  input             = -1;
            bool continueSearching = true;

            do
            {
                //If the reservation is for a specific campground
                if (!fromWholePark)
                {
                    campgrounds = campDAL.GetCampgrounds(currentPark);
                    Console.WriteLine($"Campgrounds in {currentPark.Name}");
                    PrintCampgroundList(currentPark);                       //Print list of campgrounds in park to screen

                    //Ask for user choice
                    Console.Write("Which Campground (enter 0 to cancel)? ");
                    input = CLIHelper.GetAnInteger(0, campgrounds.Count);

                    //If User chose a campground, make the list only contain their choice
                    if (input != 0)
                    {
                        campgrounds = new List <Campground>()
                        {
                            campgrounds[input - 1]
                        };
                    }
                }
                //initialize advanced search criteria

                if (input != 0)
                {
                    int  occupants    = 1;
                    bool isAccessible = false;
                    int  RVLength     = 0;
                    bool hasUtilities = false;
                    //Get reservation dates in correct format
                    Console.Write(">Enter a Start Date for Reservation:  ");
                    startDate = CLIHelper.GetDateTime(DateTime.Now.Date);
                    Console.Write(">Enter a Departure Date for Reservation:  ");
                    endDate = CLIHelper.GetDateTime(startDate);

                    //Ask user for optional advanced search
                    Console.Write("Would You Like to Preform an Advanced Search? (Y/N):  ");
                    bool isAdvancedSearch = CLIHelper.GetBoolean();

                    //Get user specified advanced search criteria
                    if (isAdvancedSearch)
                    {
                        Console.WriteLine();
                        Console.Write("How many occupants:  ");
                        occupants = CLIHelper.GetAnInteger(1, 55);
                        Console.Write("Do you need Wheelchair Accessiblity? (Y/N):  ");
                        isAccessible = CLIHelper.GetBoolean();
                        Console.Write("How long is your RV? (Enter 0 if not applicable):  ");
                        RVLength = CLIHelper.GetAnInteger(0, 35);
                        Console.Write("Utilities Required? (Y/N):  ");
                        hasUtilities = CLIHelper.GetBoolean();
                    }
                    //Print a list of sites that match the search criteria
                    sites = PrintSiteList(startDate, endDate, campgrounds, occupants, isAccessible, RVLength, hasUtilities);

                    //if there are no sites ask to try again or quit
                    if (sites.Count == 0)
                    {
                        Console.Clear();
                        Console.WriteLine("No Available Sites per Your Specifications.");
                        Console.Write("Would You Like to Try Again? (Y/N): ");
                        continueSearching = CLIHelper.GetBoolean();
                        Console.WriteLine();
                    }
                }
                //Loop while the search return empty and user has not chosen to continue/quit
            } while (sites.Count == 0 && input != 0 && continueSearching);

            //Book a reservation if sites were found
            if (sites.Count != 0)
            {
                BookAReservation(sites, startDate, endDate);
            }
        }
        private void MakeReservation()
        {
            List <Site> availableSites = new List <Site>();
            int         campgroundId   = CLIHelper.GetInteger("Which campground (ID number) would you like to reserve? Enter (0) to cancel.");

            if (campgroundId == 0)
            {
                return;
            }

            DateTime desiredStartDate = CLIHelper.GetDateTime("What is your desired arrival date? (__/__/____)");
            DateTime desiredEndDate   = CLIHelper.GetDateTime("What is your desired departure date? (__/__/____)");

            SiteSqlDAL  dal   = new SiteSqlDAL(DatabaseConnection);
            List <Site> sites = dal.SearchReservation(campgroundId, desiredStartDate, desiredEndDate);

            decimal totalFee = dal.GetFee(campgroundId, desiredStartDate, desiredEndDate);

            if (sites.Count > 0)
            {
                Console.WriteLine("Results Matching Your Search Criteria");
                Console.WriteLine("Site No.".PadRight(10) + "Max. Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max. RV Length".PadRight(15) + "Utility".PadRight(15) + "Cost");

                sites.ForEach(s =>
                {
                    Console.WriteLine(s + "    $" + Math.Round(totalFee, 2));
                });
            }
            else
            {
                Console.WriteLine("**** NO RESULTS ****");
                return;
            }

            int siteNumber = CLIHelper.GetInteger("Which site would you like to reserve? (Enter 0 to cancel)");

            //check out this fancy Linq thing that totally duplicates the commented-out stuff below
            int?tempSiteID = sites.First(s => s.SiteNumber == siteNumber)?.SiteID;

            //sites.ForEach(s =>
            //{
            //    if (s.SiteNumber == siteNumber)
            //    {
            //        tempSiteID = s.SiteID;
            //    }
            //});

            if (siteNumber == 0)
            {
                return;
            }

            string reservationName = CLIHelper.GetString("What name should the reservation be made under?");

            ReservationSqlDAL res = new ReservationSqlDAL(DatabaseConnection);
            bool result           = res.MakeReservation(reservationName, tempSiteID, desiredStartDate, desiredEndDate);

            if (result)
            {
                Console.WriteLine($"Your reservation has been created under the name {reservationName}.");
            }
            else
            {
                Console.WriteLine("Error. Reservation not created. Please try again.");
            }
        }