Exemple #1
0
 public static void UpdateBook(Book book)
 {
     try
     {
         int lkm = DBbooks.UpdateBook(cs, book.Id, book.Title, book.Author, book.Author, book.Year);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #2
0
        public static List <Book> GetBooks(Boolean useDB)
        {
            //Haetaan kirjoja, db kerroksen palauttama datatable mapataan olioiksi
            //eli tehdään ORM
            DataTable   dt;
            List <Book> temp = new List <Book>();

            try
            {
                if (useDB)
                {
                    //MessageBox.Show("Ebin");
                    dt = DBbooks.GetBooks(cs);
                }
                else
                {
                    dt = DBbooks.GetTestData();
                }
                //Tehdään ORM eli datatablen rivi muutetaan olioiksi
                Book book;
                foreach (DataRow dr in dt.Rows)
                {
                    book         = new Book((int)dr[0]);
                    book.Author  = dr["author"].ToString();
                    book.Title   = dr["name"].ToString();
                    book.Country = dr["country"].ToString();
                    book.Year    = (int)dr["year"];
                    temp.Add(book);
                }

                return(temp);
            }
            catch (Exception)
            {
                throw;
            }
        }