Beispiel #1
0
        /// <summary>
        /// Retrieves the category with the given label.
        /// </summary>
        /// <param name="label">Label of the category to retrieve.</param>
        /// <returns>Matching category if any. Null otherwise.</returns>
        public VocabCategory GetCategoryByLabel(string label)
        {
            DaoConnection connection = null;

            try
            {
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);
                IEnumerable <NameValueCollection> results = connection.Query(
                    string.Format("SELECT * FROM {0} WHERE {1}=@label",
                                  SqlHelper.Table_VocabCategory,
                                  SqlHelper.Field_VocabCategory_Label),
                    new DaoParameter("@label", label));

                VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
                if (results.Any())
                {
                    return(categoryBuilder.BuildEntity(results.First(), null));
                }

                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Includes the categories of the given meaning in the entity.
        /// </summary>
        private void IncludeMeaningCategories(DaoConnection connection, VocabMeaning meaning)
        {
            IEnumerable <NameValueCollection> categories = connection.Query(
                string.Format("SELECT vc.* FROM {0} vmvc JOIN {1} vc ON (vmvc.{2}=vc.{3}) WHERE vmvc.{4}=@mid",
                              SqlHelper.Table_VocabMeaning_VocabCategory,
                              SqlHelper.Table_VocabCategory,
                              SqlHelper.Field_VocabMeaning_VocabCategory_VocabCategoryId,
                              SqlHelper.Field_VocabCategory_Id,
                              SqlHelper.Field_VocabMeaning_VocabCategory_VocabMeaningId),
                new DaoParameter("@mid", meaning.ID));

            VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();

            foreach (NameValueCollection nvcCategory in categories)
            {
                VocabCategory category = categoryBuilder.BuildEntity(nvcCategory, null);
                meaning.Categories.Add(category);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves all vocab categories.
        /// </summary>
        /// <returns>All vocab categories.</returns>
        public IEnumerable <VocabCategory> GetAllCategories()
        {
            DaoConnection connection = null;

            try
            {
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);
                IEnumerable <NameValueCollection> results = connection.Query(
                    string.Format("SELECT * FROM {0}", SqlHelper.Table_VocabCategory));

                VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
                foreach (NameValueCollection nvcCategory in results)
                {
                    yield return(categoryBuilder.BuildEntity(nvcCategory, null));
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Includes the categories of the given meaning in the entity.
        /// </summary>
        private void IncludeMeaningCategories(DaoConnection connection, VocabMeaning meaning)
        {
            IEnumerable<NameValueCollection> categories = connection.Query(
                  "SELECT vc.* FROM " + SqlHelper.Table_VocabMeaning_VocabCategory + " vmvc "
                + "JOIN " + SqlHelper.Table_VocabCategory + " vc ON (vmvc."
                + SqlHelper.Field_VocabMeaning_VocabCategory_VocabCategoryId + "=vc."
                + SqlHelper.Field_VocabCategory_Id + ") WHERE vmvc."
                + SqlHelper.Field_VocabMeaning_VocabCategory_VocabMeaningId + "=@mid",
                new DaoParameter("@mid", meaning.ID));

            VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
            foreach (NameValueCollection nvcCategory in categories)
            {
                VocabCategory category = categoryBuilder.BuildEntity(nvcCategory, null);
                meaning.Categories.Add(category);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Include the categories of the given vocab in the entity.
        /// </summary>
        private void IncludeCategories(DaoConnection connection, VocabEntity vocab)
        {
            IEnumerable<NameValueCollection> categories = connection.Query(
                  "SELECT vc.* FROM " + SqlHelper.Table_VocabCategory_Vocab + " vcv "
                + "JOIN " + SqlHelper.Table_VocabCategory + " vc ON (vcv."
                + SqlHelper.Field_VocabCategory_Vocab_VocabCategoryId + "=vc."
                + SqlHelper.Field_VocabCategory_Id + ") WHERE vcv."
                + SqlHelper.Field_VocabCategory_Vocab_VocabId + "=@vid",
                new DaoParameter("@vid", vocab.ID));

            VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
            foreach (NameValueCollection nvcCategory in categories)
            {
                VocabCategory category = categoryBuilder.BuildEntity(nvcCategory, null);
                vocab.Categories.Add(category);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Retrieves the category with the given label.
        /// </summary>
        /// <param name="label">Label of the category to retrieve.</param>
        /// <returns>Matching category if any. Null otherwise.</returns>
        public VocabCategory GetCategoryByLabel(string label)
        {
            DaoConnection connection = null;
            try
            {
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);
                IEnumerable<NameValueCollection> results = connection.Query(
                    "SELECT * FROM " + SqlHelper.Table_VocabCategory
                    + " WHERE " + SqlHelper.Field_VocabCategory_Label + "=@label",
                    new DaoParameter("@label", label));

                VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
                if (results.Count() >= 1)
                {
                    return categoryBuilder.BuildEntity(results.First(), null);
                }

                return null;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Retrieves all vocab categories.
        /// </summary>
        /// <returns>All vocab categories.</returns>
        public IEnumerable<VocabCategory> GetAllCategories()
        {
            DaoConnection connection = null;
            try
            {
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);
                IEnumerable<NameValueCollection> results = connection.Query(
                    "SELECT * FROM " + SqlHelper.Table_VocabCategory);

                VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
                foreach (NameValueCollection nvcCategory in results)
                {
                    yield return categoryBuilder.BuildEntity(nvcCategory, null);
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }