// called every time the class is instantiated. public void SetDetailItem (Book newDetailItem) { if (DetailItem != newDetailItem) { DetailItem = newDetailItem; this.Title = DetailItem.getTitle (); // set the photo until otherwise determined //coverImage.Image = UIImage.FromBundle ("unavailable.png"); // Update the view ConfigureView (); } }
public void SetBookItem(Book newDetailItem) { if (newBook != newDetailItem) { newBook = newDetailItem; // attempt to set it manually newBook.title = newDetailItem.getTitle (); newBook.author = newDetailItem.getAuthor (); newBook.publisher = newDetailItem.getPublisher (); newBook.summary = newDetailItem.getSummary (); newBook.isbn = newDetailItem.getIsbn (); newBook.dateadded = newDetailItem.getDateAdded (); timeAdded = newDetailItem.getDateAdded (); Console.Out.WriteLine ("Time added: " + timeAdded.ToString ()); Console.Out.WriteLine ("Set Book Item entered: " + newBook.getTitle ()); } }
private void insertToDatabase(Book theBook) { var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal); _pathToDatabase = Path.Combine(documents, _databaseName); using (var db = new SQLite.SQLiteConnection(_pathToDatabase )) { db.InsertOrReplace (theBook); } Console.Out.WriteLine ("Book " + newBook.getTitle () + " inserted into database."); // ui alert to let the user know var alert = UIAlertController.Create("Book Added!", "Hit the back button to see the book in your Book List.", UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Okay", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null); }
partial void addButton_TouchUpInside(UIButton sender) { Console.Out.WriteLine("Manual add button pressed."); string titleText = titleField.Text; string authorText = authorField.Text; string pubText = pubField.Text; string summaryText = summaryField.Text; string isbnText = isbnField.Text; Console.Out.WriteLine("book info: \n" + titleText + "\n" + authorText + "\n" + pubText + "\n" + summaryText + "\n" + isbnText); // then make it into a book object and load it into the database if(string.IsNullOrEmpty(isbnText) || isbnText.Length < 9) { newBook = new Book(); // used to be blank Console.Out.WriteLine("newbook blank isbn"); newBook.usesuserphoto = true; } else { newBook = new Book(isbnText); Console.Out.WriteLine("newbook given isbn"); newBook.usesuserphoto = false; } /*if(!string.IsNullOrEmpty(photoString)) { Console.Out.WriteLine("photo string not null or empty! adding"); newBook.userimagepath = photoString; }*/ if(!string.IsNullOrEmpty(pngFilename)) { Console.Out.WriteLine("pngfile name not null or empty: " + pngFilename); newBook.userimagepath = pngFilename; } // perform user initializations newBook.title = titleText; newBook.author = authorText; newBook.publisher = pubText; newBook.summary = summaryText; newBook.coverstring = null; // this is how to tell if this class was entered from BookViewController or the UI Alert Controller if(timeAdded == new DateTime()) { var thisdate = DateTime.Now.ToLocalTime (); newBook.dateadded = thisdate; } else { newBook.dateadded = timeAdded; } // make sure that none of the important fields are empty before adding if((newBook.title == string.Empty) || (newBook.author == string.Empty)) { Console.Out.WriteLine("Hold on a minute! You didn't add a title or an author!"); string titleMessage = "Wait Just A Hot Second!"; string contentMessage = "You left the title or the author empty!\nIt's okay to write \'I don't know\' and edit it later!"; // now make an alert to notify the user var alert = UIAlertController.Create(titleMessage, contentMessage, UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Hmm...Okay", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null); // return so that the book's not added return; } insertToDatabase(newBook); }
public void deleteFromDatabase(Book oldBook) { Console.Out.WriteLine("Book " + oldBook.getTitle() + " deleted from database."); using (var db = new SQLite.SQLiteConnection(_pathToDatabase)) { Console.Out.WriteLine ("object deleted: " + oldBook.getDateAdded ()); db.Delete (oldBook); //return Delete } }
async void scanIsbn() { // start the barcode scanner var scanner = new ZXing.Mobile.MobileBarcodeScanner(); var result = await scanner.Scan(); try { // create an object to hold the book. Book newBook = new Book (result.Text); Console.Out.WriteLine ("newbook title: " + newBook.getTitle ()); // make sure it's actually a book before adding it. try { if (newBook.getAuthor().Length > 3) { insertToDatabase (newBook); Console.Out.WriteLine("newbook added"); dataSource.Objects.Insert (0, newBook); using (var indexPath = NSIndexPath.FromRowSection (0, 0)) TableView.InsertRows (new [] { indexPath }, UITableViewRowAnimation.Automatic); } else Console.Out.WriteLine ("newbook seems to be null"); } catch(Exception ex) { Console.Out.WriteLine ("Adding newbook error: " + ex.ToString ()); } } catch(Exception ex) { Console.Out.WriteLine ("scanning was probably canceled.\n" + ex.ToString ()); } }
private void insertToDatabase(Book newBook) { using (var db = new SQLite.SQLiteConnection(_pathToDatabase )) { db.Insert(newBook); } Console.Out.WriteLine ("Book " + newBook.getTitle () + " inserted into database."); }