Esempio n. 1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     using (OlympicsEntities3 db = new OlympicsEntities3())
     {
         if ((sender as Button).Name.ToString() == "btnDeleteCountry")
         {
             if (dataGridCountry.SelectedRows.Count > 0)
             {
                 int     index   = dataGridCountry.SelectedRows[0].Index;
                 int     id      = Convert.ToInt32(dataGridCountry[0, index].Value);
                 Country country = db.Country.Find(id);
                 db.Country.Remove(country);
                 db.SaveChanges();
                 Fill(dataGridCountry);
             }
             SelectRefresh(cbCountryS);
             SelectRefresh(cbCountryO);
         }
         else if ((sender as Button).Name.ToString() == "btnDeleteSport")
         {
             if (dataGridSport.SelectedRows.Count > 0)
             {
                 int    index  = dataGridSport.SelectedRows[0].Index;
                 int    id     = Convert.ToInt32(dataGridSport[0, index].Value);
                 Sports sports = db.Sports.Find(id);
                 db.Sports.Remove(sports);
                 db.SaveChanges();
                 Fill(dataGridSport);
             }
             SelectRefresh(cbSportS);
         }
         else if ((sender as Button).Name.ToString() == "btnDeleteAthletes")
         {
             if (dataGridAthletes.SelectedRows.Count > 0)
             {
                 int      index    = dataGridAthletes.SelectedRows[0].Index;
                 int      id       = Convert.ToInt32(dataGridAthletes[0, index].Value);
                 Athletes athletes = db.Athletes.Find(id);
                 db.Athletes.Remove(athletes);
                 db.SaveChanges();
                 Fill(dataGridAthletes);
             }
             SelectRefresh(cbAthleteO);
         }
         else if ((sender as Button).Name.ToString() == "btnDeleteResult")
         {
             if (dataGridResult.SelectedRows.Count > 0)
             {
                 int     index   = dataGridResult.SelectedRows[0].Index;
                 int     id      = Convert.ToInt32(dataGridResult[0, index].Value);
                 Results results = db.Results.Find(id);
                 db.Results.Remove(results);
                 db.SaveChanges();
                 Fill(dataGridResult);
             }
         }
     }
 }
Esempio n. 2
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (OlympicsEntities3 db = new OlympicsEntities3())
     {
         if ((sender as Button).Name.ToString() == "btnAddCountry")
         {
             if (flagCountry != true)
             {
                 Country country = new Country {
                     Country1 = txtCountryC.Text.ToString()
                 };
                 db.Country.Add(country);
             }
             else
             {
                 flagCountry = false;
                 int index = dataGridCountry.CurrentRow.Index;
                 int id    = Convert.ToInt32(dataGridCountry[0, index].Value);
                 db.Country.Find(id).Country1 = txtCountryC.Text.ToString();
             }
             txtCountryC.Text = null;
             db.SaveChanges();
             Fill(dataGridCountry);
             SelectRefresh(cbCountryS);
             SelectRefresh(cbCountryO);
         }
         else if ((sender as Button).Name.ToString() == "btnAddSport")
         {
             if (flagSport != true)
             {
                 Sports sport = new Sports {
                     ТNameSport = txtSportS.Text.ToString()
                 };
                 db.Sports.Add(sport);
             }
             else
             {
                 flagSport = false;
                 int index = dataGridSport.CurrentRow.Index;
                 int id    = Convert.ToInt32(dataGridSport[0, index].Value);
                 db.Sports.Find(id).ТNameSport = txtSportS.Text.ToString();
             }
             txtSportS.Text = null;
             db.SaveChanges();
             Fill(dataGridSport);
             SelectRefresh(cbSportS);
         }
         else if ((sender as Button).Name.ToString() == "btnAddAthletes")
         {
             if (flagAthlete != true)
             {
                 Athletes athletes = new Athletes();
                 athletes.FirstName = txtFirstName.Text.ToString();
                 athletes.LastName  = txtLastName.Text.ToString();
                 athletes.IDCountry = Convert.ToInt32(cbCountryS.SelectedValue);
                 athletes.IDSport   = Convert.ToInt32(cbSportS.SelectedValue);
                 athletes.Data      = dpBirthday.Value;
                 athletes.IDPicture = lwPicture.FocusedItem.Index + 1;
                 db.Athletes.Add(athletes);
             }
             else
             {
                 flagAthlete = false;
                 int index = dataGridAthletes.CurrentRow.Index;
                 int id    = Convert.ToInt32(dataGridAthletes[0, index].Value);
                 db.Athletes.Find(id).FirstName = txtFirstName.Text.ToString();
                 db.Athletes.Find(id).LastName  = txtLastName.Text.ToString();
                 db.Athletes.Find(id).IDCountry = Convert.ToInt32(cbCountryS.SelectedValue);
                 db.Athletes.Find(id).IDSport   = Convert.ToInt32(cbSportS.SelectedValue);
                 db.Athletes.Find(id).Data      = dpBirthday.Value;
             }
             txtFirstName.Text = null;
             txtLastName.Text  = null;
             db.SaveChanges();
             Fill(dataGridAthletes);
             SelectRefresh(cbAthleteO);
         }
         else if ((sender as Button).Name.ToString() == "btnAddResult")
         {
             if (flagResult != true)
             {
                 Results result = new Results();
                 result.IDCountry        = Convert.ToInt32(cbCountryO.SelectedValue);
                 result.Year             = Convert.ToInt32(txtYear.Text);
                 result.City             = txtCity.Text.ToString();
                 result.IDAthlete        = Convert.ToInt32(cbAthleteO.SelectedValue);
                 result.IDMedal          = Convert.ToInt32(cbMedal.SelectedValue);
                 result.IDTypeOfOlympiad = Convert.ToInt32(cbType.SelectedValue);
                 db.Results.Add(result);
             }
             else
             {
                 int index = dataGridResult.CurrentRow.Index;
                 int id    = Convert.ToInt32(dataGridResult[0, index].Value);
                 db.Results.Find(id).IDCountry        = Convert.ToInt32(cbCountryO.SelectedValue);
                 db.Results.Find(id).City             = txtCity.Text.ToString();
                 db.Results.Find(id).Year             = Convert.ToInt32(txtYear.Text);
                 db.Results.Find(id).IDAthlete        = Convert.ToInt32(cbAthleteO.SelectedValue);
                 db.Results.Find(id).IDMedal          = Convert.ToInt32(cbMedal.SelectedValue);
                 db.Results.Find(id).IDTypeOfOlympiad = Convert.ToInt32(cbType.SelectedValue);
             }
             txtYear.Text = null;
             txtCity.Text = null;
             db.SaveChanges();
             Fill(dataGridResult);
         }
     }
 }