Example #1
0
        private void BindGrid()
        {
            AuthorManager manager = new AuthorImpXMLManager();

            GridView1.DataSource = manager.FindAll();
            GridView1.DataBind();
        }
        private void FillComboBox(GridViewRowEventArgs e)
        {
            EditorialManager managerEditorial = new EditorialImpXMLManager();
            AuthorManager    managerAuthor    = new AuthorImpXMLManager();
            GenreManager     managerGenre     = new GenreImpXMLManager();


            DropDownList AuthorDrop    = (DropDownList)e.Row.FindControl("AuthorDropDown");
            DropDownList GenreDrop     = (DropDownList)e.Row.FindControl("GenreDropDown");
            DropDownList EditorialDrop = (DropDownList)e.Row.FindControl("EditorialDropDown");

            if (AuthorDrop != null)
            {
                AuthorDrop.DataSource     = managerAuthor.FindAll();
                AuthorDrop.DataTextField  = "Name";
                AuthorDrop.DataValueField = "Id";
                AuthorDrop.DataBind();
            }

            if (GenreDrop != null)
            {
                GenreDrop.DataSource     = managerGenre.FindAll();
                GenreDrop.DataTextField  = "Description";
                GenreDrop.DataValueField = "Id";
                GenreDrop.DataBind();
            }

            if (EditorialDrop != null)
            {
                EditorialDrop.DataSource = managerEditorial.FindAll();

                EditorialDrop.DataTextField  = "Name";
                EditorialDrop.DataValueField = "Id";
                EditorialDrop.DataBind();
            }



            dpGenre.DataSource = managerGenre.FindAll();

            dpGenre.DataTextField  = "Description";
            dpGenre.DataValueField = "Id";
            dpGenre.DataBind();

            dpEditorial.DataSource = managerEditorial.FindAll();

            dpEditorial.DataTextField  = "Name";
            dpEditorial.DataValueField = "Id";
            dpEditorial.DataBind();


            dpAuthor.DataSource = managerAuthor.FindAll();

            dpAuthor.DataTextField  = "Name";
            dpAuthor.DataValueField = "Id";
            dpAuthor.DataBind();
        }
Example #3
0
        protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow   row      = GridView1.Rows[e.RowIndex];
            int           authorId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
            AuthorManager manager  = new AuthorImpXMLManager();
            Author        author   = new Author();
            string        date     = Request.Form["txtBirthdate"];

            author.Id        = authorId;
            author.Name      = (row.FindControl("txtName") as TextBox).Text;
            author.LastName  = (row.FindControl("txtLastName") as TextBox).Text;
            author.BirthDate = Convert.ToDateTime(date);
            manager.Update(authorId, author);
            GridView1.EditIndex = -1;
            this.BindGrid();
        }
Example #4
0
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                int           authorId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
                AuthorManager manager  = new AuthorImpXMLManager();
                Author        author   = manager.FindOne(authorId);
                manager.Delete(author);

                this.BindGrid();
            }
            catch (Exception)
            {
                Response.Redirect("AuthorsInfo.aspx");
            }
        }
        protected void Insert(object sender, EventArgs e)
        {
            if (!(String.IsNullOrWhiteSpace(txtName.Text) && String.IsNullOrWhiteSpace(txtISBN.Text)))
            {
                BookManager      manager          = new BookImpXMLManager();
                EditorialManager managerEditorial = new EditorialImpXMLManager();
                AuthorManager    managerAuthor    = new AuthorImpXMLManager();
                GenreManager     managerGenre     = new GenreImpXMLManager();

                Book book = new Book();


                try
                {
                    book.Author_Id      = Convert.ToInt32(dpAuthor.SelectedItem.Value);
                    book.Name           = txtName.Text;
                    book.ISBN           = txtISBN.Text;
                    book.Published_Date = Convert.ToDateTime(Request.Form["date"].ToString());
                    book.Editorial_Id   = Convert.ToInt32(dpEditorial.SelectedItem.Value);
                    book.Genre_Id       = Convert.ToInt32(dpGenre.SelectedItem.Value);
                    book.Genre          = managerGenre.FindOne(Convert.ToInt32(dpGenre.SelectedItem.Value));
                    book.Editorial      = managerEditorial.FindOne(Convert.ToInt32(dpEditorial.SelectedItem.Value));
                    book.Author         = managerAuthor.FindOne(Convert.ToInt32(dpAuthor.SelectedItem.Value));

                    manager.Add(book);
                }
                catch (Exception exception)
                {
                    Response.Redirect("BookView.aspx");
                }


                errorMe.Text = "";
            }
            else
            {
                errorMe.Text = "NO se pueden dejar campos vacios";
            }


            this.BindGrid();
        }