Exemple #1
0
 private void LoadTemplateProperties(ObjectAssociationModel templateItem)
 {
     //var propertyItem = PropertyViewModelLocator.GetPropertyVM().GetProperty(objectAssociationItem.Association_ID, null);
     //if (templateItem != null)
     //{
     //objectAssociationItem.Name = templateItem.TemplateName;
     //objectAssociationItem.Description = templateItem.Description;
     //objectAssociationItem.AssociationType_ID = templateItem.TemplateType_ID;
     // and get any child items
     foreach (var itemAssociation in TemplateAssociationViewModelLocator.GetTemplateAssociationVM().TemplateAssociations)
     {
         if (itemAssociation.Template_ID == templateItem.Association_ID)
         {
             var propertyItem = PropertyViewModelLocator.GetPropertyVM().GetProperty(itemAssociation.Association_ID);
             if (propertyItem != null)
             {
                 ObjectAssociationModel item = new ObjectAssociationModel
                 {
                     ID                 = itemAssociation.ID,
                     Project_ID         = templateItem.Project_ID,
                     Object_ID          = templateItem.Object_ID,
                     Association_ID     = itemAssociation.Association_ID,
                     Name               = propertyItem.PropertyName,
                     Description        = propertyItem.Description,
                     AssociationType    = "TemplateProperty",
                     AssociationType_ID = itemAssociation.AssociationType_ID,
                     IsChanged          = false,
                     IsNew              = false,
                     ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                 };
                 templateItem.ChildAssociations.Add(item);
             }
         }
     }
     //}
     //else
     //{
     //    throw new System.InvalidOperationException(String.Format("Association without source\nTemplate ID: {0}\nFix in database", objectAssociationItem.Association_ID));
     //}
 }
Exemple #2
0
        public void AssociateWithObject(TreeListViewRow destination)
        {
            try
            {
                foreach (var objectItem in ObjectViewModelLocator.GetObjectVM().SelectedItems)
                {
                    switch (Globals.DraggedItem.Type)
                    {
                    case "Template":
                        foreach (var templateItem in TemplateViewModelLocator.GetTemplateVM().SelectedItems)
                        {
                            ObjectAssociationModel objectAssociationItem = new ObjectAssociationModel
                            {
                                IsNew             = true,
                                IsChanged         = false,
                                IsDeleted         = false,
                                ID                = Guid.NewGuid(),
                                Project_ID        = Globals.Project_ID,
                                Object_ID         = objectItem.ID,
                                AssociationType   = Globals.DraggedItem.Type,
                                Value             = "",
                                ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>(),
                            };
                            objectAssociationItem.Association_ID     = templateItem.ID;
                            objectAssociationItem.Name               = templateItem.TemplateName;
                            objectAssociationItem.Description        = templateItem.Description;
                            objectAssociationItem.AssociationType_ID = templateItem.TemplateType_ID;

                            foreach (var childItem in templateItem.ChildTemplates)
                            {
                                ObjectAssociationModel objectAssociationChildItem = new ObjectAssociationModel
                                {
                                    IsNew              = true,
                                    IsChanged          = false,
                                    IsDeleted          = false,
                                    ID                 = Guid.NewGuid(),
                                    AssociationType    = "Template",
                                    Project_ID         = Globals.Project_ID,
                                    Object_ID          = objectItem.ID,
                                    Association_ID     = childItem.ID,
                                    Name               = childItem.TemplateName,
                                    Description        = childItem.Description,
                                    AssociationType_ID = childItem.TemplateType_ID,
                                    Value              = "",
                                    ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                                };
                                objectAssociationItem.ChildAssociations.Add(objectAssociationChildItem);
                                LoadTemplateProperties(objectAssociationChildItem);
                            }
                            ;
                            ObjectAssociations.Add(objectAssociationItem);
                            LoadTemplateProperties(objectAssociationItem);
                        }
                        break;

                    case "Property":
                        foreach (var propertyItem in PropertyViewModelLocator.GetPropertyVM().SelectedItems)
                        {
                            ObjectAssociationModel objectAssociationItem = new ObjectAssociationModel
                            {
                                IsNew             = true,
                                IsChanged         = false,
                                IsDeleted         = false,
                                ID                = Guid.NewGuid(),
                                Project_ID        = Globals.Project_ID,
                                Object_ID         = objectItem.ID,
                                AssociationType   = Globals.DraggedItem.Type,
                                Value             = "",
                                ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>(),
                            };

                            objectAssociationItem.Association_ID     = propertyItem.ID;
                            objectAssociationItem.Name               = propertyItem.PropertyName;
                            objectAssociationItem.Description        = propertyItem.Description;
                            objectAssociationItem.AssociationType_ID = propertyItem.PropertyType_ID;

                            foreach (var childItem in propertyItem.ChildProperties)
                            {
                                ObjectAssociationModel objectAssociationChildItem = new ObjectAssociationModel
                                {
                                    IsNew              = true,
                                    IsChanged          = false,
                                    IsDeleted          = false,
                                    AssociationType    = "Property",
                                    Project_ID         = Globals.Project_ID,
                                    Object_ID          = objectItem.ID,
                                    Association_ID     = childItem.ID,
                                    Name               = childItem.PropertyName,
                                    Description        = childItem.Description,
                                    AssociationType_ID = childItem.PropertyType_ID,
                                    Value              = "",
                                    ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                                };
                                objectAssociationItem.ChildAssociations.Add(objectAssociationChildItem);
                            }
                            ObjectAssociations.Add(objectAssociationItem);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                RadWindow.Alert(ex.Message);
            }
        }
Exemple #3
0
        private void Load(Guid?associationParent_ID)
        {
            // Check if the templates and properties have ben loaded. Necessary because of the various background workers
            //while (!TemplateViewModelLocator.IsLoaded() || !PropertyViewModelLocator.IsLoaded());
            try
            {
                using (EDBEntities eDB = new EDBEntities())
                {
                    foreach (tblObjectAssociation Rec in (from o in eDB.tblObjectAssociations where (o.Project_ID == Globals.Project_ID) orderby o.AssociationType select o))
                    {
                        ObjectAssociationModel objectAssociationItem = new ObjectAssociationModel
                        {
                            ID                = Rec.ID,
                            Project_ID        = Rec.Project_ID,
                            Object_ID         = Rec.Object_ID,
                            Association_ID    = Rec.Association_ID,
                            AssociationType   = Rec.AssociationType,
                            IsChanged         = false,
                            IsNew             = false,
                            IsDeleted         = false,
                            ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>()
                        };
                        switch (objectAssociationItem.AssociationType)
                        {
                        case "Template":
                            // Get detail info of the template
                            var templateItem = TemplateViewModelLocator.GetTemplateVM().GetTemplate(objectAssociationItem.Association_ID, null);
                            if (templateItem != null)
                            {
                                objectAssociationItem.Name               = templateItem.TemplateName;
                                objectAssociationItem.Description        = templateItem.Description;
                                objectAssociationItem.AssociationType_ID = templateItem.TemplateType_ID;
                                // and get any child items
                                foreach (var childItem in templateItem.ChildTemplates)
                                {
                                    ObjectAssociationModel item = new ObjectAssociationModel
                                    {
                                        ID                 = Rec.ID,
                                        Project_ID         = childItem.Project_ID,
                                        Object_ID          = objectAssociationItem.Object_ID,
                                        Association_ID     = childItem.ID,
                                        Name               = childItem.TemplateName,
                                        Description        = childItem.Description,
                                        AssociationType    = "Template",
                                        AssociationType_ID = childItem.TemplateType_ID,
                                        ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                                    };
                                    objectAssociationItem.ChildAssociations.Add(item);
                                    LoadTemplateProperties(item);
                                }
                                LoadTemplateProperties(objectAssociationItem);
                            }
                            else
                            {
                                throw new System.InvalidOperationException(String.Format("Association without source\nTemplate ID: {0}\nFix in database", objectAssociationItem.Association_ID));
                            }

                            break;

                        case "Property":
                            var propertyItem = PropertyViewModelLocator.GetPropertyVM().GetProperty(objectAssociationItem.Association_ID, null);
                            if (propertyItem != null)
                            {
                                objectAssociationItem.Name               = propertyItem.PropertyName;
                                objectAssociationItem.Description        = propertyItem.Description;
                                objectAssociationItem.AssociationType_ID = propertyItem.PropertyType_ID;

                                // If the Object Association has a value in the table, use this as the associated value
                                // otherwise use the value defined in the property
                                if (!String.IsNullOrEmpty(Rec.Value))
                                {
                                    objectAssociationItem.Value = Rec.Value;
                                }
                                else
                                {
                                    objectAssociationItem.Value = propertyItem.Value;
                                }

                                foreach (var childItem in propertyItem.ChildProperties)
                                {
                                    ObjectAssociationModel item = new ObjectAssociationModel
                                    {
                                        ID                 = Rec.ID,
                                        Project_ID         = childItem.Project_ID,
                                        Object_ID          = objectAssociationItem.Object_ID,
                                        Association_ID     = childItem.ID,
                                        Name               = childItem.PropertyName,
                                        Description        = childItem.Description,
                                        AssociationType    = "Property",
                                        AssociationType_ID = childItem.PropertyType_ID,
                                        ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                                    };
                                    objectAssociationItem.ChildAssociations.Add(item);
                                }
                            }
                            else
                            {
                                throw new System.InvalidOperationException(String.Format("Association without source\nProperty ID: {0}\nFix in database", objectAssociationItem.Association_ID));
                            }
                            break;

                        case "TemplateProperty":
                            break;
                        }

                        ObjectAssociations.Add(objectAssociationItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Application.Current.Dispatcher.Invoke((Action) delegate { RadWindow.Alert(ex.Message); });
            }
        }