private void btnSaveBook_Click(object sender, EventArgs e) { //Create a new role that the Variable will be added into DataRow newBookrow = DM.dtBook.NewRow(); // if any of the text area is empty then do not write the data and return error message if ((cboAddBookInfoID.Text == "") || (txtAddBookInfoCost.Text == "") || (txtAddBookInfoPrice.Text == "") || (dtpAddBookPublished.Text == "") || (cboAddBookVendorID.Text == "")) { MessageBox.Show("You must type in all feilds", "Error"); } else { newBookrow["BookInfoID"] = cboAddBookInfoID.Text; newBookrow["Cost"] = txtAddBookInfoCost.Text; newBookrow["Price"] = txtAddBookInfoPrice.Text; newBookrow["DatePublished"] = dtpAddBookPublished.Text; newBookrow["VendorID"] = cboAddBookVendorID.Text; //Add the new row to the table DM.dtBook.Rows.Add(newBookrow); currencyManager.EndCurrentEdit(); // Give the user the success message MessageBox.Show("Book added successfully", "Success"); DM.UpdateBook(); } }
private void btnAddBook_Click(object sender, EventArgs e) { try { if (DM.dtClientOrder.Rows[cmClientOrder.Position]["Status"].ToString() == "Current") { DataRow UpdateBookrow = DM.dtBook.Rows[currencyManager.Position]; UpdateBookrow["ClientOrderID"] = dgvClientOrder["ClientOrderID", cmClientOrder.Position].Value; currencyManager.EndCurrentEdit(); DM.UpdateBook(); MessageBox.Show("Book Added Successfully"); } else { MessageBox.Show("Book can only be added to current order"); } } catch (ConstraintException) { MessageBox.Show("Test"); } }