示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }
示例#4
0
        /// <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);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <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;
        }
示例#7
0
        /// <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
            });
        }
示例#8
0
        /// <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);
        }
示例#9
0
 /// <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));
 }
示例#10
0
 /// <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));
 }
示例#11
0
 protected override void Load(SqlConnection conn, sp.DataRow row)
 {
     base.Load(conn, row);
     Guests = Guest.GetGuestsByRoomId(conn, Id);
 }
示例#12
0
 protected override void Load(SqlConnection conn, sp.DataRow row)
 {
     base.Load(conn, row);
     Guests = new ObservableCollection <Guest>(Guest.GetGuestsByInviteId(conn, Id));
 }
示例#13
0
 /// <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);
示例#14
0
 /// <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);
 }
示例#15
0
 internal override void Load(DbConnection conn, sp.DataRow row)
 {
     this.Load((OdbcConnection)conn, row);
 }
示例#16
0
 internal override void LoadPropertiesFromDataRow(DbConnection conn, sp.DataRow row)
 {
     base.LoadPropertiesFromDataRow(conn, row);
     this.child = GetChildByParent(conn, this);
 }