Esempio n. 1
0
        /// <summary>
        /// Find the Object with the searchItemID. This is a recursive function which looks through all levels of the tree
        /// If the treeLevel is omitted, the search will start in the root items
        /// </summary>
        /// <param name="searchItemID"></param>
        /// <param name="treeLevel"></param>
        /// <returns></returns>
        public TemplateModel GetTemplate(Guid?searchItemID, TD.ObservableItemCollection <TemplateModel> treeLevel = null)
        {
            // Select the root level if the treeLevel = null
            if (treeLevel == null)
            {
                treeLevel = Templates;
            }
            foreach (var templateItem in treeLevel)
            {
                // return the item if found on this level
                if (templateItem.ID == searchItemID)
                {
                    return(templateItem);
                }

                if (templateItem.ChildTemplates != null && templateItem.ChildTemplates.Count != 0)
                {
                    // Recursively call the method to find the item in the ChildProperties
                    TemplateModel childTemplateItem = GetTemplate(searchItemID, templateItem.ChildTemplates);
                    if (childTemplateItem != null)
                    {
                        return(childTemplateItem);
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Find the Object with the searchItemID. This is a recursive function which looks through all levels of the tree
        /// If the treeLevel is omitted, the search will start in the root items
        /// </summary>
        /// <param name="searchItemID"></param>
        /// <param name="treeLevel"></param>
        /// <returns></returns>
        public PropertyModel GetProperty(Guid?searchItemID, TD.ObservableItemCollection <PropertyModel> treeLevel = null)
        {
            // Select the root level if the treeLevel = null
            if (treeLevel == null)
            {
                treeLevel = Properties;
            }
            foreach (var propertyItem in treeLevel)
            {
                // return the item if found on this level
                if (propertyItem.ID == searchItemID)
                {
                    return(propertyItem);
                }

                if (propertyItem.ChildProperties != null)
                {
                    // Recursively call the method to find the item in the ChildProperties
                    PropertyModel childPropertyItem = GetProperty(searchItemID, propertyItem.ChildProperties);
                    if (childPropertyItem != null)
                    {
                        return(childPropertyItem);
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Find the Object with the searchItemID. This is a recursive function which looks through all levels of the tree
        /// If the treeLevel is omitted, the search will start in the root items
        /// </summary>
        /// <param name="searchItemID"></param>
        /// <param name="treeLevel"></param>
        /// <returns></returns>
        private ObjectModel GetObject(Guid?searchItemID, TD.ObservableItemCollection <ObjectModel> treeLevel = null)
        {
            // Select the root level if the treeLevel = null
            if (treeLevel == null)
            {
                treeLevel = Objects;
            }
            foreach (var objectItem in treeLevel)
            {
                // return the item if found on this level
                if (objectItem.ID == searchItemID)
                {
                    return(objectItem);
                }

                if (objectItem.ChildObjects != null)
                {
                    // Recursively call the method to find the item in the ChildObjects
                    ObjectModel childObjectItem = GetObject(searchItemID, objectItem.ChildObjects);
                    if (childObjectItem != null)
                    {
                        return(childObjectItem);
                    }
                }
            }
            return(null);
        }
Esempio n. 4
0
        public RequirementModel GetRequirement(Guid?searchItemID, TD.ObservableItemCollection <RequirementModel> treeLevel = null)
        {
            // Select the root level if the treeLevel = null
            if (treeLevel == null)
            {
                treeLevel = Requirements;
            }
            foreach (var requirementItem in treeLevel)
            {
                // return the item if found on this level
                if (requirementItem.ID == searchItemID)
                {
                    return(requirementItem);
                }

                if (requirementItem.ChildRequirements != null)
                {
                    // Recursively call the method to find the item in the ChildObjects
                    RequirementModel childRequirementItem = GetRequirement(searchItemID, requirementItem.ChildRequirements);
                    if (childRequirementItem != null)
                    {
                        return(childRequirementItem);
                    }
                }
            }
            return(null);
        }
Esempio n. 5
0
 /// <summary>
 /// Saves all changes to the ViewModel
 /// </summary>
 private void SaveLevel(TD.ObservableItemCollection <PropertyModel> treeLevel, EDBEntities eDB)
 {
     try
     {
         if (treeLevel != null)
         {
             foreach (var propertyItem in treeLevel)
             {
                 if (propertyItem.IsNew)
                 {
                     tblProperty NewRec = new tblProperty();
                     var         Rec    = eDB.tblProperties.Add(NewRec);
                     Rec.ID              = propertyItem.ID;
                     Rec.Parent_ID       = propertyItem.Parent_ID;
                     Rec.PropertyName    = propertyItem.PropertyName;
                     Rec.Description     = propertyItem.Description;
                     Rec.Project_ID      = propertyItem.Project_ID;
                     Rec.PropertyType_ID = propertyItem.PropertyType_ID;
                     Rec.Aspect          = propertyItem.Aspect;
                     Rec.Attribute1      = propertyItem.Attribute1;
                     Rec.Attribute2      = propertyItem.Attribute2;
                     Rec.Attribute3      = propertyItem.Attribute3;
                     Rec.Value           = propertyItem.Value;
                     propertyItem.IsNew  = false;
                 }
                 if (propertyItem.IsChanged)
                 {
                     tblProperty Rec = eDB.tblProperties.Where(o => o.ID == propertyItem.ID).FirstOrDefault();
                     Rec.Parent_ID          = propertyItem.Parent_ID;
                     Rec.PropertyName       = propertyItem.PropertyName;
                     Rec.Description        = propertyItem.Description;
                     Rec.Project_ID         = propertyItem.Project_ID;
                     Rec.PropertyType_ID    = propertyItem.PropertyType_ID;
                     Rec.Aspect             = propertyItem.Aspect;
                     Rec.Attribute1         = propertyItem.Attribute1;
                     Rec.Attribute2         = propertyItem.Attribute2;
                     Rec.Attribute3         = propertyItem.Attribute3;
                     Rec.Value              = propertyItem.Value;
                     propertyItem.IsChanged = false;
                 }
                 // DeleteRecursive call to add/Update children
                 if (propertyItem.ChildProperties != null)
                 {
                     SaveLevel(propertyItem.ChildProperties, eDB);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         RadWindow.Alert(new DialogParameters()
         {
             Header  = "Error",
             Content = "Fault while adding/updating to database:\n" + ex.Message
         });
     }
 }
Esempio n. 6
0
 private void SaveLevel(TD.ObservableItemCollection <AspectModel> treeLevel, EDBEntities eDB)
 {
     try
     {
         if (treeLevel != null)
         {
             foreach (var aspectItem in treeLevel)
             {
                 if (aspectItem.IsNew)
                 {
                     tblAspect NewRec = new tblAspect();
                     var       Rec    = eDB.tblAspects.Add(NewRec);
                     Rec.ID           = aspectItem.ID;
                     Rec.AspectName   = aspectItem.AspectName;
                     Rec.Description  = aspectItem.Description;
                     Rec.Project_ID   = Globals.Project_ID;
                     Rec.HardIO       = aspectItem.HardIO;
                     Rec.ExtIO        = aspectItem.ExtIO;
                     Rec.PLCTag       = aspectItem.PLCTag;
                     Rec.SCADATag     = aspectItem.SCADATag;
                     Rec.AlarmTag     = aspectItem.AlarmTag;
                     Rec.TrendTag     = aspectItem.TrendTag;
                     Rec.Note         = aspectItem.Note;
                     aspectItem.IsNew = false;
                 }
                 if (aspectItem.IsChanged)
                 {
                     tblAspect Rec = eDB.tblAspects.Where(o => o.ID == aspectItem.ID).FirstOrDefault();
                     Rec.AspectName       = aspectItem.AspectName;
                     Rec.Description      = aspectItem.Description;
                     Rec.Project_ID       = Globals.Project_ID;
                     Rec.HardIO           = aspectItem.HardIO;
                     Rec.ExtIO            = aspectItem.ExtIO;
                     Rec.PLCTag           = aspectItem.PLCTag;
                     Rec.SCADATag         = aspectItem.SCADATag;
                     Rec.AlarmTag         = aspectItem.AlarmTag;
                     Rec.TrendTag         = aspectItem.TrendTag;
                     Rec.Note             = aspectItem.Note;
                     aspectItem.IsChanged = false;
                 }
                 if (aspectItem.IsDeleted)
                 {
                     tblAspect Rec = eDB.tblAspects.Where(o => o.ID == aspectItem.ID).FirstOrDefault();
                     if (Rec != null)
                     {
                         eDB.tblAspects.Remove(Rec);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         RadWindow.Alert("Fault while saving to database: " + ex.Message);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Saves all changes to the ViewModel
 /// </summary>
 private void SaveLevel(TD.ObservableItemCollection <ObjectModel> treeLevel, EDBEntities eDB)
 {
     try
     {
         if (treeLevel != null)
         {
             foreach (var objectItem in treeLevel)
             {
                 if (objectItem.IsNew)
                 {
                     tblObject NewRec = new tblObject();
                     var       Rec    = eDB.tblObjects.Add(NewRec);
                     Rec.ID            = objectItem.ID;
                     Rec.Parent_ID     = objectItem.Parent_ID;
                     Rec.ObjectName    = objectItem.ObjectName;
                     Rec.Description   = objectItem.Description;
                     Rec.Project_ID    = Globals.Project_ID;
                     Rec.ObjectType_ID = objectItem.ObjectType_ID;
                     Rec.IsExpanded    = objectItem.IsExpanded;
                     objectItem.IsNew  = false;
                 }
                 if (objectItem.IsChanged)
                 {
                     tblObject Rec = eDB.tblObjects.Where(o => o.ID == objectItem.ID).FirstOrDefault();
                     Rec.Parent_ID        = objectItem.Parent_ID;
                     Rec.ObjectName       = objectItem.ObjectName;
                     Rec.Description      = objectItem.Description;
                     Rec.Project_ID       = objectItem.Project_ID;
                     Rec.ObjectType_ID    = objectItem.ObjectType_ID;
                     Rec.IsExpanded       = objectItem.IsExpanded;
                     objectItem.IsChanged = false;
                 }
                 // Recursive call
                 if (objectItem.ChildObjects != null)
                 {
                     SaveLevel(objectItem.ChildObjects, eDB);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         RadWindow.Alert(new DialogParameters()
         {
             Header  = "Error",
             Content = "Fault while adding/updating to database:\n" + ex.Message
         });
     }
 }
 private void SaveLevel(TD.ObservableItemCollection <ObjectRequirementModel> treeLevel, EDBEntities eDB)
 {
     try
     {
         if (treeLevel != null)
         {
             foreach (var objectRequirementItem in treeLevel)
             {
                 if (objectRequirementItem.IsNew)
                 {
                     tblObjectRequirement NewRec = new tblObjectRequirement();
                     var Rec = eDB.tblObjectRequirements.Add(NewRec);
                     Rec.Object_ID      = objectRequirementItem.Object_ID;
                     Rec.Requirement_ID = objectRequirementItem.Requirement_ID;
                     Rec.PreFATOk       = objectRequirementItem.PreFATOk;
                     Rec.FATOk          = objectRequirementItem.FATOk;
                     Rec.FATBy          = objectRequirementItem.FATBy;
                     Rec.FATDate        = objectRequirementItem.FATDate;
                     Rec.SATOk          = objectRequirementItem.SATOk;
                     Rec.SATBy          = objectRequirementItem.SATBy;
                     Rec.SATDate        = objectRequirementItem.SATDate;
                     Rec.Project_ID     = Globals.Project_ID;
                     //Rec.RequirementType_ID = objectRequirementItem.RequirementType_ID;
                     objectRequirementItem.IsNew = false;
                     RequirementViewModel requirementVM   = RequirementViewModelLocator.GetRequirementVM();
                     RequirementModel     requirementItem = requirementVM.GetRequirement(objectRequirementItem.Requirement_ID);
                 }
                 if (objectRequirementItem.IsChanged)
                 {
                     tblObjectRequirement Rec = eDB.tblObjectRequirements.Where(o => o.Object_ID == objectRequirementItem.Object_ID && o.Requirement_ID == objectRequirementItem.Requirement_ID).FirstOrDefault();
                     Rec.PreFATOk = objectRequirementItem.PreFATOk;
                     Rec.FATOk    = objectRequirementItem.FATOk;
                     Rec.FATBy    = objectRequirementItem.FATBy;
                     Rec.FATDate  = objectRequirementItem.FATDate;
                     Rec.SATOk    = objectRequirementItem.SATOk;
                     Rec.SATBy    = objectRequirementItem.SATBy;
                     Rec.SATDate  = objectRequirementItem.SATDate;
                     objectRequirementItem.IsChanged = false;
                 }
                 // Recursive call
             }
         }
     }
     catch (Exception ex)
     {
         RadWindow.Alert("Fault while saving to database: " + ex.Message);
     }
 }
Esempio n. 9
0
        private void LoadTreeStateRecursive(TD.ObservableItemCollection <RequirementModel> isExpandedCollectionLevel)
        {
            foreach (var item in isExpandedCollectionLevel)
            {
                var requirementItem = GetRequirement(item.ID);
                if (requirementItem != null)
                {
                    requirementItem.IsExpanded = item.IsExpanded;
                }

                if (requirementItem.ChildRequirements.Count != 0)
                {
                    LoadTreeStateRecursive(item.ChildRequirements);
                }
            }
        }
Esempio n. 10
0
        private void LoadTreeStateRecursive(TD.ObservableItemCollection <ControlObjectModel> isExpandedCollectionLevel)
        {
            foreach (var item in isExpandedCollectionLevel)
            {
                var controllerItem = GetController(item.ID);
                if (controllerItem != null)
                {
                    controllerItem.IsExpanded = item.IsExpanded;
                }

                if (controllerItem.ChildControlObjects.Count != 0)
                {
                    LoadTreeStateRecursive(item.ChildControlObjects);
                }
            }
        }
Esempio n. 11
0
        private void LoadTreeStateRecursive(TD.ObservableItemCollection <TemplateModel> isExpandedCollectionLevel)
        {
            foreach (var item in isExpandedCollectionLevel)
            {
                var templateItem = GetTemplate(item.ID);
                if (templateItem != null)
                {
                    templateItem.IsExpanded = item.IsExpanded;
                }

                if (templateItem.ChildTemplates.Count != 0)
                {
                    LoadTreeStateRecursive(item.ChildTemplates);
                }
            }
        }
Esempio n. 12
0
        private void LoadTreeStateRecursive(TD.ObservableItemCollection <ObjectModel> isExpandedCollectionLevel)
        {
            foreach (var item in isExpandedCollectionLevel)
            {
                var objectItem = GetObject(item.ID);
                if (objectItem != null)
                {
                    objectItem.IsExpanded = item.IsExpanded;
                }

                if (objectItem.ChildObjects.Count != 0)
                {
                    LoadTreeStateRecursive(item.ChildObjects);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use
        /// </summary>
        /// <param name="Project_ID"></param>
        /// <param name="Parent_ID"></param>
        /// <returns>Observable collection of VMObjects</returns>
        private TD.ObservableItemCollection <PropertyModel> Load(Guid?Parent_ID)
        {
            TD.ObservableItemCollection <PropertyModel> childProperties = new TD.ObservableItemCollection <PropertyModel>();

            using (EDBEntities eDB = new EDBEntities())
            {
                foreach (tblProperty Rec in (from o in eDB.tblProperties where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) orderby o.PropertyName select o))
                {
                    PropertyModel propertyItem = new PropertyModel
                    {
                        ID              = Rec.ID,
                        Parent_ID       = Rec.Parent_ID,
                        Project_ID      = Rec.Project_ID,
                        PropertyName    = Rec.PropertyName,
                        Description     = Rec.Description,
                        PropertyType_ID = (int)Rec.PropertyType_ID,
                        Aspect          = Rec.Aspect,
                        Attribute1      = Rec.Attribute1,
                        Attribute2      = Rec.Attribute2,
                        Attribute3      = Rec.Attribute3,
                        Value           = Rec.Value,
                        IsChanged       = false,
                        IsNew           = false,
                        IsDeleted       = false
                    };

                    propertyItem.ChildProperties = Load(Rec.ID);

                    // If the parent ID is null, this is a root object and needs to be added to the VM class
                    // Else it is a child object which needs to be added to the childobjectlist
                    if (Rec.Parent_ID == null)
                    {
                        Properties.Add(propertyItem);
                    }
                    else
                    {
                        childProperties.Add(propertyItem);
                    }
                }
            }

            return(childProperties);
        }
Esempio n. 14
0
 /// <summary>
 /// Saves all changes to the ViewModel
 /// </summary>
 private void SaveLevel(TD.ObservableItemCollection <AttributeModel> treeLevel, EDBEntities eDB)
 {
     try
     {
         if (treeLevel != null)
         {
             foreach (var attributeItem in treeLevel)
             {
                 if (attributeItem.IsNew)
                 {
                     tblAttribute NewRec = new tblAttribute();
                     var          Rec    = eDB.tblAttributes.Add(NewRec);
                     Rec.ID              = attributeItem.ID;
                     Rec.Attribute       = attributeItem.Attribute;
                     Rec.Description     = attributeItem.Description;
                     Rec.Project_ID      = Globals.Project_ID;
                     attributeItem.IsNew = false;
                 }
                 if (attributeItem.IsChanged)
                 {
                     tblAttribute Rec = eDB.tblAttributes.Where(o => o.ID == attributeItem.ID).FirstOrDefault();
                     Rec.Attribute           = attributeItem.Attribute;
                     Rec.Description         = attributeItem.Description;
                     Rec.Project_ID          = attributeItem.Project_ID;
                     attributeItem.IsChanged = false;
                 }
                 if (attributeItem.IsDeleted)
                 {
                     tblAttribute Rec = eDB.tblAttributes.Where(o => o.Attribute == attributeItem.Attribute).FirstOrDefault();
                     if (Rec != null)
                     {
                         eDB.tblAttributes.Remove(Rec);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         RadWindow.Alert("Fault while saving to database: " + ex.Message);
     }
 }
Esempio n. 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="treeLevel"></param>
 /// <param name="searchItem"></param>
 /// <returns></returns>
 private Boolean FindObject(TD.ObservableItemCollection <ObjectModel> treeLevel, string searchItem)
 {
     if (treeLevel == null)
     {
         treeLevel = Objects;
     }
     foreach (var objectItem in treeLevel)
     {
         if (objectItem.ObjectName == searchItem)
         {
             return(true);
         }
         if (objectItem.ChildObjects != null)
         {
             if (FindObject(objectItem.ChildObjects, searchItem))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="treeLevel"></param>
 /// <param name="searchItem"></param>
 /// <returns></returns>
 private Boolean FindObject(TD.ObservableItemCollection <PropertyModel> treeLevel, string searchItem)
 {
     if (treeLevel == null)
     {
         treeLevel = Properties;
     }
     foreach (var propertyItem in treeLevel)
     {
         if (propertyItem.PropertyName == searchItem)
         {
             return(true);
         }
         if (propertyItem.ChildProperties != null)
         {
             if (FindObject(propertyItem.ChildProperties, searchItem))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="treeLevel"></param>
 /// <param name="searchItem"></param>
 /// <returns></returns>
 private Boolean FindObject(TD.ObservableItemCollection <TemplateModel> treeLevel, string searchItem)
 {
     if (treeLevel == null)
     {
         treeLevel = Templates;
     }
     foreach (var templateItem in treeLevel)
     {
         if (templateItem.TemplateName == searchItem)
         {
             return(true);
         }
         if (templateItem.ChildTemplates != null)
         {
             if (FindObject(templateItem.ChildTemplates, searchItem))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 18
0
        private TD.ObservableItemCollection <RequirementModel> Load(Guid?Parent_ID)
        {
            TD.ObservableItemCollection <RequirementModel> childRequirements = new TD.ObservableItemCollection <RequirementModel>();

            using (EDBEntities eDB = new EDBEntities())
            {
                foreach (tblRequirement Rec in (from o in eDB.tblRequirements where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) orderby o.ArticleNo select o))
                {
                    RequirementModel requirementItem = new RequirementModel
                    {
                        ID                 = Rec.ID,
                        Parent_ID          = Rec.Parent_ID,
                        Project_ID         = Globals.Project_ID, // Rec.Project_ID,
                        ArticleNo          = Rec.ArticleNo,
                        ArticleHeader      = Rec.ArticleHeader,
                        RequirementType_ID = (int)Rec.RequirementType_ID,
                        Content            = Rec.Content,
                        Version            = Rec.Version,
                        IsChanged          = false
                    };

                    // Load objects with a parent_ID equal to the ID of this object
                    requirementItem.ChildRequirements = Load(Rec.ID);

                    // If the parent ID is null, this is a root object and needs to be added to the collection that is the itemsource of the object tree
                    // Else it is a child object which needs to be added to the childobjectlist
                    if (Rec.Parent_ID == null)
                    {
                        Requirements.Add(requirementItem);
                    }
                    else
                    {
                        childRequirements.Add(requirementItem);
                    }
                }
            }
            IsChanged = false;
            return(childRequirements);
        }
Esempio n. 19
0
        /// <summary>
        /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use
        /// </summary>
        /// <param name="Project_ID"></param>
        /// <param name="Parent_ID"></param>
        /// <returns>Observable collection of VMObjects</returns>
        private TD.ObservableItemCollection <ObjectModel> Load(Guid?Parent_ID)
        {
            TD.ObservableItemCollection <ObjectModel> childObjects = new TD.ObservableItemCollection <ObjectModel>();
            // TD.ObservableItemCollection<ObjectModel> personalLayout = new TD.ObservableItemCollection<ObjectModel>();

            using (EDBEntities eDB = new EDBEntities())
            {
                foreach (tblObject Rec in (from o in eDB.tblObjects where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) orderby o.ObjectName select o))
                {
                    ObjectModel objectItem = new ObjectModel
                    {
                        ID            = Rec.ID,
                        Parent_ID     = Rec.Parent_ID,
                        Project_ID    = Rec.Project_ID,
                        ObjectName    = Rec.ObjectName,
                        Description   = Rec.Description,
                        ObjectType_ID = (int)Rec.ObjectType_ID,
                        IsChanged     = false,
                    };

                    // Load objects with a parent_ID equal to the ID of this object
                    objectItem.ChildObjects = Load(Rec.ID);

                    // If the parent ID is null, this is a root object and needs to be added to the collection that is the itemsource of the object tree
                    // Else it is a child object which needs to be added to the childobjectlist
                    if (Rec.Parent_ID == null)
                    {
                        Objects.Add(objectItem);
                    }
                    else
                    {
                        childObjects.Add(objectItem);
                    }
                }
            }
            IsChanged = false;
            return(childObjects);
        }
Esempio n. 20
0
        /// <summary>
        /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use
        /// </summary>
        /// <param name="Project_ID"></param>
        /// <param name="Parent_ID"></param>
        /// <returns>Observable collection of VMObjects</returns>
        private TD.ObservableItemCollection <TemplateModel> Load(Guid?Parent_ID)
        {
            TD.ObservableItemCollection <TemplateModel> childTemplates = new TD.ObservableItemCollection <TemplateModel>();

            using (EDBEntities eDB = new EDBEntities())
            {
                foreach (tblTemplate Rec in (from o in eDB.tblTemplates where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) select o))
                {
                    TemplateModel templateItem = new TemplateModel
                    {
                        ID              = Rec.ID,
                        Parent_ID       = Rec.Parent_ID,
                        Project_ID      = Rec.Project_ID,
                        TemplateName    = Rec.TemplateName,
                        Description     = Rec.Description,
                        TemplateType_ID = (int)Rec.TemplateType_ID,
                        IsChanged       = false,
                        IsNew           = false,
                        IsDeleted       = false
                    };

                    templateItem.ChildTemplates = Load(Rec.ID);

                    //        // If the parent ID is null, this is a root template and needs to be added to the VM class
                    //        // Else it is a child object which needs to be added to the ChildTemplate list
                    if (Rec.Parent_ID == null)
                    {
                        Templates.Add(templateItem);
                    }
                    else
                    {
                        childTemplates.Add(templateItem);
                    }
                }
            }
            return(childTemplates);
        }
Esempio n. 21
0
        /// <summary>
        /// Method triggered by the TreeListViewDragDropBehavior Class. Takes care of moving on item in the tree, which can be from
        /// any level to any level
        /// </summary>
        /// <param name="destination"></param>
        public void MoveSelection(TreeListViewRow destination) // Collection<ObjectModel> selectedItems, ObjectModel destination )
        {
            if (destination != null)
            {
                ObjectModel destinationItem = (destination.DataContext) as ObjectModel;
                try
                {
                    // Setup a private collection with the selected items only. This is because the SelectedItems that are part of the view model collection
                    // will change as soon as we start removing and adding objects
                    TD.ObservableItemCollection <ObjectModel> selectedItems = new TD.ObservableItemCollection <ObjectModel>();
                    foreach (ObjectModel item in SelectedItems)
                    {
                        selectedItems.Add(item);
                    }

                    foreach (ObjectModel item in selectedItems)
                    {
                        // find the original parent of the object that's moved
                        ObjectModel parentSourceItem = GetObject(item.Parent_ID);

                        // If the parent is in the root level
                        if (parentSourceItem == null)
                        {
                            // Remove the item in the root level
                            Objects.Remove(item);
                        }
                        else
                        {
                            // Otherwise remove the item from the child collection
                            parentSourceItem.ChildObjects.Remove(item);
                        }

                        TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);
                        destination.UpdateLayout();
                        // If put on top of destination
                        if (relativeDropPosition == TreeListViewDropPosition.Inside)
                        {
                            // the Parent_ID of the item will become the ID of the destination
                            item.Parent_ID = destinationItem.ID;
                            destinationItem.ChildObjects.Add(item);
                        }
                        // If put before or after the destination
                        else
                        {
                            // if the desitination is in the root collection
                            if (destinationItem.Parent_ID == null)
                            {
                                // The parent_ID of the item will also be null
                                item.Parent_ID = null;
                                Objects.Insert(Objects.IndexOf(destinationItem), item);
                            }
                            else
                            {
                                // otherwise the Parent_ID of the item will be the same as that of the destination item
                                item.Parent_ID = destinationItem.Parent_ID;
                                // find the Parent of the destination item
                                parentSourceItem = GetObject(destinationItem.Parent_ID);
                                // Insert the item before or after the destination item in the ChildObject collection of the parent of the destination
                                if (relativeDropPosition == TreeListViewDropPosition.Before)
                                {
                                    parentSourceItem.ChildObjects.Insert(parentSourceItem.ChildObjects.IndexOf(destinationItem), item);
                                }
                                else
                                {
                                    parentSourceItem.ChildObjects.Insert(parentSourceItem.ChildObjects.IndexOf(destinationItem) + 1, item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RadWindow.Alert(new DialogParameters()
                    {
                        Header  = "Error",
                        Content = "Error while moving object\n" + ex.Message
                    });
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Method triggered by the TreeListViewDragDropBehavior Class. Takes care of moving on item in the tree, which can be from
        /// any level to any level
        /// </summary>
        /// <param name="destination"></param>
        public void MoveSelection(TreeListViewRow destination) // Collection<PropertyModel> selectedItems, PropertyModel destination )
        {
            if (destination != null)
            {
                PropertyModel destinationItem = (destination.DataContext) as PropertyModel;
                try
                {
                    // Setup a private collection with the selected items only. This is because the SelectedItems that are part of the view model collection
                    // will change as soon as we start removing and adding objects
                    TD.ObservableItemCollection <PropertyModel> selectedItems = new TD.ObservableItemCollection <PropertyModel>();
                    foreach (PropertyModel item in SelectedItems)
                    {
                        selectedItems.Add(item);
                    }

                    foreach (PropertyModel item in selectedItems)
                    {
                        // find the original parent of the object that's moved
                        PropertyModel parentSourceItem = GetProperty(item.Parent_ID);

                        // If the parent is in the root level
                        if (parentSourceItem == null)
                        {
                            // Remove the item in the root level
                            Properties.Remove(item);
                        }
                        else
                        {
                            // Otherwise remove the item from the child collection
                            parentSourceItem.ChildProperties.Remove(item);
                        }

                        TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);
                        destination.UpdateLayout();
                        // If put on top of destination
                        if (relativeDropPosition == TreeListViewDropPosition.Inside)
                        {
                            // the Parent_ID of the item will become the ID of the destination
                            item.Parent_ID = destinationItem.ID;
                            destinationItem.ChildProperties.Add(item);
                        }
                        // If put before or after the destination
                        else
                        {
                            // if the desitination is in the root collection
                            if (destinationItem.Parent_ID == null)
                            {
                                // The parent_ID of the item will also be null
                                item.Parent_ID = null;
                                Properties.Insert(Properties.IndexOf(destinationItem), item);
                            }
                            else
                            {
                                // otherwise the Parent_ID of the item will be the same as that of the destination item
                                item.Parent_ID = destinationItem.Parent_ID;
                                // find the Parent of the destination item
                                parentSourceItem = GetProperty(destinationItem.Parent_ID);
                                // Insert the item before or after the destination item in the ChildObject collection of the parent of the destination
                                if (relativeDropPosition == TreeListViewDropPosition.Before)
                                {
                                    parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem), item);
                                }
                                else
                                {
                                    parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem) + 1, item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RadWindow.Alert(ex.Message);
                }
            }
            //try
            //{
            //    // Setup a private collection with the selected items only. This is because the SelectedItems that are part of the view model collection
            //    // will change as soon as we start removing and adding objects
            //    TD.ObservableItemCollection<PropertyModel> selectedItems = new TD.ObservableItemCollection<PropertyModel>();
            //    foreach (PropertyModel item in SelectedItems)
            //    {
            //        selectedItems.Add(item);
            //    }

            //    foreach (PropertyModel item in selectedItems)
            //    {
            //        // find the original parent of the object that's moved
            //        PropertyModel parentSourceItem = GetProperty(item.Parent_ID);

            //        // If the parent is in the root level
            //        if (parentSourceItem == null)
            //            // Remove the item in the root level
            //            Properties.Remove(item);
            //        else
            //            // Otherwise remove the item from the child collection
            //            parentSourceItem.ChildProperties.Remove(item);


            //        if (destination != null)
            //        {
            //            TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);
            //            PropertyModel destinationItem = (destination.DataContext) as PropertyModel;
            //            // If put on top of destination
            //            if (relativeDropPosition == TreeListViewDropPosition.Inside)
            //            {
            //                // the Parent_ID of the item will become the ID of the destination
            //                item.Parent_ID = destinationItem.ID;
            //                destinationItem.ChildProperties.Add(item);
            //            }
            //            // If put before or after the destination
            //            else
            //            {
            //                // if the desitination is in the root collection
            //                if (destinationItem.Parent_ID == null)
            //                {
            //                    // The parent_ID of the item will also be null
            //                    item.Parent_ID = null;
            //                    Properties.Insert(Properties.IndexOf(destinationItem), item);
            //                }
            //                else
            //                {
            //                    // otherwise the Parent_ID of the item will be the same as that of the destination item
            //                    item.Parent_ID = destinationItem.Parent_ID;
            //                    // find the Parent of the destination item
            //                    parentSourceItem = GetProperty(destinationItem.Parent_ID);
            //                    // Insert the item above the destination item in the ChildObject collection of the parent of the destination
            //                    if (relativeDropPosition == TreeListViewDropPosition.Before)
            //                        parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem), item);
            //                    else
            //                        parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem) + 1, item);
            //                }
            //            }

            //        }
            //        else // destination is null, i.e. below the tree
            //        {
            //            item.Parent_ID = null;
            //            Properties.Add(item);
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    RadWindow.Alert(ex.Message);
            //}
        }