Esempio n. 1
0
        static void Main(string[] args)
        {
            // -------------------    VAR INIT    -----------------------------

            Room[] rooms = new Room[2]
            {
                new Room("101", 54.5, "Single Room", 120, "Description 1"),
                new Room("102", 64.5, "Double Room", 160, "Description 2")
            };
            List<string> roomsList = new List<string>();
            List<string> roomsListRead = new List<string>();
            List<string> roomsListSearched = new List<string>();
            foreach (Room r in rooms)
                roomsList.Add(r.ToString());

            Customer[] customers = new Customer[2]
            {
                new Customer("John Doe", "Main Street 1-1", "101", "2015-01-01", 5),
                new Customer("Jane Doe", "Main Street 2-2", "102", "2015-02-02", 10)
            };
            List<string> customersList = new List<string>();
            List<string> customersListRead = new List<string>();
            List<string> customersListSearched = new List<string>();
            foreach (Customer c in customers)
                customersList.Add(c.ToString());

            Hotel[] hotels = new Hotel[2]
            {
                new Hotel("Hotel 1", "2015-01-01", "Main Street 1-1", 4, roomsList, customersList),
                new Hotel("Hotel 2", "2014-01-01", "Main Street 2-2", 5, roomsList, customersList)
            };

            // -------------------    TESTING METHODS   -----------------------------

            Console.WriteLine("=============   Hotel Class   =============\n");

            hotels[0].WriteFile(hotels);
            hotels[0].ReadFile();

            Console.WriteLine("=============   Room Class   =============\n");

            rooms[0].WriteFile(rooms);
            rooms[0].ReadFile();

            Console.WriteLine("=============   Customer Class   =============\n");

            customers[0].WriteFile(customers);
            customers[0].ReadFile();

            Console.WriteLine("\nPress enter to close...");
            Console.ReadLine();
        }
Esempio n. 2
0
        public void WriteFile(Room[] rooms)
        {
            string filePath = @"room.xml";
            FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate);
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            for (int i = 0; i < rooms.Length; i++)
                binaryFormatter.Serialize(fileStream, rooms[i]);

            fileStream.Flush();
            fileStream.Close();
        }