// Добавление записи о сотруднике private void addEmployeeButton_Click(object sender, EventArgs e) { Empoyee empoyee = new Empoyee(); empoyee.FirstName = txtFirstName.Text.Trim(); empoyee.SurName = txtSurname.Text.Trim(); empoyee.Patronymic = txtPatronymic.Text.Trim(); empoyee.DateOfBirth = dateOfBirthPicker.Value; empoyee.DocSeries = txtSeries.Text.Trim(); empoyee.DocNumber = txtNumber.Text.Trim(); empoyee.Position = txtPosition.Text.Trim(); foreach (Department d in context.Department) { if (d.Name == departmentComboBox.SelectedItem.ToString()) { empoyee.DepartmentID = d.ID; } } context.Empoyee.Add(empoyee); context.SaveChanges(); ClearTextEmployees(); UpdateEmployees(); }
// Получение данных об удаляемой записи о сотруднике private void employeeDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (employeeDataGridView.CurrentRow.Index != -1) { deleting_employee.ID = (decimal)employeeDataGridView.CurrentRow.Cells["EID"].Value; using (TestDBEntities tdb = new TestDBEntities()) { deleting_employee = tdb.Empoyee.Where(x => x.ID == deleting_employee.ID).FirstOrDefault(); } deleteEmployeeButton.Enabled = true; } }
// Получение данных о редактируемой записи об сотруднике private void employeeDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (employeeDataGridView.CurrentRow.Index != -1) { updating_employee.ID = (decimal)employeeDataGridView.CurrentRow.Cells["EID"].Value; using (TestDBEntities tdb = new TestDBEntities()) { updating_employee = tdb.Empoyee.Where(x => x.ID == updating_employee.ID).FirstOrDefault(); txtFirstName.Text = updating_employee.FirstName; txtSurname.Text = updating_employee.SurName; txtPatronymic.Text = updating_employee.Patronymic; dateOfBirthPicker.Value = updating_employee.DateOfBirth; txtSeries.Text = updating_employee.DocSeries; txtNumber.Text = updating_employee.DocNumber; txtPosition.Text = updating_employee.Position; } } }