Пример #1
0
        public virtual IEnumerable Right(PXAdapter adapter)
        {
            INCategory current = Item.SelectWindowed(0, 1, CurrentSelected.FolderID);

            if (current != null)
            {
                int currentItemIndex;
                PXResultset <INCategory> items =
                    SelectSiblings(current.ParentID, current.CategoryID, out currentItemIndex);
                if (currentItemIndex > 0)
                {
                    INCategory prev = items[currentItemIndex - 1];
                    items = SelectSiblings(prev.CategoryID);
                    int index = 1;
                    if (items.Count > 0)
                    {
                        INCategory last = items[items.Count - 1];
                        index = (last.SortOrder ?? 0) + 1;
                    }
                    current           = (INCategory)Items.Cache.CreateCopy(current);
                    current.ParentID  = prev.CategoryID;
                    current.SortOrder = index;
                    Items.Update(current);
                    PXSelect <INCategory, Where <INCategory.parentID, Equal <Required <INCategory.categoryID> > > > .Clear(this);
                }
            }
            return(adapter.Get());
        }
        protected virtual void INCategory_RowDeleted(PXCache cache, PXRowDeletedEventArgs e)
        {
            INCategory row = e.Row as INCategory;

            if (row == null || row.CategoryID == null)
            {
                return;
            }
            deleteRecurring(row);
        }
Пример #3
0
 private void deleteRecurring(INCategory map)
 {
     if (map != null)
     {
         foreach (INCategory child in PXSelect <INCategory, Where <INCategory.parentID, Equal <Required <INCategory.categoryID> > > > .Select(this, map.CategoryID))
         {
             deleteRecurring(child);
         }
         Caches[typeof(INCategory)].Delete(map);
     }
 }
Пример #4
0
        protected virtual void INCategory_parentID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            INCategory row = e.Row as INCategory;

            if (row == null)
            {
                return;
            }
            e.NewValue = this.CurrentSelected.FolderID ?? 0;
            e.Cancel   = true;
        }
Пример #5
0
 private void deleteRecurring(INCategory map, bool deleteRootNode = false)
 {
     if (map != null)
     {
         foreach (INCategory child in PXSelect <INCategory,
                                                Where <INCategory.parentID, Equal <Required <INCategory.categoryID> > > >
                  .Select(this, map.CategoryID))
         {
             deleteRecurring(child);
         }
         if (deleteRootNode)
         {
             Items.Cache.Delete(map);
         }
     }
 }
Пример #6
0
        protected virtual void INCategory_CategoryCD_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            INCategory row = e.Row as INCategory;

            if (row != null && row.CategoryID != null)
            {
                INCategory item = PXSelect <INCategory,
                                            Where <INCategory.categoryCD, Equal <Required <INCategory.categoryCD> >,
                                                   And <INCategory.categoryID, NotEqual <Required <INCategory.categoryID> > > > >
                                  .SelectWindowed(this, 0, 1, e.NewValue, row.CategoryID);

                if (item != null)
                {
                    throw new PXSetPropertyException(ErrorMessages.DuplicateEntryAdded, "CategoryID");
                }
            }
        }
        public virtual IEnumerable Up(PXAdapter adapter)
        {
            INCategory curr = Folders.Current;
            INCategory prev = PXSelect <INCategory,
                                        Where <INCategory.parentID, Equal <Required <INCategory.parentID> >,
                                               And <INCategory.sortOrder, Less <Required <INCategory.parentID> > > >,
                                        OrderBy <Desc <INCategory.sortOrder> > > .SelectSingleBound(this, null, Folders.Current.ParentID,
                                                                                                    Folders.Current.SortOrder);

            if (prev != null && curr != null)
            {
                int temp = (int)curr.SortOrder;
                curr.SortOrder = prev.SortOrder;
                prev.SortOrder = temp;
                Caches[typeof(INCategory)].Update(prev);
                Caches[typeof(INCategory)].Update(curr);
            }
            return(adapter.Get());
        }
        public virtual IEnumerable Down(PXAdapter adapter)
        {
            INCategory curr = Folders.Current;
            INCategory next = PXSelect <INCategory,
                                        Where <INCategory.parentID, Equal <Required <INCategory.parentID> >,
                                               And <INCategory.sortOrder, Greater <Required <INCategory.parentID> > > >,
                                        OrderBy <Asc <INCategory.sortOrder> > > .SelectSingleBound(this, null, Folders.Current.ParentID,
                                                                                                   Folders.Current.SortOrder);

            if (next != null && curr != null)
            {
                int temp = (int)curr.SortOrder;
                curr.SortOrder = next.SortOrder;
                next.SortOrder = temp;
                Caches[typeof(INCategory)].Update(next);
                Caches[typeof(INCategory)].Update(curr);
            }
            return(adapter.Get());
        }
Пример #9
0
        public virtual IEnumerable Up(PXAdapter adapter)
        {
            int currentItemIndex;
            PXResultset <INCategory> items =
                SelectSiblings(CurrentSelected.FolderID, CurrentSelected.CategoryID, out currentItemIndex);

            if (currentItemIndex > 0)
            {
                INCategory current = items[currentItemIndex];
                INCategory prev    = items[currentItemIndex - 1];

                current.SortOrder -= 1;
                prev.SortOrder    += 1;

                Items.Update(current);
                Items.Update(prev);
            }
            return(adapter.Get());
        }
Пример #10
0
        public virtual IEnumerable Down(PXAdapter adapter)
        {
            int currentItemIndex;
            PXResultset <INCategory> items =
                SelectSiblings(CurrentSelected.FolderID, CurrentSelected.CategoryID, out currentItemIndex);

            if (currentItemIndex >= 0 && currentItemIndex < items.Count - 1)
            {
                INCategory current = items[currentItemIndex];
                INCategory next    = items[currentItemIndex + 1];

                current.SortOrder += 1;
                next.SortOrder    -= 1;

                Items.Update(current);
                Items.Update(next);
            }
            return(adapter.Get());
        }
Пример #11
0
        protected virtual void INCategory_SortOrder_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            INCategory row = (INCategory)e.Row;

            if (row == null)
            {
                return;
            }

            e.NewValue = 1;
            e.Cancel   = true;

            PXResultset <INCategory> list = Items.Select(row.ParentID);

            if (list.Count > 0)
            {
                INCategory last = list[list.Count - 1];
                e.NewValue = last.SortOrder + 1;
            }
        }
Пример #12
0
        public virtual IEnumerable addCategory(PXAdapter adapter)
        {
            int ParentID = (int)Folders.Current.CategoryID;
            var inserted = (INCategory)Caches[typeof(INCategory)].Insert(new INCategory
            {
                Description = PXMessages.LocalizeNoPrefix(Messages.NewKey),
                ParentID    = ParentID,
            });

            inserted.TempChildID  = inserted.CategoryID;
            inserted.TempParentID = ParentID;
            INCategory previous = PXSelect <INCategory,
                                            Where <INCategory.parentID, Equal <Required <INCategory.parentID> > >,
                                            OrderBy <Desc <INCategory.sortOrder> > > .SelectSingleBound(this, null, ParentID);

            int sortOrder = (int)previous.SortOrder;

            sortOrder               = sortOrder + 1;
            inserted.SortOrder      = previous != null ? sortOrder : 1;
            Folders.Cache.ActiveRow = inserted;
            return(adapter.Get());
        }
Пример #13
0
        public virtual IEnumerable Left(PXAdapter adapter)
        {
            INCategory current = Item.SelectWindowed(0, 1, CurrentSelected.FolderID);

            if (current != null && current.ParentID != 0)
            {
                INCategory parent = Item.SelectWindowed(0, 1, current.ParentID);
                if (parent != null)
                {
                    int parentIndex;
                    PXResultset <INCategory> items = SelectSiblings(parent.ParentID, parent.CategoryID, out parentIndex);
                    if (parentIndex >= 0)
                    {
                        INCategory last = items[items.Count - 1];
                        current           = (INCategory)Items.Cache.CreateCopy(current);
                        current.ParentID  = parent.ParentID;
                        current.SortOrder = last.SortOrder + 1;
                        Items.Update(current);
                        PXSelect <INCategory, Where <INCategory.parentID, Equal <Required <INCategory.categoryID> > > > .Clear(this);
                    }
                }
            }
            return(adapter.Get());
        }