예제 #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 updateProfileButton_Click(object sender, EventArgs e)
        {
            if (gridProfiles.SelectedRows.Count > 0)
            {
                int  index     = gridProfiles.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(gridProfiles[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                ProfileService profile = microDb.ProfileServices.Find(id);

                AddProfiles addProfile = new AddProfiles();
                addProfile.addProfileLastName.Text  = profile.FirstName;
                addProfile.addProfileFirstName.Text = profile.LastName;

                List <Department> departments = microDb.Departments.ToList();
                addProfile.chooseProfileDepartment.DataSource    = departments;
                addProfile.chooseProfileDepartment.ValueMember   = "Id";
                addProfile.chooseProfileDepartment.DisplayMember = "Title";

                if (profile.Department != null)
                {
                    addProfile.chooseProfileDepartment.SelectedValue = profile.Department.Id;
                }

                DialogResult result = addProfile.ShowDialog(this);

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

                profile.FirstName  = addProfile.addProfileFirstName.Text;
                profile.LastName   = addProfile.addProfileLastName.Text;
                profile.Department = (Department)addProfile.chooseProfileDepartment.SelectedItem;

                microDb.Entry(profile).State = EntityState.Modified;
                microDb.SaveChanges();

                MessageBox.Show("Object was updated");
            }
        }