向CashAccountDetails添加下一个按钮

时间:2019-03-28 17:53:44

标签: acumatica

我正在尝试在CashAccountDetails页面(CATranEnq图)上添加下一个/上一个按钮。

这是我到目前为止尝试过的:

using PX.Data;
using PX.Objects.GL;
using System.Linq;

namespace PX.Objects.CA
{
    public class CATranEnqExtension : PXGraphExtension<CATranEnq>
    {
        private class ActionsLabels
        {
            public const string NextAccount = "Compte suivant";
            public const string PreviousAccount = "Compte précédent";
        }

        public PXAction<CAEnqFilter> PreviousAccount;
        [PXUIField(DisplayName = ActionsLabels.PreviousAccount, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXPreviousButton]
        public virtual void previousAccount()
        {
            CAEnqFilter filter = Base.Filter.Current;
            Account previousaccount = new Account();
            if (!filter.AccountID.Equals(null))
            {
                Account currentAccount = PXSelect<Account, Where<Account.accountID,
                                            Equal<Required<Account.accountID>>>>.Select(Base, filter.AccountID).FirstOrDefault();
                previousaccount = PXSelect<Account,
                                Where<Account.accountCD,
                                    Less<Required<Account.accountCD>>,
                                    And<Account.isCashAccount, Equal<True>>>,
                                        OrderBy<Desc<Account.accountCD>>>.Select(Base, currentAccount.AccountCD).FirstOrDefault();
            }
            else
            {
                previousaccount = PXSelect<Account,
                                    Where<Account.isCashAccount, Equal<True>>,
                                   OrderBy<Desc<Account.accountCD>>>.Select(Base).FirstOrDefault();
            }
            filter.AccountID = previousaccount?.AccountID;
        }

        public PXAction<CAEnqFilter> NextAccount;
        [PXUIField(DisplayName = ActionsLabels.NextAccount, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXNextButton]
        public virtual void nextAccount()
        {
            CAEnqFilter filter = Base.Filter.Current;
            Account nextaccount = new Account();
            if (!filter.AccountID.Equals(null))
            {
                Account currentAccount = PXSelect<Account, Where<Account.accountID,
                                            Equal<Required<Account.accountID>>>>.Select(Base, filter.AccountID).FirstOrDefault();
                nextaccount = PXSelect<Account,
                                Where<Account.accountCD,
                                    Greater<Required<Account.accountCD>>,
                                    And<Account.isCashAccount, Equal<True>>>,
                                        OrderBy<Asc<Account.accountCD>>>.Select(Base, currentAccount.AccountCD).FirstOrDefault();
            }
            else
            {
                nextaccount = PXSelect<Account,
                                    Where<Account.isCashAccount, Equal<True>>,
                                   OrderBy<Asc<Account.accountCD>>>.Select(Base).FirstOrDefault();
            }
            filter.AccountID = nextaccount?.AccountID;
        }
    }
}

当我单击按钮时,我希望转到另一个CashAccount,但是使用了AccountID,但找不到该帐户:

https://i.imgur.com/Uo7MCWL.png

1 个答案:

答案 0 :(得分:0)

我必须使用CashAccount对象而不是帐户。

CAEnqFilter filter = Base.Filter.Current;
            CashAccount previousaccount = new CashAccount();
            if (!filter.AccountID.Equals(null))
            {
                CashAccount currentAccount = PXSelect<CashAccount, Where<CashAccount.cashAccountID,
                                            Equal<Required<CashAccount.cashAccountID>>>>.Select(Base, filter.AccountID).FirstOrDefault();
                previousaccount = PXSelect<CashAccount,
                                Where<CashAccount.cashAccountCD,
                                    Less<Required<CashAccount.cashAccountCD>>>,
                                        OrderBy<Desc<CashAccount.cashAccountCD>>>.Select(Base, currentAccount.CashAccountCD).FirstOrDefault();
            }
            else
            {
                previousaccount = PXSelectOrderBy<CashAccount,
                                   OrderBy<Desc<CashAccount.cashAccountCD>>>.Select(Base).FirstOrDefault();
            }
            filter.AccountID = previousaccount?.CashAccountID;