partial void btnAdd_TouchUpInside(UIButton sender) { // Input Validation: only insert a book if the title is not empty if (!string.IsNullOrEmpty(txtTitle.Text)) { // Insert a new book into the database var newBook = new Book { BookTitle = txtTitle.Text, ISBN = txtISBN.Text }; var db = new SQLiteConnection (filePath); db.Insert (newBook); // TODO: Add code to populate the Table View with the new values // show an alert to confirm that the book has been added new UIAlertView( "Success", string.Format("Book ID: {0} with Title: {1} has been successfully added!", newBook.BookId, newBook.BookTitle), null, "OK").Show(); PopulateTableView(); // call this method to refresh the Table View data tblBooks.ReloadData (); } else { new UIAlertView("Failed", "Enter a valid Book Title",null,"OK").Show(); } }
partial void btnAdd_TouchUpInside(UIButton sender) { if(!string.IsNullOrEmpty(txtTitle.Text)) { var newBook = new Book { BookTitle = txtTitle.Text, ISBN = txtISBN.Text }; var db = new SQLiteConnection (filePath); db.Insert (newBook); new UIAlertView("Success", string.Format("Book ID: {0} with Title: {1} has been successfully added!", newBook.BookId, newBook.BookTitle),null, "OK").Show(); PopulateTableView(); tblBooks.ReloadData(); }else { new UIAlertView("Failed", "Enter a valid Book Title", null, "OK").Show(); } }
public IEnumerable<Book> ReadBookList() { List<Book> books = new List<Book>(); if (File.Exists(filePath)) { using (BinaryReader reader = new BinaryReader(File.Open(filePath, FileMode.Open))) { while (reader.BaseStream.Position != reader.BaseStream.Length) { string author = reader.ReadString(); string title = reader.ReadString(); string publisher = reader.ReadString(); Book book = new Book(author, title, publisher); books.Add(book); } } } return books.AsEnumerable(); }