Example #1
0
        internal void copyValues(CarboGroup carboGroup)
        {
            Category    = carboGroup.Category;
            SubCategory = carboGroup.SubCategory;

            Material     = carboGroup.Material;
            MaterialName = carboGroup.MaterialName;

            AllElements = carboGroup.AllElements;

            Volume      = carboGroup.Volume;
            TotalVolume = carboGroup.TotalVolume;
            Additional  = carboGroup.Additional;
            Correction  = carboGroup.Correction;
            Density     = carboGroup.Density;
            Description = carboGroup.Description;
            EC          = carboGroup.EC;
            ECI         = carboGroup.ECI;
            Id          = carboGroup.Id;
            Mass        = carboGroup.Mass;

            isDemolished   = carboGroup.isDemolished;
            isSubstructure = carboGroup.isSubstructure;

            PerCent = carboGroup.PerCent;
        }
Example #2
0
        private static ObservableCollection <CarboGroup> AddToCarboGroup(ObservableCollection <CarboGroup> carboGroupList, CarboElement carboElement, CarboMaterial mappedMaterial)
        {
            int idbase = 1000;

            //Try Add
            foreach (CarboGroup cg in carboGroupList)
            {
                if (cg.Category == carboElement.Category)
                {
                    if (cg.MaterialName == mappedMaterial.Name)
                    {
                        cg.AllElements.Add(carboElement);
                        return(carboGroupList);
                    }
                }
            }
            //NoCategoryWasFound: make new group
            int id = carboGroupList.Count;

            CarboGroup newGroup = new CarboGroup(carboElement);

            newGroup.Id           = idbase;
            newGroup.Material     = mappedMaterial;
            newGroup.MaterialName = mappedMaterial.Name;
            newGroup.Density      = mappedMaterial.Density;
            //newGroup.ECI = mappedMaterial.ECI;
            //newGroup.EEI = mappedMaterial.EEI;
            //newGroup.Volume = carboElement.Volume;

            carboGroupList.Add(newGroup);
            return(carboGroupList);
        }
Example #3
0
        public void UpdateMaterial(CarboGroup TargetGroup, CarboMaterial NewMaterial)
        {
            if (NewMaterial != null)
            {
                foreach (CarboGroup cg in groupList)
                {
                    // Update selected group per se.
                    //
                    if (cg.Id == TargetGroup.Id)
                    {
                        cg.MaterialName = NewMaterial.Name;
                        cg.Material     = NewMaterial;
                    }

                    //Update all idential materials
                    if (cg.Material.Id == NewMaterial.Id)
                    {
                        cg.MaterialName = NewMaterial.Name;
                        cg.Material     = NewMaterial;
                    }
                }
            }

            justSaved = false;
        }
Example #4
0
 public void PurgeElements(CarboGroup carboGroup)
 {
     foreach (CarboGroup cg in groupList)
     {
         if (cg.Id == carboGroup.Id)
         {
             cg.TrucateElements();
         }
     }
 }
Example #5
0
        public void DuplicateGroup(CarboGroup carboGroup)
        {
            CarboGroup newCarboGroup = carboGroup.Copy();

            newCarboGroup.Copy();
            newCarboGroup.Description += "- Copy";

            AddGroup(newCarboGroup);

            justSaved = false;
        }
Example #6
0
        public CarboGroup Copy()
        {
            CarboGroup result = new CarboGroup();

            result.Category     = this.Category;
            result.SubCategory  = this.SubCategory;
            result.Material     = this.Material;
            result.MaterialName = this.MaterialName;
            result.AllElements  = this.AllElements;
            result.Volume       = this.Volume;

            result.RefreshValuesFromElements();

            return(result);
        }
Example #7
0
        public void DuplicateGroup(CarboGroup carboGroup)
        {
            CarboGroup newCarboGroup = new CarboGroup();

            newCarboGroup.Id = getNewId();
            newCarboGroup.TrucateElements();
            newCarboGroup.Description = carboGroup.Description + "- Copy";
            newCarboGroup.Category    = carboGroup.Category;
            newCarboGroup.SubCategory = carboGroup.SubCategory;
            newCarboGroup.Volume      = carboGroup.Volume;
            newCarboGroup.Density     = carboGroup.Density;
            newCarboGroup.Material    = carboGroup.Material;
            newCarboGroup.setMaterial(carboGroup.Material);
            AddGroup(newCarboGroup);
        }
Example #8
0
        public void UpdateGroup(CarboGroup carboGroup)
        {
            for (int i = 0; i < groupList.Count; i++)
            {
                CarboGroup cg = groupList[i];
                // Update selected group per se.
                //
                if (cg.Id == carboGroup.Id)
                {
                    cg.copyValues(carboGroup);

                    cg.CalculateTotals();
                    break;
                }
            }
        }
Example #9
0
 public void UpdateGroup(CarboGroup carboGroup)
 {
     foreach (CarboGroup cg in groupList)
     {
         // Update selected group per se.
         //
         if (cg.Id == carboGroup.Id)
         {
             cg.Category    = carboGroup.Category;
             cg.Correction  = carboGroup.Correction;
             cg.Description = carboGroup.Description;
             cg.Volume      = carboGroup.Volume;
             cg.SubCategory = carboGroup.SubCategory;
             cg.CalculateTotals();
         }
     }
 }
Example #10
0
        public bool AddGroup(CarboGroup newGroup)
        {
            bool result = false;

            if (!(groupList.Contains(newGroup)))
            {
                newGroup.Id = getNewId();
                groupList.Add(newGroup);
            }
            else
            {
                MessageBox.Show("new group already exists");
                return(false);
            }

            return(result);
        }
Example #11
0
        public CarboGroup Copy()
        {
            CarboGroup result = new CarboGroup();

            result.Category    = this.Category;
            result.SubCategory = this.SubCategory;

            result.Material     = this.Material;
            result.MaterialName = this.MaterialName;

            result.AllElements = this.AllElements;

            result.Volume      = this.Volume;
            result.TotalVolume = this.TotalVolume;
            result.Additional  = this.Additional;
            result.Correction  = this.Correction;
            result.Density     = this.Density;
            result.Description = this.Description;
            result.EC          = this.EC;
            result.ECI         = result.ECI;
            result.Id          = this.Id;
            result.Mass        = this.Mass;

            //Correction Formula
            result.Correction            = this.Correction;
            result.CorrectionDescription = this.CorrectionDescription;
            //Waste
            result.Waste            = this.Waste;
            result.WasteDescription = this.WasteDescription;
            //Additional
            result.Additional            = this.Additional;
            result.AdditionalDescription = this.AdditionalDescription;
            //B4
            result.B4Factor            = this.B4Factor;
            result.ComponentLifePeriod = this.ComponentLifePeriod;
            result.AssetLifePeriod     = this.AssetLifePeriod;
            result.B4Description       = this.B4Description;

            result.isDemolished   = this.isDemolished;
            result.isSubstructure = this.isSubstructure;

            result.PerCent = this.PerCent;

            return(result);
        }
Example #12
0
        private void NewGroup(CarboElement ceNew)
        {
            try
            {
                ceNew.isUpdated = true;
                CarboGroup newGroup = new CarboGroup(ceNew);

                CarboMaterial closestGroupMaterial = CarboDatabase.getClosestMatch(ceNew.MaterialName);
                //cg.MaterialName = closestGroupMaterial.Name;
                newGroup.setMaterial(closestGroupMaterial);
                closestGroupMaterial.CalculateTotals();

                this.AddGroup(newGroup);
            }
            catch
            {
            }
        }
Example #13
0
        public bool CreateNewGroup(string category = "")
        {
            bool result = false;

            CarboGroup newGroup = new CarboGroup();

            if (category != "")
            {
                newGroup.Category = category;
            }

            int id = getNewId();

            newGroup.Id = id;

            AddGroup(newGroup);

            return(result);
        }
Example #14
0
        public CarboGroup getTotalsGroup()
        {
            CarboGroup newGroup = new CarboGroup();

            newGroup.Category    = "Total";
            newGroup.Material    = null;
            newGroup.Description = "Totals";
            newGroup.Volume      = 0;
            newGroup.Density     = 0;
            newGroup.Mass        = 0;
            newGroup.ECI         = 0;
            newGroup.EC          = 0;
            newGroup.Id          = getNewId();
            double totals = 0;

            foreach (CarboGroup cgr in getGroupList)
            {
                totals += cgr.EC;
            }
            newGroup.EC      = Math.Round(totals, 2);
            newGroup.PerCent = 100;

            return(newGroup);
        }
Example #15
0
        private static ObservableCollection <CarboGroup> AddToCarboGroup(
            ObservableCollection <CarboGroup> carboGroupList,
            CarboElement carboElement,
            bool groupCategory,
            bool groupSubCategory,
            bool groupType,
            bool groupMaterial,
            bool groupSubStructure,
            bool groupDemolition,
            string uniqueTypeNames)
        {
            int idbase = 1000;
            //define all constnts
            bool okCategory     = false;
            bool okSubCategory  = false;
            bool okType         = false;
            bool okMaterial     = false;
            bool okSubStructure = false;
            bool okDemolition   = false;
            bool okUniqueType   = false;


            bool containsRelavantName = false;

            //split
            string[] uniquenamelist = uniqueTypeNames.Split(',');

            foreach (CarboGroup cg in carboGroupList)
            {
                bool matchCategory     = false;
                bool matchSubCategory  = false;
                bool matchType         = false;
                bool matchMaterial     = false;
                bool matchSubStructure = false;
                bool matchDemolition   = false;
                bool matchUniqueType   = false;

                okCategory     = false;
                okSubCategory  = false;
                okType         = false;
                okMaterial     = false;
                okSubStructure = false;
                okDemolition   = false;
                okUniqueType   = false;

                //Find which conditions match
                //Category
                if (cg.Category == carboElement.Category)
                {
                    matchCategory = true;
                }
                //SubCategory
                if (cg.SubCategory == carboElement.SubCategory)
                {
                    matchSubCategory = true;
                }
                //TypeName
                if (cg.AllElements[0].Name == carboElement.Name)
                {
                    matchType = true;
                }
                //Material
                if (cg.MaterialName == carboElement.MaterialName)
                {
                    matchMaterial = true;
                }
                //Substructure
                if (cg.isSubstructure == carboElement.isSubstructure)
                {
                    matchSubStructure = true;
                }
                //Demoltion
                if (carboElement.isDemolished == true)
                {
                    matchDemolition = true;
                }
                //Uniquenames

                //TBC
                bool groupContainsUniqueTypename = false;

                foreach (string str in uniquenamelist)
                {
                    string str_trimmed  = str.Trim();
                    string embededname  = cg.AllElements[0].Name;
                    bool   containsName = CaseInsensitiveContains(embededname, str_trimmed);
                    if (containsName == true)
                    {
                        //The elements in this group contain one of the words, see if they are identical
                        if (embededname == carboElement.Name)
                        {
                            //The item matched the qunique type group.
                            groupContainsUniqueTypename = true;
                            break;
                        }
                        else
                        {
                            //This is not the group you are looking for
                            groupContainsUniqueTypename = false;
                        }
                    }
                    else
                    {
                        matchUniqueType = false;
                    }
                    //Ignore switch:
                    containsRelavantName = CaseInsensitiveContains(carboElement.Name, str_trimmed);
                }

                //see if item contains unique groupname;
                //at the end of this loop we know that this group contains a type name that needs to be separated.
                //So the element can be added to this group:

                //if this group doesnt contain the type name then another group needs to be found or (at the very end) a new group will have to be made;
                if (groupContainsUniqueTypename == true)
                {
                    matchUniqueType = true;
                }

                //if all required conditions match requested then add, if not, create new.

                if (groupCategory == false)
                {
                    okCategory = true;
                }
                else
                {
                    if (matchCategory == true)
                    {
                        okCategory = true;
                    }
                    else
                    {
                        okCategory = false;
                    }
                }

                if (groupSubCategory == false)
                {
                    okSubCategory = true;
                }
                else
                {
                    if (matchSubCategory == true)
                    {
                        okSubCategory = true;
                    }
                    else
                    {
                        okSubCategory = false;
                    }
                }

                if (groupType == false)
                {
                    okType = true;
                }
                else
                {
                    if (matchType == true)
                    {
                        okType = true;
                    }
                    else
                    {
                        okType = false;
                    }
                }

                if (groupMaterial == false)
                {
                    okMaterial = true;
                }
                else
                {
                    if (matchMaterial == true)
                    {
                        okMaterial = true;
                    }
                    else
                    {
                        okMaterial = false;
                    }
                }

                if (groupSubStructure == false)
                {
                    okSubStructure = true;
                }
                else
                {
                    if (matchSubStructure == true)
                    {
                        okSubStructure = true;
                    }
                    else
                    {
                        okSubStructure = false;
                    }
                }

                if (groupDemolition == false)
                {
                    okDemolition = true;
                }
                else
                {
                    if (matchDemolition == true)
                    {
                        okDemolition = true;
                    }
                    else
                    {
                        okDemolition = false;
                    }
                }

                if (uniqueTypeNames == "")
                {
                    okUniqueType = true;
                }
                else
                {
                    if (containsRelavantName == true)
                    {
                        //If this group contains the EXCACT TYPE NAME then proceed to add;
                        if (matchUniqueType == true)
                        {
                            //The type name matched the group elements
                            okUniqueType = true;
                        }
                        else
                        {
                            okUniqueType = false;
                        }
                    }
                    else
                    {
                        okUniqueType = true;
                    }
                }



                //If all passes add to group if not skip and create new group;
                if (
                    okCategory == true &&
                    okSubCategory == true &&
                    okType == true &&
                    okMaterial == true &&
                    okSubStructure == true &&
                    okDemolition == true &&
                    okUniqueType == true)
                {
                    cg.AllElements.Add(carboElement);

                    Utils.WriteToLog("Mapped element: [" + carboElement.Category + "] - [" + carboElement.MaterialName + "] to group: [" + cg.Category + "] - [" + cg.MaterialName + "] -> " +
                                     " Category: " + okCategory +
                                     " sub Category: " + okSubCategory +
                                     " Type: " + okType +
                                     " Material: " + okMaterial +
                                     " SubStr: " + okSubStructure +
                                     " Demo: " + okDemolition +
                                     " Uniquetype: " + okUniqueType);

                    return(carboGroupList);
                }
            }

            //NoCategoryWasFound: make new group
            int id = carboGroupList.Count + idbase;

            CarboGroup newGroup = new CarboGroup(carboElement);

            newGroup.Id           = idbase + id;
            newGroup.MaterialName = carboElement.MaterialName;
            newGroup.Density      = carboElement.Density;
            newGroup.Description  = "A new group";

            newGroup.Material.Name = carboElement.MaterialName;

            //newGroup.ECI = mappedMaterial.ECI;
            //newGroup.EEI = mappedMaterial.EEI;
            //newGroup.Volume = carboElement.Volume;

            carboGroupList.Add(newGroup);

            Utils.WriteToLog("Created New group for element: " + carboElement.Category + " - " + carboElement.MaterialName + " New Group: " + newGroup.MaterialName + " -> " +
                             " Category: " + okCategory +
                             " sub Category: " + okSubCategory +
                             " Type: " + okType +
                             " Material: " + okMaterial +
                             " SubStr: " + okSubStructure +
                             " Demo: " + okDemolition +
                             " Uniquetype: " + okUniqueType);

            return(carboGroupList);
        }
Example #16
0
        /// <summary>
        /// Updates the project with the elements inside another carbogroup
        /// </summary>
        /// <param name="newProject"></param>
        public void UpdateProject(CarboProject projectWithElements)
        {
            int totalNewElements;
            int totalOldElements;
            int updatedElements        = 0;
            int newElementsInGroup     = 0;
            int newElementsWithNoGroup = 0;
            int deletedElements        = 0;
            int deletedGroups          = 0;

            //Replace All Elements iterate though each element in the new list and the following things can happen:
            // 0. Elements that dont exist in the old file need to be deleted. This will be done first to schrink the search table
            // 1. The item was found (id match and material match) the volumes are then replaced
            // 2. The element wasnt found, and thus it needs to be added to a group, or a new group will be made for it.
            // 4. cleanup, groups without elements, that had elements before will need to be deleted.
            // 5. compound elements need to be reviewed for the future, as they can be trcky to deal with atm.

            totalNewElements = projectWithElements.elementList.Count;
            totalOldElements = this.elementList.Count;

            //Update the element list;
            this.elementList = new ObservableCollection <CarboElement>();
            foreach (CarboElement ce in projectWithElements.elementList)
            {
                CarboElement ceNew = new CarboElement();
                ceNew = ce.CopyMe();
                this.elementList.Add(ceNew);
            }

            //this.elementList = new List<CarboElement>(projectWithElements.elementList);

            //Clear the project so we can track the updates.
            foreach (CarboElement ce in elementList)
            {
                ce.isUpdated = false;
            }
            foreach (CarboGroup cg in getGroupList)
            {
                if (cg.AllElements.Count > 0)
                {
                    foreach (CarboElement ce in cg.AllElements)
                    {
                        ce.isUpdated = false;
                    }
                }
            }

            //1 Update similar elements and flag the ones that are done.
            for (int i = projectWithElements.elementList.Count - 1; i >= 0; i--)
            {
                CarboElement ceNew = projectWithElements.elementList[i] as CarboElement;
                if (ceNew != null)
                {
                    bool isfoundinGroup = false;
                    //bool isfoundinElementList = false;

                    //Check and update the groups: the groups
                    isfoundinGroup = updateinGroups(ceNew);

                    //if the element was found and updated,
                    if (isfoundinGroup == true)
                    {
                        //remove from list, it has been done;
                        updatedElements++;
                        projectWithElements.elementList.RemoveAt(i);
                        //ceNew.isUpdated = true;
                    }
                }
            }

            //Elements that wern't flagged in the new list must be new, they need to be added to the right group.
            for (int i = projectWithElements.elementList.Count - 1; i >= 0; i--)
            {
                CarboElement ceNew = projectWithElements.elementList[i] as CarboElement;
                if (ceNew != null)
                {
                    //each element will be assesed individually.
                    //Look through the element list:
                    if (ceNew.isUpdated == false)
                    {
                        bool insertedinGroup = false;

                        //Check and update the groups: the groups
                        insertedinGroup = insertinGroups(ceNew);

                        if (insertedinGroup == true)
                        {
                            //The element was found in an existing group and was updated
                            newElementsInGroup++;
                            projectWithElements.elementList.RemoveAt(i);
                        }
                        else
                        {
                            //Elements that wern't flagged in the new list must need their own new group;
                            //A new group need to be made for this element;
                            newElementsWithNoGroup++;


                            this.NewGroup(ceNew);

                            //The materialname was given by the elements, the values now need to be matched with a own one.
                            //cg.MaterialName = closestGroupMaterial.Name;
                            //cg.setMaterial(closestGroupMaterial);


                            projectWithElements.elementList.RemoveAt(i);
                        }
                    }
                }
            }

            //Remove all the elements in groups that werent updated, and delete the groups if empty
            for (int i = this.groupList.Count - 1; i >= 0; i--)
            {
                CarboGroup group = this.groupList[i] as CarboGroup;

                if (group != null)
                {
                    bool deletegroup = false;

                    if (group.AllElements.Count > 0)
                    {
                        for (int j = group.AllElements.Count - 1; j >= 0; j--)
                        {
                            CarboElement ce = group.AllElements[j] as CarboElement;
                            if (ce != null)
                            {
                                if (ce.isUpdated == false)
                                {
                                    //We found a element that doesnt exist anymore
                                    group.AllElements.RemoveAt(j);
                                    deletedElements++;
                                }
                            }
                        }
                        //if the group is empty after all the elemetns are deleted, remove the group;
                        if (group.AllElements.Count == 0)
                        {
                            deletegroup = true;
                        }
                    }

                    if (deletegroup == true)
                    {
                        this.groupList.RemoveAt(i);
                        deletedGroups++;
                    }
                }
            }

            //getElementsFromGroups;

            string message =
                "Project updated: " + Environment.NewLine +
                "Old nr of elements: " + totalOldElements + Environment.NewLine +
                "New nr of elements: " + totalNewElements + Environment.NewLine +
                "Nr of elements updated: " + updatedElements + Environment.NewLine +
                "Nr of elements added to groups: " + newElementsInGroup + Environment.NewLine +
                "Nr of elements added to new groups: " + newElementsWithNoGroup + Environment.NewLine +
                "Elements deleted: " + deletedElements + Environment.NewLine +
                "Groups deleted: " + deletedGroups + Environment.NewLine;

            justSaved = false;

            MessageBox.Show(message, "Results", MessageBoxButton.OK);
        }
Example #17
0
 public void DeleteGroup(CarboGroup groupToDelete)
 {
     groupList.Remove(groupToDelete);
 }
Example #18
0
 public void DeleteGroup(CarboGroup groupToDelete)
 {
     groupList.Remove(groupToDelete);
     CalculateProject();
 }