private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (doSelectedRow)
     {
         string pesel      = selectedRow.Cells["PESEL"].Value.ToString();
         int    idEmployee = db.Employees
                             .First(check => check.PESEL == pesel).IdEmployee;
         SafetyTraining safetyTraining = db.SafetyTrainings
                                         .First(check => check.IdEmployee == idEmployee);
         safetyTraining.TrainingDate = datePickerControlDate.Value;
         db.SaveChanges();
         doSelectedRow = false;
         MessageBox.Show("Zmiany zostały zapisane!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
         dataGVOshTraining.DataSource = db.ViewOshTrainings
                                        .Where(vOsh => vOsh.Dział == domainUpDownDepartmentName.Text).ToList();
     }
     else
     {
         MessageBox.Show("Zaznacz wiersz wybranego pracownika!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void btnAddTraining_Click(object sender, EventArgs e)
 {
     if (txtBoxPesel.Text == "")
     {
         MessageBox.Show("Wpisz nr PESEL nowego pracownika!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         Employee employee = db.Employees
                             .FirstOrDefault(check => check.PESEL == txtBoxPesel.Text);
         if (employee == null)
         {
             MessageBox.Show("Pracownik o takim nr PESEL nie istnieje!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             int            idEmployee     = employee.IdEmployee;
             SafetyTraining safetyTraining = db.SafetyTrainings
                                             .FirstOrDefault(check => check.IdEmployee == idEmployee);
             if (safetyTraining != null)
             {
                 MessageBox.Show("Pracownik o takim nr PESEL nie jest nowym pracownikiem!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 SafetyTraining newSafetyTraining = new SafetyTraining();
                 newSafetyTraining.IdEmployee   = idEmployee;
                 newSafetyTraining.TrainingDate = dateTimePickerNewTraining.Value;
                 db.SafetyTrainings.Add(newSafetyTraining);
                 MessageBox.Show("Pomyślnie dodano szkolenie dla pracownika!", "Wiadomość", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 db.SaveChanges();
                 txtBoxPesel.Text = " ";
             }
         }
     }
 }