protected void grid_CallBack(object sender, PXCallBackEventArgs e)
    {
        var    tree           = sp1.FindControl("tree") as PXTreeView;
        var    grid           = sp1.FindControl("grid") as PXGrid;
        string moveGridCursor = "";

        PX.SM.WikiPageMapMaintenance graph = this.ds.DataGraph as PX.SM.WikiPageMapMaintenance;
        if (graph == null)
        {
            return;
        }

        if (e.Command.Name == "RowDown")
        {
            MoveRow(graph, true);
            moveGridCursor = "|" + grid.ClientID + "|down";
        }
        else if (e.Command.Name == "RowUp")
        {
            MoveRow(graph, false);
            moveGridCursor = "|" + grid.ClientID + "|up";
        }

        e.Result = tree.ClientID + "|" + tree.SelectedValue + moveGridCursor;
        PXSiteMap.WikiProvider.Clear();
    }
    protected string PasteArticles()
    {
        var    tree     = sp1.FindControl("tree") as PXTreeView;
        string datapath = tree.SelectedValue;

        PX.SM.WikiPageMapMaintenance graph = this.ds.DataGraph as PX.SM.WikiPageMapMaintenance;
        if (graph == null)
        {
            return(datapath);
        }

        Guid pasteid = PX.Common.GUID.CreateGuid(datapath).GetValueOrDefault();

        // check whether user is not trying to insert one of articles inside itself
        foreach (PX.SM.WikiPage item in graph.selectedArticles)
        {
            if (item.PageID == pasteid || IsPastingToChild(item.PageID.Value))             // trying to paste inside of ourselves?
            {
                return(datapath + "|" + "The destination folder is a subfolder of the source folder or folder's child.");
            }
            graph.SetParentId(item, pasteid);
        }
        graph.Children.Cache.IsDirty = false;
        graph.Children.Cache.Clear();
        graph.Children.Cache.IsDirty = false;
        graph.selectedArticles.Clear();
        return(datapath);
    }
    private void MoveRow(PX.SM.WikiPageMapMaintenance graph, bool moveDown)
    {
        var       tree    = sp1.FindControl("tree") as PXTreeView;
        var       grid    = sp1.FindControl("grid") as PXGrid;
        PXAdapter adapter = new PXAdapter(graph.Views[ds.PrimaryView]);

        adapter.SortColumns   = null;
        adapter.Descendings   = null;
        adapter.Parameters    = new object[] { tree.SelectedValue, grid.DataValues["PageID"] };
        adapter.Searches      = null;
        adapter.Filters       = null;
        adapter.StartRow      = 0;
        adapter.MaximumRows   = grid.PageSize;
        adapter.TotalRequired = true;

        foreach (PX.SM.WikiPage map in graph.Children.Select(PX.Common.GUID.CreateGuid(tree.SelectedValue)))
        {
            if (map.PageID.Value == ((grid.DataValues["PageID"] as Guid?) ?? PX.Common.GUID.CreateGuid(grid.DataValues["PageID"].ToString())))
            {
                graph.Children.Current = map;
                break;
            }
        }

        if (moveDown)
        {
            foreach (PX.SM.WikiPage item in graph.RowDown.Press(adapter))
            {
                break;
            }
        }
        else
        {
            foreach (PX.SM.WikiPage item in graph.RowUp.Press(adapter))
            {
                break;
            }
        }
        graph.Children.Cache.IsDirty = false;
    }
 protected void SetParentId(Guid nodeId, Guid parentId)
 {
     PX.SM.WikiPageMapMaintenance graph = this.ds.DataGraph as PX.SM.WikiPageMapMaintenance;
     graph.SetParentId(nodeId, parentId);
 }