【问题标题】:How to avoid duplicate entries in Acumatica grid both on the screen and import scenario如何在屏幕和导入场景中避免 Acumatica 网格中的重复条目
【发布时间】:2020-01-30 14:02:57
【问题描述】:

我有一个表单和网格的自定义屏幕,当用户在网格中选择相同的值时,它允许保存记录,但在我的情况下,当用户插入/更新时,它也不应该允许在网格中插入相同的记录通过导入场景记录它的行为应该相同。

例如:

下面是代码

 public class KWStoreTrafficEntityMaint : PXGraph<KWStoreTrafficEntityMaint, KWStoreTrafficEntity>
    {
        public PXSelect<KWStoreTrafficEntity> Document;

        [PXImport(typeof(KWStoreTrafficEntity))]
        public PXSelect<KWStoreTrafficEntityDetails, Where<KWStoreTrafficEntityDetails.entityNbr,
            Equal<Current<KWStoreTrafficEntity.entityNbr>>>, OrderBy<Asc<KWStoreTrafficEntityDetails.sortOrder>>> Transactions;

            #region Event Handlers

             protected virtual void KWStoreTrafficEntityDetails_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            KWStoreTrafficEntityDetails items = e.Row as KWStoreTrafficEntityDetails;

            if (items == null)
                return;

            if (items.Period == "9 AM")
                items.SortOrder = 1;
            else if (items.Period == "10 AM")
                items.SortOrder = 2;
            else if (items.Period == "11 AM")
                items.SortOrder = 3;
            else if (items.Period == "12 PM")
                items.SortOrder = 4;
            else if (items.Period == "1 PM")
                items.SortOrder = 5;
            else if (items.Period == "2 PM")
                items.SortOrder = 6;
            else if (items.Period == "3 PM")
                items.SortOrder = 7;
            else if (items.Period == "4 PM")
                items.SortOrder = 8;
            else if (items.Period == "5 PM")
                items.SortOrder = 9;
            else if (items.Period == "6 PM")
                items.SortOrder = 10;
            else if (items.Period == "7 PM")
                items.SortOrder = 11;
        }
        protected virtual void KWStoreTrafficEntity_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            KWStoreTrafficEntity row = e.Row as KWStoreTrafficEntity;

            if (row == null)
                return;

            if(this.IsImport)
            {
                if (row.EntityDate == null)
                    return;

                foreach(KWStoreTrafficEntityDetails items in this.Transactions.Cache.Cached)
                {
                    PXTrace.WriteInformation(items.Period);
                }
            }

            if ((this.Document.Cache.GetStatus(this.Document.Current) == PXEntryStatus.Inserted || this.Document.Cache.GetStatus(this.Document.Current) == PXEntryStatus.Updated))
            {
                decimal? total = default(decimal);

                foreach (KWStoreTrafficEntityDetails items in this.Transactions.Select())
                {
                    total = total + items.TotalVisitors;                    
                }

                row.TotalVisitors = total;
            }
        }

        #endregion

    }

【问题讨论】:

    标签: acumatica acumatica-kb


    【解决方案1】:

    对于应该唯一的字段(以避免重复),将其声明为数据库和 Acumatica DAC 中的关键字段。

    在数据库中,确保数据库字段被声明为唯一键字段: https://docs.microsoft.com/en-us/sql/relational-databases/tables/create-primary-keys?view=sql-server-ver15

    在 Acumatica DAC 中,使用 IsKey=True 属性来指示它是唯一的关键字段: https://help-2018r1.acumatica.com/Wiki/ShowWiki.aspx?pageid=cef47ebf-cb3f-41dd-a137-be0201c84140

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 2014-06-17
      • 2017-06-23
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      相关资源
      最近更新 更多