コード例 #1
0
        private void Add_Click(object sender, EventArgs e)
        {
            string   datewt = dateTimePicker1.Value.Date.ToShortDateString();
            string   date0  = datewt + " 0:00:00";
            DateTime date;

            DateTime.TryParse(date0, out date);
            if (KoS.SelectedItem != null /*&& Jud.SelectedItem != null && Spo.SelectedItem != null*/)
            {
                KindOfSport kindOfSport = null;
                Boolean     exist       = false;
                //judge = Jud.SelectedItem.ToString();
                //sponsor = Spo.SelectedItem.ToString();
                kindofsport = KoS.SelectedItem.ToString();
                foreach (KindOfSport kind in db.KindsOfSport)
                {
                    if (kind.NameOfSport.Equals(kindofsport))
                    {
                        kindOfSport = kind;
                    }
                }
                Competition newData = new Competition()
                {
                    Date        = date,
                    KindOfSport = kindOfSport,
                };
                foreach (Competition com in db.Competitions)
                {
                    if (com.Date.Equals(newData.Date))
                    {
                        /*if (com.Judges.Equals(newData.Judges))
                         * {
                         *  if (com.Sponsor.Equals(newData.Sponsor))
                         *  {*/
                        if (com.KindOfSport.Equals(newData.KindOfSport))
                        {
                            exist = true;
                            break;
                        }

                        /*}
                         * }*/
                    }
                }
                if (!exist)
                {
                    db.Competitions.Add(newData);
                    db.SaveChanges();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Такое соревнование уже существует.");
                }
            }
            else
            {
                MessageBox.Show(null, "Сначала заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void Add_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Replace(" ", "") != "" && strCategory != "")
            {
                Boolean  exist    = false;
                Category category = null;


                foreach (Category cat in db.Categories)
                {
                    if (cat.Name.Equals(strCategory))
                    {
                        category = cat;
                    }
                }

                KindOfSport newData = new KindOfSport()
                {
                    NameOfSport = textBox1.Text,
                    Category    = category
                };

                foreach (KindOfSport ks in db.KindsOfSport)
                {
                    if (ks.NameOfSport.Equals(newData.NameOfSport))
                    {
                        exist = true;
                        break;
                    }
                }
                if (!exist)
                {
                    db.KindsOfSport.Add(newData);
                    db.SaveChanges();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Такой вид спорта уже существует.");
                }
            }
            else
            {
                MessageBox.Show(null, "Сначала заполните поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
 private void Delete_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count > 0)
     {
         if (MessageBox.Show("Вы действительно хотите удалить выбранный вид спорта?", "Удалить", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             int         id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
             KindOfSport ks = (from KindOfSport in db.KindsOfSport
                               where KindOfSport.Id == id
                               select KindOfSport).FirstOrDefault <KindOfSport>();
             db.KindsOfSport.Remove(ks);
             db.SaveChanges();
             loadData();
         }
     }
     else
     {
         MessageBox.Show("Выделите строку с видом спорта");
     }
 }
コード例 #4
0
        private void Edit_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count >= 1)
            {
                EditKindOfSport form = new EditKindOfSport();
                form.db = db;
                int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);

                KindOfSport ks = (from KindOfSport in db.KindsOfSport
                                  where KindOfSport.Id == id
                                  select KindOfSport).FirstOrDefault <KindOfSport>();
                Category cat = (from KindOfSport in db.KindsOfSport
                                where KindOfSport.Id == id
                                select KindOfSport.Category).FirstOrDefault <Category>();
                form.cat = cat;
                form.ks  = ks;
                form.ShowDialog();
                loadData();
            }
            else
            {
                MessageBox.Show("Выделите строку с видом спорта");
            }
        }