示例#1
0
        public static List <Book> GetBooks(bool useDB)
        {
            DataTable   dt;
            List <Book> books = new List <Book>();
            Book        book;

            if (useDB)
            {
                dt = DBBookshop.GetBooks(cs);
            }
            else
            {
                dt = DBBookshop.GetTestData();
            }

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