Exemple #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);
 }
Exemple #2
0
        private void AddEmployeesToProject()
        {
            var employeesToUncheck = new List <string>();

            foreach (var employeeOib in _checkedEmployeesOibList)
            {
                if (RelationProjectEmployeeRepo.IsEmployeeOnProject(employeeOib, OldName))
                {
                    continue;
                }
                var addHours = new AddHoursForm(NameTextBox.Text, EmployeeRepo.GetEmployeeByOib(employeeOib).Name, false);
                addHours.ShowDialog();
                if (addHours.HoursToAdd == 0)
                {
                    var hoursError =
                        new ErrorForm(
                            $"Employee {EmployeeRepo.GetEmployeeByOib(employeeOib).Name} could not be added!\nAn employee cannot work 0 hours on a project!");
                    hoursError.ShowDialog();
                    employeesToUncheck.Add(employeeOib);
                    continue;
                }
                RelationProjectEmployeeRepo.TryAdd(OldName, employeeOib, addHours.HoursToAdd);
            }
            UncheckEmployees(employeesToUncheck);
        }
Exemple #3
0
        private static void SetEmployeeProjects(ListViewItem destination, Employee projectSource)
        {
            var projectsEnded    = 0;
            var projectsActive   = 0;
            var projectsUpcoming = 0;

            foreach (var project in RelationProjectEmployeeRepo.GetProjectsByEmployee(projectSource.Oib))
            {
                if (project.HasEnded())
                {
                    projectsEnded++;
                }
                if (project.HasStarted() && !project.HasEnded())
                {
                    projectsActive++;
                }
                if (!project.HasStarted())
                {
                    projectsUpcoming++;
                }
            }

            destination.SubItems.Add(projectsEnded.ToString());
            destination.SubItems.Add(projectsActive.ToString());
            destination.SubItems.Add(projectsUpcoming.ToString());
        }
Exemple #4
0
 private static void AddEmployeeSubItems(ListViewItem destination, Employee source)
 {
     destination.SubItems.Add(source.LastName);
     destination.SubItems.Add($"{source.DateOfBirth:d}");
     destination.SubItems.Add(source.Oib);
     destination.SubItems.Add(source.Position.ToString());
     destination.SubItems.Add(RelationProjectEmployeeRepo.EmployeeThisWeeksWorkHours(source.Oib).ToString());
 }
Exemple #5
0
 private static void Delete(Project toDelete)
 {
     ProjectRepo.Remove(toDelete);
     foreach (var employee in RelationProjectEmployeeRepo.GetEmployeesOnProject(toDelete.Name))
     {
         RelationProjectEmployeeRepo.Remove(RelationProjectEmployeeRepo.GetRelation(employee.Oib, toDelete.Name));
     }
 }
Exemple #6
0
 private void UpdateProjectName()
 {
     foreach (var relation
              in RelationProjectEmployeeRepo.GetAllRelations())
     {
         if (relation.NameOfProject == OldName)
         {
             relation.NameOfProject = NameTextBox.Text;
         }
     }
 }
Exemple #7
0
 private void UpdateOib()
 {
     foreach (var relation
              in RelationProjectEmployeeRepo.GetAllRelations())
     {
         if (relation.Oib == OldOib)
         {
             relation.Oib = OibTextBox.Text;
         }
     }
 }
Exemple #8
0
 private void CheckEmployeesOnProject(string projectName)
 {
     foreach (var employee in RelationProjectEmployeeRepo.GetEmployeesOnProject(projectName))
     {
         for (var i = 0; i < EmployeeListBox.Items.Count; i++)
         {
             if (EmployeeListBox.Items[i].ToString().GetOib() != employee.ToString().GetOib())
             {
                 continue;
             }
             EmployeeListBox.SetItemChecked(i, true);
             break;
         }
     }
 }
Exemple #9
0
 private static void SetEmployeeBackColor(ListViewItem destination, Employee hoursSource)
 {
     if (RelationProjectEmployeeRepo.EmployeeThisWeeksWorkHours(hoursSource.Oib) > 40)
     {
         destination.BackColor = Color.Red;
     }
     else if (RelationProjectEmployeeRepo.EmployeeThisWeeksWorkHours(hoursSource.Oib) < 30)
     {
         destination.BackColor = Color.Goldenrod;
     }
     else
     {
         destination.BackColor = Color.MediumSeaGreen;
     }
 }
Exemple #10
0
 private void CheckProjectsByEmployee(string employeeOib)
 {
     foreach (var project in RelationProjectEmployeeRepo.GetProjectsByEmployee(employeeOib))
     {
         for (var i = 0; i < ProjectListBox.Items.Count; i++)
         {
             if (ProjectListBox.Items[i].ToString().GetProjectName() != project.ToString().GetProjectName())
             {
                 continue;
             }
             ProjectListBox.SetItemChecked(i, true);
             break;
         }
     }
 }
Exemple #11
0
 private void RemoveUncheckedEmployees()
 {
     foreach (var employeeItem in EmployeeListBox.Items)
     {
         if (EmployeeListBox.CheckedItems.Contains(employeeItem))
         {
             continue;
         }
         if (RelationProjectEmployeeRepo.IsEmployeeOnProject(employeeItem.ToString().GetOib(),
                                                             OldName))
         {
             RelationProjectEmployeeRepo.Remove(
                 RelationProjectEmployeeRepo.GetRelation(employeeItem.ToString().GetOib(),
                                                         OldName));
         }
     }
 }
Exemple #12
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);
            }
        }
Exemple #13
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);
     }
 }
Exemple #14
0
        private void RefreshProjectDetails()
        {
            var detailsText = "";

            foreach (var project in ProjectsToShow)
            {
                detailsText += $"{project.Name}\n{project.StartOfProject:d} - {project.EndOfProject:d}\n\n";

                foreach (var position in Enum.GetNames(typeof(Position)))
                {
                    var positionEmployees = new List <Employee>();
                    foreach (var employee in RelationProjectEmployeeRepo.GetEmployeesOnProject(project.Name))
                    {
                        if (employee.Position.ToString() == position)
                        {
                            positionEmployees.Add(employee);
                        }
                    }

                    if (positionEmployees.Count == 0)
                    {
                        continue;
                    }

                    detailsText += $"{position} ({positionEmployees.Count})\n";

                    foreach (var employee in positionEmployees)
                    {
                        detailsText +=
                            $"\t{employee.Name} {employee.LastName} ({RelationProjectEmployeeRepo.GetRelation(employee.Oib, project.Name).HoursOfWork} hours)\n";
                    }

                    detailsText += "\n";
                }

                detailsText += "\n";
            }

            ProjectDetailsTextBox.Text = detailsText;
        }