private ElectricalPropertyValue GetPropertyValue(ElectricalEquipmentComponent controlSystemComponent, ElectricalEquipmentComponentTypeProperty controlSystemComponentProperty) { var propertyValue = (from x in controlSystemComponent.ElectricalPropertyValues where x.ElectricalEquipmentPropertyId == controlSystemComponentProperty.ElectricalEquipmentPropertyId && x.ElectricalEquipmentComponentId == controlSystemComponent.Id select x).FirstOrDefault(); if (propertyValue == null) { propertyValue = new ElectricalPropertyValue { ElectricalEquipmentComponentId = controlSystemComponent.Id, ElectricalEquipmentPropertyId = controlSystemComponentProperty.ElectricalEquipmentPropertyId, Value = controlSystemComponentProperty.ElectricalEquipmentProperty.DefaultValue }; controlSystemComponent.ElectricalPropertyValues.Add(propertyValue); } return propertyValue; }
private void BuildPropertyValues(ElectricalEquipmentComponent componentIn, ElectricalComponentDataAdapter adapter) { foreach (KeyValuePair<string, string> pair in adapter.PropertyValues) { //DOES PROPERTY EXIST? ElectricalEquipmentProperty property = (from x in mExistingEquipmentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault(); if (property == null) { if (CanCreateProperties) { property = new ElectricalEquipmentProperty { Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)." }; mExistingEquipmentProperties.Add(property);//update cache } else { //ERROR! RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Name {3}' : The property does not exist.", WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.ComponentName)); continue; } } //CHECK ElectricalEquipmentComponentTypeProperty Exists ElectricalEquipmentComponentTypeProperty equipmentComponentTypeProperty = null; if (mExistingEquipmentComponentTypeProperty.Any()) { equipmentComponentTypeProperty = (from x in mExistingEquipmentComponentTypeProperty where x.ElectricalEquipmentComponentType.Name.ToLower() == componentIn.ElectricalEquipmentComponentType.Name.ToLower() && x.ElectricalEquipmentProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); } if (equipmentComponentTypeProperty == null) { if (CanCreateProperties) { //CREATE JOIN ROW equipmentComponentTypeProperty = new ElectricalEquipmentComponentTypeProperty(); equipmentComponentTypeProperty.ElectricalEquipmentComponentType = componentIn.ElectricalEquipmentComponentType; //note: set the object! equipmentComponentTypeProperty.ElectricalEquipmentProperty = property; //not set the object! mExistingEquipmentComponentTypeProperty.Add(equipmentComponentTypeProperty); //update cache } else { //ERROR! RaiseMessage(CommonUtils.MessageType.Warning, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Type {3}' : The property {4} does not belong to the Component Type.", WorkSheetName, adapter.RowNumber, adapter.Tag, componentIn.ElectricalEquipmentComponentType.Name, property.Name)); continue; } } property.ElectricalEquipmentComponentTypeProperties.Add(equipmentComponentTypeProperty); //CHECK PROPERTYVALUE EXISTS ElectricalPropertyValue propertyValue = null; if (mExistingPropertyValues.Any()) { propertyValue = (from x in mExistingPropertyValues where x.ElectricalEquipmentComponent.Name.ToLower() == componentIn.Name.ToLower() && x.ElectricalEquipmentProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); } if (propertyValue == null) { propertyValue = new ElectricalPropertyValue(); propertyValue.ElectricalEquipmentComponent = componentIn; propertyValue.ElectricalEquipmentProperty = property; mExistingPropertyValues.Add(propertyValue);//update cache } //set value if (!string.IsNullOrEmpty(pair.Value)) { propertyValue.Value = pair.Value.ChangeNullToEmptyString(); } componentIn.ElectricalPropertyValues.Add(propertyValue); } }