private void LoadVerses() { this.versesDictionaryLeft = null; this.versesDictionaryRight = null; string bibleKeyRemoved = Formatters.RemoveBibleId(this.selectedKey); this.versesDictionaryLeft = BiblesData.Database.GetVerses($"{this.BibleLeft.BibleId}||{bibleKeyRemoved}"); this.versesDictionaryRight = BiblesData.Database.GetVerses($"{this.BibleRight.BibleId}||{bibleKeyRemoved}"); this.ResetversSetup(); #region LOAD LEFTSIDE for (int verse = 1; verse <= this.versesDictionaryLeft.Count; ++verse) { BibleVerseModel item = this.versesDictionaryLeft[verse]; StackPanel panel = BibleLoader.GetVerseNumberPanel(this.BibleLeft.BibleId, item, 0); this.uxVerseGrid.Children.Add(panel); HighlightRitchTextBox textBox = BibleLoader.GetVerseAsTextBox(this.BibleLeft.BibleId, item, 1); textBox.GotFocus += this.VerseLeft_GotFocus; this.uxVerseGrid.Children.Add(textBox); this.loadedTextBoxDictionaryLeft.Add(verse, textBox); this.loadedVerseStackDictionaryLeft.Add(verse, panel); } #endregion #region LOAD RIGHT for (int verse = 1; verse <= this.versesDictionaryRight.Count; ++verse) { BibleVerseModel item = this.versesDictionaryRight[verse]; StackPanel panel = BibleLoader.GetVerseNumberPanel(this.BibleRight.BibleId, item, 2); this.uxVerseGrid.Children.Add(panel); HighlightRitchTextBox textBox = BibleLoader.GetVerseAsTextBox(this.BibleLeft.BibleId, item, 3); textBox.GotFocus += this.VerseRight_GotFocus; this.uxVerseGrid.Children.Add(textBox); this.loadedTextBoxDictionaryRight.Add(verse, textBox); this.loadedVerseStackDictionaryRight.Add(verse, panel); } #endregion }
public ActionResult EnterVerse(BibleVerseModel verseModel) { MyLogger.GetInstance().Info("Entering BibleController.EnterVerse()"); //create an instance of the security service to access the create method SecurityService securityService = new SecurityService(); //return the results to a bool to show if the creation was successful or not Boolean success = securityService.Create(verseModel); try { //check the results and return the appropriate page if (success) { MyLogger.GetInstance().Info("Exiting BibleController.EnterVerse() with successful creation of a new verse."); return(View("NewVerseSuccess", verseModel)); } else { MyLogger.GetInstance().Info("Exiting BibleController.EnterVerse() with failed creation of a new verse."); return(View("NewVerseFailure")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception BibleController.EnterVerse()", e.Message); string errMessage = e.Message; return(View("Error", errMessage)); } }
private void LoadVerses() { this.versesDictionary = null; this.versesDictionary = Formatters.IsBiblesKey(this.selectedKey) ? BiblesData.Database.GetVerses(this.selectedKey) : BiblesData.Database.GetVerses($"{this.Bible.BibleId}||{this.selectedKey}"); this.ResetversSetup(); for (int verse = 1; verse <= this.versesDictionary.Count; ++verse) { BibleVerseModel item = this.versesDictionary[verse]; StackPanel panel = BibleLoader.GetVerseNumberPanel(this.Bible.BibleId, item, 0); this.uxVerseGrid.Children.Add(panel); HighlightRitchTextBox textBox = BibleLoader.GetVerseAsTextBox(this.Bible.BibleId, item, 1); textBox.GotFocus += this.Verse_GotFocus; this.uxVerseGrid.Children.Add(textBox); this.loadedTextBoxDictionary.Add(verse, textBox); this.loadedVerseStackDictionary.Add(verse, panel); } }
public ActionResult FindVerse(BibleVerseModel verseModel) { MyLogger.GetInstance().Info("Entering BibleController.FindVerse()"); //create an instance of the security service to access the search method SecurityService securityService = new SecurityService(); //set the results to a new bibleversemodel BibleVerseModel verseFound = new BibleVerseModel(securityService.Search(verseModel).Testament, securityService.Search(verseModel).Book, securityService.Search(verseModel).ChapterNumber, securityService.Search(verseModel).VerseNumber, securityService.Search(verseModel).VerseText); try { //check the results and return the appropriate page if (securityService.Search(verseModel) != null) { MyLogger.GetInstance().Info("Exiting BibleController.FindVerse() with successful search of a certain verse."); return(View("FindVerseSuccess", verseFound)); } else { MyLogger.GetInstance().Info("Exiting BibleController.FindVerse() with failed search of a certain verse."); return(View("FindVerseFailure")); } } catch (Exception e) { MyLogger.GetInstance().Error("Exception BibleController.FindVerse()", e.Message); string errMessage = e.Message; return(View("Error", errMessage)); } }
public BibleVerseModel FindVerse(BibleVerseModel bibleVerse) { //provide the wuery string with a parameter placeholder string queryString = "select * from dbo.Bible where test = @Testament and b = @Book and c = @ChapterNumber and v = @VerseNumber"; //create and open the connection in a using block. This ensures that all resources will be closed and disclosed when the code exists using (SqlConnection conn = new SqlConnection(connectionString)) { //create the command and parameter objects SqlCommand command = new SqlCommand(queryString, conn); command.Parameters.Add("@Testament", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.Testament; command.Parameters.Add("@Book", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.Book; command.Parameters.Add("@ChapterNumber", System.Data.SqlDbType.Int).Value = bibleVerse.ChapterNumber; command.Parameters.Add("@VerseNumber", System.Data.SqlDbType.Int).Value = bibleVerse.VerseNumber; try { conn.Open(); // Using a DataReader see if query returns any rows SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { return(new BibleVerseModel(reader["test"].ToString(), reader["b"].ToString(), int.Parse(reader["c"].ToString()), int.Parse(reader["v"].ToString()), reader["t"].ToString())); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(new BibleVerseModel()); }
private void OnReaderSelectedVerse_Changed(object sender, BibleVerseModel verse) { try { Guid senderKey = sender.GetPropertyValue("ReaderKey").ParseToGuid(); this.selectedItemKey = verse.BibleVerseKey; if (GlobalResources.UserPreferences.SynchronizzeTabs) { foreach (UserControlBase tabItem in this.uxMainTab.Items) { Guid readerKey = tabItem.GetPropertyValue("ReaderKey").ParseToGuid(); if (senderKey == readerKey) { continue; } tabItem.InvokeMethod(tabItem, "SetChapter", new object[] { verse.BibleVerseKey }); tabItem.InvokeMethod(tabItem, "SetVerse", new object[] { verse.BibleVerseKey }); } } } catch (Exception err) { ErrorLog.ShowError(err); } }
internal static HighlightRitchTextBox GetVerseAsTextBox(int bibleId, BibleVerseModel verse, int column) { HighlightRitchTextBox result = new HighlightRitchTextBox { Text = verse.VerseText, Tag = verse, BorderBrush = Brushes.Transparent, IsReadOnly = true, Margin = new Thickness(2, 0, 0, 15) }; List <HighlightVerseModel> verseColours = BiblesData.Database.GetVerseColours(verse.BibleVerseKey); foreach (HighlightVerseModel colour in verseColours) { string[] itemSplit = colour.BibleVerseKeyId.Split(BibleLoader.veseSplitValues); result.HighlightText(itemSplit[1].ToInt32(), itemSplit[2].ToInt32(), ColourConverters.GetBrushfromHex(colour.HexColour)); } Grid.SetRow(result, (Formatters.GetVerseFromKey(verse.BibleVerseKey) - 1)); Grid.SetColumn(result, column); return(result); }
private void RightVerseChanged(object sender, BibleVerseModel verse) { try { this.uxReaderLeft.SelectVerse(verse.BibleVerseKey); } catch (Exception err) { ErrorLog.ShowError(err); } }
public LinkEditor(int bibleId, BibleVerseModel verse) { this.InitializeComponent(); this.parentVerse = verse; this.uxParentVerse.Content = verse.VerseText; this.uxReader.SetBible(bibleId); this.SetVerseLinkText(); }
private void ChildVerse_Changed(object sender, BibleVerseModel verse) { try { this.childVerse = verse; this.SetVerseLinkText(); } catch (Exception err) { ErrorLog.ShowError(err); } }
public void InsertBibleVerse(BibleVerseModel verse) { Task <BibleVerseModel> existing = BiblesData.database.Table <BibleVerseModel>().FirstOrDefaultAsync(v => v.BibleVerseKey == verse.BibleVerseKey); if (existing.Result != null) { existing.Result.VerseText = verse.VerseText; BiblesData.database.UpdateAsync(existing.Result); return; } BiblesData.database.InsertAsync(verse); }
private void OnReaderSelectedVerse_Changed(object sender, BibleVerseModel verse) { try { this.selectedItemKey = verse.BibleVerseKey; if (GlobalResources.UserPreferences.SynchronizzeTabs) { } } catch (Exception err) { ErrorLog.ShowError(err); } }
internal static StackPanel GetVerseNumberPanel(int bibleId, BibleVerseModel verse, int column) { StackPanel result = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; BibleLoader.RefreshVerseNumberPanel(result, bibleId, verse); Grid.SetRow(result, (Formatters.GetVerseFromKey(verse.BibleVerseKey) - 1)); Grid.SetColumn(result, column); return(result); }
private static UIElement[] GetVerseNumberElements(int bibleId, BibleVerseModel verse) { UIElement[] result = new UIElement[4]; Label labelVerse = new Label { Content = Formatters.GetVerseFromKey(verse.BibleVerseKey), Foreground = Brushes.LightGray, Tag = verse }; result[0] = labelVerse; result[1] = BibleLoader.GetVerseBookmarkImage(bibleId, verse.BibleVerseKey); result[2] = BibleLoader.GetStudyBookmarkImage(bibleId, verse.BibleVerseKey); result[3] = BibleLoader.GetLinkImage(verse.BibleVerseKey); return(result); }
private void LinkVerse_Cliked(object sender, RoutedEventArgs e) { if (this.selectedKey.IsNullEmptyOrWhiteSpace()) { MessageDisplay.Show("Please select a Verse."); return; } try { Type linkType = Type.GetType("Bibles.Link.LinkEditor,Bibles.Link"); BibleVerseModel verseModel = this.uxSearchPager .ItemsSource .Items .FirstOrDefault(vk => ((BibleVerseModel)vk).BibleVerseKey == this.selectedKey) .To <BibleVerseModel>(); object[] args = new object[] { Formatters.GetBibleFromKey(this.selectedKey), verseModel }; UserControlBase linkEditor = Activator.CreateInstance(linkType, args) as UserControlBase; string title = $"Link - {GlobalStaticData.Intance.GetKeyDescription(this.selectedKey)}"; linkEditor.Height = this.Height; if (ControlDialog.ShowDialog(title, linkEditor, "AcceptLink", false).IsFalse()) { return; } int selectedVerse = Formatters.GetVerseFromKey(this.selectedKey); } catch (Exception err) { ErrorLog.ShowError(err); } }
public ActionResult OnSearch(BibleVerseModel bibleVerse) { //Call the Security Business Service authenticate method from the Login() method BibleVerseBusinessService service = new BibleVerseBusinessService(); // the results of the method call is saved in local method sucess BibleVerseModel verse = service.Search(bibleVerse); if (verse != null) { //if finds verse, navigate to ResultSuccess View return(View("ResultSuccess", verse)); } else { //if does not find, navigate to ResultFailed View return(View("ResultFailed")); } }
public BibleVerseModel Search(BibleVerseModel bibleVerse) { BibleVerseModel verse = new BibleVerseModel(); // queryString with a placeholder string queryString = "select * from dbo.Bible where testament like @testament and book like @book and chapternumber like @chapternumber and versenumber like @versenumber"; //create and open connection using block, connection will be closed after command is executed using (SqlConnection connection = new SqlConnection(connectionString)) { //Create command and Parameter objects SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.Add("@testament", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.Testament; command.Parameters.Add("@book", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.Book; command.Parameters.Add("@chapternumber", System.Data.SqlDbType.Int).Value = bibleVerse.ChapterNumber; command.Parameters.Add("@versenumber", System.Data.SqlDbType.Int).Value = bibleVerse.VerseNumber; try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { verse = new BibleVerseModel(reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5)); } } reader.Close(); // Exception handler that returns error message } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(verse); }
public bool EnterNewVerse(BibleVerseModel bibleVerse) { //assume that nothing is in the query bool success = false; //provide the wuery string with a parameter placeholder string queryString = "insert into dbo.Bible (b, c, v, t, test) values (@Book, @ChapterNumber, @VerseNumber, @VerseText, @Testament)"; //create and open the connection in a using block. This ensures that all resources will be closed and disclosed when the code exists using (SqlConnection conn = new SqlConnection(connectionString)) { //create the command and parameter objects SqlCommand command = new SqlCommand(queryString, conn); command.Parameters.Add("@Testament", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.Testament; command.Parameters.Add("@Book", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.Book; command.Parameters.Add("@ChapterNumber", System.Data.SqlDbType.Int).Value = bibleVerse.ChapterNumber; command.Parameters.Add("@VerseNumber", System.Data.SqlDbType.Int).Value = bibleVerse.VerseNumber; command.Parameters.Add("@VerseText", System.Data.SqlDbType.VarChar, 50).Value = bibleVerse.VerseText; try { conn.Open(); //save to see how many rows were affected by the creation in the database int rowsAffected = command.ExecuteNonQuery(); conn.Close(); //check if the creation was successful if (rowsAffected > 0) { success = true; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(success); }
public List <BibleVerseModel> SearchByPhrase(string phrase) { BibleVerseModel verse = new BibleVerseModel(); List <BibleVerseModel> foundVerses = new List <BibleVerseModel>(); // queryString with a placeholder string queryString = "select * from dbo.Bible where versetext like @versetext "; //create and open connection using block, connection will be closed after command is executed using (SqlConnection connection = new SqlConnection(connectionString)) { //Create command and Parameter objects SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@versetext", "%" + phrase + "%"); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { verse = new BibleVerseModel(reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5)); foundVerses.Add(verse); } } reader.Close(); // Exception handler that returns error message } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(foundVerses); }
public bool AcceptLink() { try { LinkModel link = new LinkModel { LinkKeyId = $"{this.parentVerse.BibleVerseKey}*{this.childVerse.BibleVerseKey}", Comments = this.uxLinkComments.Text }; BiblesData.Database.CreateLink(link); string message = GlobalStaticData.Intance.GetKeyDescription(this.parentVerse.BibleVerseKey) + " was linked to " + GlobalStaticData.Intance.GetKeyDescription(this.childVerse.BibleVerseKey) + "." + Environment.NewLine + Environment.NewLine + "Would you like to link another one?"; if (MessageDisplay.Show(message, "Link Another?", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { return(true); } this.childVerse = null; this.SetVerseLinkText(); return(false); } catch (Exception err) { ErrorLog.ShowError(err); return(false); } }
public BibleVerseModel Search(BibleVerseModel bibleVerseModel) { SecurityDAO service = new SecurityDAO(); return(service.FindVerse(bibleVerseModel)); }
public bool Create(BibleVerseModel bibleVerseModel) { SecurityDAO service = new SecurityDAO(); return(service.EnterNewVerse(bibleVerseModel)); }
public static bool LoadBible(string path) { string bibleName = Path.GetFileNameWithoutExtension(path); BibleModel bibleModel = BiblesData.Database.GetBible(bibleName); if (bibleModel != null) { BiblesData.Database.DeleteBibleVerses(bibleModel.BiblesId); //return true; } bibleModel = new BibleModel { BiblesId = 0, BibleName = bibleName }; BiblesData.Database.InsertBible(bibleModel); BibleModel added = BiblesData.Database.GetBible(bibleName); while (added == null) { Sleep.ThreadWait(100); added = BiblesData.Database.GetBible(bibleName); } bibleModel.BiblesId = added.BiblesId; List <string> bibleVerses = new List <string>(); List <BibleVerseModel> bulkList = new List <BibleVerseModel>(); bibleVerses.AddRange(File.ReadAllLines(path)); foreach (string verseLine in bibleVerses) { int breakIndex = verseLine.LastIndexOf("||") + 2; string verseKey = verseLine.Substring(0, breakIndex); string verseText = verseLine.Substring(breakIndex, verseLine.Length - breakIndex); BibleVerseModel verseModel = new BibleVerseModel { BibleVerseKey = $"{bibleModel.BiblesId}||{verseKey}", VerseText = verseText }; bulkList.Add(verseModel); } int skipIndex = 0; int takeValue = 500; try { while (skipIndex <= bulkList.Count) { List <BibleVerseModel> addList = bulkList.Skip(skipIndex).Take(takeValue).ToList(); BiblesData.Database.InsertBibleVerseBulk(addList); skipIndex += takeValue; string checkKey = addList.Last().BibleVerseKey; int waitIndex = 0; while (BiblesData.Database.GetVerse(checkKey) == null) { Sleep.ThreadWait(200); ++waitIndex; if (waitIndex >= 20) { foreach (BibleVerseModel verseModel in addList) { BiblesData.Database.InsertBibleVerse(verseModel); } } } } } catch (Exception err) { throw; } return(true); }
private void LoadBibleVerses(Dispatcher dispatcher, BibleModel bibleModel) { string bibleFormatName = bibleModel.BibleName .Replace(' ', '_') .Replace('-', '_'); var bible = typeof(Properties.Resources) .GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public) .Where(p => p.PropertyType == typeof(string) && p.Name == bibleFormatName) .Select(x => new { Bible = x.GetValue(null, null) }) .FirstOrDefault(); List <string> verses = bible.Bible .ParseToString() .Split(new char[] { '\n', '\r' }, System.StringSplitOptions.RemoveEmptyEntries) .ToList(); List <BibleVerseModel> bulkList = new List <BibleVerseModel>(); foreach (string verseLine in verses) { int breakIndex = verseLine.LastIndexOf("||") + 2; string verseKey = verseLine.Substring(0, breakIndex); string verseText = verseLine.Substring(breakIndex, verseLine.Length - breakIndex); BibleVerseModel verseModel = new BibleVerseModel { BibleVerseKey = $"{bibleModel.BiblesId}||{verseKey}", VerseText = verseText }; bulkList.Add(verseModel); } int skipIndex = 0; int takeValue = 500; while (skipIndex <= bulkList.Count) { List <BibleVerseModel> addList = bulkList.Skip(skipIndex).Take(takeValue).ToList(); BiblesData.Database.InsertBibleVerseBulk(addList); skipIndex += takeValue; string checkKey = addList.Last().BibleVerseKey; int waitIndex = 0; while (BiblesData.Database.GetVerse(checkKey) == null) { Sleep.ThreadWait(200); ++waitIndex; if (waitIndex >= 20) { dispatcher.Invoke(() => { this.InitialDataLoadCompleted?.Invoke(this, $"Loading...{bibleModel.BibleName}", false, null); }); foreach (BibleVerseModel verseModel in addList) { BiblesData.Database.InsertBibleVerse(verseModel); } } } } }
public static void RefreshVerseNumberPanel(StackPanel versePanel, int bibleId, BibleVerseModel verse) { versePanel.Children.Clear(); UIElement[] children = BibleLoader.GetVerseNumberElements(bibleId, verse); versePanel.Children.Add(children[0]); for (int x = 1; x < children.Length; ++x) { if (children[x] == null) { continue; } versePanel.Children.Add(children[x]); } }
public BibleVerseModel Search(BibleVerseModel bibleVerse) { BibleVerseDataService service = new BibleVerseDataService(); return(service.Search(bibleVerse)); }