Exemplo n.º 1
0
 private void btnSaveNewBook_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         book = new CBook(txtISBN.Text, txtAuthor.Text, txtTitle.Text, Convert.ToDouble(txtPrice.Text));
         this.Close();
     }
 }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmNewBook addNewBook = new frmNewBook();
            CBook      book       = addNewBook.GetNewBook();

            if (book != null)
            {
                books.Add(book);
                BookDB.AddNewBook(books);
                FillBookListBox();
            }
        }
Exemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int i = lstBook.SelectedIndex;

            if (i != -1)
            {
                CBook  book    = (CBook)books[i];
                string message = "Are you sure you want to delete "
                                 + book._Title + "?";
                DialogResult button =
                    MessageBox.Show(message, "Confirm Delete",
                                    MessageBoxButtons.YesNo);
                if (button == DialogResult.Yes)
                {
                    books.Remove(book);
                    BookDB.AddNewBook(books);
                    FillBookListBox();
                }
            }
        }
Exemplo n.º 4
0
        public static List <CBook> GetBooks()
        {
            // create the list
            List <CBook> books = new List <CBook>();

            // create the xmlReaderSettings  object
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;

            // create the XmlReader object
            XmlReader xmlIn = XmlReader.Create(Path, settings);

            // read past all nodes to the first Student node
            if (xmlIn.ReadToDescendant("Book"))
            {
                // create one Student object for each Student node
                do
                {
                    CBook book = new CBook();
                    xmlIn.ReadStartElement("Book");
                    book._ISBN =
                        xmlIn.ReadElementContentAsString();
                    book._Author =
                        xmlIn.ReadElementContentAsString();
                    book._Title =
                        xmlIn.ReadElementContentAsString();
                    book._Price =
                        xmlIn.ReadElementContentAsDouble();
                    books.Add(book);
                }while (xmlIn.ReadToNextSibling("Book"));
            }

            // close the XmlReader object
            xmlIn.Close();

            return(books);
        }