Example #1
0
 public static List <Book> GetBooks(bool useDB)
 {
     try {
         DataTable   dt;
         List <Book> books = new List <Book>();
         if (useDB)
         {
             dt = DBBookshop.GetBooks(cs);
         }
         else
         {
             dt = DBBookshop.GetTestData();
         }
         Book book;
         foreach (DataRow row in dt.Rows)
         {
             book         = new Book((int)row[0]);
             book.Name    = row["name"].ToString();
             book.Author  = row["author"].ToString();
             book.Country = row["country"].ToString();
             book.Year    = (int)row["year"];
             books.Add(book);
         }
         return(books);
     } catch (Exception ex) {
         throw ex;
     }
 }
Example #2
0
 public static List <Book> GetBooks(bool useDB)
 {
     try
     {
         DataTable   dt;
         List <Book> books = new List <Book>();
         if (useDB)
         {
             // Pyydetään DB-kerrokselta kirjojen tiedot
             dt = DBBookshop.GetBooks(cs);
         }
         else
         {
             dt = DBBookshop.GetTestData();
         }
         // ORM = muutetaan datatablen rivit olioiksi
         Book book;
         foreach (DataRow row in dt.Rows)
         {
             book         = new Book((int)row[0]);
             book.Name    = row["name"].ToString();
             book.Author  = row["author"].ToString();
             book.Country = row["country"].ToString();
             book.Year    = (int)row["year"];
             books.Add(book);
         }
         return(books);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }