/// <summary> /// When the Add Electronics button is clicked, open up a new form /// and then repopulate the list when it is closed. /// </summary> private void addElectCmd_Click(object sender, EventArgs e) { addElectFrm addForm = new addElectFrm(); addForm.ShowDialog(); List <Electronic> allElectronics = ElectronicDb.GetAllElectronics(); populateList(allElectronics); }
/// <summary> /// When the Update Electronic button is pressed, open up a new form /// with the information of that electronic already populated. The user may /// then update any information regarding the electronic. After closing, /// the listbox is once again repopulated. Displays an error /// message if there is no electronic selected. /// </summary> private void updateElectCmd_Click(object sender, EventArgs e) { if (productLstBox.SelectedIndex < 0) { MessageBox.Show("You must choose a product to update."); return; } Electronic electToUpdate = productLstBox.SelectedItem as Electronic; addElectFrm updateForm = new addElectFrm(electToUpdate); updateForm.ShowDialog(); populateList(ElectronicDb.GetAllElectronics()); }
/// <summary> /// When the Delete Electronic button is pressed, a message box is /// presented that prompts the user whether to actually delete the electronic or not. /// If yes is clicked, then the electronic is deleted from the database. Once again, /// the listbox is repopulated if the user clicks yes. Displays an error message if /// there is no electronic selected. /// </summary> private void deleteElectCmd_Click(object sender, EventArgs e) { if (productLstBox.SelectedIndex < 0) { MessageBox.Show("You must select a product to delete."); return; } Electronic elecToDelete = productLstBox.SelectedItem as Electronic; DialogResult result = MessageBox.Show( text: $"Are you sure you want to delete {elecToDelete.ProductId}:{elecToDelete.Manufacturer}:{elecToDelete.Name}", caption: "Delete?", buttons: MessageBoxButtons.YesNo, icon: MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ElectronicDb.Delete(elecToDelete.ProductId); populateList(ElectronicDb.GetAllElectronics()); } }
/// <summary> /// When the form loads, call a method to get all the electronics from the database /// and populate the listbox with them. /// </summary> private void MainForm_Load(object sender, EventArgs e) { List <Electronic> allElectronics = ElectronicDb.GetAllElectronics(); populateList(allElectronics); }