//Create object Book private Book createBook() { Book abook = new Book(); abook.BkISBN = Convert.ToInt64(textBoxBkISBN.Text); abook.BkTitle = textBoxBktitle.Text; abook.BkQOH = Convert.ToInt32(textBoxBkQOH.Text); abook.BkDate = dateTimePickerBook.Value; abook.BkAuthor = AuthorDA.SearchID(Convert.ToInt32(textBoxBkAuthorID.Text)); abook.BkCategory = textBoxBkCategory.Text; abook.BkUnitPrice = Convert.ToDecimal(textBoxBkUP.Text); abook.BkPublisher = comboBoxBkPub.Text; return(abook); }
//Enable the buttons delete and update in case of a valid entered ID private void textBoxAutID_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxAutID.Text)) { buttonAutDel.Enabled = false; buttonAutUpd.Enabled = false; return; } if (AuthorDA.SearchID(Convert.ToInt32(textBoxAutID.Text)) != null) { buttonAutDel.Enabled = true; buttonAutUpd.Enabled = true; return; } buttonAutDel.Enabled = false; buttonAutUpd.Enabled = false; }
//Search private void buttonAutSearch_Click(object sender, EventArgs e) { Author aAuthor = new Author(); if (!string.IsNullOrEmpty(textBoxAutSearch.Text)) { switch (comboBoxAutSearch.SelectedIndex) { case -1: MessageBox.Show("Please select a valid search option!"); return; case 0: int tempId; if (!int.TryParse(textBoxAutSearch.Text, out tempId)) { MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; } aAuthor = AuthorDA.SearchID(Convert.ToInt32(textBoxAutSearch.Text)); break; case 1: aAuthor = AuthorDA.SearchFirst(textBoxAutSearch.Text); break; case 2: aAuthor = AuthorDA.SearchLast(textBoxAutSearch.Text); break; } if (aAuthor == null) { MessageBox.Show("Author not found!", "Not found!"); textBoxAutSearch.Clear(); textBoxAutSearch.Focus(); return; } AuthorDA.ListSearchResult(aAuthor, listViewAuthor); return; } MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; }