/// <summary> /// Creates a new MediaItem object using the data in a data row /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="row">DataRow containing the data for the media item</param> /// <returns>MediaItem object with properties loaded from the database</returns> internal static MediaItem FromDataRow(SqlConnection conn, sp.DataRow row) { MediaItemTypeEnum type = (MediaItemTypeEnum)Convert.ToInt16(row["Type"]); MediaItem mediaItem; switch (type) { case MediaItemTypeEnum.Video: mediaItem = Video.FromDataRow(row); break; case MediaItemTypeEnum.Song: mediaItem = Song.FromDataRow(row); break; default: throw new UnknownEnumValueException(type); } mediaItem.id = (Int64)row["Id"]; mediaItem.Genre = (String)row["Genre"]; mediaItem.name = (String)row["Name"]; mediaItem.isHidden = (Boolean)row["IsHidden"]; mediaItem.dateCreated = (DateTime)row["DateCreated"]; mediaItem.dateModified = (DateTime)row["DateModified"]; mediaItem.UserName = (String)row["UserName"]; mediaItem.playHistory = Data.MediaItem.GetMediaItemPlayHistoryById(conn, mediaItem.id, mediaItem.Type); mediaItem.parts = MediaItemPart.GetMediaItemPartsById(conn, mediaItem.Id, mediaItem.Type); mediaItem.tags = new ObservableCollection <IntelligentString>(Data.MediaItem.GetMediaItemTagsById(conn, mediaItem.id, mediaItem.Type)); mediaItem.IsInDatabase = true; return(mediaItem); }
/// <summary> /// Creates a new Video object using the data in a data row /// </summary> /// <param name="row">DataRow containing the data for the video</param> /// <returns>Video object with properties loaded from the database</returns> internal new static Video FromDataRow(sp.DataRow dr) { Video video = new Video(); video.Program = (String)dr["Program"]; video.Series = (Int16)dr["Series"]; video.Episode = (Int16)dr["Episode"]; video.NumberOfEpisodes = (Int16)dr["NumberOfEpisodes"]; return(video); }
/// <summary> /// Creates a new RootFolder object using the data in a data row /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="row">DataRow containing the data for the root folder</param> /// <returns>RootFolder object with properties loaded from the database</returns> internal static RootFolder FromDataRow(SqlConnection conn, sp.DataRow row) { RootFolder rootFolder = new RootFolder(); rootFolder.MediaItemType = (MediaItemTypeEnum)Convert.ToInt16(row["MediaItemType"]); rootFolder.Priority = (Int16)row["Priority"]; rootFolder.Path = (String)row["Path"]; rootFolder.Tags = new ObservableCollection <IntelligentString>(Data.RootFolder.GetRootFolderTagsByPriority(conn, rootFolder.MediaItemType, rootFolder.priority)); rootFolder.IsInDatabase = true; return(rootFolder); }
/// <summary> /// Creates a new FileType object using the data in a data row /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="row">DataRow containing the data for the file type</param> /// <returns>FileType object with properties loaded from the database</returns> internal static FileType FromDataRow(SqlConnection conn, sp.DataRow row) { FileType fileType = new FileType(); fileType.id = (Int16)row["Id"]; fileType.name = (String)row["Name"]; fileType.mediaItemType = (MediaItemTypeEnum)((Int16)row["MediaItemType"]); fileType.extensions = Data.FileType.GetExtensionsByFileTypeId(conn, fileType.Id); fileType.IsInDatabase = true; return(fileType); }
/// <summary> /// Creates a new Video object using the data in a data row /// </summary> /// <param name="row">DataRow containing the data for the video</param> /// <returns>Video object with properties loaded from the database</returns> internal new static Song FromDataRow(sp.DataRow dr) { Song song = new Song(); song.Artist = (String)dr["Artist"]; song.Album = (String)dr["Album"]; song.DiskNumber = (Int16)dr["DiskNumber"]; song.NumberOfDisks = (Int16)dr["NumberOfDisks"]; song.TrackNumber = (Int16)dr["TrackNumber"]; song.NumberOfTracks = (Int16)dr["NumberOfTracks"]; song.Year = (Int16)dr["Year"]; song.iTunesId = (Int16)dr["iTunesId"]; return(song); }
/// <summary> /// Loads the values in the in the data row into the object /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="row">Data row containing the data for the object</param> internal virtual void LoadPropertiesFromDataRow(DbConnection conn, sp.DataRow row) { Type type = GetType(); //get the value of the ID property DbObjectMetaDataAttribute metaData = type.GetCustomAttribute <DbObjectMetaDataAttribute>(); PropertyInfo idPi = type.GetProperty("Id"); idPi.SetValue(this, row[metaData.IdParameterName]); //load other properties foreach (PropertyInfo pi in type.GetProperties().Where(p => Attribute.IsDefined(p, typeof(sp.DataColumnAttribute)))) { sp.DataColumnAttribute attribute = pi.GetCustomAttribute <sp.DataColumnAttribute>(); pi.SetValue(this, row[attribute.ColumnName]); } IsInDatabase = true; }
/// <summary> /// Loads an instance of the Guest class using the data found in the data row /// </summary> /// <param name="row">Data row containing the data for the guest</param> /// <returns>Instance of the Guest class using the data found in the data row</returns> internal static Guest FromDataRow(sp.DataRow row) { Int32 id = (Int32)row["GuestId"]; String forename = (String)row["Forename"]; String surname = (String)row["Surname"]; Boolean? isAttending = (Boolean?)row["IsAttending"]; DateTime?dateOfRsvp = (DateTime?)row["DateOfRsvp"]; Boolean isChild = (Boolean)row["IsChild"]; Boolean isVegetarian = (Boolean)row["IsVegetarian"]; Boolean canBringPlusOne = (Boolean)row["CanBringPlusOne"]; Boolean isBringingPlusOne = (Boolean)row["IsBringingPlusOne"]; String plusOneForename = (String)row["PlusOneForename"]; String plusOneSurname = (String)row["PlusOneSurname"]; Boolean plusOneIsVegetarian = (Boolean)row["PlusOneIsVegetarian"]; Int32? tableId = (Int32?)row["TableId"]; Int32? roomId = (Int32?)row["RoomId"]; String notes = (String)row["Notes"]; return(new Guest() { Id = id, Forename = forename, Surname = surname, IsAttending = isAttending, DateOfRsvp = dateOfRsvp, IsChild = isChild, IsVegetarian = isVegetarian, CanBringPlusOne = canBringPlusOne, IsBringingPlusOne = isBringingPlusOne, PlusOneForename = plusOneForename, PlusOneSurname = plusOneSurname, PlusOneIsVegetarian = plusOneIsVegetarian, TableId = tableId, RoomId = roomId, Notes = notes }); }
/// <summary> /// Maps a data row to an object /// </summary> /// <typeparam name="T">Type of object to map the data to</typeparam> /// <typeparam name="TIdType">Type of the unique identifier of the object</typeparam> /// <param name="row">Data row containing the row being mapped</param> /// <param name="conn">Open connection to the database</param> /// <returns>Data row, mapped to an object</returns> private static T ExecuteMappedSingleReader <T, TIdType>(db.DbConnection conn, sp.DataRow row) where T : DbObject <TIdType> { //create a new item DbObject <TIdType> item = Activator.CreateInstance <T>() as DbObject <TIdType>; item.Load(conn, row); return((T)item); }
/// <summary> /// Executes a command and maps the single selected row to an object /// </summary> /// <typeparam name="T">Type of object to map the data to</typeparam> /// <param name="mapper">Mapper used to map the data to an object</param> /// <returns>Single row selected by the command, mapped to an object</returns> public T ExecuteMappedSingleReader <T>(Func <sp.DataRow, T> mapper) { sp.DataRow row = ExecuteSingleReader(); return(mapper(row)); }
/// <summary> /// Executes a command and maps the single selected row to an object /// </summary> /// <typeparam name="T">Type of object to map the data to</typeparam> /// <typeparam name="TIdType">Type of the unique identifier of the object</typeparam> /// <returns>Single row selected by the command, mapped to an object</returns> public T ExecuteMappedSingleReader <T, TIdType>() where T : DbObject <TIdType> { sp.DataRow row = ExecuteSingleReader(); return(ExecuteMappedSingleReader <T, TIdType>(connection, row)); }
protected override void Load(SqlConnection conn, sp.DataRow row) { base.Load(conn, row); Guests = Guest.GetGuestsByRoomId(conn, Id); }
protected override void Load(SqlConnection conn, sp.DataRow row) { base.Load(conn, row); Guests = new ObservableCollection <Guest>(Guest.GetGuestsByInviteId(conn, Id)); }
/// <summary> /// Loads the values in the in the data row into the object /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="row">Data row containing the data for the object</param> internal abstract void Load(DbConnection conn, sp.DataRow row);
/// <summary> /// Loads the values in the in the data row into the object /// </summary> /// <param name="conn">Open connection to the database</param> /// <param name="row">Data row containing the data for the object</param> protected virtual void Load(OdbcConnection conn, sp.DataRow row) { LoadPropertiesFromDataRow(conn, row); }
internal override void Load(DbConnection conn, sp.DataRow row) { this.Load((OdbcConnection)conn, row); }
internal override void LoadPropertiesFromDataRow(DbConnection conn, sp.DataRow row) { base.LoadPropertiesFromDataRow(conn, row); this.child = GetChildByParent(conn, this); }