public static List <Room> FetchRooms() { MySqlConnection con = InitConnection(); List <Room> rooms = new List <Room>(); try { con.Open(); String query = "SELECT * FROM room"; MySqlCommand command = new MySqlCommand(query, con); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { String room_id = reader.GetString("room_id"); int number = reader.GetInt32("room_number"); String type = reader.GetString("type"); Room newRoom = null; if (type == typeof(PrivateRoom).ToString()) { newRoom = new PrivateRoom { ID = room_id, RoomNumber = number } } ; else if (type == typeof(SemiPrivateRoom).ToString()) { newRoom = new SemiPrivateRoom { ID = room_id, RoomNumber = number } } ; else if (type == typeof(StandardWard).ToString()) { newRoom = new StandardWard { ID = room_id, RoomNumber = number } } ; rooms.Add(newRoom); } } catch { Console.WriteLine("Error Occured Fetching Rooms."); } finally { con.Close(); } return(rooms); }
public void addRoom() { if (RoomType == "Private") { PrivateRoom newPrivateRoom = new PrivateRoom { RoomNumber = int.Parse(RoomNumber), }; Rooms.Add( new RoomCardViewModel { ID = newPrivateRoom.ID, RoomNumber = newPrivateRoom.RoomNumber, Type = "Private Room", Capacity = newPrivateRoom.Patients.Count.ToString() + '/' + newPrivateRoom.Capacity.ToString() } ); FilteredRooms.Add( new RoomCardViewModel { ID = newPrivateRoom.ID, RoomNumber = newPrivateRoom.RoomNumber, Type = "Private Room", Capacity = newPrivateRoom.Patients.Count.ToString() + '/' + newPrivateRoom.Capacity.ToString() } ); Hospital.Rooms.Add(newPrivateRoom.ID, newPrivateRoom); HospitalDB.InsertRoom(newPrivateRoom); } else if (RoomType == "Semi Private") { SemiPrivateRoom newSemiPrivateRoom = new SemiPrivateRoom { RoomNumber = int.Parse(RoomNumber) }; Rooms.Add( new RoomCardViewModel { ID = newSemiPrivateRoom.ID, RoomNumber = newSemiPrivateRoom.RoomNumber, Type = "Semi Private Room", Capacity = newSemiPrivateRoom.Patients.Count.ToString() + '/' + newSemiPrivateRoom.Capacity.ToString() } ); FilteredRooms.Add( new RoomCardViewModel { ID = newSemiPrivateRoom.ID, RoomNumber = newSemiPrivateRoom.RoomNumber, Type = "Semi Private Room", Capacity = newSemiPrivateRoom.Patients.Count.ToString() + '/' + newSemiPrivateRoom.Capacity.ToString() } ); Hospital.Rooms.Add(newSemiPrivateRoom.ID, newSemiPrivateRoom); HospitalDB.InsertRoom(newSemiPrivateRoom); } else if (RoomType == "Standard Ward") { StandardWard newStandardWardRoom = new StandardWard { RoomNumber = int.Parse(RoomNumber) }; Rooms.Add( new RoomCardViewModel { ID = newStandardWardRoom.ID, RoomNumber = newStandardWardRoom.RoomNumber, Type = "StandardWard Room", Capacity = newStandardWardRoom.Patients.Count.ToString() + '/' + newStandardWardRoom.Capacity.ToString() } ); FilteredRooms.Add( new RoomCardViewModel { ID = newStandardWardRoom.ID, RoomNumber = newStandardWardRoom.RoomNumber, Type = "StandardWard Room", Capacity = newStandardWardRoom.Patients.Count.ToString() + '/' + newStandardWardRoom.Capacity.ToString() } ); Hospital.Rooms.Add(newStandardWardRoom.ID, newStandardWardRoom); HospitalDB.InsertRoom(newStandardWardRoom); } }