private void deleteProductButton_Click(object sender, EventArgs e) { try { DataGridViewRow selectedRow = ProductsDGV.SelectedRows[0]; var toDelete = Convert.ToInt32(selectedRow.Cells["ProductID"].Value); Product prodToDelete = Inventory.lookupProduct(toDelete); Debug.WriteLine(prodToDelete.AssociatedParts.Count); if (prodToDelete.AssociatedParts.Count() > 0) { MessageBox.Show("Cannot delete a product with associated Parts. Please remove them first."); return; } else if (MessageBox.Show($"are you sure you want to delete {prodToDelete.Name}?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Inventory.removeProduct(toDelete); PartsDGV.DataSource = null; PartsDGV.DataSource = Inventory.AllParts; PartsDGV.Refresh(); } } catch (ArgumentOutOfRangeException) { MessageBox.Show("Please select something to delete."); return; } }
private void button1_Click(object sender, EventArgs e) //Parts Search Button { PartsDGV.ClearSelection(); bool result = false; for (int i = 0; i < Inventory.AllParts.Count; i++) { if (Inventory.AllParts[i].Name.ToUpper().Contains(searchInput.Text.ToUpper())) //should this iterate over the DGV instead? https://www.youtube.com/watch?v=JL30gSE3WaQ { PartsDGV.Rows[i].Selected = true; result = true; } } if (!result) { MessageBox.Show("Search returned no results."); } }
private void delPart_Click(object sender, EventArgs e) { try { DataGridViewRow selectedRow = PartsDGV.SelectedRows[0]; var toDelete = Convert.ToInt32(selectedRow.Cells["PartID"].Value); Classes.Part partToDelete = Inventory.lookupPart(toDelete); if (MessageBox.Show($"are you sure you want to delete {partToDelete.Name}?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Inventory.deletePart(partToDelete); // probably a hack - DGV index errors after deleting a row so im rebuilding the DGV to reflect the changes PartsDGV.DataSource = null; PartsDGV.DataSource = Inventory.AllParts; PartsDGV.Refresh(); } } catch (ArgumentOutOfRangeException) { MessageBox.Show("Please select something to delete."); return; } }