示例#1
0
    protected void gridViewBooks_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //get the list of books from the app cache
        this.books = (Book[])this.Application["BooksList"];

        //get the selected book
        Book selectedBook = this.books[Convert.ToInt32(e.CommandArgument)];


        //check for "view" command and redirect to list
        if (e.CommandName.ToLower() == "view")
        {
            this.Response.Redirect("bookdetails.aspx?view=" + selectedBook.BookId.ToString());
        }
        //check for "edit" command
        else if (e.CommandName.ToLower() == "edit")
        {
            this.Response.Redirect("bookdetails.aspx?edit=" + selectedBook.BookId.ToString());
        }
        //check for delete command
        else if (e.CommandName.ToLower() == "delete")
        {
            //delete the book. And because we have a PArent -> Child with a One to Many cardinality
            //and cascade delete , the related records from BookAuthors will also be deleted.
            BookPersistentObject perst = new BookPersistentObject(selectedBook);
            perst.Delete(selectedBook);

            this.Response.Redirect("books.aspx");
        }
    }
示例#2
0
    private void Search(string item)
    {
        this.labelTitleResults.Visible = true;
        this.labelResult.Visible       = false;
        this.gridViewResults.Visible   = false;


        Book bk = new Book();
        BookPersistentObject bookPerst = new BookPersistentObject(bk);

        QueryCriteria qc = new QueryCriteria(bk);

        qc.Add(CriteriaOperator.Like, bk.GetField("Name"), item);

        Book[] resultBooks = (Book[])bookPerst.GetTableMetadata(qc);

        if (resultBooks.Length == 0)
        {
            this.labelResult.Visible   = true;
            this.labelResult.Text      = "No results found";
            this.labelResult.Font.Bold = true;
        }
        else
        {
            Application.Add("SearchResults", resultBooks);

            this.gridViewResults.Visible    = true;
            this.gridViewResults.DataSource = resultBooks;
            this.gridViewResults.DataBind();
        }
    }
示例#3
0
        public void SetThingsUp()
        {
            global::voidsoft.DataBlock.Configuration.ReadConfigurationFromConfigFile();

            bk      = new Book();
            bkPerst = new BookPersistentObject(bk);

            at      = new Author();
            atPerst = new AuthorPersistentObject(at);
        }
示例#4
0
    /// <summary>
    /// Load the list of books and bind them to the grid
    /// </summary>
    private void LoadBooks()
    {
        Book bk = new Book();
        BookPersistentObject bookPerst = new BookPersistentObject(bk);

        this.books = (Book[])bookPerst.GetTableMetadata();

        this.Application.Remove("BooksList");

        this.Application.Add("BooksList", this.books);

        this.gridViewBooks.DataSource = this.books;
        this.gridViewBooks.DataBind();
    }
示例#5
0
    private bool ValidateData()
    {
        //validate

        //validate the user name
        if (this.textBoxName.Text.Trim() == string.Empty)
        {
            this.labelError.Text    = "Please enter the book's name";
            this.labelError.Visible = true;
            return(false);
        }



        //check if the number of pages is numeric
        if (this.textBoxPage.Text.Trim() != string.Empty)
        {
            int result;
            if (Int32.TryParse(this.textBoxPage.Text.Trim(), out result) == false)
            {
                this.labelError.Text    = "The book's nr of pages must be numeric";
                this.labelError.Visible = true;
                return(false);
            }
        }



        //check if the grade is numeric
        if (this.textBoxGrade.Text.Trim() != string.Empty)
        {
            short result;
            if (Int16.TryParse(this.textBoxGrade.Text.Trim(), out result) == false)
            {
                this.labelError.Text    = "The book's grade must be numeric";
                this.labelError.Visible = true;
                return(false);
            }
        }

        //check if the book's name is unique

        Book bk = new Book();
        BookPersistentObject perst = new BookPersistentObject(bk);
        DatabaseField        field = bk.GetField("Name");

        //check if the name is unique


        //check if the name has changes
        if (this.isNew == false && this.editableBook.Name == this.textBoxName.Text.Trim())
        {
            //the name was not changed
            return(true);
        }


        bool isUnique = perst.IsUnique(field, this.textBoxName.Text.Trim());


        if (isUnique == false)
        {
            this.labelError.Text    = "The book's name is not unique. Please insert another name";
            this.labelError.Visible = true;
            return(false);
        }



        //everything seems fine
        return(true);
    }
示例#6
0
    protected void buttonSubmit_Click(object sender, EventArgs e)
    {
        //validate the entered data
        if (this.ValidateData())
        {
            if (this.isNew)
            {
                //create new book

                Book newBook = new Book();
                newBook.Name = this.textBoxName.Text.Trim();

                if (this.textBoxPage.Text.Trim() != string.Empty)
                {
                    newBook.Pages = Convert.ToInt32(this.textBoxPage.Text.Trim());
                }
                else
                {
                    newBook.SetNullValue("Pages");
                }


                if (this.textBoxISBN.Text.Trim() != string.Empty)
                {
                    newBook.ISBN = this.textBoxISBN.Text;
                }
                else
                {
                    newBook.SetNullValue("ISBN");
                }


                if (this.textBoxGenre.Text.Trim() != string.Empty)
                {
                    newBook.Genre = this.textBoxGenre.Text;
                }
                else
                {
                    newBook.SetNullValue("Genre");
                }


                if (this.textBoxGrade.Text.Trim() != string.Empty)
                {
                    newBook.Grade = Int16.Parse(this.textBoxGrade.Text);
                }
                else
                {
                    newBook.SetNullValue("Grade");
                }



                //add the authors

                List <int> listId = new List <int>();

                foreach (ListItem var in this.listCheckboxes.Items)
                {
                    if (var.Selected)
                    {
                        listId.Add(Int32.Parse(var.Value));
                    }
                }

                //add the book authors
                BookAuthors[] bk = new BookAuthors[listId.Count];

                //set the author id
                for (int i = 0; i < bk.Length; i++)
                {
                    bk[i]          = new BookAuthors();
                    bk[i].AuthorId = listId[i];
                }

                //attach the book authors to our
                foreach (BookAuthors bauth in bk)
                {
                    newBook.AttachTableMetadata(bauth);
                }

                //create the book
                BookPersistentObject perst = new BookPersistentObject(newBook);
                perst.Create(newBook);

                //redirect to the main
                this.Response.Redirect("books.aspx");
            }
            else
            {
                //update
                Book bk = new Book();
                BookPersistentObject perst = new BookPersistentObject(bk);
                Book editBook = (Book)perst.GetTableMetadata(this.bookId);

                editBook.Name  = this.textBoxName.Text.Trim();
                editBook.Pages = Int32.Parse(this.textBoxPage.Text.Trim());
                editBook.Grade = Int16.Parse(this.textBoxGrade.Text.Trim());
                editBook.ISBN  = this.textBoxISBN.Text;
                editBook.Genre = this.textBoxGenre.Text;


                //get the attached authors
                BookAuthors[] booksAuthors = (BookAuthors[])editBook.GetBookAuthors();

                //add the authors
                foreach (ListItem var in this.listCheckboxes.Items)
                {
                    if (var.Selected)
                    {
                        //is new ?
                        bool isNewAddition = true;

                        foreach (BookAuthors bsk in booksAuthors)
                        {
                            if (bsk.AuthorId.ToString() == var.Value)
                            {
                                isNewAddition = false;
                                break;
                            }
                        }

                        if (isNewAddition)
                        {
                            BookAuthors bkAuth = new BookAuthors();
                            bkAuth.AuthorId = Int32.Parse(var.Value);

                            editBook.AttachTableMetadata(bkAuth);
                        }
                    }
                    else
                    {
                        foreach (BookAuthors bsk in booksAuthors)
                        {
                            if ((bsk.AuthorId.ToString() == var.Value) && (var.Selected == false))
                            {
                                editBook.RemoveTableMetadata(bsk);
                            }
                        }
                    }
                }

                //update the book
                perst.Update(editBook);

                //redirect to the main page
                this.Response.Redirect("books.aspx");
            }
        }
    }