void Rom::reservationByName(std::string name, int action) { for (int i = 1; i <= Reservations->no_of_elements(); i++) { Reservasjon* temp = (Reservasjon*) Reservations->remove_no(i); if (temp->sameNameAsReservation(name)) { temp->display(); // If this method was called with action set to REMOVE, // ask the user whether or not to remove the reservation. if(action == REMOVE && readChar("Delete reservation?", 'y','n') == 'y') { Reservations->destroy(temp->getArrival()); } // If the action is set to CHECKIN, and today is the expected arrival date, and the user answers "y" to "Check-in?", // then set checkin timestamp to current datetime by passing no parameters to setCheckin. else if(action == CHECKIN && temp->getArrival() == tid.hent_dato() && readChar("Check-in?",'y','n') == 'y') { temp->setCheckin(); Reservations->add(temp); } else Reservations->add(temp); } else { Reservations->add(temp); } } }
/****************************************************************************** name: bool checkReservationData(string, int) description: Checks if a reservation really exist. This functions checks both the registered user AND the registered date. parameters: string name, int date returns: (int) 1 or 0 0 = reservation does NOT exist 1 = reservation exist ******************************************************************************/ bool Rom::checkReservationData(string name, int date) { for (int i = 1; i <= Reservations->no_of_elements(); i++) { Reservasjon * temp = (Reservasjon *) Reservations->remove_no(i); Reservations->add(temp); if (temp->getArrival() == date && temp->sameNameAsReservation(name)) return true; else return false; } }
/****************************************************************************** name: void editReservation(string, int) description: Edit a reservation. If possible, you can change the arrival and/or departure date. parameters: (string) name, (int) date returns: n/a ******************************************************************************/ void Rom::editReservation(string name, int date) { extern Timer tid; int todaysDate = tid.hent_dato(); int newDate; char userCommand; for (int i = 1; i <= Reservations->no_of_elements(); i++) { Reservasjon * temp = (Reservasjon *) Reservations->remove_no(i); if (temp->getArrival() == date && temp->sameNameAsReservation(name)) { if (temp->getInUse() == 0) { cout << "\nAvailable choices:"; cout << "\n\t 1) Change arrival date"; cout << "\n\t 2) Change departure date"; cout << "\n\t Q) QUIT"; userCommand = readCommand(); switch(userCommand) { case '1': { do { // Gir "kunde" den allerede registrerte datoen, i // tilfellet ikke ledig i andre tidsperioder. // (For å hindre en loop man ikke kommer seg ut av) cout << "Arrival date already registered: " << temp->getArrival() << "\n"; cout << "\nEnter the new arrival date: "; cin >> newDate; cin.ignore(); // Check if room is reserved between the new date and deparature. } while (this->isReserved(newDate, tid.forskjell_datoer(newDate, date))); temp->setArrival(newDate); cout << "\nNotice: Arrival date has been updated.\n"; cin.get(); break; } case '2': { do { // Gir "kunde" den allerede registrerte datoen, // i tilfellet ikke ledig i andre tidsperioder. // (For å hindre en loop man ikke kommer seg ut av) cout << "The departure date already registered: " << temp->getDeparture() << "\n"; cout << "\nEnter the new departure date: "; cin >> newDate; cin.ignore(); } while (this->isReserved( temp->getArrival(), tid.forskjell_datoer(temp->getArrival(), newDate)) ); temp->setDeparture(newDate); cout << "\nNotice: Departure date has been updated.\n"; cin.get(); break; } } } else if(temp->getInUse() == 1) { cout << "\nAvailable choices:"; cout << "\n\t 1) Change departure date"; cout << "\n\t Q) QUIT"; userCommand = readCommand(); } else { cout << "Error: Can't change arrival date. This person has already checked in.\n"; cout << "Press any key to continue"; cin.get(); } }