下面是一個示例,瞭解如何使用Acumatica ERP中的Form Detail視圖獲取父/子DAC。 對於乞討,讓我們創建一個以下列方式親子SQL表: 家長:
/****** Object: Table [dbo].[SOCustomParentTable] Script Date: 07/03/2017 12:55:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SOCustomParentTable](
[CompanyID] [int] NOT NULL,
[ParentID] [int] IDENTITY(1,1) NOT NULL,
[Description] [nvarchar](255) NULL,
[SomeOtherField] [nvarchar](50) NULL,
[ParentCD] [nvarchar](15) NOT NULL
) ON [PRIMARY]
GO
而且孩子現在我們有SQL表準備好,讓我們創建DAC的爲以下
/****** Object: Table [dbo].[SOCustomChildTable] Script Date: 07/03/2017 12:54:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SOCustomChildTable](
[CompanyID] [int] NOT NULL,
[ChildID] [int] IDENTITY(1,1) NOT NULL,
[ParentID] [int] NOT NULL,
[Description] [nvarchar](255) NULL,
[SomeOtherField] [nvarchar](50) NULL
) ON [PRIMARY]
GO
類:
家長:
using System;
using PX.Data;
namespace DemoParentChild
{
[Serializable]
public class SOCustomParentTable: IBqlTable
{
#region ParentID
[PXDBIdentity()]
public int? ParentID { get; set; }
public class parentID : IBqlField{}
#endregion
#region Description
[PXDBString(255, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Description")]
public string Description { get; set; }
public class description : IBqlField{}
#endregion
#region SomeOtherField
[PXDBString(50, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Some Other Field")]
public string SomeOtherField { get; set; }
public class someOtherField : IBqlField{}
#endregion
#region ParentCD
[PXDBString(15,IsKey = true, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Parent ID")]
public string ParentCD { get; set; }
public class parentCD : IBqlField{}
#endregion
}
}
那孩子:
using System;
using PX.Data;
namespace DemoParentChild
{
[Serializable]
public class SOCustomChildTable: IBqlTable
{
#region ChildID
[PXDBIdentity(IsKey=true)]
public int? ChildID { get; set; }
public class childID : IBqlField{}
#endregion
#region ParentID
[PXDBInt()]
[PXDBDefault(typeof(SOCustomParentTable.parentID))]
[PXParent(typeof(Select<SOCustomParentTable, Where<SOCustomParentTable.parentID, Equal<Current<SOCustomChildTable.parentID>>>>))]
public int? ParentID { get; set; }
public class parentID : IBqlField{}
#endregion
#region Description
[PXDBString(255, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Description")]
public string Description { get; set; }
public class description : IBqlField{}
#endregion
#region SomeOtherField
[PXDBString(50, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Some Other Field")]
public string SomeOtherField { get; set; }
public class someOtherField : IBqlField{}
#endregion
}
}
而要完成我們的工作,讓我們創建FormDetail類型的頁面與下圖:
using System;
using PX.Data;
namespace DemoParentChild
{
public class tmp : PXGraph<tmp>
{
public PXSave<SOCustomParentTable> Save;
public PXCancel<SOCustomParentTable> Cancel;
public PXPrevious<SOCustomParentTable> Prev;
public PXNext<SOCustomParentTable> Next;
public PXSelect<SOCustomParentTable> MasterView;
public PXSelect<SOCustomChildTable,Where<SOCustomChildTable.parentID,Equal<Current<SOCustomParentTable.parentID>>>> DetailsView;
}
}
現在,讓我們明白這一切是如何工作。 正如您所看到的,ParentID是SQL中的Identity,並且在DAC中設置爲PXDBIdentity,但它不會被設置爲DAC的關鍵字,因爲我們將使用ParentCD作爲可見的Key。 同樣在Child類中,ChildID被設置爲PXDBIdentity,但它被設置爲Key,因爲我們不需要該行具有用戶的可見鍵。 另外在子類中我們將創造的父/子關係如下:
[PXDBInt()]
[PXDBDefault(typeof(SOCustomParentTable.parentID))]
[PXParent(typeof(Select<SOCustomParentTable, Where<SOCustomParentTable.parentID, Equal<Current<SOCustomChildTable.parentID>>>>))]
public int? ParentID { get; set; }
凡PXDefault是孩子的設置ParendID到當前父的ID和PXParent創造目前孩子和家長之間的關係。
通常會爲父母上的子女和線路計數器創建線路號碼,以瞭解子女的計數。
完整的定製,你可以下載here
在你插入代碼,你沒有提供的情況下插入,你忘了將其添加到這個問題? –
也嘗試在頭中使用PXDBInt(IsKey = true)替換PXDBIdentity,並在DCRule中添加IsKey = true PXDBInt –
感謝您的評論。我沒有通過實例,因爲我只是想用默認值插入。我也嘗試傳遞實例,但同樣的錯誤。將嘗試執行身份替換和更改,因爲您建議 –