public Customer(int id, string name, string address, string telephone, int numNights, Hotel hotel, int idHotel, string idRoom) { this.id = id; this.name = name; this.address = address; this.telephone = telephone; this.numNights = numNights; bookRoom(id, hotel, idHotel, idRoom); writeToFile(); }
public void serializeHotel(Hotel[] hotel) { FileStream fileStream = new FileStream(filePathHotel, FileMode.OpenOrCreate); SoapFormatter soapFormatter = new SoapFormatter(); for (int i = 0; i < hotel.Length; i++) soapFormatter.Serialize(fileStream, hotel[i]); fileStream.Flush(); fileStream.Close(); }
public void serializeHotel(Hotel hotel) { FileStream fileStream = new FileStream(filePathHotel, FileMode.OpenOrCreate); SoapFormatter soapFormatter = new SoapFormatter(); soapFormatter.Serialize(fileStream, hotel); fileStream.Flush(); fileStream.Close(); }
public Hotel[] deserializeHotelAsArray() { FileStream fileStream = new FileStream(filePathHotel, FileMode.Open); SoapFormatter soapFormatter = new SoapFormatter(); object obj = null; ArrayList list = new ArrayList(); for (; ; ) { try { obj = soapFormatter.Deserialize(fileStream); if (obj is Hotel) { list.Add((Hotel)obj); } } catch (EndOfStreamException) { } catch (SerializationException) { //Console.WriteLine(e.Message); break; } catch (System.Xml.XmlException) { //Console.WriteLine(e.Message); break; } } Hotel[] hotel = new Hotel[list.Count]; for (int i = 0; i < list.Count; i++) hotel[i] = (Hotel)list[i]; fileStream.Flush(); fileStream.Close(); return hotel; }
static void Main(string[] args) { ObjectReader or = new ObjectReader(); or.clearFiles(); // Test Hotel Class Functions Console.WriteLine("Hotel Data Create:"); Console.WriteLine("---------------------------"); Hotel hotel = new Hotel(0, "Avalon", "The Palm 32, Dubai"); hotel.addRoom(0, "A1", 2, 1000.0f); hotel.addRoom(0, "A2", 3, 1500.0f); Console.WriteLine(hotel.getInfo(0)); // Test Read Room Class From File ArrayList rooms = or.getRoomsList(); // get objects from file Console.WriteLine("READ/ WRITE FROM FILE PART:"); Console.WriteLine("Room Array writen from file:"); Console.WriteLine("---------------------------"); for (int i = 0; i < rooms.Count; i++) Console.WriteLine(((Room)rooms[i]).getInfo()); // Test Read Room Class From File (after some changes) - test changeInFile() function ((Room)rooms[0]).setRoomNotAvailable("A1"); ((Room)rooms[1]).setPricePerNight("A2", 2100.0f); ArrayList rooms2 = or.getRoomsList(); Console.WriteLine("Room Array writen from file after changes:"); Console.WriteLine("---------------------------"); for (int i = 0; i < rooms.Count; i++) Console.WriteLine(((Room)rooms2[i]).getInfo()); // Create Customer Data to read /write from file ArrayList customers = new ArrayList(); customers.Add(new Customer(0, "Lionel Messi", "Royal Residence 3, Barcelona", "+48 832333222", 5, 0.5f)); customers.Add(new Customer(1, "Mao Asada", "Ice Palace 14, Tokyo", "+321 2243332223", 3, 0.05f)); // Test Read Customers Class From File ArrayList customers2 = or.getCustomersList(rooms); // get objects from file Console.WriteLine("Customer Array writen from file:"); Console.WriteLine("---------------------------"); for (int i = 0; i < customers2.Count; i++) Console.WriteLine(((Customer)customers2[i]).getInfo()); // Test Read Customers Class Array and Room Class Array From File (after some changes in Customer Class) - test changeInFile() function ((Customer)customers2[0]).bookRoom(0, rooms, "A1"); //((Customer)customers2[0]).bookRoom(0, rooms, "A2"); Console.WriteLine("Room and Customer Array after changes:"); Console.WriteLine("---------------------------"); for (int i = 0; i < rooms.Count; i++) Console.WriteLine(((Room)rooms[i]).getInfo()); for (int i = 0; i < customers2.Count; i++) Console.WriteLine(((Customer)customers2[i]).getInfo()); // Customers from file test ArrayList customers3 = or.getCustomersList(or.getRoomsList()); // get objects from file Console.WriteLine("Customer Array after changes - writen from file:"); Console.WriteLine("---------------------------"); for (int i = 0; i < customers3.Count; i++) Console.WriteLine(((Customer)customers3[i]).getInfo()); // Serialization Part TEST hotel.actualizeRooms(0, or.getRoomsList()); ((Customer)customers3[1]).bookRoom(1, hotel, 0, "A2"); // make some changes Console.WriteLine("SERIALIZE PART:"); Console.WriteLine("Hotel before serialization:"); Console.WriteLine("---------------------------"); Console.WriteLine(hotel.getInfo(0)); or.serializeHotel(hotel); Console.WriteLine("Hotel after deserialization:"); Console.WriteLine("---------------------------"); Hotel hotel2 = or.deserializeHotel(); Console.WriteLine(hotel2.getInfo(0)); or.serializeHotel(hotel); Console.WriteLine("Hotel after deserialization to array:"); Console.WriteLine("---------------------------"); Hotel [] hotel3 = or.deserializeHotelAsArray(); if (hotel3 != null) for (int i = 0; i < hotel3.Length; i++) Console.WriteLine(hotel3[i].getInfo(i)); }
public void checkOut(int id, Hotel hotel, int idHotel, string idRoom) { if (id == this.id) { this.checkInStatus = false; this.room = hotel.changeRoomStatus(idHotel, convertStringFormat(idRoom, 5), checkInStatus); this.idRoom = convertStringFormat("", 5); changeInFile(id, 7); changeInFile(id, 6); } }
public void bookRoom(int id, Hotel hotel, int idHotel, string idRoom) { if (id == this.id) { string idRoom2 = convertStringFormat(idRoom, 5); this.checkInStatus = true; this.room = hotel.changeRoomStatus(idHotel, idRoom2, checkInStatus); if (this.room != null) { this.idRoom = idRoom2; } else this.checkInStatus = false; changeInFile(id, 7); changeInFile(id, 6); } }