Skip to content

Commit

Permalink
Merge pull request #945 from rappen/browsepages-#153
Browse files Browse the repository at this point in the history
Browse Pages issue #153
  • Loading branch information
rappen authored Aug 6, 2023
2 parents 24e9b6c + 4be5e6b commit 4f55606
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 29 deletions.
63 changes: 61 additions & 2 deletions FetchXmlBuilder/AppCode/QueryInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,72 @@
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Rappen.XRM.Helpers.FetchXML;
using System;
using System.Xml;

namespace Rappen.XTB.FetchXmlBuilder.AppCode
{
internal class QueryInfo
{
public QueryBase Query;
private QueryBase query;
private EntityCollection result;
internal int PageSize = 0;
internal int PageNo = 1;
internal int Pages = -1;
internal int RecordFrom = -1;
internal int RecordTo = -1;

public string QuerySignature;
public string AttributesSignature;
public EntityCollection Results;

public QueryBase Query
{
get { return query; }
set
{
query = value;
if (query is FetchExpression fetch)
{
var fetchdoc = new XmlDocument();
fetchdoc.LoadXml(fetch.Query);
if (fetchdoc.SelectSingleNode("fetch") is XmlElement fetchnode)
{
if (fetchnode.AttributeInt("count") is int count)
{
PageSize = count;
}
if (fetchnode.AttributeInt("page") is int page)
{
PageNo = page;
}
}
}
}
}

public EntityCollection Results
{
get { return result; }
set
{
result = value;
if (!string.IsNullOrEmpty(result.PagingCookie))
{
var cookdoc = new XmlDocument();
cookdoc.LoadXml(result.PagingCookie);
if (cookdoc.SelectSingleNode("cookie") is XmlElement cookie &&
cookie.AttributeInt("page") is int page)
{
PageNo = page;
}
}
if (result.TotalRecordCount > -1 && PageSize > 0)
{
Pages = (int)Math.Ceiling((decimal)result.TotalRecordCount / PageSize);
}
RecordFrom = 1 + (PageNo - 1) * PageSize;
RecordTo = RecordFrom - 1 + result.Entities.Count;
}
}
}
}
25 changes: 24 additions & 1 deletion FetchXmlBuilder/Builder/TreeNodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Rappen.XTB.FetchXmlBuilder.Builder
{
internal class TreeNodeHelper
internal static class TreeNodeHelper
{
/// <summary>
/// Reuses an existing node in a tree to represent a new FetchXML item
Expand Down Expand Up @@ -590,5 +590,28 @@ private static List<string> GetEntitysChilds(XmlNode ent)
}
return result;
}

internal static void SetNodeAttributeValue(this TreeNode node, string attribute, string value)
{
var collec = (Dictionary<string, string>)node.Tag;
if (collec.ContainsKey(attribute))
{
collec[attribute] = value;
}
else
{
collec.Add(attribute, value);
}
}

internal static string GetNodeAttributeValue(this TreeNode node, string attribute)
{
var collec = (Dictionary<string, string>)node.Tag;
if (collec.ContainsKey(attribute))
{
return collec[attribute];
}
return null;
}
}
}
108 changes: 83 additions & 25 deletions FetchXmlBuilder/DockControls/ResultGrid.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f55606

Please sign in to comment.