void btnAdd_Click(object sender, EventArgs e) { using (FormArmourDetails formArmourDetails = new FormArmourDetails()) { formArmourDetails.ShowDialog(); if (formArmourDetails.Armour != null) AddArmour(formArmourDetails.Armour); } }
void btnAdd_Click(object sender, EventArgs e) { using (FormArmourDetails formArmourDetails = new FormArmourDetails()) { formArmourDetails.ShowDialog(); if (formArmourDetails.Armour != null) { AddArmour(formArmourDetails.Armour); } } }
void btnEdit_Click(object sender, EventArgs e) { if (lbDetails.SelectedItem != null) { string detail = lbDetails.SelectedItem.ToString(); string[] parts = detail.Split(','); string entity = parts[0].Trim(); ArmourData data = ItemDataManager.ArmourData[entity]; ArmourData newData = null; using (FormArmourDetails formArmourDetails = new FormArmourDetails()) { formArmourDetails.Armour = data; formArmourDetails.ShowDialog(); if (formArmourDetails.Armour == null) { return; } if (formArmourDetails.Armour.Name == entity) { ItemDataManager.ArmourData[entity] = formArmourDetails.Armour; FillListBox(); return; } newData = formArmourDetails.Armour; } DialogResult result = MessageBox.Show( "Name has changed. Do you want to add a new entry?", "New Entry", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } if (ItemDataManager.ArmourData.ContainsKey(newData.Name)) { MessageBox.Show("Entry already exists. Use Edit to modify the entry."); return; } lbDetails.Items.Add(newData); ItemDataManager.ArmourData.Add(newData.Name, newData); } }
void btnEdit_Click(object sender, EventArgs e) { if (lbDetails.SelectedItem != null) { string detail = lbDetails.SelectedItem.ToString(); string[] parts = detail.Split(','); string entity = parts[0].Trim(); ArmourData data = ItemDataManager.ArmourData[entity]; ArmourData newData = null; using (FormArmourDetails formArmourDetails = new FormArmourDetails()) { formArmourDetails.Armour = data; formArmourDetails.ShowDialog(); if (formArmourDetails.Armour == null) return; if (formArmourDetails.Armour.Name == entity) { ItemDataManager.ArmourData[entity] = formArmourDetails.Armour; FillListBox(); return; } newData = formArmourDetails.Armour; } DialogResult result = MessageBox.Show( "Name has changed. Do you want to add a new entry?", "New Entry", MessageBoxButtons.YesNo); if (result == DialogResult.No) return; if (ItemDataManager.ArmourData.ContainsKey(newData.Name)) { MessageBox.Show("Entry already exists. Use Edit to modify the entry."); return; } lbDetails.Items.Add(newData); ItemDataManager.ArmourData.Add(newData.Name, newData); } }