Beispiel #1
0
        public bool SavePipePropertyValues(List<PipePropertyValue> pipeComponentPropertyValues)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                foreach (var pipeComponentPropertyValue in pipeComponentPropertyValues)
                {
                    var q = (from x in cee.PipePropertyValues
                             where x.Id == pipeComponentPropertyValue.Id
                             select x).FirstOrDefault();

                    if (q == null)
                    {
                        q = new PipePropertyValue
                            {
                                ComponentId = pipeComponentPropertyValue.ComponentId,
                                PipePropertyId = pipeComponentPropertyValue.PipePropertyId,
                                Value = pipeComponentPropertyValue.Value
                            };
                        cee.PipePropertyValues.Add(q);
                        //cee.AddToPipePropertyValues(q);
                    }
                    else
                    {
                        q.PipePropertyId = pipeComponentPropertyValue.PipePropertyId;
                        q.ComponentId = pipeComponentPropertyValue.ComponentId;
                        q.Value = pipeComponentPropertyValue.Value;
                    }
                    cee.SaveChanges();
                }
            }
            return true;
        }
        private void BuildPropertyValues(PipeComponent componentIn, PipeComponentDataAdapter adapter, int index)
        {
            foreach (var pair in adapter.PropertyValues)
            {
                //DOES PROPERTY EXIST?
                PipeProperty property = (from x in mExistingComponentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault();
                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new PipeProperty {Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)."};
                        mExistingComponentProperties.Add(property); //update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1} Tag {2} Component Name {3}' : The property does not exist.", WorkSheetName, index, adapter.Tag, adapter.ComponentName));
                        continue;
                    }
                }

                //CHECK PipeEquipmentComponentTypeProperty Exists
                PipeComponentTypeProperty equipmentComponentTypeProperty = null;
                if (mExistingEquipmentComponentTypeProperty.Any())
                {
                    equipmentComponentTypeProperty =
                        (from x in mExistingEquipmentComponentTypeProperty
                            where x.PipeComponentType.Name.ToLower() == componentIn.PipeComponentType.Name.ToLower()
                                  && x.PipeProperty.Name.ToLower() == property.Name.ToLower()
                            select x).FirstOrDefault();
                }

                if (equipmentComponentTypeProperty == null)
                {
                    if (CanCreateProperties)
                    {
                        //CREATE JOIN ROW
                        equipmentComponentTypeProperty = new PipeComponentTypeProperty();
                        equipmentComponentTypeProperty.PipeComponentType = componentIn.PipeComponentType; //note: set the object!
                        equipmentComponentTypeProperty.PipeProperty = 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.PipeComponentType.Name, property.Name));
                        continue;
                    }
                }
                property.PipeComponentTypeProperties.Add(equipmentComponentTypeProperty);

                //CHECK PROPERTYVALUE EXISTS
                PipePropertyValue propertyValue = null;
                if (mExistingPropertyValues.Any())
                {
                    propertyValue = (from x in mExistingPropertyValues
                        where x.PipeComponent.Name.ToLower() == componentIn.Name.ToLower()
                              && x.PipeProperty.Name.ToLower() == property.Name.ToLower()
                        select x).FirstOrDefault();
                }

                if (propertyValue == null)
                {
                    propertyValue = new PipePropertyValue();
                    propertyValue.PipeComponent = componentIn;
                    propertyValue.PipeProperty = property;
                    mExistingPropertyValues.Add(propertyValue); //update cache
                }

                //set value
                if (!string.IsNullOrEmpty(pair.Value))
                {
                    propertyValue.Value = pair.Value.ChangeNullToEmptyString();
                }
                componentIn.PipePropertyValues.Add(propertyValue);
            }
        }
        private PipePropertyValue GetPropertyValue(PipeComponent controlSystemComponent,
            PipeComponentTypeProperty controlSystemComponentProperty)
        {
            var propertyValue = (from x in controlSystemComponent.PipePropertyValues
                                 where x.PipePropertyId == controlSystemComponentProperty.PipePropertyId &&
                                       x.ComponentId == controlSystemComponent.Id
                                 select x).FirstOrDefault();

            if (propertyValue == null)
            {
                propertyValue = new PipePropertyValue
                {
                    ComponentId = controlSystemComponent.Id,
                    PipePropertyId = controlSystemComponentProperty.PipePropertyId,
                    Value = controlSystemComponentProperty.PipeProperty.DefaultValue
                };

                controlSystemComponent.PipePropertyValues.Add(propertyValue);
            }
            return propertyValue;
        }
 public PipeComponentPropertyValueViewModel(PipePropertyValue pcpv)
 {
     mPipeComponentPropertyValue = pcpv;
 }