在Acumatica中,可以使用未绑定的DAC获得图形/页面吗? [英] In Acumatica, can you have a graph/page using an unbound DAC?

查看:41
本文介绍了在Acumatica中,可以使用未绑定的DAC获得图形/页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使图形和页面利用完全未绑定的DAC?

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

当前在4.20中尝试此操作时,我收到以下错误消息:

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'.

如果我在数据库中创建一个表并将DAC字段从PXInt更改为PXDBInt,则页面加载,但是对于我尝试执行的操作,我并不需要实际存储数据。

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示例:

    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
    }
}

图样本:

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


推荐答案

控制选择流程,您需要创建一个在选择UnboundInfo视图时将调用的委托:

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" };
}

如果您需要以某种方式允许用户编辑UnboundDAC中的值,您可以利用缓存,并在第一次选择视图时将记录插入缓存:

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;
}

最后,您可以看一下PXFilter的内部实现; PXFilter是一种专用的PXSelect,实际上并没有从数据库中选择任何内容。它所做的一切都会在第一次选择它时在缓存中插入一行,并防止该行持久化。您可以使用类似的技术来创建PXUnboundSelect类,该类可以在多个图形中轻松重用。

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.

这篇关于在Acumatica中,可以使用未绑定的DAC获得图形/页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆