Beispiel #1
0
 private void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     if (selectedButton == App.SelectedButton.Add)
     {
         if (!Globals.isEverythingNotNull <Employee>(EmployeeData))
         {
             MessageBox.Show("Fill all fields", "Don't mess with me!!!", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         try
         {
             Employee addEmployee = new Employee();
             Globals.copyObject(EmployeeData, addEmployee);
             FactoryBL.BL_instance.addEmployee(addEmployee);
             IdComboBox.Items.Clear();
             foreach (Employee emp in FactoryBL.BL_instance.getAllEmployees())
             {
                 IdComboBox.Items.Add(emp.Id);
             }
         }
         catch (Exception err)
         {
             MessageBox.Show(err.Message, "Don't mess with me!!!", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
     }
     if (selectedButton == App.SelectedButton.Edit)
     {
         if (!Globals.isEverythingNotNull <Employee>(EmployeeData))
         {
             MessageBox.Show("Fill all fields", "Don't mess with me!!!", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         try
         {
             Employee oldEmployee  = FactoryBL.BL_instance.getAllEmployees().Find(x => x.Id == EmployeeData.Id);
             Employee editEmployee = new Employee();
             Globals.copyObject <Employee>(EmployeeData, editEmployee);
             FactoryBL.BL_instance.updateEmployee(editEmployee, oldEmployee);
         }
         catch (Exception err)
         {
             MessageBox.Show(err.Message, "Don't mess with me!!!", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
     }
     if (selectedButton == App.SelectedButton.Remove)
     {
         if (EmployeeData.Id == null)
         {
             MessageBox.Show("Fill ID", "Don't mess with me!!!", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         try
         {
             Employee removeEmployee = new Employee();
             Globals.copyObject(EmployeeData, removeEmployee);
             FactoryBL.BL_instance.removeEmployee(removeEmployee);
             IdComboBox.Items.Clear();
             foreach (Employee emp in FactoryBL.BL_instance.getAllEmployees())
             {
                 IdComboBox.Items.Add(emp.Id);
             }
         }
         catch (Exception err)
         {
             MessageBox.Show(err.Message, "Don't mess with me!!!", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
     }
     selectedButton        = App.SelectedButton.None;
     IdComboBox.IsEditable = false;
     Globals.swapGridsVisibility(SaveCancelGrid, AddEditRemoveGrid);
     Globals.enableFields(EmployeesPropertiesGrid, false, null, false);
     Globals.emptyAllFields(EmployeesPropertiesGrid);
 }
 // triggers INotify since copy
 void updateUIContract(BE.Contract newContract)
 => Globals.CopyObject(newContract, UIContract);