private void Add_B_Click(object sender, EventArgs e) { try { Modification_F modification = new Modification_F(true); if (modification.ShowDialog() == DialogResult.OK) { Runner runnerDB = new Runner { Height = Convert.ToDouble(modification.Height_TB.Text.Trim()), Weight = Convert.ToDouble(modification.Weight_TB.Text.Trim()), Age = Convert.ToInt32(modification.Age_TB.Text.Trim()), Name = modification.Name_TB.Text.Trim(), Surname = modification.Surname_TB.Text.Trim(), Ranked = Convert.ToInt32(modification.Ranked_TB.Text.Trim()), }; context.Runners.Add(runnerDB); context.SaveChanges(); Runners.Add(runnerDB); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void Update_B_Click(object sender, EventArgs e) { try { Modification_F modification = new Modification_F(false); Runner runnerDB = Spisok_LB.SelectedItem as Runner; if (runnerDB == null) { throw new Exception("Необходимо выбрать объект"); } modification.Height_TB.Text = runnerDB.Height.ToString(); modification.Weight_TB.Text = runnerDB.Weight.ToString(); modification.Age_TB.Text = runnerDB.Age.ToString(); modification.Name_TB.Text = runnerDB.Name; modification.Surname_TB.Text = runnerDB.Surname; modification.Ranked_TB.Text = runnerDB.Ranked.ToString(); if (modification.ShowDialog() == DialogResult.OK) { Runner runnerContext = Spisok_LB.SelectedItem as Runner; runnerContext.Height = Convert.ToDouble(modification.Height_TB.Text.Trim()); runnerContext.Weight = Convert.ToDouble(modification.Weight_TB.Text.Trim()); runnerContext.Age = Convert.ToInt32(modification.Age_TB.Text.Trim()); runnerContext.Name = modification.Name_TB.Text.Trim(); runnerContext.Surname = modification.Surname_TB.Text.Trim(); runnerContext.Ranked = Convert.ToInt32(modification.Ranked_TB.Text.Trim()); context.SaveChanges(); Runners.Remove(runnerDB); Runners.Add(runnerContext); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }