Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
            }
        }