コード例 #1
0
        private void SubjectHeder_Browsed(object sender, string buttonKey)
        {
            try
            {
                switch (buttonKey)
                {
                case "StudyCategoryBrowse":

                    StudyCategories category = new StudyCategories();

                    if (ControlDialog.ShowDialog("Categories", category, string.Empty, autoSize: false).IsFalse())
                    {
                        return;
                    }

                    if (category.SelectedCategory == null)
                    {
                        throw new ApplicationException("Category not Selected.");
                    }

                    StudyCategoryModel categoryModel = category.SelectedCategory;

                    this.SubjectHeader.StudyCategoryId = categoryModel.StudyCategoryId;

                    this.SubjectHeader.StudyCategoryName = categoryModel.CategoryName;

                    break;
                }
            }
            catch (Exception err)
            {
                ErrorLog.ShowError(err);
            }
        }
コード例 #2
0
        public int InsertCategory(string name, int parentId)
        {
            StudyCategoryModel category = new StudyCategoryModel
            {
                CategoryName          = name,
                ParentStudyCategoryId = parentId
            };

            Task <int> insertTask = BiblesData.database.InsertAsync(category);

            int insetValue = insertTask.Result;

            return(category.StudyCategoryId);
        }
コード例 #3
0
        private void SelectedCategory_Changed(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            try
            {
                StudyCategoryModel category = this.uxStudyCategories.SelectedCategory;

                if (category == null)
                {
                    this.CategoryStudyHeaders = new StudyHeaderModel[] { };

                    return;
                }

                this.CategoryStudyHeaders = BiblesData.Database.GetStudyHeaderByCategory(category.StudyCategoryId).ToArray();
            }
            catch (Exception err)
            {
                ErrorLog.ShowError(err);
            }
        }
コード例 #4
0
        private void ExportStudy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SaveFileDialog saveDlg = new SaveFileDialog();

                saveDlg.Title = "Export Study";

                saveDlg.DefaultExt = ".study";

                saveDlg.Filter = "Bible Study (.study)|*.study";

                saveDlg.FileName = this.SubjectHeader.StudyName;

                if (saveDlg.ShowDialog(this.GetParentWindow()).IsFalse())
                {
                    return;
                }

                if (!this.SaveStudy())
                {
                    return;
                }

                StringBuilder result = new StringBuilder();

                #region CATEGORIES

                StudyCategoryModel category = BiblesData.Database.GetCategory(this.SubjectHeader.StudyCategoryId);

                result.AppendLine(JsonConvert.SerializeObject(category));

                while (category.ParentStudyCategoryId > 0)
                {
                    category = BiblesData.Database.GetCategory(category.ParentStudyCategoryId);

                    result.AppendLine(JsonConvert.SerializeObject(category));
                }

                #endregion

                result.AppendLine(Constants.StudyBookarkMark);

                #region BOOKMARKS

                foreach (ModelsBookmark bookmark in this.uxStudyBookmarks.Bookmarks)
                {
                    StudyBookmarkModel studyBookmark = bookmark.CopyToObject(new StudyBookmarkModel()).To <StudyBookmarkModel>();

                    studyBookmark.StudyName = this.SubjectHeader.StudyName;

                    result.AppendLine(JsonConvert.SerializeObject(studyBookmark));
                }

                #endregion

                result.AppendLine(Constants.StudyMark);

                #region STUDY

                StudyHeaderModel headerModel = this.SubjectHeader.CopyToObject(new StudyHeaderModel()).To <StudyHeaderModel>();

                result.AppendLine(JsonConvert.SerializeObject(headerModel));

                result.AppendLine(Constants.StudyContentMark);

                result.AppendLine(JsonConvert.SerializeObject(this.SubjectContent));

                #endregion

                File.WriteAllText(saveDlg.FileName, result.ToString());
            }
            catch (Exception err)
            {
                ErrorLog.ShowError(err);
            }
        }
コード例 #5
0
        public bool ImportStudy(string fileName)
        {
            try
            {
                StudyHeaderModel studyHeader = null;

                Dictionary <int, string> categoryNames = new Dictionary <int, string>();

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

                List <StudyBookmarkModel> bookmarksList = new List <StudyBookmarkModel>();

                List <string> fileLines = new List <string>();

                fileLines.AddRange(File.ReadAllLines(fileName));

                int constantIndex = 0;

                foreach (string line in fileLines)
                {
                    #region ACTION SWITCH

                    if (line == Constants.StudyBookarkMark)
                    {
                        constantIndex = 1;

                        continue;
                    }
                    else if (line == Constants.StudyMark)
                    {
                        constantIndex = 2;

                        continue;
                    }
                    else if (line == Constants.StudyContentMark)
                    {
                        constantIndex = 3;

                        continue;
                    }

                    #endregion

                    if (constantIndex == 0)
                    {
                        #region CATEGORIES

                        StudyCategoryModel category = JsonConvert.DeserializeObject(line, typeof(StudyCategoryModel)).To <StudyCategoryModel>();

                        categoryNames.Add(category.StudyCategoryId, category.CategoryName);

                        StudyCategoryModel existing = BiblesData.Database.GetCategory(category.CategoryName);

                        if (existing == null)
                        {
                            int parentId = categoryIdMapping.ContainsKey(category.ParentStudyCategoryId) ?
                                           categoryIdMapping[category.ParentStudyCategoryId]
                                :
                                           0;

                            int newId = BiblesData.Database.InsertCategory(category.CategoryName, parentId);

                            categoryIdMapping.Add(category.StudyCategoryId, newId);
                        }
                        else
                        {
                            categoryIdMapping.Add(category.StudyCategoryId, existing.StudyCategoryId);
                        }

                        #endregion
                    }
                    else if (constantIndex == 1)
                    {
                        #region BOOKMARKS

                        StudyBookmarkModel bookmark = JsonConvert.DeserializeObject(line, typeof(StudyBookmarkModel)).To <StudyBookmarkModel>();

                        bookmarksList.Add(bookmark);

                        #endregion
                    }
                    else if (constantIndex == 2)
                    {
                        #region STUDY HEADER

                        studyHeader = JsonConvert.DeserializeObject(line, typeof(StudyHeaderModel)).To <StudyHeaderModel>();

                        studyHeader.StudyCategoryId = categoryIdMapping[studyHeader.StudyCategoryId];

                        StudyHeaderModel existing = BiblesData.Database.GetStudyInCategory(studyHeader.StudyName, studyHeader.StudyCategoryId);

                        if (existing != null)
                        {
                            studyHeader = existing.CopyTo(studyHeader);
                        }

                        studyHeader.StudyHeaderId = BiblesData.Database.InsertSubjectHeader(studyHeader);

                        #endregion

                        #region INSERT BOOKMARKS

                        foreach (StudyBookmarkModel bookmark in bookmarksList)
                        {
                            bookmark.StudyVerseKey = $"{studyHeader.StudyHeaderId}||{bookmark.VerseKey}";

                            BiblesData.Database.InsertStudyBookmarkModel(bookmark);
                        }

                        #endregion
                    }
                    else if (constantIndex == 3)
                    {
                        #region STUDY CONTENT

                        StudyContentModel content = JsonConvert.DeserializeObject(line, typeof(StudyContentModel)).To <StudyContentModel>();

                        content.StudyHeaderId = studyHeader.StudyHeaderId;

                        BiblesData.Database.InsertStudyContent(content);

                        #endregion
                    }
                }
            }
            catch (Exception err)
            {
                ErrorLog.ShowError(err);

                return(false);
            }

            return(true);
        }