Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e) //редактируем задачу
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Task task = db.Tasks.Find(id);

                TaskEditing tForm = new TaskEditing();
                tForm.textBox1.Text = task.Name;

                DialogResult result = tForm.ShowDialog(this);

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

                task.Name = tForm.textBox1.Text;

                db.Entry(task).State = EntityState.Modified;
                db.SaveChanges();

                MessageBox.Show("Задача обновлена.");
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e) //добавляем задачу
        {
            TaskEditing tForm = new TaskEditing();

            DialogResult result = tForm.ShowDialog(this);

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

            Task task = new Task();

            task.Name = tForm.textBox1.Text;

            db.Tasks.Add(task);
            db.SaveChanges();

            MessageBox.Show("Новая задача добавлена.");
        }