public void GenerateDummyList() { //Create a large list of dummy elements; elementList = new ObservableCollection <CarboElement>(); Random rnd = new Random(1000); for (int i = 0; i < 100; i++) { double volume = rnd.Next(10, 100); // creates a random Volume int value1 = rnd.Next(1, 5); // creates a random Volume int value2 = rnd.Next(1, 5); // creates a random Volume string materialName = CarboElementImporter.getRandomMaterial(value1); string category = CarboElementImporter.getRandomCategory(value2); int id = rnd.Next(10000, 20000); CarboElement carboLifeElement = new CarboElement(); carboLifeElement.Id = id; carboLifeElement.MaterialName = materialName; carboLifeElement.Volume = volume; carboLifeElement.Category = category; carboLifeElement.SubCategory = ""; carboLifeElement.Density = 1000; //carboLifeElement.Material = new CarboMaterial(materialName); elementList.Add(carboLifeElement); } CalculateProject(); }
private CarboElement addBufferToElements(List <CarboElement> elementbuffer, CarboElement cElement, out bool ok) { ok = false; if (elementbuffer != null) { if (elementbuffer.Count > 0) { //searc the buffer for the right totals foreach (CarboElement buffer_CE in elementbuffer) { try { if (buffer_CE.Id == cElement.Id) { //Set the values; cElement.EC_Total = buffer_CE.EC_Total; cElement.ECI_Total = buffer_CE.ECI_Total; cElement.Volume_Total = buffer_CE.Volume_Total; ok = true; break; } } catch (Exception ex) { ok = false; MessageBox.Show(ex.Message); } } } } justSaved = false; return(cElement); }
private bool updateinElementList(CarboElement ceNew) { bool result = false; //check all existing elements for its foreach (CarboElement ceOld in elementList) { bool isSimilar = isElementSimilar(ceOld, ceNew); if (ceOld.Id == ceNew.Id && ceOld.MaterialName == ceNew.MaterialName && ceOld.isUpdated == false) { //A match was found, update the element //These two match, we can update the volume ceOld.Volume = ceNew.Volume; ceOld.Volume_Total = 0; //not sure about the below: ceOld.Category = ceNew.Category; ceOld.Category = ceNew.SubCategory; //Set Flags ceOld.isUpdated = true; justSaved = false; return(true); } } //element is not found return(result); }
internal CarboElement CopyMe() { CarboElement clone = new CarboElement(); clone.Id = this.Id; clone.Name = this.Name; //Imported Material Name clone.MaterialName = this.MaterialName; //Matched To Material Name clone.CarboMaterialName = this.CarboMaterialName; clone.Category = this.Category; clone.SubCategory = this.SubCategory; clone.Volume = this.Volume; clone.Mass = this.Mass; clone.Density = this.Density; clone.Level = this.Level; clone.isDemolished = this.isDemolished; clone.isExisting = this.isExisting; clone.isSubstructure = this.isSubstructure; clone.r = this.r; clone.g = this.g; clone.b = this.b; clone.ECI = this.ECI; clone.EC = this.EC; clone.ECI_Total = this.ECI_Total; clone.EC_Total = this.EC_Total; clone.Volume_Total = this.Volume_Total; return(clone); }
private bool insertinGroups(CarboElement ceNew) { bool result = false; foreach (CarboGroup cg in getGroupList) { if (cg.AllElements.Count > 0) { foreach (CarboElement ceOld in cg.AllElements) { //to be added, the category, subcategory & materialname need to be identical if ( ceOld.Category == ceNew.Category && ceOld.SubCategory == ceNew.SubCategory && ceOld.MaterialName == ceNew.MaterialName ) { //A match was found, check the materials ceNew.isUpdated = true; cg.AllElements.Add(ceNew); justSaved = false; return(true); //break; } } } } //element is not found this will be put in a new group; justSaved = false; return(result); }
public CarboGroup(CarboElement carboElement) { Id = -999; MaterialName = carboElement.MaterialName; Category = carboElement.Category; SubCategory = carboElement.SubCategory; Description = ""; Volume = carboElement.Volume; Density = 0; Mass = 0; //EEI = 0; ECI = 0; //EE = 0; EC = 0; PerCent = 0; Material = new CarboMaterial(); Material = carboElement.Material; AllElements = new List <CarboElement>(); AllElements.Add(carboElement); isDemolished = carboElement.isDemolished; isSubstructure = carboElement.isSubstructure; }
private bool isElementSimilar(CarboElement ceOld, CarboElement ceNew) { bool result = false; if (ceOld.Id == ceNew.Id && ceOld.MaterialName == ceNew.MaterialName && ceOld.isUpdated == false) { return(true); } return(result); }
public CarboGroup(CarboElement carboElement) { Id = -999; MaterialName = carboElement.MaterialName; Category = carboElement.Category; SubCategory = carboElement.SubCategory; Description = ""; Volume = carboElement.Volume; Density = 0; Mass = 0; //EEI = 0; ECI = 0; //EE = 0; EC = 0; //Correction Formula Correction = ""; CorrectionDescription = ""; //Waste Waste = 0; WasteDescription = ""; //Additional Additional = 0; AdditionalDescription = ""; //B4 B4Factor = 1; ComponentLifePeriod = 50; AssetLifePeriod = 50; B4Description = ""; PerCent = 0; //get the material Material = new CarboMaterial(); //Material = carboElement.Material; removed from CarboElement AllElements = new List <CarboElement>(); AllElements.Add(carboElement); isDemolished = carboElement.isDemolished; isSubstructure = carboElement.isSubstructure; }
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 { } }
private void setElementotals() { //Generate a new ALL elements list from the calculated values in the Groups List <CarboElement> elementbuffer = getTemporaryElementListWithTotals(); //Now Imprint them into the elements totals bool okSet = false; foreach (CarboGroup cg in groupList) { if (cg.AllElements != null) { if (cg.AllElements.Count > 0) { for (int i = 0; i <= cg.AllElements.Count - 1; i++) { CarboElement ce = cg.AllElements[i]; ce = addBufferToElements(elementbuffer, ce, out okSet); } } } } }
private bool updateinGroups(CarboElement ceNew) { bool result = false; foreach (CarboGroup cg in getGroupList) { if (cg.AllElements.Count > 0) { foreach (CarboElement ceOld in cg.AllElements) { bool isSimilar = isElementSimilar(ceOld, ceNew); if (isSimilar == true) { //A match was found, check the materials ceOld.Volume = ceNew.Volume; ceOld.Volume_Total = 0; //not sure about the below: //ceOld.Category = ceNew.Category; //ceOld.SubCategory = ceNew.SubCategory; //Set Flags ceOld.isUpdated = true; //Dont go looking for more elements return(true); //break; } } //group found, don't go looking for more groups } } //element is not found justSaved = false; return(result); }
/// <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); }
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); }
private List <CarboElement> addToBuffer(List <CarboElement> elementbuffer, CarboElement cElement, out bool ok) { bool isUnique = true; ok = false; if (elementbuffer != null) { foreach (CarboElement buffer_CE in elementbuffer) { try { if (buffer_CE.Id == cElement.Id) { //Merge Elements //double density = buffer_CE.EC_Total / (buffer_CE.Volume * buffer_CE.ECI_Total); double volume_Total = buffer_CE.Volume + cElement.Volume; double mass_Total = buffer_CE.Mass + cElement.Mass; double mass_TotalCheck = (buffer_CE.EC / buffer_CE.ECI) + (cElement.EC / cElement.ECI); //double Density_Total = mass_Total / volume_Total; double EC_Total = buffer_CE.EC_Total + cElement.EC; //Calculate combined ECI. double ECI_Total = EC_Total / mass_Total; //Total EC: buffer_CE.EC_Total = EC_Total; //Total Volume buffer_CE.Volume_Total = volume_Total; //Total ECI buffer_CE.ECI_Total = ECI_Total; //mass Total buffer_CE.Mass = mass_Total; //Density Total // n/a isUnique = false; ok = true; break; } } catch (Exception ex) { ok = false; MessageBox.Show(ex.Message); } } //The element doesnt exist yet in the list; add to the list as a new element. if (isUnique == true) { CarboElement newElement = new CarboElement(); newElement.Id = cElement.Id; newElement.Volume = cElement.Volume; newElement.ECI_Total = cElement.ECI; newElement.EC_Total = cElement.EC; newElement.Volume_Total = cElement.Volume; newElement.Mass = cElement.Mass; elementbuffer.Add(newElement); ok = true; } } justSaved = false; return(elementbuffer); }
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); }
private static bool ElementExists(ObservableCollection <CarboGroup> carboGroupList, CarboElement carboelement) { bool result = false; foreach (CarboGroup cg in carboGroupList) { foreach (CarboElement ce in cg.AllElements) { if (ce.Id == carboelement.Id) { result = true; } break; } } return(result); }
private static ObservableCollection <CarboGroup> UpdateElement(ObservableCollection <CarboGroup> carboGroupList, CarboElement carboElement) { foreach (CarboGroup cg in carboGroupList) { foreach (CarboElement ce in cg.AllElements) { if (ce.Id == carboElement.Id) { if (ce.Category == carboElement.Category) { ce.Volume = carboElement.Volume; } ce.SubCategory = carboElement.Category; } break; } } return(carboGroupList); }
private static ObservableCollection <CarboGroup> AddToCarboGroup(ObservableCollection <CarboGroup> carboGroupList, CarboElement carboElement, bool hasPrimaryClass, bool hasSecondaryClass, bool hasSpecialRequests, bool hasSubstructure, bool hasDemolition) { //OBsolete return(carboGroupList); }
public void AddElement(CarboElement carboElement) { elementList.Add(carboElement); }
public void AddElement(CarboElement carboElement) { elementList.Add(carboElement); justSaved = false; }