예제 #1
0
        // редактирование
        private void updateDepartmentButton_Click(object sender, EventArgs e)
        {
            if (gridDepartments.SelectedRows.Count > 0)
            {
                int  index     = gridDepartments.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(gridDepartments[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Department department = microDb.Departments.Find(id);

                AddDepartments addDepartment = new AddDepartments();
                addDepartment.textBox1.Text = department.Title;

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

                department.Title = addDepartment.textBox1.Text;

                microDb.Entry(department).State = EntityState.Modified;
                microDb.SaveChanges();
                MessageBox.Show("Объект обновлен");
            }
        }
예제 #2
0
        // добавление
        private void addDepartmentButton_Click(object sender, EventArgs e)
        {
            AddDepartments addDepartments = new AddDepartments();
            DialogResult   result         = addDepartments.ShowDialog(this);

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

            Department department = new Department();

            department.Title = addDepartments.textBox1.Text;

            microDb.Departments.Add(department);
            microDb.SaveChanges();
            MessageBox.Show("Новый объект добавлен");
        }