-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #945 from rappen/browsepages-#153
Browse Pages issue #153
- Loading branch information
Showing
5 changed files
with
226 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.