private void btnDeleteCopy_Click(object sender, EventArgs e) { Copy c = new Copy(); c.CopyNumber = Convert.ToInt32(txtCopyNumber.Text); CopyDAO.Delete(c); dgvCopies.DataSource = CopyDAO.GetDataTable(Convert.ToInt32(txtBookNumber1.Text)); MessageBox.Show("Delete Successful"); display(5); }
private void btnCopyDelete_Click(object sender, EventArgs e) { if (!isSelected()) { return; } int copyNumber = (int)dataGridView2.Rows[0].Cells["copyNumber"].Value; DialogResult dr = MessageBox.Show(String.Format("Do you want to delete this copy number {0}?", copyNumber), "Confirm deleting", MessageBoxButtons.YesNo); if (dr == DialogResult.No) { return; } CopyDAO.Delete(copyNumber); ViewCopies(); }
//button select or delete on grid view protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { //must add inside or else exception index=-1(default) occurs int index = Int32.Parse(e.CommandArgument.ToString()); if (copyExist == false) { GridViewRow gvRow = GridView1.Rows[index]; txtTitle.Text = gvRow.Cells[3].Text; //title //default blank in gridview = txtAuthor.Text = gvRow.Cells[4].Text.Trim().Equals(" ") ? "" : gvRow.Cells[4].Text; //author txtPublisher.Text = gvRow.Cells[5].Text.Trim().Equals(" ") ? "" : gvRow.Cells[5].Text; //publisher bo = new Book(); bo.BookNumber = Int32.Parse(gvRow.Cells[2].Text.ToString()); //book number } else { GridViewRow gridViewRow = GridView2.Rows[index]; txtTypecopy.Text = gridViewRow.Cells[5].Text.ToString(); // type txtPrice.Text = gridViewRow.Cells[6].Text.Equals(" ") ? "" : gridViewRow.Cells[6].Text; // price co = new Copy(); co.CopyNumber = Int32.Parse(gridViewRow.Cells[2].Text.ToString()); } } //delete if (e.CommandName == "Del") { int index = Int32.Parse(e.CommandArgument.ToString()); if (copyExist == false) { GridViewRow gvRow = GridView1.Rows[index]; int bookNum = Int32.Parse(gvRow.Cells[2].Text.ToString()); if (BookDAO.Delete(bookNum)) { reload(); } else { return; } } else { GridViewRow gridViewRow = GridView2.Rows[index]; int copyNum = Int32.Parse(gridViewRow.Cells[2].Text.ToString()); if (CopyDAO.Delete(copyNum)) { reload(); } else { return; } } } }