예제 #1
0
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="media">The memory stream containing the media.</param>
        /// <param name="type">The media type.</param>
        /// <param name="rpu">A delegate of type <see cref="StatusMessageReportProgress"/> used to send messages back to the calling object.</param>
        /// <param name="caller">The calling object.</param>
        /// <returns>The id for the new media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public int CreateMedia(System.IO.Stream media, MLifter.DAL.Interfaces.EMedia type, MLifter.DAL.Tools.StatusMessageReportProgress rpu, object caller)
        {
            int          newId;
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "INSERT INTO MediaContent (data, media_type) VALUES (@data, @type); SELECT @@IDENTITY;";
            cmd.Parameters.Add("@data", SqlDbType.Image);
            cmd.Parameters.Add("@type", SqlDbType.NVarChar, 100);
            cmd.Parameters["@data"].Value = GetByteArrayFromStream(media, rpu, caller);
            cmd.Parameters["@type"].Value = type.ToString();
            newId = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd));

            return(newId);
        }
예제 #2
0
        public void SetCardMedia(int id, int cardid, MLifter.DAL.Interfaces.Side side, MLifter.DAL.Interfaces.WordType type, bool isDefault, MLifter.DAL.Interfaces.EMedia mediatype)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                SqlCeTransaction tran = cmd.Connection.BeginTransaction();

                ClearCardMedia(cardid, side, type, mediatype);

                cmd.CommandText = "INSERT INTO \"Cards_MediaContent\" (media_id, cards_id, side, type, is_default) " +
                                  "VALUES (@mediaid, @cardid, @side, @type, @isdefault);";
                cmd.Parameters.Add("@mediaid", id);
                cmd.Parameters.Add("@cardid", cardid);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@isdefault", isDefault);
                MSSQLCEConn.ExecuteNonQuery(cmd);

                tran.Commit();
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }