private void btnDelete_Click(object sender, EventArgs e) { materialUsedDAL dalMatUsed = new materialUsedDAL(); dalMatUsed.Delete(); DataGridView dgv = dgvItemList; Cursor = Cursors.WaitCursor; // change cursor to hourglass type if (dgv.SelectedRows.Count > 0) { int n = dgv.CurrentCell.RowIndex; DialogResult dialogResult = MessageBox.Show("Are you sure want to delete?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { if (cmbCat.Text.Equals("Part")) { uItem.item_code = dgv.Rows[n].Cells[dalItem.ItemCode].Value.ToString(); trfHistDAL dalTrfHist = new trfHistDAL(); dalTrfHist.Delete(uItem.item_code); bool success = dalItem.Delete(uItem); if (success == true) { //item deleted successfully MessageBox.Show("Item deleted successfully"); uJoin.join_parent_code = uItem.item_code; uJoin.join_child_code = uItem.item_code; dalJoin.itemDelete(uJoin); resetForm(); } else { //Failed to delete item MessageBox.Show("Failed to delete item"); } } else { uMaterial.material_code = dgv.Rows[n].Cells[dalItem.ItemCode].Value.ToString();; bool success = dalMaterial.Delete(uMaterial); if (success) { //item deleted successfully MessageBox.Show("Material deleted successfully"); uItem.item_code = dgv.Rows[n].Cells[dalItem.ItemCode].Value.ToString(); //to-do //update item material to null for all the item using same material //DataTable dtItem = dalItem.itemMaterialSearch(uItem.item_code); bool success2 = dalItem.Delete(uItem); if (success2 == true) { //item deleted successfully MessageBox.Show("Item deleted successfully"); } else { //Failed to delete item MessageBox.Show("Failed to delete item"); } resetForm(); } else { //Failed to delete item MessageBox.Show("Failed to delete material"); } } } } else { MessageBox.Show("Please select a data"); } Cursor = Cursors.Arrow; // change cursor to normal type }