示例#1
0
        public PipeProperty SavePipeProperty(PipeProperty pipeProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                PipeProperty original = (from x in cee.PipeProperties where x.Id == pipeProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.PipeProperties.Add(pipeProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(pipeProperty);
                }

                cee.SaveChanges();
            }
            return pipeProperty;
        }
 public PipeComponentPropertyViewModel(PipeProperty pcp)
 {
     mPcp = pcp;
 }
示例#3
0
        public PipeProperty AddPipeProperty(PipeProperty pcp)
        {
            PipeProperty tempPcp;
            using (CmsEntities cee = new CmsEntities())
            {
                //Check if this component property already exist
                tempPcp = (from x in cee.PipeProperties
                           where x.Id == pcp.Id
                           select x).FirstOrDefault();

                if (tempPcp != null)
                {
                    //Edit the Component Property
                    tempPcp.Name = pcp.Name;
                    tempPcp.DefaultValue = pcp.DefaultValue;
                    tempPcp.Description = pcp.Description;
                }
                else
                {
                    //Add new Component Type
                    tempPcp = new PipeProperty();
                    tempPcp.Name = pcp.Name;
                    tempPcp.DefaultValue = pcp.DefaultValue;
                    tempPcp.Description = pcp.Description;
                    cee.PipeProperties.Add(tempPcp);
                }
                cee.SaveChanges();

                return tempPcp;
            }
        }
示例#4
0
        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);
            }
        }