示例#1
0
        private void RedCountryBtn_Click(object sender, EventArgs e)
        {
            int  index     = dataGridCountry.SelectedRows[0].Index;
            int  id        = 0;
            bool converted = Int32.TryParse(dataGridCountry[0, index].Value.ToString(), out id);

            if (converted == false)
            {
                return;
            }
            Країни        lst        = db.Країни.Find(id);
            AddNewCountry newCountry = new AddNewCountry();

            newCountry.Text           = "Редагувати Країну";
            newCountry.button1.Text   = "     Редагувати";
            newCountry.textBox1.Text  = lst.Країна;
            newCountry.idCountry.Text = lst.id.ToString();

            DialogResult result = newCountry.ShowDialog(this);


            if (result == DialogResult.Cancel)
            {
                return;
            }

            lst.Країна = newCountry.textBox1.Text;

            db.Entry(lst).State = EntityState.Modified;
            db.SaveChanges();
            refresCountry();
        }
示例#2
0
        private void DelCountryBtn_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Дійсно хочете видалити?", null, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                int  index     = dataGridCountry.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridCountry[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Країни lst = db.Країни.Find(id);
                db.Країни.Remove(lst);
                db.SaveChanges();
                refresCountry();
            }
        }
示例#3
0
        private void AddCountryBtn_Click(object sender, EventArgs e)
        {
            AddNewCountry newCountry = new AddNewCountry();

            newCountry.Text         = "Новий країна";
            newCountry.button1.Text = "     Додати";

            DialogResult result = newCountry.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Країни lst = new Країни();

            lst.Країна = newCountry.textBox1.Text;
            db.Країни.Add(lst);
            db.SaveChanges();
            refresCountry();
        }