Пример #1
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();
         }
         // OMR 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);
         }
         //palautus
         return(books);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
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;
     }
 }
Пример #3
0
 public static int UpdateBook(Book book)
 {
     try {
         int lkm = DBBookShop.UpdateBook(cs, book.ID, book.Name, book.Author, book.Country, book.Year);
         return(lkm);
     } catch (Exception ex) {
         throw ex;
     }
 }
Пример #4
0
 public static bool DeleteBook(Book book)
 {
     try {
         int lkm = DBBookShop.DeleteBook(cs, book.ID);
         if (lkm > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     } catch (Exception ex) {
         throw ex;
     }
 }
Пример #5
0
 public static bool InsertBook(Book book)
 {
     try {
         int lkm = DBBookShop.InsertBook(cs, book.Name, book.Author, book.Country, book.Year);
         if (lkm > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     } catch (Exception ex) {
         throw ex;
     }
 }