/// <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); }
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); }
/// <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); }
/// <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); }
/// <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 }); } } }
/// <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); //} }