Пример #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
 public void FillTable()
 {
     using (LoveDataContext db = new LoveDataContext())
     {
         Ankets = new BindingList <Anketa>(db.Anketa.Include(a => a.Uvlechenia).ToList());
         Cities = new BindingList <City>(db.City.ToList());
     }
 }
Пример #3
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();
            }
        }
Пример #4
0
        private void buttonShowTheAnk_Click(object sender, EventArgs e)
        {
            if (dataGridViewAnk.SelectedRows.Count == 0)
            {
                MessageBox.Show("Пожалуйста, выберите строку!");
                return;
            }

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


            using (LoveDataContext db = new LoveDataContext())
            {
                AnketaDetails anketaDetails = new AnketaDetails(Cities);
                anketaDetails.comboBoxCity.DataSource = Cities;

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

                anketaDetails.textBoxFIO.Text          = anketa.FIO;
                anketaDetails.comboBoxPol.SelectedItem = anketa.Pol;
                if (anketa.Uvlechenia != null)
                {
                    anketaDetails.checkBoxSport.Checked = (bool)anketa.Uvlechenia.Sport;
                    anketaDetails.checkBoxTrav.Checked  = (bool)anketa.Uvlechenia.Travelling;
                    anketaDetails.checkBoxTV.Checked    = (bool)anketa.Uvlechenia.TV;
                    anketaDetails.checkBoxShop.Checked  = (bool)anketa.Uvlechenia.Shopping;
                }
                anketaDetails.maskedTextBoxPhone.Text = anketa.Phone;
                anketaDetails.comboBoxCity.Text       = anketa.City.CityName;
                anketaDetails.numericUpDownAge.Value  = (decimal)anketa.Age;

                anketaDetails.textBoxFIO.Enabled         = false;
                anketaDetails.comboBoxPol.Enabled        = false;
                anketaDetails.checkBoxSport.Enabled      = false;
                anketaDetails.checkBoxTrav.Enabled       = false;
                anketaDetails.checkBoxTV.Enabled         = false;
                anketaDetails.checkBoxShop.Enabled       = false;
                anketaDetails.maskedTextBoxPhone.Enabled = false;
                anketaDetails.comboBoxCity.Enabled       = false;
                anketaDetails.numericUpDownAge.Enabled   = false;

                anketaDetails.buttonCancel.Visible  = false;
                anketaDetails.buttonAddCity.Visible = false;
                anketaDetails.ShowDialog();
            }
        }
Пример #5
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;
            }
        }