/// <summary>
        /// Allocates the new project criterion.
        /// </summary>
        /// <param name="projCritToAllocate">The proj crit to allocate.</param>
        /// <param name="index">The index.</param>
        /// Erstellt von Veit Berg, am 27.01.16
        public void AllocateNewProjectCriterion(ProjectCriterion projCritToAllocate, int index)
        {
            try{
            ProjCrits.Add(projCritToAllocate);
            projCritCont.ChangeAllocationOfProjectCriterionsInDb(ProjectId, ProjCrits);
             //          AllCrits.Remove((Criterion)projCritToAllocate);
            //foreach (ProjectCriterion projCrit in ProjCrits)
            //{
            //    Criterion allocatedCrit = AllCrits.Single(crit => crit.Criterion_Id == projCrit.Criterion_Id);
            //    AllCrits.Remove(allocatedCrit);
            //}

            using (CriterionController critCont = new CriterionController())
            {
                AllCrits = critCont.GetAllCriterionsFromDb();

                if (ProjCrits.Count != 0)
                {
                    foreach (ProjectCriterion projCrit in ProjCrits)
                    {
                        Criterion allocatedCrit = AllCrits.Single(crit => crit.Criterion_Id == projCrit.Criterion_Id);
                        AllCrits.Remove(allocatedCrit);
                    }
                }
            }

            using (ProjectCriterionController proCriCont = new ProjectCriterionController())
            {
                ProjCrits = proCriCont.GetAllProjectCriterionsForOneProject(ProjectId);

            }
            using (CriterionController critCont = new CriterionController())
            {
                AllCrits = critCont.GetAllCriterionsFromDb();

                if (ProjCrits.Count != 0)
                {
                    foreach (ProjectCriterion projCrit in ProjCrits)
                    {
                        Criterion allocatedCrit = AllCrits.Single(crit => crit.Criterion_Id == projCrit.Criterion_Id);
                        AllCrits.Remove(allocatedCrit);
                    }
                }
            }
            dataGridView_CritAvail.DataSource = null;
            dataGridView_CritAvail.DataSource = AllCrits;

            refreshGridL();
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }
        }
        //// Esrstellt von Weloko Tchokoua
        //public void UpdateAllPercentageProjectWeightings(int projectId)
        //{
        //    // calculate all weightings for the base layer
        //    List<ProjectCriterion> baseProjectCriterions = GetBaseProjectCriterions(projectId);
        //    CalculatePercentageProjectWeighting(ref baseProjectCriterions);
        //    // write calculated weightings back to db
        //    foreach (ProjectCriterion baseProjCrit in baseProjectCriterions)
        //    {
        //        UpdateProjectCriterionDataSet(baseProjCrit);
        //    }
        //    // calculate all weightings for all child project criterions
        //    List<ProjectCriterion> allProjectCriterions = GetAllProjectCriterionsForOneProject(projectId);
        //    foreach (ProjectCriterion projCrit in allProjectCriterions)
        //    {
        //        List<ProjectCriterion> eventualChildrenOfCurrentProjCriterion = GetChildCriterionsByParentId(projectId, projCrit.Criterion_Id);
        //        if (eventualChildrenOfCurrentProjCriterion.Count > 0)
        //        {
        //            CalculatePercentageProjectWeighting(ref eventualChildrenOfCurrentProjCriterion);
        //            foreach (ProjectCriterion childProjCrit in eventualChildrenOfCurrentProjCriterion)
        //            {
        //                UpdateProjectCriterionDataSet(childProjCrit);
        //            }
        //        }
        //    }
        //}
        /// <summary>
        /// Checks if same project criterions.
        /// </summary>
        /// <param name="projCritOne">The proj crit one.</param>
        /// <param name="projCritTwo">The proj crit two.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        private static bool checkIfSameProjectCriterions(ProjectCriterion projCritOne, ProjectCriterion projCritTwo)
        {
            bool sameParentCritId = projCritOne.Parent_Criterion_Id == projCritTwo.Parent_Criterion_Id;
            bool sameLayerDepth = projCritOne.Layer_Depth == projCritTwo.Layer_Depth;
            bool sameCardinalWeighting = projCritOne.Weighting_Cardinal == projCritTwo.Weighting_Cardinal;
            bool samePercentageLayerWeighting = projCritOne.Weighting_Percentage_Layer == projCritTwo.Weighting_Percentage_Layer;
            bool samePercentageProjectWeighting = projCritOne.Weighting_Percentage_Project == projCritTwo.Weighting_Percentage_Project;

            return sameCardinalWeighting &&
                   sameLayerDepth &&
                   sameParentCritId &&
                   samePercentageLayerWeighting &&
                   samePercentageProjectWeighting;
        }
        /// <summary>
        /// Updates the project criterion in database.
        /// </summary>
        /// <param name="alteredProjectCriterion">The altered project criterion.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        /// <exception cref="NWATException"></exception>
        public bool UpdateProjectCriterionInDb(ProjectCriterion alteredProjectCriterion)
        {
            bool updateSuccess;
            updateSuccess = UpdateProjectCriterionDataSet(alteredProjectCriterion);
            if (!updateSuccess)
            {
                throw new NWATException(MessageUpdateProjectCriterionFailed(alteredProjectCriterion.Criterion.Name));
            }

            int projectId = alteredProjectCriterion.Project_Id;
            UpdateLayerDepthForSingleProjectCriterion(projectId, alteredProjectCriterion.Criterion_Id);
            UpdateAllPercentageLayerWeightings(projectId);
            UpdateAllPercentageProjectWeightings(projectId);

            return updateSuccess;
        }
 /// <summary>
 /// Imports the project criterion.
 /// </summary>
 /// <param name="importProjectCriterion">The import project criterion.</param>
 /// <returns></returns>
 /// Erstellt von Joshua Frey, am 20.01.2016
 public bool ImportProjectCriterion(ProjectCriterion importProjectCriterion)
 {
     return InsertProjectCriterionIntoDb(importProjectCriterion, true);
 }
 /// <summary>
 /// Handles the Click event of the btn_zuordnen control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 /// Erstellt von Veit Berg, am 27.01.16
 private void btn_zuordnen_Click(object sender, EventArgs e)
 {
     try{
     Criterion selectedParentCiterion = (Criterion)comboBox_CritName.SelectedItem;
         ProjectCriterion projCritToAllocate = new ProjectCriterion()
         {
             Project_Id = ProjectId,
             Criterion_Id = CriterionIdToAllocate,
             Parent_Criterion_Id = selectedParentCiterion.Criterion_Id
         };
         ParentView.AllocateNewProjectCriterion(projCritToAllocate, CriterionIdDeleteFromList);
         this.Close();
     }
     catch (Exception x)
     {
         MessageBox.Show(x.Message);
     }
 }
        /// <summary>
        /// Updates the percentage project weighting for one criterion.
        /// </summary>
        /// <param name="projectCrit">The project crit.</param>
        /// Erstellt von Joshua Frey, am 20.01.2016
        private double UpdatePercentageProjectWeightingForOneCriterion(ProjectCriterion projectCrit)
        {
            int projectId = projectCrit.Project_Id;
            int criterionId = projectCrit.Criterion_Id;

            double percentageProjectWeightingValue = 1;
            List<ProjectCriterion> allProjectCriterions = GetAllProjectCriterionsForOneProject(projectId);
            ProjectCriterion involvedProjCriterion;
            involvedProjCriterion = allProjectCriterions.Single(projCrit => projCrit.Criterion_Id == criterionId);

            bool hasParent = false;

            // traverse all parent criterions and multiply their layer weightings
            do
            {
                // multiplies weightingvalue by percentageLayerWeighting of current involved proj crit
                percentageProjectWeightingValue *= involvedProjCriterion.Weighting_Percentage_Layer.Value;
                if (involvedProjCriterion.Parent_Criterion_Id != null && involvedProjCriterion.Parent_Criterion_Id.Value != 0)
                {
                    int parentCritId = involvedProjCriterion.Parent_Criterion_Id.Value;
                    hasParent = true;
                    involvedProjCriterion = allProjectCriterions.Single(projCrit => projCrit.Criterion_Id == parentCritId);
                }
                else
                {
                    hasParent = false;
                }
            } while (hasParent);

            return Math.Round(percentageProjectWeightingValue, 6, MidpointRounding.ToEven);
        }
 private bool InsertProjectCriterionIntoDb(ProjectCriterion newProjectCriterion)
 {
     return InsertProjectCriterionIntoDb(newProjectCriterion, false);
 }
 /// <summary>
 /// Gets the layer depth for single project criterion.
 /// </summary>
 /// <returns></returns>
 /// Erstellt von Joshua Frey, am 28.01.2016
 private int GetLayerDepthForSingleProjectCriterion(ProjectCriterion involvedProjCriterion, List<ProjectCriterion> allProjectCriterionsForThisProject)
 {
     bool hasParent = false;
     int layerCounter = 1;
     // traverse all parent criterion and count them in layerCounter
     do
     {
         // check if involvedProjCriterion has a parent
         if (involvedProjCriterion.Parent_Criterion_Id != null && involvedProjCriterion.Parent_Criterion_Id.Value != 0)
         {
             int parentCritId = involvedProjCriterion.Parent_Criterion_Id.Value;
             hasParent = true;
             // for each parent inkrement counter
             layerCounter++;
             // parent is new involvedProjCriterion now
             involvedProjCriterion = allProjectCriterionsForThisProject.Single(projCrit => projCrit.Criterion_Id == parentCritId);
         }
         else
         {
             hasParent = false;
         }
     } while (hasParent);
     return layerCounter;
 }
 partial void DeleteProjectCriterion(ProjectCriterion instance);
Esempio n. 10
0
 partial void UpdateProjectCriterion(ProjectCriterion instance);
Esempio n. 11
0
 partial void InsertProjectCriterion(ProjectCriterion instance);
Esempio n. 12
0
		private void detach_ProjectParentCriterion(ProjectCriterion entity)
		{
			this.SendPropertyChanging();
			entity.ParentCriterion = null;
		}
Esempio n. 13
0
		private void attach_ProjectCriterion(ProjectCriterion entity)
		{
			this.SendPropertyChanging();
			entity.Criterion = this;
		}
 /// <summary>
 /// Handles the Click event of the btn_cancle control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 /// Erstellt von Veit Berg, am 27.01.16
 private void btn_cancle_Click(object sender, EventArgs e)
 {
     try{
     ProjectCriterion projCritToAllocate = new ProjectCriterion()
     {
         Project_Id = ProjectId,
         Criterion_Id = CriterionIdToAllocate
     };
     ParentView.AllocateNewProjectCriterion(projCritToAllocate, CriterionIdDeleteFromList);
     this.Close();
     }
     catch (Exception x)
     {
         MessageBox.Show(x.Message);
     }
 }
 private static string MessageUserDecisionOfDeallocatingAllChildCriterions(ProjectCriterion projCrit, List<ProjectCriterion> eventualChildCriterions)
 {
     string critName = projCrit.Criterion.Name;
     // user is asked if he wants to deallocate the subordinated criterions
     string decisionMessage = @"Dem Kriterium " + critName + " sind noch folgende Kriterien untergeordnet: \n";
     foreach (ProjectCriterion childProjCrit in eventualChildCriterions)
     {
         decisionMessage += childProjCrit.Criterion.Name + "\n";
     }
     decisionMessage += "Wenn Sie das Kriterium dem Projekt entziehen, werden auch alle untergeordneten Kriterien dem Projekt entzogen\n" +
         "Des Weiteren werden alle Erfüllungseinträge mit den betroffenen Kriterien für dieses Projekt entfernt.\n" +
         "Möchten Sie das Kriterium " + critName + " und dessen Unterkriterien vom Projekt entkoppeln?";
     return decisionMessage;
 }
        /// <summary>
        /// Allocates the criterion.
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="projCrit">The proj crit.</param>
        /// <returns>
        /// bool if insertions in projectCriterion table and fulfillment table were successful
        /// </returns>
        /// Erstellt von Joshua Frey, am 04.01.2016
        /// <exception cref="NWATException"></exception>
        private bool AllocateCriterion(int projectId, ProjectCriterion projCrit)
        {
            bool insertionProjectCritionSuccessful = true;
            bool insertionFulfillmentSuccessful = true;

            int projCritId = projCrit.Criterion_Id;
            if (projCritId != 0 && projCrit.Project_Id != 0)
            {
                insertionProjectCritionSuccessful = InsertProjectCriterionIntoDb(projCrit);

                // get all project products for insertion to fulfillment table
                List<ProjectProduct> allProjectProducts;
                using (ProjectProductController projProdCont = new ProjectProductController())
                {
                    allProjectProducts = projProdCont.GetAllProjectProductsForOneProject(projectId);
                }

                // insert criterions into fulfillment table for each product
                using (FulfillmentController fulfillContr = new FulfillmentController())
                {
                    foreach (ProjectProduct projProd in allProjectProducts)
                    {
                        int productId = projProd.Product_Id;

                        // new fulfillment which will be inserted into fulfillment table.
                        // default values for Fulfilled and Comment (false and null)
                        Fulfillment newFulfillment = new Fulfillment()
                        {
                            Project_Id = projectId,
                            Product_Id = productId,
                            Criterion_Id = projCritId,
                            Fulfilled = false,
                            Comment = null
                        };

                        if (!fulfillContr.InsertFullfillmentInDb(newFulfillment))
                        {
                            insertionFulfillmentSuccessful = false;
                            throw (new NWATException(CommonMethods.MessageInsertionToFulFillmentTableFailed(productId, projCritId)));
                        }
                    }
                }
            }
            return insertionFulfillmentSuccessful && insertionProjectCritionSuccessful;
        }
        /// <summary>
        /// Gets the project criterion by line from import file.
        /// </summary>
        /// <param name="projectCriterionImportLine">The project criterion import line.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 20.01.2016
        /// <exception cref="NWATException"></exception>
        private ProjectCriterion GetProjectCriterionByLineFromImportFile(string projectCriterionImportLine)
        {
            ProjectCriterion importProjectCriterion;
            // Project_Id|Criterion_Id|Layer_Depth|Parent_Criterion_Id|Weighting_Cardinal|Weighting_Percentage_Layer|Weigthing_Percentage_Project
            var lineAsArray = projectCriterionImportLine.Split(this._delimiter);

            int projectId;
            int criterionId;
            int layerDepth;
            System.Nullable<int> parentCritId;
            int cardinalWeighting;
            System.Nullable<double> percentageLayerWeighting;
            System.Nullable<double> percentageProjectWeighting;
            try
            {
                projectId = Convert.ToInt32(lineAsArray[0]);
                criterionId = Convert.ToInt32(lineAsArray[1]);
                layerDepth = Convert.ToInt32(lineAsArray[2]);
                parentCritId = CommonMethods.GetNullableIntValueFromString(lineAsArray[3]);
                cardinalWeighting = Convert.ToInt32(lineAsArray[4]);
                percentageLayerWeighting = CommonMethods.GetNullableDoubleValueFromString(lineAsArray[5]);
                percentageProjectWeighting = CommonMethods.GetNullableDoubleValueFromString(lineAsArray[6]);
            }
            catch (FormatException formatException)
            {
                throw new NWATException(String.Format("{0}\n\n{1}",
                    formatException,
                    MessageWrongDatatypeInExportedLine("Product", projectCriterionImportLine, "int|int|int|int|int|double (mit Kommata)|double (mit Kommata)")));
            }

            importProjectCriterion = new ProjectCriterion()
            {
                Project_Id = projectId,
                Criterion_Id = criterionId,
                Layer_Depth = layerDepth,
                Parent_Criterion_Id = parentCritId,
                Weighting_Cardinal = cardinalWeighting,
                Weighting_Percentage_Layer = percentageLayerWeighting,
                Weighting_Percentage_Project = percentageProjectWeighting
            };
            return importProjectCriterion;
        }
        /// <summary>
        /// Inserts the project criterion data set into Db
        /// </summary>
        /// <param name="newProjectCriterion">The new project criterion.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        /// <exception cref="NWATException">
        /// </exception>
        private bool InsertProjectCriterionDataSet(ProjectCriterion newProjectCriterion, bool isImported)
        {
            if (newProjectCriterion != null)
            {
                int projectId = newProjectCriterion.Project_Id;
                int criterionId = newProjectCriterion.Criterion_Id;

                if (!isImported)
                {
                    // set equal weighting when inserting a new project criterion
                    newProjectCriterion.Weighting_Cardinal = 1;
                    // set default layer depth to 1
                    newProjectCriterion.Layer_Depth = 1;
                }
                // if == null then this project criterion does not exist yet and it can be inserted into db
                if (!CheckIfProjectCriterionAlreadyExists(projectId, criterionId))
                {
                    base.DataContext.ProjectCriterion.InsertOnSubmit(newProjectCriterion);
                    base.DataContext.SubmitChanges();
                }

                // project criterion already exists --> throw exception
                else
                {
                    ProjectCriterion alreadyExistingProjectCriterion = this.GetProjectCriterionByIds(projectId, criterionId);
                    string projectName = alreadyExistingProjectCriterion.Project.Name;
                    string criterionName = alreadyExistingProjectCriterion.Criterion.Name;
                    throw (new NWATException((MessageProjectCriterionAlreadyExists(projectName, criterionName))));
                }
                return checkIfSameProjectCriterions(newProjectCriterion, this.GetProjectCriterionByIds(projectId, criterionId));
            }
            else
            {
                throw (new NWATException(MessageProjectCriterionCouldNotBeSavedEmptyObject()));
            }
        }
 /// <summary>
 /// Deallocates the criterion and all child criterions from project. This includes the entries in the fulfillment table
 /// User will be asked, if children should be deallocated
 /// </summary>
 /// <param name="projectId">The project identifier.</param>
 /// <param name="projCrit">The proj crit.</param>
 /// <returns></returns>
 /// Erstellt von Joshua Frey, am 13.01.2016
 public bool DeallocateCriterionAndAllChildCriterions(int projectId, ProjectCriterion projCrit)
 {
     return DeallocateCriterionAndAllChildCriterions(projectId, projCrit, false);
 }
        /// <summary>
        /// Inserts the project criterion into database.
        /// </summary>
        /// <param name="newProjectCriterion">The new project criterion.</param>
        /// <returns>
        /// bool if insertion was sucessfully
        /// </returns>
        /// Erstellt von Joshua Frey, am 22.12.2015
        /// <exception cref="NWATException">
        /// </exception>
        private bool InsertProjectCriterionIntoDb(ProjectCriterion newProjectCriterion, bool isImported)
        {
            bool success;
            try
            {
                success = InsertProjectCriterionDataSet(newProjectCriterion, isImported);
            }
            catch (Exception e)
            {
                throw (e);
            }
            if (success)
            {
                int projectId = newProjectCriterion.Project_Id;

                if(!isImported)
                {
                    UpdateLayerDepthForSingleProjectCriterion(projectId, newProjectCriterion.Criterion_Id);
                    UpdateAllPercentageLayerWeightings(projectId);
                    UpdateAllPercentageProjectWeightings(projectId);
                }
            }
            return success;
        }
        /// <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>
        /// Updates the project criterion data set.
        /// </summary>
        /// <param name="alteredProjectCriterion">The altered project criterion.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        private bool UpdateProjectCriterionDataSet(ProjectCriterion alteredProjectCriterion)
        {
            int projectId = alteredProjectCriterion.Project_Id;
            int criterionId = alteredProjectCriterion.Criterion_Id;
            ProjectCriterion resultProjectCriterion = base.DataContext.ProjectCriterion.SingleOrDefault(projectCriterion => projectCriterion.Criterion_Id == criterionId
                                                                           && projectCriterion.Project_Id == projectId);
            resultProjectCriterion.Parent_Criterion_Id = alteredProjectCriterion.Parent_Criterion_Id;
            resultProjectCriterion.Weighting_Cardinal = alteredProjectCriterion.Weighting_Cardinal;
            resultProjectCriterion.Layer_Depth = alteredProjectCriterion.Layer_Depth;
            resultProjectCriterion.Weighting_Percentage_Layer = alteredProjectCriterion.Weighting_Percentage_Layer;
            resultProjectCriterion.Weighting_Percentage_Project = alteredProjectCriterion.Weighting_Percentage_Project;
            base.DataContext.SubmitChanges();

            ProjectCriterion changedProjCritFromDb = GetProjectCriterionByIds(alteredProjectCriterion.Project_Id, alteredProjectCriterion.Criterion_Id);

            bool successfulUpdate = checkIfSameProjectCriterions(alteredProjectCriterion, changedProjCritFromDb);

            return successfulUpdate;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisResultCrit"/> class.
 /// </summary>
 /// <param name="projCrit">The proj crit.</param>
 /// Erstellt von Joshua Frey, am 20.01.2016
 public AnalysisResultCrit(ProjectCriterion projCrit)
 {
     this.ProjCrit = projCrit;
     this.IsReCalculated = false;
     this.ResultValue = this.ProjCrit.Weighting_Percentage_Project.Value;
 }