public SpecObjectViewerWindow(SpecobjectViewModel specObject)
        {
            InitializeComponent();

            _specObject = specObject;

            //Create temporary collection of attributes
            _attributes = new ObservableCollection <AttributeValueViewModel>();
            foreach (var value in specObject.Values)
            {
                AttributeValue AttributeValue;
                if (value.AttributeValue != null)
                {
                    AttributeValue = value.AttributeValue.Clone();
                    AttributeValue.PropertyChanged += AttributeValue_PropertyChanged;
                }
                else
                {
                    AttributeValue = null;
                }
                _attributes.Add(new AttributeValueViewModel()
                {
                    AttributeValue      = AttributeValue,
                    AttributeDefinition = value.AttributeDefinition
                });
            }
            DataTable.ItemsSource    = _attributes;
            InfoExpander.DataContext = specObject;
        }
예제 #2
0
        public SpecObjectsViewModel(ReqIFContent content)
        {
            foreach (SpecObject specObject in content.SpecObjects)
            {
                SpecobjectViewModel specobjectViewModel = new SpecobjectViewModel()
                {
                    Identifier    = specObject.Identifier,
                    AlternativeId = specObject.AlternativeId,
                    Description   = specObject.Description,
                    LastChange    = specObject.LastChange,
                    LongName      = specObject.LongName,
                    Type          = specObject.Type,
                    SpecType      = specObject.SpecType
                };
                foreach (AttributeDefinition attributeDefinition in content.SpecTypes.Single(x => x == specObject.SpecType).SpecAttributes)
                {
                    AttributeValue attributeValue = specObject.Values.Where(x => x.AttributeDefinition == attributeDefinition).FirstOrDefault();

                    specobjectViewModel.Values.Add(new AttributeValueViewModel()
                    {
                        AttributeValue = attributeValue, AttributeDefinition = attributeDefinition
                    });
                }
                this.SpecObjects.Add(specobjectViewModel);
            }
        }
예제 #3
0
        public void Add_SpecObject(string position)
        {
            SpecobjectViewModel specObject = new SpecobjectViewModel()
            {
                Identifier = Guid.NewGuid().ToString(),
                LastChange = DateTime.Now
            };

            foreach (AttributeDefinition attributeDefinition in content.SpecTypes.First().SpecAttributes)
            {
                specObject.Values.Add(new AttributeValueViewModel()
                {
                    AttributeValue      = null,
                    AttributeDefinition = attributeDefinition
                });
            }
            Edit_SpecObject(specObject, true, position);
        }
예제 #4
0
        public void Edit_SpecObject(SpecobjectViewModel specObject, bool createSpecObject, string position = null)
        {
            SpecObjectViewerWindow SpecObjectViewer = new SpecObjectViewerWindow(specObject);

            SpecObjectViewer.Owner = Window.GetWindow(this);
            if (SpecObjectViewer.ShowDialog() == true)
            {
                if (createSpecObject)
                {
                    int currentIndex = 0;
                    SpecobjectViewModel currentModelObject = (Application.Current.MainWindow as MainWindow).MainDataGrid.SelectedItem as SpecobjectViewModel;
                    SpecObject          currentObject      = (Application.Current.MainWindow as MainWindow).content.SpecObjects.Single(x => x.Identifier == currentModelObject.Identifier);
                    var specifications = (Application.Current.MainWindow as MainWindow).content.Specifications;

                    //Create new SpecObject and add Attributes
                    SpecObject newSpecObject = new SpecObject()
                    {
                        Description = specObject.Description,
                        Identifier  = specObject.Identifier,
                        LastChange  = specObject.LastChange,
                        Type        = currentObject.Type
                    };
                    foreach (var attribute in specObject.Values)
                    {
                        if (attribute.AttributeValue != null)
                        {
                            newSpecObject.Values.Add(attribute.AttributeValue);
                        }
                    }

                    //Add SpecObject to SpecHierarchy and to SpecObjects
                    SpecHierarchy specHierarchy = specifications.First().Children.First().Descendants()
                                                  .Where(node => node.Object == currentObject).First();
                    if (position == "after")
                    {
                        SpecHierarchy parentSpecHierarchy = specHierarchy.Container;
                        int           specHierarchyIndex  = parentSpecHierarchy.Children.IndexOf(specHierarchy);
                        parentSpecHierarchy.Children.Insert(specHierarchyIndex + 1, new SpecHierarchy()
                        {
                            Object     = newSpecObject,
                            Identifier = Guid.NewGuid().ToString(),
                            LastChange = DateTime.Now
                        });
                        var previousObject = specHierarchy.Descendants().Last().Object;
                        currentIndex = (Application.Current.MainWindow as MainWindow).content.SpecObjects.IndexOf(previousObject);
                    }
                    else if (position == "under")
                    {
                        specHierarchy.Children.Insert(0, new SpecHierarchy()
                        {
                            Object     = newSpecObject,
                            Identifier = Guid.NewGuid().ToString(),
                            LastChange = DateTime.Now
                        });
                        currentIndex = (Application.Current.MainWindow as MainWindow).MainDataGrid.SelectedIndex;
                    }
                    this.specObjectsViewModel.SpecObjects.Insert(currentIndex + 1, specObject);
                    this.content.SpecObjects.Insert(currentIndex + 1, newSpecObject);
                }
                else
                {
                    var originalSpecObject = content.SpecObjects.Single(x => x.Identifier == specObject.Identifier);
                    //Update changed AttributeValues
                    foreach (var definition in specObject.Values.Where(x => x.changed == true))
                    {
                        originalSpecObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).ObjectValue
                            = specObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).AttributeValue.ObjectValue;
                    }
                    //Add new AttributeValues to original SpecObject
                    foreach (var definition in specObject.Values.Where(x => x.added == true))
                    {
                        originalSpecObject.Values.Add(specObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition).AttributeValue);
                    }
                    // Remove AttributeValues from original SpecObject
                    foreach (var definition in specObject.Values.Where(x => x.removed == true))
                    {
                        originalSpecObject.Values.Remove(originalSpecObject.Values.Single(x => x.AttributeDefinition == definition.AttributeDefinition));
                    }
                }
            }
        }