protected void ButInsert_Click(object sender, EventArgs e)
        {
            // Set book
            Books book = new Books();

            book.Title     = boxTitle.Text;
            book.Author    = boxAuthor.Text;
            book.SectionId = Convert.ToInt32(ddlSection.SelectedValue);
            book.Ibsn      = Convert.ToInt32(boxIbsn.Text);

            // Set Copy
            Copy     copy   = new Copy();
            DateTime renewD = DateTime.ParseExact(boxRenewal.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            copy.RenewalDate = renewD;
            DateTime purchaseD = DateTime.ParseExact(boxPurchase.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            copy.PurchaseDate = purchaseD;

            // Set the number of copies
            int numberCopies = Convert.ToInt32(boxCopies.Text);

            // Insert Book and go the list page
            int bookId = BBooks.insert(book, copy, numberCopies);

            Response.Redirect("~/Book/MainList.aspx");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Get the index of the book to update
                index = Convert.ToInt32(Request.QueryString["bookId"]);

                // Get the record and save it in viewstate
                bookToUpdate = BBooks.getById(index);
                ViewState["bookToUpdate"] = bookToUpdate;

                // Load Section dropDownList
                ddlSection.DataSource     = BSection.getAll();
                ddlSection.DataTextField  = "Name";
                ddlSection.DataValueField = "SectionId";
                ddlSection.DataBind();

                // Fill the textBoxes
                boxTitle.Text            = bookToUpdate.Title;
                boxAuthor.Text           = bookToUpdate.Author;
                ddlSection.SelectedValue = bookToUpdate.SectionId.ToString();

                boxIbsn.Enabled = false;
                boxIbsn.Text    = bookToUpdate.Ibsn.ToString();
            }
        }
Exemple #3
0
        protected void filterBySectionAndCopy()
        {
            // 1.- Get latest datasource
            allBooks = (List <BookDTO>)ViewState["allBooks"];

            // 2.- Filter by Section and fill Grid
            if (DropDownSection.SelectedValue != "-1")
            {
                allBooks = BBooks.getBookDTOBySection(allBooks, DropDownSection.SelectedItem.Text);
            }

            // 3.- Filter by copy and fill Grid
            if (DropDownCopies.SelectedValue != "-1")
            {
                allBooks = BBooks.getBookDTOByCopies(allBooks, Convert.ToInt32(DropDownCopies.SelectedValue));
            }

            // 5.- Filter by author or title
            allBooks = BBooks.getBookDTOByAuthorOrTitle(allBooks, TextBoxSearch.Text);

            // 4.- Fill Grid and save it in viewState
            ViewState["filterBooks"] = allBooks;
            GridMainList.DataSource  = allBooks;
            GridMainList.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Fill the grid
            List <BookDTO> allBooks = new List <BookDTO>();

            allBooks = BBooks.getBookDTOAll();

            GridUpdateList.DataSource = allBooks;
            GridUpdateList.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Fill the grid
            List <Books> allBooks = new List <Books>();

            allBooks = BBooks.getAll();

            gridBookList.DataSource = allBooks;
            gridBookList.DataBind();

            // Insert Books
            Books book = new Books();
        }
        protected void ButUpdate_Click(object sender, EventArgs e)
        {
            // Gets record to update
            bookToUpdate = (Books)ViewState["bookToUpdate"];

            // Modify record
            bookToUpdate.Title     = boxTitle.Text;
            bookToUpdate.Author    = boxAuthor.Text;
            bookToUpdate.SectionId = Convert.ToInt32(ddlSection.SelectedValue);

            // Update record and goes to MainList.aspx
            BBooks.update(bookToUpdate);
            Response.Redirect("~/Book/MainList.aspx");
        }
        protected void buttonInsertBook_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // Insert books
                Books book = new Books();

                book.Title     = boxTitle.Text;
                book.Author    = boxAuthor.Text;
                book.SectionId = Convert.ToInt32(boxSection.Text);

                BBooks.insert(book);
                Response.Redirect("~/ListBooks.aspx");
            }
        }
        protected void boxIbsn_TextChanged(object sender, EventArgs e)
        {
            // Enable Fields
            boxTitle.Enabled = true;
            //boxTitle.Text = "";

            boxAuthor.Enabled = true;
            //boxAuthor.Text = "";

            ddlSection.Enabled = true;

            // Validate text field
            literalIbsn.Text = "";
            int value;

            if (!int.TryParse(boxIbsn.Text, out value))
            {
                literalIbsn.Text = writeDigitsLabel();
            }

            // If textBox contains data and is a number it does the logic
            if (!string.IsNullOrEmpty(boxIbsn.Text) && int.TryParse(boxIbsn.Text, out value))
            {
                int ibsnToCheck = Convert.ToInt32(boxIbsn.Text);
                int bookId      = BBooks.ibsnExist(ibsnToCheck);
                // If ibsn exist, some controls are filled and ibsn is blocked
                if (bookId > 0)
                {
                    // Get the book record
                    Books book = new Books();
                    book = BBooks.getById(bookId);

                    // Book: Fill fields and diable them
                    boxTitle.Enabled = false;
                    boxTitle.Text    = book.Title;

                    boxAuthor.Enabled = false;
                    boxAuthor.Text    = book.Author;

                    ddlSection.Enabled       = false;
                    ddlSection.SelectedValue = book.SectionId.ToString();
                }
            }
        }
Exemple #9
0
        protected void ButDelete_Click(object sender, EventArgs e)
        {
            changeColorTextBox();

            // Get record from viewstate
            bookToUpdate = (Books)ViewState["bookToUpdate"];

            // Delete record in COPIES kand goes to DeleteList.aspx
            try
            {
                BBooks.deleteAllCopiesById(bookToUpdate.BookId);
                Response.Redirect("~/Book/MainList.aspx");
            }
            catch (Exception generalException)
            {
                PanelDeleteBook.Visible = true;
                LiteralDeleteBook.Text  = generalException.Message;
            }
        }
 public void AddBook(Book b)
 {
     BBooks.Add(b);
 }