In Acumatica, can you have a graph/page using an u

2019-02-26 23:22发布

Is it possible to have a Graph and page utilize an completely unbound DAC?

When attempting this currently in 4.20 I'm receiving the following error message:

Incorrect syntax near the keyword 'FROM'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'FROM'.

If I create a table in the database and change my DAC fields from say PXInt to PXDBInt, then the page loads however for what I'm attempting to do I have no need to actually store the data.

DAC sample:

    namespace Acumatica1
{
    [PXPrimaryGraph(typeof(UnboundDataTest))]
    [System.SerializableAttribute()]
    public class UnboundDAC : PX.Data.IBqlTable
        {
        public abstract class unboundKey : PX.Data.IBqlField
        {
        }
        protected int _UnboundKey;
        [PXInt(IsKey = true)]
        [PXUIField(Visible = false)]
        public virtual int UnboundKey
        {
            get
            {
                return this._UnboundKey;
            }
            set
            {
                this._UnboundKey = value;
            }
        }

        #region UnboundText
        public abstract class unboundText : PX.Data.IBqlField
        {
        }
        protected string _UnboundText;
        [PXString]
        [PXUIField(DisplayName = "Text")]
        public virtual string UnboundText
        {
            get
            {
                return this._UnboundText;
            }
            set
            {
                this._UnboundText = value;
            }
        }
        #endregion
    }
}

Graph Sample:

public class UnboundDataTest: PXGraph<UnboundDataTest>
{
    public PXSelect<UnboundDAC> UnboundInfo;
}

标签: acumatica
1条回答
放我归山
2楼-- · 2019-02-26 23:58

To take control of the select process, you need to create a delegate that will be invoked when the UnboundInfo view is selected:

public IEnumerable unboundInfo()
{
    //TODO: Put your logic to return a new instance of UnboundDAC here
}

Inside this delegate, you are free to use whatever mechanism you want to retrieve the record(s) that should be returned by this unbound select. For example, you can create one or more objects on the fly and return them:

public IEnumerable unboundInfo()
{
    yield return new UnboundDAC() { UnboundKey = 1, UnboundText = "A" };
    yield return new UnboundDAC() { UnboundKey = 2, UnboundText = "B" };
}

If you somehow need to allow the user to edit the values in your UnboundDAC, you could leverage the Cache, and insert the records in the cache the first time the view is selected:

public IEnumerable unboundInfo()
{
    PXCache cache = _Graph.Caches[typeof(Table)];
    cache._AllowInsert = true;
    cache._AllowUpdate = true;

    if(cache.Current == null)
    {
        cache.SetStatus(new UnboundDAC() { UnboundKey = 1, UnboundText = "A" }, PXEntryStatus.Held);
        cache.SetStatus(new UnboundDAC() { UnboundKey = 2, UnboundText = "B" }, PXEntryStatus.Held);
    }

    return UnboundInfo.Cache.Cached;
}

Finally, you could take a look at the internal implementation of PXFilter; PXFilter is a specialized PXSelect that doesn't actually select anything from the database; all it does it insert one row in the cache the first time it is selected, and prevent persisting of this row. You could use a similar technique to create a PXUnboundSelect class that could be reused easily in multiple graphs.

查看更多
登录 后发表回答