private void Add_Button_Click(object sender, EventArgs e) { Dish_Description NewElementWindow = new Dish_Description(); NewElementWindow.Text = "Добавление элемента"; if (NewElementWindow.ShowDialog() == DialogResult.OK) { Element NewElement = new Element(NewElementWindow.DishName.Text.Trim(), double.Parse(NewElementWindow.DishWeight.Text), int.Parse(NewElementWindow.DishCostPrice.Text), int.Parse(NewElementWindow.DishPrice.Text)); Entries.Items.Add(NewElement); } }
private void Change_Button_Click(object sender, EventArgs e) { Dish_Description OldElementWindow = new Dish_Description(); OldElementWindow.Text = "Изменение элемента"; Element OldElement = Entries.SelectedItem as Element; OldElementWindow.DishName.Text = OldElement.Name; OldElementWindow.DishWeight.Text = OldElement.Weight.ToString(); OldElementWindow.DishCostPrice.Text = OldElement.Cost_Price.ToString(); OldElementWindow.DishPrice.Text = OldElement.Price.ToString(); if (OldElementWindow.ShowDialog() == DialogResult.OK) { OldElement.Name = OldElementWindow.DishName.Text; OldElement.Weight = double.Parse(OldElementWindow.DishWeight.Text); OldElement.Cost_Price = int.Parse(OldElementWindow.DishCostPrice.Text); OldElement.Price = int.Parse(OldElementWindow.DishPrice.Text); Entries.Items[Entries.SelectedIndex] = OldElement; } }