private void comboBoxUsers_SelectedIndexChanged(object sender, EventArgs e) { selectedUser = UserRequsts.GetUserById((int)comboBoxUsers.SelectedValue); ProjectsForUser = ProjectsRequst.GetProjectsByUserId((int)comboBoxUsers.SelectedValue); if (ProjectsForUser != null) { for (int i = 0; i < ProjectsForteamLeader.Count; i++) { for (int j = 0; j < ProjectsForUser.Count; j++) { if (ProjectsForteamLeader[i].ProjectId == ProjectsForUser[j].ProjectId) { commonProjectsInTheList.Add(ProjectsForteamLeader[i]); } } } //var results = ProjectsForteamLeader.Join(ProjectsForUser, ptl => ptl.ProjectId, p => p.ProjectId, (post, meta) => new { Post = post, Meta = meta }); comboBoxProjects.SelectedIndexChanged -= new EventHandler(comboBoxProjects_SelectedIndexChanged); comboBoxProjects.DataSource = commonProjectsInTheList; comboBoxProjects.DisplayMember = "ProjectName"; comboBoxProjects.ValueMember = "ProjectId"; comboBoxProjects.SelectedIndexChanged += comboBoxProjects_SelectedIndexChanged; numericCountHours.Value = 0; // MessageBox.Show("success"); } else { comboBoxProjects.DataSource = null; } }
private void buttonUpdate_Click(object sender, EventArgs e) { workerToProject.Hours = (int)numericCountHours.Value; //update the worker to project with the houers //check if is valid var validationContext = new ValidationContext(workerToProject, null, null); var results = new List <ValidationResult>(); if (Validator.TryValidateObject(workerToProject, validationContext, results, true)) { sumAllActual = 0; flagHours = false; User tmpUser; var kindId = selectedUser.UserKindId; allWorkersToProject = allWorkersToProject.Where(p => p.ProjectId == selectedProject.ProjectId).ToList(); foreach (var item in allWorkersToProject) { tmpUser = UserRequsts.GetUserById(item.UserId); if (tmpUser.UserKindId == kindId && tmpUser.UserId != this.selectedUser.UserId) { sumAllActual += item.Hours; } } // workerToProject.Hours switch (kindId) { case 3: if (selectedProject.DevelopersHours < this.sumAllActual + workerToProject.Hours) { MessageBox.Show("Exceeded the hours allotted for development for this project"); flagHours = true; } break; case 4: if (selectedProject.QaHours < this.sumAllActual + workerToProject.Hours) { MessageBox.Show("Exceeded the hours allotted for QA for this project"); flagHours = true; } break; case 5: if (selectedProject.UiUxHours < this.sumAllActual + workerToProject.Hours) { MessageBox.Show("Exceeded the hours allotted for Ui/Ux for this project"); flagHours = true; } break; } if (this.flagHours == false) { if (WokrerToProjectRequst.UpdateWorkerToProject(workerToProject)) { MessageBox.Show("update success"); } else { MessageBox.Show("update filed"); } } else { MessageBox.Show("update filed"); } } else { MessageBox.Show(string.Join(",\n", results.Select(p => p.ErrorMessage))); } }