Exemple #1
0
        /// <summary>
        /// Override to return the children defined to us when we were created
        /// </summary>
        /// <value>The actual children.</value>
        protected override ConcurrentBag <BaseItem> LoadChildren()
        {
            var originalChildSource = ChildSource.ToList();

            var kids = originalChildSource;

            if (GroupContents)
            {
                // Recursively group up the chain
                var group            = true;
                var isSubsequentLoop = false;

                while (group)
                {
                    kids = isSubsequentLoop || kids.Any(i => i.GroupInIndex)
                               ? GroupedSource(kids).ToList()
                               : originalChildSource;

                    group            = kids.Any(i => i.GroupInIndex);
                    isSubsequentLoop = true;
                }
            }

            // Now - since we built the index grouping from the bottom up - we now need to properly set Parents from the top down
            SetParents(this, kids.OfType <IndexFolder>());

            return(new ConcurrentBag <BaseItem>(kids));
        }
        public void RefreshContainer_OfWrapperPropertyIfSourceHasChanged_RefreshesChild()
        {
            VM.Revalidate(ValidationScope.SelfAndLoadedDescendants);

            VM.WrapperPropertySource = new ChildSource();
            var childVM = VM.GetValue(x => x.WrapperProperty);

            var newSource = new ChildSource();

            VM.WrapperPropertySource = newSource;

            VM.ValidatorResults.Reset();

            VM.RefreshContainer(x => x.WrapperProperty);

            Assert.AreEqual(newSource, childVM.Source);
            Assert.IsTrue(childVM.WasRefreshed);

            VM.ValidatorResults.ExpectInvocationOf
            .PropertyValidation
            .Targeting(VM.GetValue(x => x.WrapperProperty), x => x.ChildProperty)
            .On(VM);

            VM.ValidatorResults.VerifyInvocationSequence();
        }
        public void OnSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action != NotifyCollectionChangedAction.Add || e.NewItems == null)
            {
                return;
            }

            if (Source == null)
            {
                Source = new WMSBusinessCollection <Entity2GC>();
            }

            foreach (var item in e.NewItems)
            {
                if (item == null)
                {
                    continue;
                }

                if (Source == null)
                {
                    continue;
                }
                var newItem = new Entity2GC
                {
                    ENTITY2GCKEY = ((WMSBusinessObject)item).GetKey().ToString()
                };

                Source.Add(newItem);
                ChildSource.Add((WMSBusinessObject)item);
            }
        }
        public void OnSourcePropertyInternalChanged(object newvalue)
        {
            if (newvalue == null)
            {
                CurrentItem = null;
            }

            if (Source == null)
            {
                return;
            }

            UpdateSource(null);
            ChildSource.Clear();
            if (Source == null || Source.Count == 0)
            {
                return;
            }

            var keys         = Source.Select(item => (object)item.ENTITY2GCKEY).ToList();
            var pk           = WMSBusinessObject.GetPrimaryKeyPropertyName(_itemType);
            var pkSourceName = SourceNameHelper.Instance.GetPropertySourceName(_itemType, pk);

            using (var mgr = GetManager(_itemType))
            {
                var items = mgr.GetFiltered(FilterHelper.GetFilterIn(pkSourceName, keys));
                ChildSource.AddRange(items);
            }
        }
        public void OnDelete()
        {
            if (!ConnectionManager.Instance.AllowRequest())
            {
                return;
            }

            if (!CanDelete())
            {
                return;
            }

            try
            {
                if (GetViewService().ShowDialog(StringResources.Confirmation
                                                , StringResources.ConfirmationDeleteObject
                                                , MessageBoxButton.YesNo
                                                , MessageBoxImage.Question
                                                , MessageBoxResult.Yes) != MessageBoxResult.Yes)
                {
                    return;
                }

                var items = SelectedItems.Cast <EditableBusinessObject>().ToList();

                foreach (var item in items)
                {
                    ChildSource.Remove(item);

                    var key = ((WMSBusinessObject)item).GetKey().ToString();
                    if (!string.IsNullOrEmpty(key))
                    {
                        var exit = false;
                        while (!exit)
                        {
                            var e2gc = Source.FirstOrDefault(x => string.Equals(key, x.ENTITY2GCKEY));
                            if (e2gc != null)
                            {
                                Source.Remove(e2gc);
                            }
                            else
                            {
                                exit = true;
                            }
                        }
                    }
                }
                Revalidate();
            }
            catch (Exception ex)
            {
                throw new OperationException(ExceptionResources.ItemCantDelete, ex);
            }
        }
        public void Refresh_OfWrapperProperty_SetsSourceOnChildAndRefreshesChild()
        {
            VM.WrapperPropertySource = new ChildSource();
            var childVM = VM.GetValue(x => x.WrapperProperty);

            var newSource = new ChildSource();

            VM.WrapperPropertySource = newSource;

            VM.Refresh(x => x.WrapperProperty);
            Assert.AreEqual(newSource, childVM.Source);
            Assert.IsTrue(childVM.WasRefreshed);
        }
Exemple #7
0
        public void RefreshContainer_OfWrapperCollection_SynchronizesFromSourceItems()
        {
            var existing    = new ChildVM(new ChildSource());
            var removed     = new ChildVM(new ChildSource());
            var addedSource = new ChildSource();

            VM.WrapperProperty.Add(removed);
            VM.WrapperProperty.Add(existing);

            VM.WrapperPropertySource.Remove(removed.Source);
            VM.WrapperPropertySource.Insert(0, addedSource);

            VM.RefreshContainer(x => x.WrapperProperty);

            Assert.AreSame(addedSource, VM.WrapperProperty[0].Source);
            Assert.AreSame(existing, VM.WrapperProperty[1]);
        }
Exemple #8
0
        public void Refresh_OfWrapperCollectionProperty_RepopulatesCollectionReusingItemVMsForSameSourceItems()
        {
            var sharedSource = new ChildSource();
            var reusedVM     = new ChildVM(sharedSource);
            var previousVM   = new ChildVM(new ChildSource());

            VM.WrapperProperty.Add(reusedVM);
            VM.WrapperProperty.Add(previousVM);

            var newSource = new ChildSource();

            VM.WrapperPropertySource = new List <ChildSource> {
                sharedSource, newSource
            };
            VM.Refresh(x => x.WrapperProperty);

            Assert.AreEqual(2, VM.WrapperProperty.Count);
            Assert.AreEqual(reusedVM, VM.WrapperProperty[0]);
            Assert.AreEqual(newSource, VM.WrapperProperty[1].Source);
        }
Exemple #9
0
        public void Refresh_OfWrapperCollectionProperty_RefreshesReusedItemVMs()
        {
            RefreshTrace.StartTrace();

            var sharedSource = new ChildSource();
            var reusedVM     = new ChildVM(sharedSource);
            var previousVM   = new ChildVM(new ChildSource());

            VM.WrapperProperty.Add(reusedVM);
            VM.WrapperProperty.Add(previousVM);

            var newSource = new ChildSource();

            VM.WrapperPropertySource = new List <ChildSource> {
                sharedSource, newSource
            };
            VM.Refresh(x => x.WrapperProperty);

            Assert.AreEqual(2, VM.WrapperProperty.Count);
            Assert.IsTrue(VM.WrapperProperty[0].WasRefreshed);
            Assert.IsFalse(VM.WrapperProperty[1].WasRefreshed);
        }
        private CustomLookUpOptPopupContent CreateWindow()
        {
            var destType = typeof(IListViewModel <>).MakeGenericType(_itemType);
            var model    = (IObjectListViewModel)IoC.Instance.Resolve(destType, null);

            model.Mode = ObjectListMode.LookUpList3Points;
            model.ParentViewModelSource = ParentViewModelSource;
            model.AllowAddNew           = true;
            model.InitializeMenus();

            var modelCapt = model as PanelViewModelBase;

            if (modelCapt != null)
            {
                modelCapt.SetPanelCaptionPrefix(DataContext.GetType());
                modelCapt.IsActive = true;
            }

            if (_lookupInfo != null)
            {
                string str;
                Dictionary <string, Dictionary <string, string> > varFilter;
                LookupHelper.InitializeVarFilter(_lookupInfo.Filter, out str, out varFilter);

                string filter = null;
                if (ChildSource != null && ChildSource.Count > 0)
                {
                    filter = (FilterHelper.GetFilterIn(_itemType, ChildSource.Cast <IKeyHandler>())).Replace(" IN ", " NOT IN ");
                }

                if (!string.IsNullOrEmpty(str))
                {
                    filter = string.IsNullOrEmpty(filter) ? str : str + " AND " + filter;
                }

                if (varFilter != null && varFilter.Count > 0)
                {
                    var filterParent = new StringBuilder();
                    foreach (var add in varFilter.Select(key => UpdateFilter(key.Key, ParentViewModelSource, varFilter)).Where(add => !string.IsNullOrEmpty(add)))
                    {
                        filterParent.Append(filterParent.Length > 0 ? " AND " + add : add);
                    }

                    if (filterParent.Length > 0)
                    {
                        filter = string.IsNullOrEmpty(filter) ? filterParent.ToString() : filter + " AND " + filterParent;
                    }
                }

                model.ApplyFilter(filter);
            }

            var result = new CustomLookUpOptPopupContent
            {
                DataContext = model
            };

            if (result.Owner == null && Application.Current.MainWindow.IsActive)
            {
                result.Owner = Application.Current.MainWindow;
            }
            return(result);
        }