示例#1
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (dataGridViewAnk.SelectedRows.Count == 0)
            {
                MessageBox.Show("Пожалуйста, выберите строку!");
                return;
            }

            int rowIndex = dataGridViewAnk.SelectedRows[0].Index;



            using (LoveDataContext db = new LoveDataContext())
            {
                Anketa anketa = db.Anketa.Find(Convert.ToInt32(dataGridViewAnk[0, rowIndex].Value));

                DialogResult dialogResult = MessageBox.Show($"Вы увены, что хотите удалить анкету {anketa.FIO}?", "", MessageBoxButtons.OKCancel);

                if (dialogResult != DialogResult.OK)
                {
                    return;
                }
                db.Anketa.Remove(anketa);
                db.SaveChanges();
            }

            FillTable();
            ShowAll();
        }
示例#2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            using (LoveDataContext db = new LoveDataContext())
            {
                BindingList <City> CitiesForNewAnketa = new BindingList <City>();
                foreach (var c in Cities)
                {
                    if (c.CityName != "Любой")
                    {
                        CitiesForNewAnketa.Add(c);
                    }
                }
                AnketaDetails anketaDetails = new AnketaDetails(CitiesForNewAnketa);
                anketaDetails.comboBoxCity.DataSource = CitiesForNewAnketa;
                DialogResult dialogResult = anketaDetails.ShowDialog();

                if (dialogResult != DialogResult.OK)
                {
                    return;
                }

                string city = (anketaDetails.comboBoxCity.SelectedItem as City).CityName;



                Anketa anketa = new Anketa
                {
                    FIO        = anketaDetails.textBoxFIO.Text,
                    Pol        = anketaDetails.comboBoxPol.SelectedItem.ToString(),
                    Uvlechenia = new Uvlechenia
                    {
                        Sport      = anketaDetails.checkBoxSport.Checked,
                        Travelling = anketaDetails.checkBoxTrav.Checked,
                        TV         = anketaDetails.checkBoxTV.Checked,
                        Shopping   = anketaDetails.checkBoxShop.Checked
                    },
                    Phone = anketaDetails.maskedTextBoxPhone.Text.ToString(),
                    City  = db.City.Where(c => c.CityName == city).FirstOrDefault(),
                    Age   = (int)anketaDetails.numericUpDownAge.Value
                };

                db.Anketa.Add(anketa);
                db.SaveChanges();

                FillTable();
                ShowAll();
            }
        }
示例#3
0
        private void buttonAddCity_Click(object sender, EventArgs e)
        {
            CityAdding   cityAdding   = new CityAdding();
            DialogResult dialogResult = cityAdding.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                return;
            }

            using (LoveDataContext db = new LoveDataContext())
            {
                db.City.Add(new City {
                    CityName = cityAdding.textBoxCity.Text
                });
                db.SaveChanges();

                cities = new BindingList <City>(db.City.ToList());
                comboBoxCity.DataSource = cities;
            }
        }