private void EditJewelry(Object parameter) { try { if (SelectedJewelry == string.Empty) { MessageBox.Show("Please choose jewelry."); return; } var editedIndex = JewelryList.FindIndex(x => x.ToString() == SelectedJewelry); Jewelry editedJewelry = JewelryList.Find(x => x.ToString() == SelectedJewelry); if (editedJewelry == null) { MessageBox.Show($"Choose one jewerly from dropdown menu."); return; } editJewelryView.InitJewelryFields(ref editedJewelry); JewelryList.RemoveAt(editedIndex); JewelryListUI.RemoveAt(editedIndex); JewelryList.Add(editedJewelry); JewelryListUI.Add(editedJewelry); CurrentAppScreen = (int)ApplicationScreen.EditJewelry; } catch (Exception ex) { MessageBox.Show($"Could not edit jewerly. Reason: {ex.Message}"); } }
private void DeleteJewelry(object p) { if (string.IsNullOrEmpty(SelectedJewelry)) { MessageBox.Show("Please choose a jewelry from the list."); return; } try { var removalIndex = JewelryList.FindIndex(x => x.ToString() == SelectedJewelry); JewelryList.RemoveAt(removalIndex); JewelryListUI.RemoveAt(removalIndex); MessageBox.Show($"Successfully removed."); } catch (Exception ex) { MessageBox.Show($"Could not remove jewelry. Reason: {ex.Message}"); } }
private void AddJewelry(Object parameter) { try { CurrentJewelryMaterials.RemoveAll(x => !IsMaterialAlterred(x)); if (CurrentJewelryMaterials.Count == 0) { MessageBox.Show("No materials were choosen for this jewelry. Please add some."); return; } if (string.IsNullOrEmpty(JewelryName)) { MessageBox.Show("Please choose some name for your jewelry."); return; } var jewelry = jewelryFactory.NewJewelry(SelectedJewelryType); var visitor = new JewelryVisitor(this); jewelry.Accept(visitor); MessageBox.Show($"Successfully added {jewelry.Name}."); JewelryList.Add(jewelry); JewelryListUI.Add(jewelry); ClearFields(); CurrentJewelryMaterials = null; CurrentJewelryMaterials = new List <Material>(); } catch (Exception ex) { MessageBox.Show($"Can't add jewelry. Reason: {ex.Message}."); } }