Example #1
0
        private void renBtnAvtor_Click(object sender, EventArgs e)
        {
            if (dataGridAvtors.SelectedRows.Count > 0)
            {
                int  index     = dataGridAvtors.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridAvtors[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }
                Автори      lst    = db.Автори.Find(id);
                AddNewAvtor newAvt = new AddNewAvtor();
                newAvt.Text          = "Редагувати автора";
                newAvt.AddBtn.Text   = "     Редагувати";
                newAvt.textBox1.Text = lst.Автор;
                newAvt.idAvtor.Text  = lst.id.ToString();

                DialogResult result = newAvt.ShowDialog(this);


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

                lst.Автор = newAvt.textBox1.Text;

                db.Entry(lst).State = EntityState.Modified;
                db.SaveChanges();
                refresAvtors();
            }
        }
Example #2
0
        private void addBtnAvror_Click(object sender, EventArgs e)
        {
            AddNewAvtor newAvt = new AddNewAvtor();

            newAvt.Text        = "Новий автор";
            newAvt.AddBtn.Text = "     Додати";

            DialogResult result = newAvt.ShowDialog(this);

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

            Автори lst = new Автори();

            lst.Автор = newAvt.textBox1.Text;
            db.Автори.Add(lst);
            db.SaveChanges();
            refresAvtors();
        }