Ejemplo n.º 1
0
 public void addVerse(ref Verse verse)
 {
     if (verse.is_last_verse_of_chapter)
         last_verse = verse;
     verses.Add(verse.verse_id, verse);
     num_verses++;
 }
Ejemplo n.º 2
0
        /**/
        public static Hashtable getListOfChapters()
        {
            string sqlQuery = "SELECT name, count(DISTINCT Chapter)  as chapter_count"
            + " FROM bible INNER JOIN books ON (books.id = bible.Book) WHERE translation = 1 GROUP BY book, translation";

            MySqlConnection conn = DBManager.getConnection();
            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                Hashtable book_chapters = new Hashtable();
                while (rdr.Read())
                {
                    book_chapters.Add((rdr[0]).ToString(), (rdr[1]).ToString());
                }
                rdr.Close();
                conn.Close();
                return book_chapters;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                conn.Close();
                return null;
            }
        }

        //returns comma delimited string list of short codes for given book.
        public static String getShortCodeStringList(String book)
        {
            if (book_abbr_map.ContainsKey(book.ToUpper()))
            {
                return book_abbr_map[book.ToUpper()];
            }
            else
            {
                return "";
            }
        }

        public static List<Testament> getTestaments()
        {
            string sqlQuery = "SELECT * FROM testament";
            MySqlConnection conn = DBManager.getConnection();
            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                List<Testament> testaments = new List<Testament>();
                while (rdr.Read())
                {
                    testaments.Add(new Testament(Int32.Parse((rdr[0]).ToString()),
                                                               (rdr[1]).ToString()));
                }
                rdr.Close();
                return testaments;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return null;
            }
            finally
            {
                conn.Close();
            }
        }

        /*the start and end for now cant span more than one book*/
        public static String getVerseSectionReference(Verse start_verse, Verse end_verse)
        {
            if (start_verse != null)
            {
                return getVerseSectionReferenceWithoutTranslation(start_verse, end_verse) + " (" + start_verse.translation.name + ")";
            }
            else
            {
                return "";
            }
        }
Ejemplo n.º 3
0
        /*the start and end for now cant span more than one book*/
        public static String getVerseSectionReferenceWithoutTranslation(Verse start_verse, Verse end_verse)
        {
            string section = "";
            if (start_verse != null)
            {

                section = start_verse.book.name + " "
                    + start_verse.chapter.chapter_id + ":" + start_verse.verse_id;
                if (end_verse == null || (end_verse != null
                                                && start_verse.getVerseReference() == end_verse.getVerseReference()))
                {
                    //dont do anything
                }
                else if (start_verse.chapter == end_verse.chapter)
                {
                    section += "-" + end_verse.verse_id;
                }
                else if (start_verse.chapter == end_verse.chapter)
                {
                    section += "-" + end_verse.chapter + ":" + end_verse.verse_id;
                }
            }
            return section;
        }
Ejemplo n.º 4
0
        /*this adds the verses to the chapter*/
        public static void addChapterVerses(ref Chapter chapter, ref Translation translation)
        {
            Testament book_test = chapter.testament;
            Book book = chapter.book;
            string sqlQuery = "SELECT Verse, VerseText"
            + " FROM bible WHERE translation = '" + translation.translation_id+ "' AND book ='" + book.id + "'"
            + " AND Chapter = '"+chapter.chapter_id+"' ORDER BY Verse";
            MySqlConnection conn = DBManager.getConnection();
            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();

                Verse prev_verse = null;
                Verse next_verse = null;
                if (rdr.HasRows)
                {
                    rdr.Read();

                    Verse curr_verse = new Verse(
                                            Int32.Parse((rdr[0]).ToString()),
                                            (rdr[1]).ToString(),
                                            ref book_test,
                                            ref book,
                                            ref chapter,
                                            ref translation);

                    while (curr_verse != null)
                    {
                        //curr_chapter.prev_chapter = prev_chapter;
                        if (rdr.Read())
                        {

                            next_verse = new Verse(
                                            Int32.Parse((rdr[0]).ToString()),
                                            (rdr[1]).ToString(),
                                            ref book_test,
                                            ref book,
                                            ref chapter,
                                            ref translation
                                            );
                            curr_verse.prev_verse = prev_verse;
                            curr_verse.next_verse = next_verse;
                            chapter.addVerse(ref curr_verse);
                            prev_verse = curr_verse;
                            curr_verse = next_verse;
                        }
                        else
                        {
                            curr_verse.prev_verse = prev_verse;
                            curr_verse.next_verse = null;
                            curr_verse.is_last_verse_of_chapter = true;
                            chapter.addVerse(ref curr_verse);
                            break;
                        }

                    }
                }
                rdr.Close();
                conn.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                conn.Close();

            }
        }