Ejemplo n.º 1
0
        public void AddNewBook(Book book)
        {
            DbAccessor dbAccessor = new DbAccessor();
            var        conn       = dbAccessor.OpenConnection();

            SqlCommand cmd = new SqlCommand(String.Format("INSERT INTO [BooksForAppoo].[dbo].[Books] VALUES({0}, \'{1}\', {2}, {3});", book.getId(), book.getName(), book.getPrice(), book.getQuantity()), conn);

            cmd.ExecuteNonQuery();

            dbAccessor.CloseConnection(conn);
        }
Ejemplo n.º 2
0
        public void ChangeQuantity(int id, int quantity)
        {
            DbAccessor dbAccessor = new DbAccessor();
            var        conn       = dbAccessor.OpenConnection();

            SqlCommand cmd = new SqlCommand(String.Format("UPDATE[BooksForAppoo].[dbo].[Books] SET quantity = {1} WHERE id = {0}", id, quantity), conn);

            cmd.ExecuteNonQuery();

            dbAccessor.CloseConnection(conn);
        }
Ejemplo n.º 3
0
        public void ShowBookById(int id)
        {
            DbAccessor dbAccessor = new DbAccessor();
            var        conn       = dbAccessor.OpenConnection();

            SqlCommand cmd = new SqlCommand(String.Format("Select * From Books WHERE id = {0} ", id), conn);

            // dbAccessor.PrintBooks(cmd);

            dbAccessor.CloseConnection(conn);
        }
Ejemplo n.º 4
0
        public void ShowCatalog()
        {
            DbAccessor dbAccessor = new DbAccessor();
            var        conn       = dbAccessor.OpenConnection();

            SqlCommand cmd = new SqlCommand("Select * From Books", conn);

            // dbAccessor.PrintBooks(cmd);

            dbAccessor.CloseConnection(conn);
        }
Ejemplo n.º 5
0
        public void DeleteBookById(int id)
        {
            DbAccessor dbAccessor = new DbAccessor();
            var        conn       = dbAccessor.OpenConnection();

            SqlCommand cmd = new SqlCommand(String.Format("Delete from [BooksForAppoo].[dbo].[Books] WHERE id = {0}", id), conn);

            cmd.ExecuteNonQuery();

            dbAccessor.CloseConnection(conn);
        }
Ejemplo n.º 6
0
        public List <Book> ReturnAllBooks()
        {
            DbAccessor dbAccessor = new DbAccessor();
            var        conn       = dbAccessor.OpenConnection();

            SqlCommand cmd   = new SqlCommand("Select * From Books", conn);
            var        books = dbAccessor.ReturnBooks(cmd);

            dbAccessor.CloseConnection(conn);

            return(books);
        }