Common building blocks in EP pages

I always find myself in the position to go and gather all the basic blocks of code necessary (more or less) in a EP web page from other already written pages. Of course, for this purpose,  you can try to use the AxBaseUserControl web control already shipping with the EP standard code. It is useful when you have a simple scenario of building a page with an AxForm, I am not using it that much ... So, without other comments here is the list:

(a short comment: if it happens that the new line feed character is not working when doing Copy - Paste from here to VS, try to paste first in a Word document, and Copy the text from there to VS)


using System.Globalization;

using Microsoft.Dynamics.AX.Framework.Portal.Data;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.Portal.UI;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using AppProxy = Microsoft.Dynamics.Portal.Application.Proxy;
using BCProxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;



    private const string AotPageDefinitonsPath = "\\Web\\Web Files\\Page Definitions\\";

 
    AxBaseWebPart webPart;
    /// <summary>
    /// get the webpart
    /// </summary>
    protected AxBaseWebPart WebPart
    {
        get
        {
            if (webPart == null)
                webPart = AxBaseWebPart.GetWebpart(this);

            return webPart;
        }
    }

    /// <summary>
    /// Gets the current Web Part Session.
    /// </summary>
    protected ISession AxSession
    {
        get
        {
            AxBaseWebPart webpart = this.WebPart;
            return webpart == null ? null : webpart.Session;
        }
    }

    /// <summary>
    /// Gets a CultureInfo that represents the current users preferred culture.
    /// </summary>
    protected CultureInfo UserPreferredCulture
    {
        get
        {
            AxBaseWebPart webPart = this.WebPart;
            System.Diagnostics.Debug.Assert(webPart != null);
            return webPart == null ? CultureInfo.CurrentCulture : webPart.CultureInfo;
        }
    }


    /// <summary>
    /// Returns the current queryString
    /// </summary>
    private AxQueryString AxQueryString
    {
        get
        {
            return AxQueryString.GetCurrent(this.Page);
        }
    }



    /// <summary>
    /// Returns the page definition metadata from AOT
    /// </summary>
    private BCProxy.webPageDefNode PageDefinition
    {
        get
        {
            try
            {
                BCProxy.TreeNode pageDef;
                pageDef = BCProxy.TreeNode.findNode(this.WebPart.Session.AxaptaAdapter, AotPageDefinitonsPath + "PageName");
                if (pageDef != null)
                    return new BCProxy.webPageDefNode(this.WebPart.Session.AxaptaAdapter, pageDef.AxaptaObjectAdapter);
                else
                    return null;
            }
            catch (System.Exception ex)
            {
                AxExceptionCategory exceptionCategory;
                // This returns true if the exception can be handled here
                if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
                {
                    // The exception is system fatal - in this case we re-throw.                                   
                    throw;
                }
            }

            return null;
        }
    }


     private DataSetViewRow CurrentRow
    {
        get
        {
            DataSet ds = this.AxDataSource1.GetDataSet();
            return ds.DataSetViews[this.AxDataSource1.ProviderView].GetCurrent();
        }
    }


    /// <summary>
    /// Returns the mode from the query string
    /// 0 = ReadOnly; 1 = Edit; 2 = Insert
    /// </summary>
    private AppProxy.EPFormAction FormMode
    {
        get { return (AppProxy.EPFormAction)Convert.ToInt16(this.Page.Request.QueryString.Get("mode")); }
    } 



     private IAxaptaRecordAdapter CurrentRecord
    {
        get
        {
            return (this.CurrentRow == null) ? null : this.CurrentRow.GetRecord();
        }
    }
 

No comments:

Post a Comment