示例#1
0
 public static bool DeleteBook(Book book)
 {
     try
     {
         int c = DBBookShop.DeleteBook(cs, book.ID);
         return(c > 0);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#2
0
 public static int UpdateBook(Book book)
 {
     try
     {
         int c = DBBookShop.UpdateBook(cs, book.ID, book.Name, book.Author, book.Country, book.Year);
         return(c);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#3
0
 public static bool InsertBook(Book book)
 {
     try
     {
         int c = DBBookShop.InsertBook(cs, book.Name, book.Author, book.Country, book.Year);
         return(c > 0);
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#4
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();
                }

                // ORM =  Muutetaan datatablen rivit olioiksi
                Book book;

                foreach (DataRow row in dt.Rows)
                {
                    book         = new Book((int)row[0]);
                    book.Name    = row[1].ToString();
                    book.Author  = row[2].ToString();
                    book.Country = row[3].ToString();
                    book.Year    = (int)row[4];
                    books.Add(book);
                }

                // Palautus
                return(books);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }