protected TreeViewItemViewModel(TreeViewItemViewModel parent, bool lazyLoadChildren) { _parent = parent; _children = new ObservableCollection <TreeViewItemViewModel>(); if (lazyLoadChildren) { _children.Add(DummyChild); } }
/// <summary> /// Move selected asset to new parent with new customer /// Update open Asset windows /// </summary> /// <param name="assetid"></param> /// <param name="newparentassetid"></param> /// <param name="newcustomerid"></param> public static void MoveAsset(int assetid, int newparentassetid, int newcustomerid) { Window owner = Application.Current.Windows[0]; FullyObservableCollection <TVCustomerViewModel> customers = (owner.DataContext as AssetTreeExViewModel).allcustomers; TreeViewItemViewModel asset = null; //get the node representing the asset foreach (TVCustomerViewModel cm in customers) { asset = GetAssetDFS(cm, assetid); if (asset != null) { break; } } TVCustomerViewModel customer; if (asset != null) { TreeViewItemViewModel parentasset = null; //new parent id = 0 occurs when the asset is added directly to customer if (newparentassetid != 0) { foreach (TVCustomerViewModel cm in customers) { parentasset = GetAssetDFS(cm, newparentassetid); if (parentasset != null) { break; } } } else { parentasset = GetCustomerNode(newcustomerid); } //in error condition, check that parent asset is not null - rare but still should be checked if (parentasset != null) { //check to see if asset is directly under a customer or if its under another asset if ((asset as TVAssetViewModel).Asset.ParentAssetID == 0) { //get customer node from customerid //remove asset node from customer node if customerid !=0 if ((asset as TVAssetViewModel).Asset.CustomerID != 0) { customer = GetCustomerNode((asset as TVAssetViewModel).Asset.CustomerID); customer.Children.Remove(asset); } } else { asset.Parent.Children.Remove(asset); } //add movement to log LogMovement(ActivityType.Transfer, assetid, (asset as TVAssetViewModel).Asset.CustomerID, newcustomerid); //update child assets to correct customerid and status UpdateChildAsset(assetid, newcustomerid, 1); UpdateCustomerID(asset.Children, newcustomerid); //update open windows to reflect the changes made to data UpdateRelatedWindow(assetid, newcustomerid, 1, owner); (asset as TVAssetViewModel).Asset.ParentAssetID = newparentassetid; (asset as TVAssetViewModel).Asset.CustomerID = newcustomerid; (asset as TVAssetViewModel).Asset.StatusID = 1; (asset as TVAssetViewModel).IsExpanded = true; parentasset.Children.Add(asset); parentasset.IsExpanded = true; asset.Parent = parentasset; } } }