/// <summary>
        /// Gets the size of the default.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public int GetDefaultSize(int id)
        {
            BoxSizes?sizes = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.DefaultBoxSizes, Parent.CurrentUser.ConnectionString.LmId)] as BoxSizes?;

            if (sizes.HasValue)
            {
                return(sizes.Value.Sizes[id]);
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "SELECT Boxes.* FROM Boxes INNER JOIN Settings ON Boxes.id = Settings.boxes INNER JOIN LearningModules ON Settings.id = LearningModules.default_settings_id WHERE LearningModules.id = @lm_id";
                cmd.Parameters.Add("@lm_id", Parent.CurrentUser.ConnectionString.LmId);
                SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);
                reader.Read();
                sizes = new BoxSizes(int.MaxValue,
                                     Convert.ToInt32(reader["box1_size"]),
                                     Convert.ToInt32(reader["box2_size"]),
                                     Convert.ToInt32(reader["box3_size"]),
                                     Convert.ToInt32(reader["box4_size"]),
                                     Convert.ToInt32(reader["box5_size"]),
                                     Convert.ToInt32(reader["box6_size"]),
                                     Convert.ToInt32(reader["box7_size"]),
                                     Convert.ToInt32(reader["box8_size"]),
                                     Convert.ToInt32(reader["box9_size"]),
                                     int.MaxValue);
                reader.Close();

                Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.DefaultBoxSizes, Parent.CurrentUser.ConnectionString.LmId)] = sizes.Value;

                return(sizes.Value.Sizes[id]);
            }
        }
        /// <summary>
        /// Gets the size.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public int GetSize(int id)
        {
            BoxSizes?sizes = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.BoxSizes, Parent.CurrentUser.ConnectionString.LmId)] as BoxSizes?;

            if (sizes.HasValue)
            {
                return(sizes.Value.Sizes[id]);
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                sizes           = new BoxSizes(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                cmd.CommandText = @"SELECT UserCardState.box AS box, count(*) AS count FROM UserCardState, Chapters_Cards
	                                WHERE UserCardState.active=1 and 
		                            Chapters_Cards.cards_id=UserCardState.cards_id and UserCardState.user_id=@user_id and 
		                            Chapters_Cards.chapters_id IN (
			                            SELECT chapters_id FROM SelectedLearnChapters INNER JOIN UserProfilesLearningModulesSettings
					                    ON SelectedLearnChapters.settings_id=UserProfilesLearningModulesSettings.settings_id
				                        WHERE UserProfilesLearningModulesSettings.user_id=@user_id and UserProfilesLearningModulesSettings.lm_id=@lm_id
		                            ) GROUP BY UserCardState.box"        ;
                cmd.Parameters.Add("@user_id", Parent.CurrentUser.Id);
                cmd.Parameters.Add("@lm_id", Parent.CurrentUser.ConnectionString.LmId);

                SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);
                while (reader.Read())
                {
                    sizes.Value.Sizes[Convert.ToInt32(reader["box"])] = Convert.ToInt32(reader["count"]);
                }
                reader.Close();

                Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.BoxSizes, Parent.CurrentUser.ConnectionString.LmId, cacheLifeSpan)] = sizes.Value;

                return(sizes.Value.Sizes[id]);
            }
        }
        public List <ICard> GetCards(int id)
        {
            List <ICard> cardsCache = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardsList, id)] as List <ICard>;

            if (cardsCache != null)
            {
                return(cardsCache);
            }

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "SELECT cards_id FROM \"LearningModules_Cards\" WHERE lm_id=@id";
                cmd.Parameters.Add("@id", id);
                SqlCeDataReader reader;
                try { reader = MSSQLCEConn.ExecuteReader(cmd); }
                catch { throw new IdAccessException(id); }

                List <ICard> cards = new List <ICard>();
                while (reader.Read())
                {
                    cards.Add(new DbCard(Convert.ToInt32(reader["cards_id"]), false, Parent));
                }
                reader.Close();
                Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.CardsList, id)] = cards;

                return(cards);
            }
        }
        /// <summary>
        /// Gets the settings value.
        /// </summary>
        /// <param name="typeGradingsId">The type gradings id.</param>
        /// <param name="cacheObjectType">Type of the cache object.</param>
        /// <param name="cacheValue">The cache value.</param>
        /// <remarks>Documented by Dev08, 2009-01-13</remarks>
        private void GetSettingsValue(int typeGradingsId, CacheObject cacheObjectType, out object cacheValue)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT * FROM \"TypeGradings\" WHERE id=@id";
                cmd.Parameters.Add("@id", typeGradingsId);

                SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);
                reader.Read();

                int? gid         = DbValueConverter.Convert <int>(reader["id"]);
                bool?allCorrect  = DbValueConverter.Convert <bool>(reader["all_correct"]);
                bool?halfCorrect = DbValueConverter.Convert <bool>(reader["half_correct"]);
                bool?noneCorrect = DbValueConverter.Convert <bool>(reader["none_correct"]);
                bool?prompt      = DbValueConverter.Convert <bool>(reader["prompt"]);
                reader.Close();

                //cache values
                DateTime expires = DateTime.Now.Add(Cache.DefaultSettingsValidationTime);
                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsTypeGradingsAllCorrect, typeGradingsId, expires)]  = allCorrect;
                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsTypeGradingsHalfCorrect, typeGradingsId, expires)] = halfCorrect;
                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsTypeGradingsNoneCorrect, typeGradingsId, expires)] = noneCorrect;
                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsTypeGradingsPrompt, typeGradingsId, expires)]      = prompt;
                parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsTypeGradingsId, typeGradingsId, expires)]          = gid;

                //set output value
                switch (cacheObjectType)
                {
                case CacheObject.SettingsTypeGradingsAllCorrect: cacheValue = allCorrect; break;

                case CacheObject.SettingsTypeGradingsHalfCorrect: cacheValue = halfCorrect; break;

                case CacheObject.SettingsTypeGradingsNoneCorrect: cacheValue = noneCorrect; break;

                case CacheObject.SettingsTypeGradingsPrompt: cacheValue = prompt; break;

                case CacheObject.SettingsTypeGradingsId: cacheValue = gid; break;

                default: cacheValue = null; break;
                }
            }
        }
Esempio n. 5
0
        private BoxSizes GetCurrentBoxContent()
        {
            BoxSizes sizes;

            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                sizes           = new BoxSizes(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                cmd.CommandText = @"SELECT CS.box AS box, count(*) AS count FROM UserCardState CS
                                        INNER JOIN Cards C ON C.id = CS.cards_id AND C.lm_id=@lm_id
                                        WHERE CS.active = 1 AND CS.user_id = @user_id  
                                      GROUP BY CS.box";
                cmd.Parameters.Add("@user_id", Parent.CurrentUser.Id);
                cmd.Parameters.Add("@lm_id", Parent.CurrentUser.ConnectionString.LmId);

                SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);
                while (reader.Read())
                {
                    sizes.Sizes[Convert.ToInt32(reader["box"])] = Convert.ToInt32(reader["count"]);
                }
                reader.Close();

                return(sizes);
            }
        }