Пример #1
0
        /// <summary>
        /// Gets the settings.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-01-15</remarks>
        public ISettings GetSettings(int id)
        {
            int?chapterSettingsId = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.ChapterSetting, id)] as int?;

            if (chapterSettingsId.HasValue)
            {
                return(new DbSettings(chapterSettingsId.Value, false, Parent));
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "SELECT settings_id FROM \"Chapters\" WHERE id=@id";
                cmd.Parameters.Add("@id", id);

                int?sid = MSSQLCEConn.ExecuteScalar <int>(cmd);

                if (sid.HasValue)
                {
                    Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.ChapterSetting, id)] = sid;
                    return(new DbSettings(sid.Value, false, Parent));
                }
                else
                {
                    return(null);
                }
            }
        }
        /// <summary>
        /// Creates the new word.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="word">The word.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="isDefault">if set to <c>true</c> [is default].</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public IWord CreateNewWord(int id, string word, Side side, WordType type, bool isDefault)
        {
            if (word != null)
            {
                SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                cmd.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                cmd.Parameters.Add("@id", id);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());

                int    currentPos = 0;
                object retval     = MSSQLCEConn.ExecuteScalar(cmd);
                if (retval != DBNull.Value)
                {
                    currentPos = Convert.ToInt32(retval);
                }
                cmd.Parameters.Clear();

                cmd.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                cmd.Parameters.Add("@id", id);
                cmd.Parameters.Add("@text", word);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@position", currentPos + 10);
                cmd.Parameters.Add("@isdefault", isDefault);

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));

                return(new DbWord(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)), word, type, isDefault, Parent));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Sets the chapter for a card.
        /// </summary>
        /// <param name="id">The card id.</param>
        /// <param name="chapter">The chapter id.</param>
        /// <remarks>Documented by Dev03, 2008-08-06</remarks>
        /// <remarks>Documented by Dev08, 2009-01-09</remarks>
        public void SetChapter(int id, int chapter)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                SqlCeTransaction transaction = cmd.Connection.BeginTransaction();
                cmd.CommandText = "SELECT count(*) FROM \"Chapters\" WHERE id=@chapterid";
                cmd.Parameters.Add("chapterid", chapter);
                if (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) < 1)
                {
                    throw new IdAccessException(chapter);
                }
                Dictionary <int, int> cardChapterCache = parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardChapterList, 0)] as Dictionary <int, int>;
                if (cardChapterCache != null)
                {
                    cardChapterCache[id] = chapter;
                }

                using (SqlCeCommand cmd2 = MSSQLCEConn.CreateCommand(parent.CurrentUser))
                {
                    cmd2.CommandText  = "DELETE FROM \"Chapters_Cards\" WHERE cards_id=@id; ";
                    cmd2.CommandText += "INSERT INTO \"Chapters_Cards\" (chapters_id, cards_id) VALUES (@chapterid, @id);";
                    cmd2.CommandText += "UPDATE Cards SET chapters_id=@chapterid WHERE id=@id;";
                    cmd2.Parameters.Add("@chapterid", chapter);
                    cmd2.Parameters.Add("@id", id);
                    MSSQLCEConn.ExecuteNonQuery(cmd2);
                }
                transaction.Commit();
            }
        }
        /// <summary>
        /// Checks if the card exists and throws an IdAccessException if not.
        /// </summary>
        /// <param name="id">The card id.</param>
        /// <remarks>Documented by Dev03, 2008-08-06</remarks>
        /// <remarks>Documented by Dev08, 2009-01-09</remarks>
        public void CheckCardId(int id)
        {
            List <int> cardIdsCache = parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardIdsList, 0)] as List <int>;

            if (cardIdsCache != null && cardIdsCache.Contains(id))
            {
                return;
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "(SELECT lm_id FROM \"LearningModules_Cards\" WHERE cards_id=@id)";
                cmd.Parameters.Add("@id", id);
                int lmId = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd));
                cmd.Parameters.Clear();

                cmd.CommandText = "SELECT id FROM \"Cards\" WHERE id IN " +
                                  "(SELECT cards_id FROM \"LearningModules_Cards\" WHERE lm_id=@lm_id)";
                cmd.Parameters.Add("@lm_id", lmId);
                SqlCeDataReader reader;
                try { reader = MSSQLCEConn.ExecuteReader(cmd); }
                catch { throw new IdAccessException(id); }

                List <int> cardIds = new List <int>();
                while (reader.Read())
                {
                    cardIds.Add(Convert.ToInt32(reader["id"]));
                }
                reader.Close();

                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.CardIdsList, 0)] = cardIds;
            }
        }
        /// <summary>
        /// Gets the default.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public bool GetDefault(int id)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT is_default FROM TextContent WHERE id=@id";
            cmd.Parameters.Add("@id", id);
            return(Convert.ToBoolean(MSSQLCEConn.ExecuteScalar(cmd)));
        }
        /// <summary>
        /// Gets the type.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public WordType GetType(int id)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT type FROM TextContent WHERE id=@id";
            cmd.Parameters.Add("@id", id);
            return((WordType)Enum.Parse(typeof(WordType), MSSQLCEConn.ExecuteScalar(cmd).ToString(), true));
        }
        /// <summary>
        /// Gets the word.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public string GetWord(int id)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT text FROM TextContent WHERE id=@id";
            cmd.Parameters.Add("@id", id);
            return(MSSQLCEConn.ExecuteScalar(cmd).ToString());
        }
        /// <summary>
        /// Gets the chapter for a card.
        /// </summary>
        /// <param name="id">The card id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2008-08-06</remarks>
        /// <remarks>Documented by Dev08, 2009-01-09</remarks>
        public int GetChapter(int id)
        {
            Dictionary <int, int> cardChaptersCache = parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardChapterList, 0)] as Dictionary <int, int>;

            if (cardChaptersCache != null && cardChaptersCache.ContainsKey(id))
            {
                return(cardChaptersCache[id]);
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "(SELECT lm_id FROM \"LearningModules_Cards\" WHERE cards_id=@id)";
                cmd.Parameters.Add("@id", id);
                int lmid = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd));

                cmd.Parameters.Clear();

                cmd.CommandText = "SELECT chapters_id, cards_id FROM Chapters_Cards WHERE chapters_id IN " +
                                  "(SELECT chapters_id FROM Chapters WHERE lm_id=@lmid)";
                cmd.Parameters.Add("@lmid", lmid);
                SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);

                Dictionary <int, int> cardChapters = new Dictionary <int, int>();

                while (reader.Read())
                {
                    object[] chapters = new object[2];
                    reader.GetValues(chapters);
                    int chid = Convert.ToInt32(chapters[0]);
                    int cid  = Convert.ToInt32(chapters[1]);
                    if (!cardChapters.ContainsKey(cid))
                    {
                        cardChapters[cid] = chid;
                    }
                }
                reader.Close();

                // this should fix the bug where for some reason a card didn't have chapter assigned [ML-1708] (and similar)
                int chapterId = 0;
                if (!cardChapters.TryGetValue(id, out chapterId))
                {
                    lock (cardChapters)
                    {
                        foreach (int c in cardChapters.Values)
                        {
                            chapterId = c;
                            break;
                        }
                        SetChapter(id, chapterId);
                        cardChapters.Add(id, chapterId);
                    }
                }

                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.CardChapterList, 0, new TimeSpan(23, 59, 59))] = cardChapters;

                return(chapterId);
            }
        }
Пример #9
0
 /// <summary>
 /// Gets the associated lm id of the chapter.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev02, 2008-08-05</remarks>
 /// <remarks>Documented by Dev05, 2009-01-15</remarks>
 public int GetLmId(int id)
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
     {
         cmd.CommandText = "SELECT lm_id FROM \"Chapters\" WHERE id=@id";
         cmd.Parameters.Add("@id", id);
         return(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)));
     }
 }
Пример #10
0
 /// <summary>
 /// Gets the GUID.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev08, 2009-01-12</remarks>
 public string GetGuid(int id)
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
     {
         cmd.CommandText = "SELECT guid FROM \"LearningModules\" WHERE id=@id";
         cmd.Parameters.Add("@id", id);
         return(Convert.ToString(MSSQLCEConn.ExecuteScalar(cmd)));
     }
 }
Пример #11
0
        /// <summary>
        /// Determines whether this media is available.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>
        ///     <c>true</c> if media is available; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Documented by Dev05, 2009-03-30</remarks>
        public bool IsMediaAvailable(int id)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT count(*) FROM MediaContent WHERE id=@id AND data IS NOT NULL";
            cmd.Parameters.Add("@id", id);

            return(MSSQLCEConn.ExecuteScalar <int>(cmd).Value > 0);
        }
        /// <summary>
        /// Gets the card style.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev08, 2009-01-12</remarks>
        public string GetCardStyle(int id)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT value FROM \"CardStyles\" WHERE id=@id";
                cmd.Parameters.Add("@id", id);

                return(MSSQLCEConn.ExecuteScalar(cmd).ToString());
            }
        }
        /// <summary>
        /// Determines whether [is stream available] [the specified GUID].
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns>
        ///     <c>true</c> if [is stream available] [the specified GUID]; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Documented by Dev02, 2009-07-06</remarks>
        public bool IsStreamAvailable(Guid guid)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT count(*) FROM Extensions WHERE guid=@guid AND data IS NOT NULL";
                cmd.Parameters.Add("@guid", guid.ToString());

                return(MSSQLCEConn.ExecuteScalar <int>(cmd).Value > 0);
            }
        }
Пример #14
0
 /// <summary>
 /// Creates the id.
 /// </summary>
 /// <returns></returns>
 /// <remarks>Documented by Dev05, 2009-01-15</remarks>
 public ICardStyle CreateId()
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
     {
         cmd.CommandText = "INSERT INTO \"CardStyles\" (value) VALUES (@value); SELECT @@IDENTITY;";
         cmd.Parameters.Add("@value", "<cardStyle></cardStyle>");
         int?id = MSSQLCEConn.ExecuteScalar <int>(cmd);
         return(new DbCardStyle(id.GetValueOrDefault(), false, Parent));
     }
 }
Пример #15
0
        /// <summary>
        /// Gets the content protected.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2009-02-13</remarks>
        public bool GetContentProtected(int id)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT content_protected FROM \"LearningModules\" WHERE id=@id;";
                cmd.Parameters.Add("@id", id);
                bool?val = MSSQLCEConn.ExecuteScalar <bool>(cmd);

                return(val.HasValue ? val.Value : false);        //[ML-2477] Exception on start page with DRM module and key file on USB stick
            }
        }
        /// <summary>
        /// Gets the extension start file.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev08, 2009-07-02</remarks>
        public string GetExtensionStartFile(Guid guid)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT startfile FROM \"Extensions\" WHERE guid=@guid";
                cmd.Parameters.Add("@guid", guid.ToString());
                object startfile = MSSQLCEConn.ExecuteScalar(cmd);

                return(startfile as string == null ? string.Empty : startfile as string);
            }
        }
Пример #17
0
        /// <summary>
        /// Checks if the media object exists.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <remarks>Documented by Dev02, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void CheckMediaId(int id)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT count(*) FROM MediaContent WHERE id=@id;";
            cmd.Parameters.Add("@id", id);
            if (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) < 1)
            {
                throw new IdAccessException(id);
            }
        }
Пример #18
0
 /// <summary>
 /// Checks the chapter id of the chapter.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <remarks>Documented by Dev02, 2008-08-05</remarks>
 /// <remarks>Documented by Dev05, 2009-01-15</remarks>
 public void CheckChapterId(int id)
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
     {
         cmd.CommandText = "SELECT count(*) FROM \"Chapters\" WHERE id=@id";
         cmd.Parameters.Add("@id", id);
         if (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) != 1)
         {
             throw new IdAccessException(id);
         }
     }
 }
        /// <summary>
        /// Gets the user id of the given user name (--> normal login).
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="sid">NOT used.</param>
        /// <param name="closeOpenSessions">NOT used.</param>
        /// <param name="standAlone">NOT used.</param>
        /// <returns>The user id.</returns>
        /// <remarks>Documented by Dev05, 2009-01-13</remarks>
        public int LoginListUser(string username, Guid sid, bool closeOpenSessions, bool standAlone)
        {
            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.UserList, 0));

            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT id FROM \"UserProfiles\" " +
                              "WHERE username=@user;";
            cmd.Parameters.Add("@user", username);

            return(MSSQLCEConn.ExecuteScalar <int>(cmd).Value);
        }
Пример #20
0
 /// <summary>
 /// Checks the id of the learning module for correctness.
 /// </summary>
 /// <param name="lmid">The id of the learning module.</param>
 /// <remarks>Documented by Dev02, 2008-08-05</remarks>
 /// <remarks>Documented by Dev08, 2009-01-12</remarks>
 public void CheckLMId(int lmid)
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
     {
         cmd.CommandText = "SELECT count(*) FROM \"LearningModules\" WHERE id=@lmid";
         cmd.Parameters.Add("@lmid", lmid);
         if (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) != 1)
         {
             throw new IdAccessException(lmid);
         }
     }
 }
Пример #21
0
        /// <summary>
        /// Gets the highscore.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev08, 2009-01-13</remarks>
        public double GetHighscore(int id)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT highscore FROM \"UserProfilesLearningModulesSettings\" WHERE user_id=@uid AND lm_id=@lm_id;";
                cmd.Parameters.Add("@uid", parent.CurrentUser.Id);
                cmd.Parameters.Add("@lm_id", id);

                double?value = MSSQLCEConn.ExecuteScalar <double>(cmd);
                return(value.HasValue ? value.Value : 0);
            }
        }
        /// <summary>
        /// Creates the given user and returns his id (--> Create New User).
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="sid">NOT used.</param>
        /// <param name="closeOpenSessions">NOT used.</param>
        /// <param name="standAlone">NOT used.</param>
        /// <returns>The user id.</returns>
        /// <remarks>Documented by Dev05, 2009-01-13</remarks>
        public int LoginFormsUser(string username, string userId, Guid sid, bool closeOpenSessions, bool standAlone)
        {
            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.UserList, 0));

            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "INSERT INTO \"UserProfiles\" (username, local_directory_id, user_type) " +
                              "VALUES (@user, @id, 'ListAuthentication'); SELECT @@IDENTITY;";
            cmd.Parameters.Add("@user", username);
            cmd.Parameters.Add("@id", userId);

            return(MSSQLCEConn.ExecuteScalar <int>(cmd).Value);
        }
Пример #23
0
 public void CheckCardMediaId(int id, int cardid)
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
     {
         cmd.CommandText = "SELECT count(*) FROM \"Cards_MediaContent\" WHERE media_id=@id AND cards_id=@cardid;";
         cmd.Parameters.Add("@id", id);
         cmd.Parameters.Add("@cardid", cardid);
         if (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) < 1)
         {
             throw new IdAccessException(id);
         }
     }
 }
Пример #24
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);
        }
Пример #25
0
 /// <summary>
 /// Finds the chapter.
 /// </summary>
 /// <param name="lmid">The id of the learning module.</param>
 /// <param name="title">The title.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev02, 2008-08-05</remarks>
 /// <remarks>Documented by Dev08, 2009-01-12</remarks>
 public int FindChapter(int lmid, string title)
 {
     using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
     {
         cmd.CommandText = "SELECT id FROM \"Chapters\" WHERE title LIKE @title AND lm_id=@lmid";
         cmd.Parameters.Add("@title", title);
         cmd.Parameters.Add("@lmid", lmid);
         object result = MSSQLCEConn.ExecuteScalar(cmd);
         if (result == null)
         {
             return(-1);
         }
         return(Convert.ToInt32(result));
     }
 }
        /// <summary>
        /// Checks the id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <remarks>
        /// Documented by FabThe, 9.1.2009
        /// </remarks>
        public void CheckId(int id)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT count(*) FROM \"CardStyles\" WHERE id=@id";
                cmd.Parameters.Add("@id", id);

                int?count = MSSQLCEConn.ExecuteScalar <int>(cmd);

                if (!count.HasValue || count.Value < 1)
                {
                    throw new IdAccessException(id);
                }
            }
        }
Пример #27
0
 /// <summary>
 /// Gets the type of the media.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev02, 2009-06-25</remarks>
 /// <remarks>Documented by Dev02, 2009-06-25</remarks>
 public EMedia GetMediaType(int id)
 {
     try
     {
         SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
         cmd.CommandText = "SELECT media_type FROM MediaContent WHERE id=@id";
         cmd.Parameters.Add("@id", SqlDbType.Int, 4);
         cmd.Parameters["@id"].Value = id;
         return((EMedia)Enum.Parse(typeof(EMedia), Convert.ToString(MSSQLCEConn.ExecuteScalar(cmd))));
     }
     catch (ArgumentException)
     {
         return(EMedia.Unknown);
     }
 }
Пример #28
0
        /// <summary>
        /// Gets the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="cacheConnector">The cache connector.</param>
        /// <returns>A memory stream for the media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public System.IO.Stream GetMediaStream(int id, IDbMediaConnector cacheConnector)
        {
            MemoryStream stream = null;
            SqlCeCommand cmd    = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=@id;";
            cmd.Parameters.Add("@id", id);
            byte[] media = (byte[])MSSQLCEConn.ExecuteScalar(cmd);
            if (media != null)
            {
                stream = new MemoryStream(media);
                stream.Seek(0, SeekOrigin.Begin);
            }
            return(stream);
        }
Пример #29
0
        /// <summary>
        /// Gets the chapter count in the specified learning module.
        /// </summary>
        /// <param name="lmid">The id of the learning module.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2008-08-05</remarks>
        /// <remarks>Documented by Dev08, 2009-01-12</remarks>
        public int GetChapterCount(int lmid)
        {
            IList <int> chaptersCache = parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.ChaptersList, lmid)] as IList <int>;

            if (chaptersCache != null)
            {
                return(chaptersCache.Count);
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT count(*) FROM \"Chapters\" WHERE lm_id=@lmid";
                cmd.Parameters.Add("@lmid", lmid);
                return(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)));
            }
        }
        /// <summary>
        /// Gets the type of the extension.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev08, 2009-07-02</remarks>
        public ExtensionType GetExtensionType(Guid guid)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT type FROM \"Extensions\" WHERE guid=@guid";
                cmd.Parameters.Add("@guid", guid.ToString());
                object type = MSSQLCEConn.ExecuteScalar(cmd);

                if (type as string == null)
                {
                    return(ExtensionType.Unknown);
                }

                return((ExtensionType)Enum.Parse(typeof(ExtensionType), type as string));
            }
        }