//Methods /// <summary> /// Override of ToString method. /// </summary> /// <returns>Properly formatted site information</returns> /// Method pulls database information for campground name and campground cost. public string ToString(int numDays) { string connectionString = ConfigurationManager.ConnectionStrings["CapstoneDatabase"].ConnectionString; CampgroundDAL cgDAL = new CampgroundDAL(connectionString); Campground cg = cgDAL.GetCampgroundByID(this.CampgroundID); string result; result = cg.Name.PadRight(35); result += this.SiteNumber.ToString().PadRight(10); result += this.MaxOccupancy.ToString().PadRight(12); result += this.Accessible ? "YES".PadRight(15) : "NO".PadRight(15); if (this.MaxRVLength > 0) { result += this.MaxRVLength.ToString().PadRight(10); } else { result += "N/A".PadRight(10); } result += this.Utilities ? "YES".PadRight(11) : "N/A".PadRight(11); result += cg.CalculateFee(numDays); return(result); }
public Campground GetCampgroundFromReader(SqlDataReader reader) { Campground item = new Campground(); item.CampgroundID = Convert.ToInt32(reader["campground_id"]); item.ParkID = Convert.ToInt32(reader["park_id"]); item.Name = Convert.ToString(reader["name"]); item.OpenMonth = Convert.ToInt32(reader["open_from_mm"]); item.CloseMonth = Convert.ToInt32(reader["open_to_mm"]); item.DailyFee = Convert.ToInt32(reader["daily_fee"]); return(item); }
// LEVEL: CAMPGROUND ///////////////////////////////////////// private int[] GetCampgroundAvailability_View(int campgroundID, DateTime startDate, DateTime endDate) { CampgroundSqlDAL campDAL = new CampgroundSqlDAL(DatabaseConnection); IList <Campsite> availableCampsites = campDAL.CampgroundAvailability(campgroundID, startDate, endDate); int lengthOfStay = (int)(endDate - startDate).TotalDays; Campground campground = campDAL.CampgroundDetails(campgroundID); if (availableCampsites.Count > 0) { int[] output = new int[availableCampsites.Count]; decimal cost = 0; decimal fee = 0; Console.WriteLine( "Campground".PadRight(30) + "Site No.".PadRight(15) + "Max Occup.".ToString().PadRight(15) + "Accessible".PadRight(15) + "RV Len".PadRight(15) + "Utility".PadRight(15) + "Cost".PadLeft(20)); int i = 0; foreach (Campsite campsite in availableCampsites) { output[i] = campsite.Site_Number; fee = campground.Daily_Fee; cost = fee * lengthOfStay; this.PrintCampsiteAvailability( campground.Name, campsite.Site_Number, campsite.Max_Occupancy, campsite.IsAccessible, campsite.Max_RV_Length, campsite.HasUtilities, cost); i++; } return(output); } else { Console.WriteLine("**** NO RESULTS ****"); return(new int[0]); } }
public void GetAvailableSites() { Console.Write($"Please enter the desired campground ID number (enter 0 to cancel)?: "); //TODO Site Id Num bool parsedToInt; int campgroundSelection; parsedToInt = int.TryParse(Console.ReadLine().Trim(), out campgroundSelection); if (!parsedToInt || campgroundSelection < 0 || !campgroundList.Contains(campgroundSelection)) { Console.Clear(); menu.PrintHeader(); DisplayParkCampgrounds(parkID); Console.WriteLine("Invalid option. Please try again."); GetAvailableSites(); } else if (campgroundSelection == 0) { Console.Clear(); menu.PrintHeader(); SelectPark(parkID); } else { do { Console.Write($"What is the arrival date? (MM/DD/YYYY): "); arrivalDate = CLIHelper.GetDateTime(Console.ReadLine().Trim()); Console.Write($"What is the departure date? (MM/DD/YYYY): "); departureDate = CLIHelper.GetDateTime(Console.ReadLine().Trim()); if (departureDate < arrivalDate) { Console.SetCursorPosition(0, Console.CursorTop - 1); Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r"); Console.SetCursorPosition(0, Console.CursorTop - 1); Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r"); Console.WriteLine("Departure date must be after arrival date."); } } while (departureDate < arrivalDate); IList <Site> sites = siteDAO.GetAvailableSites(campgroundSelection, arrivalDate, departureDate); if (sites.Count == 0) { Console.Clear(); Console.Write("There are no campsites available for those dates. Would you like to try again (Y/N)?: "); string tryAgain;// = Console.ReadLine(); bool validAnswer = false; do { switch (tryAgain = Console.ReadLine().ToUpper()) { case "Y": validAnswer = true; GetAvailableSites(); break; case "N": validAnswer = true; RunCLI(); break; default: Console.WriteLine("Please answer Y or N."); break; } } while (!validAnswer); } else { Console.Clear(); List <int> siteIds = new List <int>(); do { menu.PrintHeader(); Campground campground = campgroundDAO.SelectCampground(campgroundSelection); Console.WriteLine("Sites are listed in order of popularity."); Console.WriteLine(); foreach (Site site in sites) { Console.WriteLine($"Site No.:".PadRight(15) + "Max Occupancy:".PadRight(20) + "Accessible?:".PadRight(15) + "Max RV Length:".PadRight(20) + "Utility:".PadRight(15) + "Daily Fee:"); Console.WriteLine($"#{site.Id,-14}{site.MaxOccupancy,-20}{(site.Accessible ? "Yes" : "No"),-15}{(site.MaxRVLength > 0 ? site.MaxRVLength.ToString() : "N/A"),-20}{(site.Utilities ? "Yes" : "No"),-15}{campground.DailyFee:C2}"); //Pad Right 20 after names Console.WriteLine(); siteIds.Add(site.Id); } Console.Write("Which site would you like to reserve (enter 0 to cancel)?: "); bool couldParse; couldParse = int.TryParse(Console.ReadLine().Trim(), out siteID); if (siteID == 0) { Console.Clear(); RunCLI(); } else if (!siteIds.Contains(siteID)) { Console.WriteLine("Please select a site ID from the list above."); } } while (!siteIds.Contains(siteID)); Console.Write("What name should the reservation be made under?: "); reservationName = Console.ReadLine().Trim(); } } AddReservations(); }
//Method to calculate cost of a stay based on daily rate x price: public decimal CalculateCost(Campground campground, int numDays) { decimal cost = campground.DailyFee * numDays; return(cost); }