示例#1
0
 private bool TryRemoveUncheckedProjects()
 {
     foreach (var projectItem in ProjectListBox.Items)
     {
         if (ProjectListBox.CheckedItems.Contains(projectItem))
         {
             continue;
         }
         if (!RelationProjectEmployeeRepo.IsEmployeeOnProject(OldOib, projectItem.ToString().GetProjectName())
             )
         {
             continue;
         }
         if (RelationProjectEmployeeRepo.TryRemove(
                 RelationProjectEmployeeRepo.GetRelation(OldOib, projectItem.ToString().GetProjectName())))
         {
             continue;
         }
         var lastEmployeeError = new ErrorForm($"{NameTextBox.Text} could not be removed from project {projectItem.ToString().GetProjectName()}\n" +
                                               "He is the last employee on that project");
         lastEmployeeError.ShowDialog();
         return(false);
     }
     return(true);
 }
示例#2
0
        private bool CheckForErrors()
        {
            if (string.IsNullOrWhiteSpace(NameTextBox.Text))
            {
                new ErrorForm("You are missing some required fields!").ShowDialog();
                return(true);
            }

            if (_checkedEmployeesOibList.Count == 0)
            {
                new ErrorForm("A project must have at least one employee!").ShowDialog();
                return(true);
            }

            if (IsAdd)
            {
                OldName = NameTextBox.Text;
                if (ProjectRepo.GetProjectByName(OldName) != null)
                {
                    var existingProjectError = new ErrorForm("A project with that name already exists!");
                    existingProjectError.ShowDialog();
                    return(true);
                }
            }
            else
            {
                if (OldName != NameTextBox.Text && ProjectRepo.GetProjectByName(NameTextBox.Text) != null)
                {
                    var existingProjectError = new ErrorForm("A project with that name already exists!");
                    existingProjectError.ShowDialog();
                    return(true);
                }
            }

            if (StartDatePicker.Value <= EndDatePicker.Value)
            {
                return(false);
            }
            var dateError = new ErrorForm("A project cannot end before it has started!");

            dateError.ShowDialog();
            return(true);
        }
示例#3
0
        private static void TryDelete(Employee toRemove)
        {
            var errorCount = 0;

            foreach (var project in RelationProjectEmployeeRepo.GetProjectsByEmployee(toRemove.Oib))
            {
                if (RelationProjectEmployeeRepo.TryRemove(
                        RelationProjectEmployeeRepo.GetRelation(toRemove.Oib, project.Name)))
                {
                    continue;
                }
                errorCount++;
                var lastEmployeeOnProjectError = new ErrorForm($"Employee {toRemove.Name} {toRemove.LastName} could not be deleted!\nHe is the last employee on one or more projects!");
                lastEmployeeOnProjectError.ShowDialog();
                break;
            }
            if (errorCount == 0)
            {
                EmployeeRepo.Remove(toRemove);
            }
        }
示例#4
0
 private void AddProjectsToEmployee(IEnumerable <string> projectNameListSource)
 {
     foreach (var projectName in projectNameListSource)
     {
         if (RelationProjectEmployeeRepo.IsEmployeeOnProject(OldOib, projectName))
         {
             continue;
         }
         var addHours = new AddHoursForm(projectName, NameTextBox.Text, true);
         addHours.ShowDialog();
         if (addHours.HoursToAdd == 0)
         {
             var hoursError =
                 new ErrorForm(
                     $"Project {projectName} could not be added!\nAn employee cannot work 0 hours on a project!");
             hoursError.ShowDialog();
             continue;
         }
         RelationProjectEmployeeRepo.TryAdd(projectName, OldOib, addHours.HoursToAdd);
     }
 }
示例#5
0
        private bool CheckForErrors()
        {
            if (string.IsNullOrWhiteSpace(NameTextBox.Text) ||
                string.IsNullOrWhiteSpace(LastNameTextBox.Text) ||
                string.IsNullOrWhiteSpace(OibTextBox.Text) ||
                string.IsNullOrWhiteSpace(PositionComboBox.Text))
            {
                new ErrorForm("You are missing some required fields!").ShowDialog();
                return(true);
            }

            if (!OibTextBox.Text.IsOibValid())
            {
                new ErrorForm("That is not a valid OIB!").ShowDialog();
                return(true);
            }

            if (IsAdd)
            {
                OldOib = OibTextBox.Text;
                if (EmployeeRepo.GetEmployeeByOib(OldOib) == null)
                {
                    return(false);
                }
                var existingEmployeeError = new ErrorForm("An employee with that OIB already exists!");
                existingEmployeeError.ShowDialog();
                return(true);
            }
            else
            {
                if (OldOib == OibTextBox.Text || EmployeeRepo.GetEmployeeByOib(OibTextBox.Text) == null)
                {
                    return(false);
                }
                var existingEmployeeError = new ErrorForm("An employee with that OIB already exists!");
                existingEmployeeError.ShowDialog();
                return(true);
            }
        }