Exemplo n.º 1
0
        public Book GetByID(int ID)
        {
            try
            {
                Book book = null;

                connection.Connect();

                var command = connection.CreateCommand();
                command.CommandText = ("Books_GetByID");
                command.CommandType = CommandType.StoredProcedure;

                var IDParam = command.CreateParameter(); IDParam.ParameterName = "@IDParam"; IDParam.DbType = DbType.Int32; IDParam.Value = ID; command.Parameters.Add(IDParam);
                var dr      = command.ExecuteReader();

                while (dr.Read())
                {
                    int       bookID        = dr.GetInt32(0);
                    int       ISBN          = dr.GetInt32(1);
                    Editorial editorial     = editorialRepository.GetByID(dr.GetInt32(2));
                    Author    author        = authorRepository.GetByID(dr.GetInt32(3));
                    string    title         = dr.GetString(4);
                    int       edition       = dr.GetInt32(5);
                    int       year          = dr.GetInt32(6);
                    int       editionYear   = dr.GetInt32(7);
                    string    deterioration = dr.GetString(8);

                    book = new Book(bookID, ISBN, title, editorial, edition, year, editionYear, author, deterioration);
                    bookList.Add(book);
                }

                dr.Close();
                return(book);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                connection.Disconnect();
            }
        }
Exemplo n.º 2
0
        private void btnAddEditorial_Click(object sender, EventArgs e)
        {
            try
            {
                Editorial editorial = new Editorial(editorialID, editorialName);
                editorial.Name = txbAddEditorial.Text;

                if (editorialController.AddEditorial(editorial) != null)
                {
                    MessageBox.Show("Se agregó una editorial con éxito.");
                }

                updateAll();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                MessageBox.Show(error);
            }
        }
Exemplo n.º 3
0
        public List <Book> GetAll()
        {
            try
            {
                connection.Connect();

                var command = connection.CreateCommand();
                command.CommandText = ("Books_GetAll");
                command.CommandType = CommandType.StoredProcedure;

                var dr = command.ExecuteReader();
                while (dr.Read())
                {
                    int       bookID        = dr.GetInt32(0);
                    int       ISBN          = dr.GetInt32(1);
                    string    title         = dr.GetString(2);
                    Editorial editorial     = editorialRepository.GetByID(dr.GetInt32(3));
                    int       edition       = dr.GetInt32(4);
                    int       year          = dr.GetInt32(5);
                    int       editionYear   = dr.GetInt32(6);
                    Author    author        = authorRepository.GetByID(dr.GetInt32(7));
                    string    deterioration = dr.GetString(8);

                    Book book = new Book(bookID, ISBN, title, editorial, edition, year, editionYear, author, deterioration);
                    bookList.Add(book);
                }

                dr.Close();
                return(bookList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                connection.Disconnect();
            }
        }
Exemplo n.º 4
0
        private void btnAddBook_Click(object sender, EventArgs e)
        {
            try
            {
                if ((bookController.CheckBook((int)nudBookISBN.Value)) == null)
                {
                    Editorial editorial = new Editorial(editorialID, editorialName);
                    Author    author    = new Author(authorID, authorName);
                    Book      book      = new Book(bookID, ISBN, title, editorial, edition, year, editionYear, author, deterioration);
                    book.ISBN          = (int)nudBookISBN.Value;
                    book.Title         = txbBookName.Text;
                    book.Year          = (int)nudBookYear.Value;
                    book.EditionYear   = (int)nudBookEditionYear.Value;
                    book.Deterioration = txbBookDeterioration.Text;
                    book.Author        = (Author)cmbBookAuthor.SelectedItem;
                    book.Editorial     = (Editorial)cmbBookEditorial.SelectedItem;
                    book.Edition       = (int)nudBookEdition.Value;

                    if (bookController.AddBook(book) != null)
                    {
                        MessageBox.Show("Se agregó un libro con éxito.");
                    }
                }
                else
                {
                    MessageBox.Show("Ya existe un libro con ese ISBN.");
                }

                updateAll();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                MessageBox.Show(error);
            }
        }