protected void UpdateUpDowns(VerseKey keyVerse) { System.Diagnostics.Debug.Assert(!m_bDisableInterrupts); m_bDisableInterrupts = true; // initialize the combo boxes for this new situation if (keyVerse.Book() != m_nBook) { domainUpDownBookNames.SelectedItem = keyVerse.getBookAbbrev(); m_nBook = keyVerse.Book(); int nNumChapters = keyVerse.chapterCount(keyVerse.Testament(), keyVerse.Book()); numericUpDownChapterNumber.Maximum = nNumChapters; // if the book changes, then the chapter number changes implicitly m_nChapter = 0; } if (keyVerse.Chapter() != m_nChapter) { m_nChapter = keyVerse.Chapter(); numericUpDownChapterNumber.Value = m_nChapter; int nNumVerses = keyVerse.verseCount(keyVerse.Testament(), keyVerse.Book(), keyVerse.Chapter()); numericUpDownVerseNumber.Maximum = nNumVerses; } if (keyVerse.Verse() != m_nVerse) { m_nVerse = keyVerse.Verse(); numericUpDownVerseNumber.Value = (decimal)m_nVerse; } m_bDisableInterrupts = false; }
public List <string> getBooks(string moduleName) { List <string> books = new List <string>(); VerseKey verseKey = new VerseKey("Gen 1:1"); while (verseKey.Error() == '\0') { books.Add(verseKey.getBookName()); verseKey.Book((char)((int)verseKey.Book() + 1)); } return(books); }
/// <summary> /// Returns the verse text. /// </summary> /// <param name="version">Bible version - obtained from getBibles()</param> /// <param name="b">1-based book (1..66)</param> /// <param name="c">1-based chapter (1..150)</param> /// <param name="v">2-based verse (1..?)</param> /// <returns></returns> public string getVerseText(string version, int b, int c, int v) { SWModule module = getModule(version); VerseKey vk = new VerseKey(); vk.AutoNormalize((char)0); // Or else it will get improperly normalized before it's fully configured. if (b < 40) { vk.Testament((char)1); // OT = 1..39 -> Sword = 1..39 vk.Book((char)b); } else { vk.Testament((char)2); // NT = 40..66 -> Sword = 1..27 vk.Book((char)(b - 39)); } vk.Chapter(c); vk.Verse(v); /* vk.Error() would return an error (non-zero) if only vk.Testament is set (even though * it sets Book = Chapter = Verse = 1). * * If there's an error in vk, the increment below would be ignored, so we either have * to call vk.Error() to clear it, or set the Book, Chapter, and Verse. * vk.Error(); * vk.Book((char)1); * vk.Chapter(1); * vk.Verse(1); * * The following two don't work because incrementing the index takes us through * headings and other non-verse indices: * vk.increment(verseIdx); * vk.Index(vk.Index() + verseIdx); */ if (vk.Error() != '\0') { // report the error } return(DreamTools.Sword_ConvertEncoding(module.RenderText(vk)).Trim()); }
protected void DisplayVerses() { VerseKey keyVerse = new VerseKey(ScriptureReference); int nBook = keyVerse.Book(); int nChapter = keyVerse.Chapter(); int nVerse = keyVerse.Verse(); bool bJustUpdated = false; if ((nBook != m_nBook) || (nChapter != m_nChapter)) { // something changed // Build up the string which we're going to put in the HTML viewer StringBuilder sb = new StringBuilder(CstrHtmlTableBegin); // Do the whole chapter VerseKey keyWholeOfChapter = new VerseKey(keyVerse); keyWholeOfChapter.Verse(1); while ((keyWholeOfChapter.Chapter() == nChapter) && (keyWholeOfChapter.Book() == nBook) && (keyWholeOfChapter.Error() == '\0')) { // get the verse and remove any line break signals string strVerseHtml = moduleVersion.RenderText(keyWholeOfChapter).Replace(verseLineBreak, null); if (String.IsNullOrEmpty(strVerseHtml)) { strVerseHtml = "Passage not available in this version"; } // insert a button (for drag-drop) and the HTML into a table format // kindof a cheat, but I don't mind (this should be done better...) string strModuleVersion = moduleVersion.Name(); if ((strModuleVersion == CstrHindiModule) || (strModuleVersion == CstrKangriModule)) { strVerseHtml = String.Format(CstrAddFontFormat, strVerseHtml, CstrFontForHindi); } else if (strModuleVersion == CstrFarsiModule) { strVerseHtml = String.Format(CstrAddDirFormat, strVerseHtml); strVerseHtml = String.Format(CstrAddFontFormat, strVerseHtml, CstrFontForFarsi); } string strButtonLabel; /* * This was a nice idea (of making the selected verse bold), but then * we need to re-do the DocumentText each time * if (nVerse == keyWholeOfChapter.Verse()) * strButtonLabel = String.Format("<b>{0}</b>", * keyWholeOfChapter.getShortText()); * else */ strButtonLabel = keyWholeOfChapter.getShortText(); string strLineHtml = String.Format(CstrHtmlLineFormat, keyWholeOfChapter.Verse(), strButtonLabel, strVerseHtml); sb.Append(strLineHtml); // next verse until end of chapter keyWholeOfChapter.Verse(keyWholeOfChapter.Verse() + 1); } // delimit the table sb.Append(CstrHtmlTableEnd); // set this along with scripts for clicks and such into the web browser. webBrowserNetBible.DocumentText = preDocumentDOMScript + sb + postDocumentDOMScript; bJustUpdated = true; } // if (nVerse != m_nVerse) { strIdToScrollTo = nVerse.ToString(); if (!bJustUpdated) { ScrollToElement(); } } Properties.Settings.Default.LastNetBibleReference = ScriptureReference; // update the updown controls UpdateUpDowns(keyVerse); }
public BibleVersion(BackgroundWorker worker, DoWorkEventArgs evArg, string version, System.Data.DataTable replacements) { _version = version; _replacements = replacements; int i = 0, b = -1, book; System.EventArgs e = new System.EventArgs(); SWModule module = SwordW.Instance().getModule(version); VerseKey vk = new VerseKey("Gen 1:1"); while (vk.Error() == '\0') { if ((i % 300) == 0) { int progress = (int)(((float)i / 31102F) * 100); worker.ReportProgress(progress); } string t = DreamTools.Sword_ConvertEncoding(module.RenderText(vk)).Trim(); book = vk.Book(); // Book numbering is 1-based and starts back up from 1 in the New Testament // OT = 1, NT = 2 if (vk.Testament() == (char)2) { book += 39; } BibleVerse v = new BibleVerse(i, book - 1, vk.Chapter(), vk.Verse(), Replace(t)); verses[i] = v; // book is 1-based, b is 0-based if (b < book - 1) { b = book - 1; BibleBooks[b].Long = vk.getBookName(); Console.WriteLine("Processing " + BibleBooks[b].Long); if (worker.CancellationPending) { evArg.Cancel = true; } } i++; vk.increment(); } _VerseCount = i; for (i = 0; i < this.BibleBooks.Length; i++) { if (BibleBooks[i].Long == null) { BibleBooks[i].Long = ""; } string bk = BibleBooks[i].Long; bk = Regex.Replace(bk.Trim(), @"^III ", "3 "); bk = Regex.Replace(bk, @"^II ", "2 "); bk = Regex.Replace(bk, @"^I ", "1 "); BibleBooks[i].Long = bk; BibleBooks[i].Short = bk; } worker.ReportProgress(100); }