public AddExistingPipeComponentProperty(PipeComponentTypeProperty pcpt)
        {
            InitializeComponent();
            mPipeComponentTypeProperty = pcpt;
            mPipeComponentPropertyTypeViewModel = new PipeComponentPropertyTypeViewModel(pcpt);

            propertyComboBox.Items.Add(mPipeComponentPropertyTypeViewModel.ComponentProperty);
            propertyComboBox.SelectedItem = mPipeComponentPropertyTypeViewModel.ComponentProperty;

            propertyComboBox.IsEnabled = false;

            this.DataContext = mPipeComponentPropertyTypeViewModel;
        }
        public AddExistingPipeComponentProperty(int componentTypeId)
        {
            InitializeComponent();
            mPipeComponentTypeProperty = new PipeComponentTypeProperty();
            mPipeComponentTypeProperty.ComponentTypeId = componentTypeId;
            mPipeComponentPropertyTypeViewModel = new PipeComponentPropertyTypeViewModel(mPipeComponentTypeProperty);

            //Load Component types
            EventHandler<GetAllPipePropertiesCompletedEventArgs> fetchPipeComponentPropertiesCompleted = null;
            fetchPipeComponentPropertiesCompleted = (s, eventArgs) =>
            {

                List<PipeProperty> pipeComponentProperties = new List<PipeProperty>();

                mCmsWebServiceClient.GetPipePropertiesCompleted +=
                    (s1, e1)
                    =>
                        {
                            List<int> listOfAssignedPropertyIds = new List<int>();
                            e1.Result.ForEach(x => listOfAssignedPropertyIds.Add(x.Id));

                            //Remove already assgned properties
                            foreach (var pipeComponentProperty in eventArgs.Result)
                            {
                                if (!listOfAssignedPropertyIds.Contains(pipeComponentProperty.Id))
                                {
                                    pipeComponentProperties.Add(pipeComponentProperty);
                                }
                            }

                            propertyComboBox.ItemsSource = pipeComponentProperties;

                            if (pipeComponentProperties.Count > 0)
                            {
                                mPipeComponentPropertyTypeViewModel.ComponentProperty = pipeComponentProperties[0];
                                propertyComboBox.SelectedItem = mPipeComponentPropertyTypeViewModel.ComponentProperty;
                            }

                            OKButton.IsEnabled = pipeComponentProperties.Count > 0;
                        };

                mCmsWebServiceClient.GetPipePropertiesAsync(componentTypeId);

            };
            mCmsWebServiceClient.GetAllPipePropertiesCompleted += fetchPipeComponentPropertiesCompleted;
            mCmsWebServiceClient.GetAllPipePropertiesAsync(componentTypeId);

            this.DataContext = mPipeComponentPropertyTypeViewModel;
        }
Exemplo n.º 3
0
        public PipeComponentTypeProperty AddPipeComponentTypeProperty(PipeComponentTypeProperty pcpt)
        {
            PipeComponentTypeProperty tempPcpt;

            using (CmsEntities cee = new CmsEntities())
            {
                //Check if this component property already exist
                tempPcpt = (from x in cee.PipeComponentTypeProperties
                            where x.PipeProperty.Id == pcpt.PipePropertyId &&
                                  x.PipeComponentType.Id == pcpt.ComponentTypeId
                            select x).FirstOrDefault();

                if (tempPcpt == null)
                {
                    //Add new Component Type
                    tempPcpt = new PipeComponentTypeProperty();
                    tempPcpt.PipePropertyId = pcpt.PipePropertyId;
                    tempPcpt.ComponentTypeId = pcpt.ComponentTypeId;
                    tempPcpt.Ordinal = pcpt.Ordinal;

                    cee.PipeComponentTypeProperties.Add(tempPcpt);
                    cee.SaveChanges();
                }
                else
                {
                    tempPcpt.Ordinal = pcpt.Ordinal;
                    cee.SaveChanges();
                }
                return tempPcpt;
            }
        }
        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;
        }
Exemplo n.º 5
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);
            }
        }
 public PipeComponentPropertyTypeViewModel(PipeComponentTypeProperty pcpt)
 {
     mPipeComponentTypeProperty = pcpt;
 }