/// <summary> /// Deallocates the criterion and all child criterions from project. This includes the entries in the fulfillment table /// </summary> /// <param name="projectId">The project identifier.</param> /// <param name="projCrit">The proj crit.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 04.01.2016 public bool DeallocateCriterionAndAllChildCriterions(int projectId, ProjectCriterion projCrit, bool forceDeallocationOfChildren) { int projectCriterionId = projCrit.Criterion_Id; // checks if criterion has any children criterion (is a parent criterion) List<ProjectCriterion> eventualChildCriterions = GetChildCriterionsByParentId(projectId, projectCriterionId); bool deletionPermitted = true; if (eventualChildCriterions.Count > 0) { string decisionMessage = MessageUserDecisionOfDeallocatingAllChildCriterions(projCrit, eventualChildCriterions); const string caption = "Kriterienentkopplung"; // only ask user if children should be deallocated when forceDeallocationOfChildre = false if (!forceDeallocationOfChildren) { var result = MessageBox.Show(decisionMessage, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { deletionPermitted = false; } } if (deletionPermitted) { foreach (ProjectCriterion childProjCrit in eventualChildCriterions) { deletionPermitted = DeallocateCriterionAndAllChildCriterions(projectId, childProjCrit, forceDeallocationOfChildren); } } } string projCritName = projCrit.Criterion.Name; if (deletionPermitted) { // delete all fulfillment entries which point to this project criterion bool fulfillmentDeletionSuccessfull; using (FulfillmentController fulfillmentContr = new FulfillmentController()) { fulfillmentDeletionSuccessfull = fulfillmentContr.DeleteAllFulfillmentsForOneCriterionInOneProject(projectId, projCrit.Criterion_Id); } if (fulfillmentDeletionSuccessfull && DeleteProjectCriterionFromDb(projectId, projectCriterionId)) { if (!forceDeallocationOfChildren) { MessageBox.Show("Das Kriterium " + projCritName + " wurde erfolgreich vom Projekt entkoppelt."); } return true; } else { MessageBox.Show("Bei dem Löschvorgang ist ein Fehler aufgetreten."); return false; } } else { MessageBox.Show("Löschen von " + projCritName + " konnte nicht durchgeführt werden, weil ein Löschvorgang vom Benutzer abgelehnt wurde."); return false; } }
/// <summary> /// Deallocates the criterion and all child criterions from project. This includes the entries in the fulfillment table /// </summary> /// <param name="projectId">The project identifier.</param> /// <param name="projCrit">The proj crit.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 04.01.2016 public bool DeallocateCriterionAndAllChildCriterions(int projectId, ProjectCriterion projCrit, bool forceDeallocationOfChildren) { int projectCriterionId = projCrit.Criterion_Id; // checks if criterion has any children criterion (is a parent criterion) List <ProjectCriterion> eventualChildCriterions = GetChildCriterionsByParentId(projectId, projectCriterionId); bool deletionPermitted = true; if (eventualChildCriterions.Count > 0) { string decisionMessage = MessageUserDecisionOfDeallocatingAllChildCriterions(projCrit, eventualChildCriterions); const string caption = "Kriterienentkopplung"; // only ask user if children should be deallocated when forceDeallocationOfChildre = false if (!forceDeallocationOfChildren) { var result = MessageBox.Show(decisionMessage, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { deletionPermitted = false; } } if (deletionPermitted) { foreach (ProjectCriterion childProjCrit in eventualChildCriterions) { deletionPermitted = DeallocateCriterionAndAllChildCriterions(projectId, childProjCrit, forceDeallocationOfChildren); } } } string projCritName = projCrit.Criterion.Name; if (deletionPermitted) { // delete all fulfillment entries which point to this project criterion bool fulfillmentDeletionSuccessfull; using (FulfillmentController fulfillmentContr = new FulfillmentController()) { fulfillmentDeletionSuccessfull = fulfillmentContr.DeleteAllFulfillmentsForOneCriterionInOneProject(projectId, projCrit.Criterion_Id); } if (fulfillmentDeletionSuccessfull && DeleteProjectCriterionFromDb(projectId, projectCriterionId)) { if (!forceDeallocationOfChildren) { MessageBox.Show("Das Kriterium " + projCritName + " wurde erfolgreich vom Projekt entkoppelt."); } return(true); } else { MessageBox.Show("Bei dem Löschvorgang ist ein Fehler aufgetreten."); return(false); } } else { MessageBox.Show("Löschen von " + projCritName + " konnte nicht durchgeführt werden, weil ein Löschvorgang vom Benutzer abgelehnt wurde."); return(false); } }