public string DisplaySitesAndGetUserInput(List <Site> sites, Campground campground, DateTime userArrivalDate, DateTime userDepartureDate) { Console.Clear(); string snName = "Search for Campground Reservation Menu"; Console.SetCursorPosition((Console.WindowWidth - snName.Length) / 2, Console.CursorTop); Console.WriteLine(snName); string snNameDash = "--------------------------------------"; Console.SetCursorPosition((Console.WindowWidth - snNameDash.Length) / 2, Console.CursorTop); Console.WriteLine(snNameDash); Console.WriteLine(); Console.WriteLine("{0,-25}{1,-15}{2,-15}{3,-15}", "CAMPGROUND", "OPEN", "CLOSE", "DAILY FEE"); Console.WriteLine("{0,-25}{1,-15}{2,-15}{3,-15}", campground.Name, campground.GetMonthString(true), campground.GetMonthString(false), campground.DailyFee); Console.WriteLine(); Console.WriteLine($"Reservation Start Date: {userArrivalDate.ToShortDateString()}"); Console.WriteLine($"Reservation End Date: {userDepartureDate.ToShortDateString()}"); Console.WriteLine($"Reservation Total Fee: " + campground.CostOfStayForSite(userArrivalDate, userDepartureDate).ToString("c")); Console.WriteLine(); string input = "zzz"; if (sites.Count() > 5) { for (int i = 1; i <= 5; i++) { if (i == 1) { Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "SITE NO.", "MAX OCCUP.", "ACCESSIBLE", "RV LENGTH", "UTILITY"); } Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", sites[i - 1].SiteId, sites[i - 1].MaxOccupancy, sites[i - 1].Accessible, sites[i - 1].MaxRVLength, sites[i - 1].Utilities); } Console.WriteLine(); input = CLIHelper.GetIntInRangeOrQ("Select a Site Number (+ enter) to Make a Reserveration or Press (R + enter) to Return to Previous Menu", sites[0].SiteId, sites[sites.Count() - 1].SiteId, "R", false); } else if (sites.Count() < 6 && sites.Count() > 0) { for (int i = 1; i <= sites.Count(); i++) { if (i == 1) { Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "SITE NO.", "MAX OCCUP.", "ACCESSIBLE", "RV LENGTH", "UTILITY"); } Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", sites[i - 1].SiteId, sites[i - 1].MaxOccupancy, sites[i - 1].Accessible, sites[i - 1].MaxRVLength, sites[i - 1].Utilities); } Console.WriteLine(); input = CLIHelper.GetIntInRangeOrQ("Select a Site Number (+ enter) to Make a Reserveration or Press (R + enter) to Return to Previous Menu", sites[0].SiteId, sites[sites.Count() - 1].SiteId, "R", false); } else if (sites.Count() == 0) { Console.WriteLine("Sorry There are no sites available at your selected campground on your selected dates :("); Console.WriteLine("Press Any Key to return to the Park Menu"); Console.ReadKey(); } return(input); }
private Dictionary <bool, DateTime> GetStartAndEndDates() { Dictionary <bool, DateTime> startDateTrueEndDateFalse = new Dictionary <bool, DateTime>(); bool isDone = false; while (!isDone) { Console.WriteLine(); DateTime userArrivalDate = CLIHelper.GetDateTime("What is your arrival date? mm/dd/yyyy"); Console.WriteLine(); DateTime userDepartureDate = CLIHelper.GetDateTime("What is your departure date? mm/dd/yyyy"); Console.WriteLine(); ReservationDAL reservationDAL = new ReservationDAL(DatabaseConnection); bool hasNoExceptions = true; Reservation testReservation = new Reservation() { Name = "Test", ReservationId = 0, SiteId = 0, FromDate = userArrivalDate, ToDate = userDepartureDate, CreateDate = DateTime.Now }; List <string> exceptionMessages = new List <string>(); try { reservationDAL.IsEndDateAfterStartDate(testReservation); } catch (Exception e) { exceptionMessages.Add(e.Message); hasNoExceptions = false; } try { reservationDAL.IsReservationInTheFuture(testReservation); } catch (Exception e) { exceptionMessages.Add(e.Message); hasNoExceptions = false; } int counter = 0; foreach (string msg in exceptionMessages) { counter++; Console.WriteLine(msg); if (counter == exceptionMessages.Count()) { Console.WriteLine("Press Any Key To Try Again"); Console.ReadKey(); } } if (hasNoExceptions == true) { startDateTrueEndDateFalse.Add(true, userArrivalDate); startDateTrueEndDateFalse.Add(false, userDepartureDate); isDone = true; } } return(startDateTrueEndDateFalse); }
private void ParkWideSearchCLI(Park park) { Console.WriteLine("UNDER CONSTRUCTION: Parkwide Search feature coming soon!"); CampgroundDAL campgroundDAL = new CampgroundDAL(DatabaseConnection); SiteDAL siteDAL = new SiteDAL(DatabaseConnection); ReservationDAL reservationDAL = new ReservationDAL(DatabaseConnection); //Get start and end dates for reservation Dictionary <bool, DateTime> startDateTrueEndDateFalse = GetStartAndEndDates(); DateTime userArrivalDate = startDateTrueEndDateFalse[true]; DateTime userDepartureDate = startDateTrueEndDateFalse[false]; //Get all campgrounds for park List <Campground> campgrounds = campgroundDAL.GetAllCampgroundsForPark(park); Dictionary <int, Campground> campgroundDictionary = new Dictionary <int, Campground>(); foreach (Campground item in campgrounds) { campgroundDictionary.Add(item.CampgroundId, item); } //Shit getting real BELOW! bool doneWithMenu = false; while (!doneWithMenu) { Console.Clear(); string snName = "Available Park Sites Menu"; Console.SetCursorPosition((Console.WindowWidth - snName.Length) / 2, Console.CursorTop); Console.WriteLine(snName); string snNameDash = "--------------------------------------"; Console.SetCursorPosition((Console.WindowWidth - snNameDash.Length) / 2, Console.CursorTop); Console.WriteLine(snNameDash); Console.WriteLine(); Console.WriteLine($"Reservation Start Date: {userArrivalDate.ToShortDateString()}"); Console.WriteLine($"Reservation End Date: {userDepartureDate.ToShortDateString()}"); Dictionary <int, Site> allSitesInPark = new Dictionary <int, Site>(); int campgroundDisplayLoopCounter = 0; foreach (Campground campground in campgrounds) { //Write Header For Each Campground Console.WriteLine(); if (campgroundDisplayLoopCounter == 0) { Console.WriteLine("---------------------------------------------------------------------------"); } Console.WriteLine(campground.Name.ToUpper() + " CAMPGROUND"); //Check if Campground is Closed bool campgroundOpen = true; try { reservationDAL.IsCampgroundOpen(campground, userArrivalDate, userDepartureDate); } catch (Exception e) { campgroundOpen = false; Console.WriteLine(e.Message); Console.WriteLine(); } List <Site> sites = siteDAL.GetTopFiveAvailableSites(campground, userArrivalDate, userDepartureDate); if (sites.Count() > 0 && campgroundOpen) { Console.WriteLine("{0,-15}{1,-15}{2,-15}", "OPEN", "CLOSE", "DAILY FEE"); Console.WriteLine("{0,-15}{1,-15}{2,-15}", campground.GetMonthString(true), campground.GetMonthString(false), campground.DailyFee); Console.WriteLine(); Console.WriteLine($"Reservation Total Fee: " + campground.CostOfStayForSite(userArrivalDate, userDepartureDate).ToString("c")); Console.WriteLine(); } if (sites.Count() > 5 && campgroundOpen) { for (int i = 1; i <= 5; i++) { if (i == 1) { Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "SITE NO.", "MAX OCCUP.", "ACCESSIBLE", "RV LENGTH", "UTILITY"); } Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", sites[i - 1].SiteId, sites[i - 1].MaxOccupancy, sites[i - 1].Accessible, sites[i - 1].MaxRVLength, sites[i - 1].Utilities); allSitesInPark.Add(sites[i - 1].SiteId, sites[i - 1]); } } else if (sites.Count() < 6 && sites.Count() > 0 && campgroundOpen) { for (int i = 1; i <= sites.Count(); i++) { if (i == 1) { Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "SITE NO.", "MAX OCCUP.", "ACCESSIBLE", "RV LENGTH", "UTILITY"); } Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", sites[i - 1].SiteId, sites[i - 1].MaxOccupancy, sites[i - 1].Accessible, sites[i - 1].MaxRVLength, sites[i - 1].Utilities); allSitesInPark.Add(sites[i - 1].SiteId, sites[i - 1]); } } else if (sites.Count() == 0 && campgroundOpen) { Console.WriteLine("There are no sites available at your selected campground on your selected dates :("); } Console.WriteLine("---------------------------------------------------------------------------"); campgroundDisplayLoopCounter++; } //Get user input List <int> siteIDs = new List <int>(); foreach (KeyValuePair <int, Site> item in allSitesInPark) { siteIDs.Add(item.Key); } string userSelection = CLIHelper.GetIntInListOrQ("Please enter a site ID to make a reservation or enter R to return to the Park Information Menu", siteIDs, "r", false); if (userSelection.ToLower() == "r") { doneWithMenu = true; } else { int selectedSiteID = int.Parse(userSelection); Site selectedSite = allSitesInPark[selectedSiteID]; Campground selectedCampground = campgroundDictionary[selectedSite.CampgroundId]; MakeReservationCLI(selectedCampground, selectedSiteID, userArrivalDate, userDepartureDate); doneWithMenu = true; } } }
private void GetAllCampgroundsForParkCLI(Park park) { CampgroundDAL campgroundDAL = new CampgroundDAL(DatabaseConnection); ReservationDAL reservationDAL = new ReservationDAL(DatabaseConnection); List <Campground> campgrounds = campgroundDAL.GetAllCampgroundsForPark(park); bool doneWithMenu = false; while (!doneWithMenu) { Console.Clear(); //Displaying menu items string snName = "Park Campground Menu"; Console.SetCursorPosition((Console.WindowWidth - snName.Length) / 2, Console.CursorTop); Console.WriteLine(snName); string snNameDash = "--------------------"; Console.SetCursorPosition((Console.WindowWidth - snNameDash.Length) / 2, Console.CursorTop); Console.WriteLine(snNameDash); Console.WriteLine(); for (int i = 1; i <= campgrounds.Count; i++) { if (i == 1) { Console.WriteLine("{0,-5}{1,-35}{2,-10}{3,-10}{4,-10}", " ", "NAME", "OPEN", "CLOSE", "DAILY FEE"); } Console.WriteLine("{0,-5}{1,-35}{2,-10}{3,-10}{4,-10}", i + ")", campgrounds[i - 1].Name, campgrounds[i - 1].GetMonthString(true), campgrounds[i - 1].GetMonthString(false), campgrounds[i - 1].DailyFee.ToString("c")); } Console.WriteLine($""); //Selecting a campground string userCampground = CLIHelper.GetIntInRangeOrQ("Which campground would you like to make a reservation at? [or press (Q) to quit]", 1, campgrounds.Count(), "q", true); Console.WriteLine(); if (userCampground.ToLower() == "q") { doneWithMenu = true; } else { //Get Date and Time Dictionary <bool, DateTime> startDateTrueEndDateFalse = GetStartAndEndDates(); DateTime userArrivalDate = startDateTrueEndDateFalse[true]; DateTime userDepartureDate = startDateTrueEndDateFalse[false]; bool datesGood = false; while (!datesGood) { bool campgroundOpen = true; try { reservationDAL.IsCampgroundOpen(campgrounds[int.Parse(userCampground) - 1], userArrivalDate, userDepartureDate); } catch (Exception e) { Console.WriteLine(e.Message); campgroundOpen = false; } if (campgroundOpen) { datesGood = true; } } bool wantAdvancedSearch = CLIHelper.GetBoolCustom("Would you like to check additional site requirements with our advanced search?", "yes", "no"); if (wantAdvancedSearch) { AdvancedSearchGetSitesCLI(campgrounds[int.Parse(userCampground) - 1], userArrivalDate, userDepartureDate); } else if (!wantAdvancedSearch) { GetAllSitesForCampgroundCLI(campgrounds[int.Parse(userCampground) - 1], userArrivalDate, userDepartureDate); } doneWithMenu = true; } } }