private int num_verses = 0; //we set this once so we dont have to calculate it everytime #endregion Fields #region Constructors public Chapter( int chapter_id, ref Testament testament, ref Book book) { this.chapter_id = chapter_id; this.testament = testament; this.book = book; verses = new Hashtable(); }
public Book( int id, string name, string abbr, ref Testament testament) { this.id = id; this.name = name; this.testament = testament; this.abbr = abbr; chapters = new Hashtable(); }
/*add finally blocks*/ public static List<Book> getListOfBooks() { string sqlQuery = "Select id, abbr, testament, name From books Order by id"; MySqlConnection conn = DBManager.getConnection(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(sqlQuery, conn); MySqlDataReader rdr = cmd.ExecuteReader(); List<Book> list = new List<Book>(); Testament old_testament = new Testament(0, Testament.OLD_TESTAMENT_NAME); Testament new_testament = new Testament(1, Testament.NEW_TESTAMENT_NAME); while (rdr.Read()) { //quick hack int testament_id = Int32.Parse(rdr[2].ToString()); if (testament_id == 0) { list.Add( new Book( Int32.Parse((rdr[0]).ToString()), rdr[3].ToString(), ((rdr[1]).ToString()), ref old_testament)); } else { list.Add( new Book( Int32.Parse((rdr[0]).ToString()), rdr[3].ToString(), ((rdr[1]).ToString()), ref new_testament)); } } rdr.Close(); conn.Close(); return list; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); conn.Close(); return null; } }
/*this adds the books to the testament*/ public static void addTestamentBooks(ref Testament testament) { string sqlQuery = "Select id, abbr, testament, name From books WHERE " + " testament ='" + testament.testament_id + "' Order by id"; MySqlConnection conn = DBManager.getConnection(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(sqlQuery, conn); MySqlDataReader rdr = cmd.ExecuteReader(); Book prev_book = null; Book next_book = null; if (rdr.HasRows) { rdr.Read(); Book curr_book = new Book( Int32.Parse((rdr[0]).ToString()), rdr[3].ToString(), ((rdr[1]).ToString()), ref testament); while (curr_book != null) { //curr_chapter.prev_chapter = prev_chapter; if (rdr.Read()) { next_book = new Book( Int32.Parse((rdr[0]).ToString()), rdr[3].ToString(), ((rdr[1]).ToString()), ref testament); curr_book.prev_book = prev_book; curr_book.next_book = next_book; testament.addBook(ref curr_book); prev_book = curr_book; curr_book = next_book; } else { curr_book.prev_book = prev_book; curr_book.next_book = null; testament.addBook(ref curr_book); break; } } } /*while (rdr.Read()) { Book aBook = new Book( Int32.Parse((rdr[0]).ToString()), rdr[3].ToString(), ((rdr[1]).ToString()), ref testament); testament.addBook(ref aBook); }*/ rdr.Close(); conn.Close(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); conn.Close(); } }