Ejemplo n.º 1
0
        private static void ConfirmSubmission(HotelDatabase hotelDatabase, RoomType room, string name, DateTime date, int daysStaying)
        {
            Console.WriteLine("Please review your information.");
            Console.Write
            (
                "Name: " + name + "\r\n" +
                "Room Type: " + room.ToString() + "\r\n" +
                "Date of Arrival: " + date.Date.ToString() + "\r\n" +
                "Days Staying: " + daysStaying + "\r\n" +
                "Total Cost: " + (int)room * daysStaying + "\r\n"
            );
            Console.WriteLine("Is this what you want (y/n)?");
            string response = Console.ReadLine();

            if (response.ToLower().Equals("y"))
            {
                hotelDatabase.AddReservation(new Reservation(name, room, date, daysStaying));
                Console.WriteLine("Thank you for choosing to stay with us, I hope you enjoy your stay!");
            }
            else if (response.ToLower().Equals("n"))
            {
                Console.WriteLine("Well, maybe next time then. Take care!");
            }
            else
            {
                Console.WriteLine("Well, maybe next time then. Take care!");
            }
        }
Ejemplo n.º 2
0
        public static HotelDatabase LoadDB()
        {
            HotelDatabase data = null;

            try
            {
                using (FileStream file = new FileStream(file_path, FileMode.Open))
                {
                    file.Position = 0;
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    data = (HotelDatabase)binaryFormatter.Deserialize(file);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The Database has failed to load, data may be corrupted, loading database defaults");
                Console.WriteLine(e.StackTrace);
            }

            if (data == null)
            {
                return(new HotelDatabase());
            }
            else
            {
                return(data);
            }
        }
Ejemplo n.º 3
0
        public static HotelDatabase GetDatabase()
        {
            if (database != null)
            {
                return(database);
            }

            if (File.Exists(file_path))
            {
                database = LoadDB();
                return(database);
            }
            else
            {
                database = new HotelDatabase();
                return(database);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            HotelDatabase hotelDatabase = HotelDatabase.GetDatabase();

            DisplayWelcomeMessage();
            try
            {
                RoomType room        = GetRoomType();
                string   name        = GetName();
                DateTime date        = GetDate();
                int      daysStaying = GetDays();
                ConfirmSubmission(hotelDatabase, room, name, date, daysStaying);
            }
            catch (Exception)
            {
                Console.WriteLine("An error has occurred. Please restart.");
            }

            Console.Read();
        }
Ejemplo n.º 5
0
        private static RoomType GetRoomType()
        {
            Console.WriteLine("Room type's available \n" +
                              "===========================================\n" +
                              "1) Single: $" + (int)RoomType.Single + "\n" +
                              "2) Twin: $" + (int)RoomType.Twin + "\n" +
                              "3) Studio: $" + (int)RoomType.Studio + "\n" +
                              "4) Joint: $" + (int)RoomType.Joint + "\n" +
                              "5) Deluxe: $" + (int)RoomType.Deluxe + "\n" +
                              "6) Suite: $" + (int)RoomType.Suite + "\n" +
                              "7) Penthouse: $" + (int)RoomType.Penthouse + "\n" +
                              "8) Presidential: $" + (int)RoomType.Presidential + "\n");

            bool result = int.TryParse(Console.ReadLine(), out int roomType);

            if (!result)
            {
                throw new IllegalDataException();
            }

            return(HotelDatabase.ParseRoomType(roomType));
        }