//delete book from the table private void btnDeleteBook_Click(object sender, EventArgs e) { DataRow deleteBookRow = DM.dtBook.Rows[currencyManager.Position]; //check if book was ordered if (txtClientID.Text != "") { MessageBox.Show("You may only delete Books which weren't ordered", "Error"); } else { if (MessageBox.Show("Are you sure want to delete this Book?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { deleteBookRow.Delete(); DM.UpdateBook(); } } }
//Add book to order private void btnAddBook_Click(object sender, EventArgs e) { //check status if (DM.dtClientOrder.Rows[cmClientOrder.Position]["Status"].ToString() == "Current") { int aBookID = Convert.ToInt32(dgvBook.CurrentRow.Cells[0].Value); cmBook.Position = DM.BookView.Find(aBookID); DataRow BookRow = DM.dtBook.Rows[cmBook.Position]; BookRow["ClientOrderID"] = Convert.ToString(DM.dtClientOrder.Rows[cmClientOrder.Position]["ClientOrderID"]); cmBook.EndCurrentEdit(); MessageBox.Show("Book added successfully", "Success"); DM.UpdateBook(); //renewing datagridview with unordered books clearBooks2(); dgvBook.DataSource = null; dgvBook.DataSource = dtStoreBook; } else { MessageBox.Show("Books can only be added to current orders", "Error"); } }