private void EditVerse_Cliked(object sender, RoutedEventArgs e) { if (this.SelectedBookmark == null) { MessageDisplay.Show("Please select a Bookmark"); return; } try { ModelsBookmark bookmark = this.SelectedBookmark.CopyTo(new ModelsBookmark()); ModelView.OnItemBrowse += this.BookmarkModel_Browse; if (ModelView.ShowDialog(this.GetParentWindow(), true, "Bookmark", bookmark).IsFalse()) { return; } this.SelectedBookmark = bookmark.CopyTo(this.SelectedBookmark); StudyBookmarkModel dbModel = this.SelectedBookmark.CopyToObject(new StudyBookmarkModel()).To <StudyBookmarkModel>(); dbModel.StudyVerseKey = $"{this.StudyId}||{this.SelectedBookmark.VerseKey}"; BiblesData.Database.InsertStudyBookmarkModel(dbModel); } catch (Exception err) { ErrorLog.ShowError(err); } }
public void InsertStudyBookmarkModel(StudyBookmarkModel bookmark) { Task <StudyBookmarkModel> existing = BiblesData.database.Table <StudyBookmarkModel>() .FirstOrDefaultAsync(bm => bm.StudyVerseKey == bookmark.StudyVerseKey); if (existing.Result == null) { bookmark.BookmarkDate = DateTime.Now; BiblesData.database.InsertAsync(bookmark); } else { existing.Result.BookMarkName = bookmark.BookMarkName; existing.Result.Description = bookmark.Description; existing.Result.VerseRangeEnd = bookmark.VerseRangeEnd; BiblesData.database.UpdateAsync(existing.Result); } }
private void Bookmark_Cliked(object sender, RoutedEventArgs e) { try { int selectedVerse = Formatters.GetVerseFromKey(this.selectedKey); if (selectedVerse <= 0) { throw new ApplicationException("Please select a Verse."); } Dictionary <int, UserControlBase> openStudies = new Dictionary <int, UserControlBase>(); Dictionary <int, StudyHeader> studyHeaders = new Dictionary <int, StudyHeader>(); #region CHECK FOR OPEN STUDIES foreach (Window window in Application.Current.Windows) { if (window.GetType() != typeof(ControlWindow)) { continue; } UserControlBase controlBase = window.GetPropertyValue("ControlContent").To <UserControlBase>(); if (controlBase.GetType() != typeof(EditStudy)) { continue; } StudyHeader studyHeader = controlBase.GetPropertyValue("SubjectHeader").To <StudyHeader>(); if (studyHeader.StudyHeaderId <= 0) { string studyName = studyHeader.StudyName.IsNullEmptyOrWhiteSpace() ? "Unknown" : studyHeader.StudyName; string message = $"Study {studyName} have not been saved yet. This study will not be available for bookmarks."; MessageDisplay.Show(message); continue; } openStudies.Add(studyHeader.StudyHeaderId, controlBase); studyHeaders.Add(studyHeader.StudyHeaderId, studyHeader); } #endregion ModelsBookmark bookmark = new ModelsBookmark(); ModelView.OnItemBrowse += this.BookmarkModel_Browse; if (Formatters.IsBiblesKey(this.selectedKey)) { bookmark.SetVerse(this.selectedKey); } else { bookmark.SetVerse($"{this.Bible.BibleId}||{this.selectedKey}"); } if (studyHeaders.Count > 0) { #region STUDY BOOKMARKS StudyBookmarksModel studyMark = bookmark.CopyToObject(new StudyBookmarksModel()).To <StudyBookmarksModel>(); List <DataItemModel> studyOptions = new List <DataItemModel>(); studyOptions.Add(new DataItemModel { DisplayValue = $"<{this.Bible.BibleName}>", ItemKey = -1 }); foreach (KeyValuePair <int, StudyHeader> studyKey in studyHeaders) { studyOptions.Add(new DataItemModel { DisplayValue = studyKey.Value.StudyName, ItemKey = studyKey.Key }); } studyMark.AvailableStudies = studyOptions.ToArray(); if (ModelView.ShowDialog("Bookmark", studyMark).IsFalse()) { return; } if (studyMark.Study <= 0) { BookmarkModel dbModel = studyMark.CopyToObject(new BookmarkModel()).To <BookmarkModel>(); BiblesData.Database.InsertBookmarkModel(dbModel); } else { StudyBookmarkModel dbModel = studyMark.CopyToObject(new StudyBookmarkModel()).To <StudyBookmarkModel>(); dbModel.StudyName = studyMark.AvailableStudies.First(st => st.ItemKey.ToInt32() == studyMark.Study).DisplayValue; dbModel.StudyVerseKey = $"{studyMark.Study}||{dbModel.VerseKey}"; BiblesData.Database.InsertStudyBookmarkModel(dbModel); this.InvokeMethod(openStudies[studyMark.Study], "AddBookmark", new object[] { bookmark }); } #endregion } else { #region NORMAL BOOKMARKS if (ModelView.ShowDialog("Bookmark", bookmark).IsFalse()) { return; } BookmarkModel dbModel = bookmark.CopyToObject(new BookmarkModel()).To <BookmarkModel>(); BiblesData.Database.InsertBookmarkModel(dbModel); #endregion } BibleLoader.RefreshVerseNumberPanel ( this.loadedVerseStackDictionary[selectedVerse], this.Bible.BibleId, this.versesDictionary[selectedVerse] ); } catch (Exception err) { ErrorLog.ShowError(err); } finally { ModelView.OnItemBrowse -= this.BookmarkModel_Browse; } }
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); } }
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); }