private void btnAddOrUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txt_BookIDNum.Text) || string.IsNullOrWhiteSpace(txt_Title.Text) || string.IsNullOrWhiteSpace(txt_Pages.Text) || string.IsNullOrWhiteSpace(txt_Publisher.Text) || string.IsNullOrWhiteSpace(txt_CopyrightYear.Text)) { MessageBox.Show("Incomplete Information!\nPlease enter values in textboxes that has (*) indicator."); } else { if (bk.CheckValidCopyrightYear() == false) { MessageBox.Show("Invalid Copyright Year!"); } else { if (btnAddOrUpdate.Text == "ADD") { bk.BookIDNumber = txt_BookIDNum.Text; bk.BookType = cmbBookType.Text; bk.ISBN = txt_ISBN.Text; bk.AccessionNumber = int.Parse(txt_AccessionNumber.Text); bk.CallNumber = txt_CallNumber.Text; bk.DateReceived = DateTime.Parse(dtp_DateReceived.Text); bk.Title = txt_Title.Text; bk.Author = txt_Author.Text; bk.Publisher = txt_Publisher.Text; bk.CopyrightYear = int.Parse(txt_CopyrightYear.Text); bk.Edition = txt_Edition.Text; bk.Volume = txt_Volume.Text; bk.Pages = int.Parse(txt_Pages.Text); bk.Status = cmb_Status.Text; bk.Remarks = txt_Remarks.Text; bk.AddRecord(); using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "JPEG|*.jpg", ValidateNames = true }) { if (sfd.ShowDialog() == DialogResult.OK) { pb_QRBook.Image.Save(sfd.FileName, ImageFormat.Jpeg); } } dgvBook.DataSource = db.sp_ViewBook();; MessageBox.Show("Sucessfully Added!"); ClearText(); EnableTextboxes(); txt_BookIDNum.Text = bk.GenerateBookIDNum(); cmbBookType.Text = "References"; } else { BookCopy bc = new BookCopy(txt_BookIDNum.Text); bc.Show(); this.Hide(); } } } }
private void btnAddOrAddBookCopy_Click(object sender, EventArgs e) { bk.BookIDNumber = txt_BookIDNum.Text; bk.BookType = cmbBookType.selectedValue; bk.ISBN = txt_ISBN.Text; if (txt_AccessionNumber.Text != "") { bk.AccessionNumber = int.Parse(txt_AccessionNumber.Text); } bk.CallNumber = txt_CallNumber.Text; bk.DateReceived = DateTime.Parse(dtp_DateReceived.Text); bk.Title = txt_Title.Text; bk.Author = txt_Author.Text; bk.Publisher = txt_Publisher.Text; if (txt_CopyrightYear.Text != "") { bk.CopyrightYear = int.Parse(txt_CopyrightYear.Text); } bk.Edition = txt_Edition.Text; bk.Volume = txt_Volume.Text; if (txt_Pages.Text != "") { bk.Pages = int.Parse(txt_Pages.Text); } bk.Status = cmb_Status.selectedValue; bk.Remarks = txt_Remarks.Text; if (btnAddOrAddBookCopy.Text == "ADD") { if (bk.HasNullValues() == true) { MessageBox.Show("Incomplete Information!\nPlease enter values in textboxes that has (*) indicator."); } else { if (bk.DoesBookCopyExist("ISBN", txt_ISBN.Text) == true) { MessageBox.Show("Book already exist in the database. Please add a copy instead."); dgvBook.DataSource = db.sp_SearchBook("ISBN", txt_ISBN.Text); AssignValuesToTextBox(); } else { bk.AddRecord(); dgvBook.DataSource = db.sp_ViewBook();; MessageBox.Show("Sucessfully Added!"); ClearText(); txt_BookIDNum.Text = bk.GenerateIDNumber(); cmbBookType.selectedIndex = 0; gb_Copy.Visible = true; btnUpdate.Visible = false; lbl_NumCopies.Visible = false; } } } else { BookCopy bc = new BookCopy(usertype, txt_BookIDNum.Text); bc.Show(); this.Hide(); } }