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()); }
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; } } }
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); } }