添加新项目时未插入子 DAC
Child DAC are not inserting when add a new Item
我有 2 个场景,我遇到了问题。
- 我有3个DAC,一个是Parent,另外2个是child DAC。
- 我有选项卡视图,并相应地显示数据。
第一个选项卡显示父 DAC 数据。
第二个和第三个显示子 DAC 数据。
我正在创建新项目,现在我按添加 (+) 按钮并填写父选项卡中的信息,但未在第二和第三选项卡中填写任何数据,当我按保存时,只有父 DAC 保存,第二和数据库中没有创建第 3 个选项卡行,我也想保存第 2 个和第 3 个选项卡 DAC,我该怎么办?
另一种情况:
我不允许 DAC 更新,我正在设置 DAC.Cahce.AllowUpdated = false;除了 Checkbox 之外的所有控件都被禁用,为什么?
另外,当我们在第 3 个选项卡上并单击工具栏导航按钮时,第 1 个选项卡数据不会刷新,它显示的是之前选择的项目数据。如何解决这个问题?
我们没有将 PXGrid 用于任何子数据,所有 3 个 DAC 之间存在一对一的关系。
/// Parent View
public SelectFrom<Parent>.View parentTran;
/// Child view
public SelectFrom<Child> .Where<Child.tranId.IsEqual<Parent.nCTranId.AsOptional>>.View
childAnalysis;
#region TranId
// Child DAC Field.
public abstract class tranId:PX.Data.BQL.BqlInt.Field<tranId> {
}
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(Parent.nCTranId))]
[PXParent(typeof(Select<Parent, Where<Parent.nCTranId, Equal<Current<tranId>>>>))]
public virtual int? TranId {
get; set;
}
#endregion
查看有关 Master-Detail 关系的 T210。它包含一个关于插入默认记录的部分,这听起来像您尝试用 child DAC 做的事情。可以在 Acumatica 网站上的 https://openuni.acumatica.com/courses/development/t210-development-customized-forms-and-master-detail-relationship/ 找到培训。具体看103页和104页
在本部分的第 3 步中,您将看到使用 RowInserted 事件插入 child 记录。由于 RowInserted 事件仅在创建记录时触发,因此可以安全地插入 child 记录。
请参阅以下代码示例。我尝试尽可能多地使用您的示例,但我将其与培训指南中显示的技术合并。免责声明:它会编译,但我还没有构建完全测试代码的先决条件。
using PX.Data;
using PX.Data.BQL.Fluent;
namespace SSCS.CodeSample
{
public class CodeSampleEntry : PXGraph<CodeSampleEntry, DACParent>
{
#region Data Views
/// Parent View
[PXViewName("Parent View - Primary")]
public SelectFrom<DACParent>.View ParentTran;
/// Child view
[PXViewName("Child View")]
public SelectFrom<DACChild>
.Where<DACChild.tranId.IsEqual<DACParent.nCTranId.FromCurrent>>
.View ChildAnalysis;
#endregion
// RowInserted Event to Create a Default Child Record
// See T210 Master-Detail training guide from Acumatica
protected virtual void _(Events.RowInserted<DACParent> e)
{
// Ensure there isn't a child record already
if (ChildAnalysis.Select().Count == 0)
{
// Save state of IsDirty so that we can restore it
// after inserting the default child record
// so that we don't force the user to save
// unless they actually enter data somewhere
bool oldDirty = ChildAnalysis.Cache.IsDirty;
// Create an object for the child
// and fill in any data that should be
// populated by default
DACChild newChild = new DACChild();
newChild.MyData = "My Value";
// Insert the new child record into the cache
ChildAnalysis.Insert(newChild);
// Restore the IsDirty flag
// The insert above will have marked the view as
// dirty. If it wasn't dirty before, it should be
// treated as if it still isn't
ChildAnalysis.Cache.IsDirty = oldDirty;
}
}
}
[PXCacheName("Parent DAC")]
public class DACParent : IBqlTable
{
#region NCTranId
[PXDBIdentity]
public virtual int? NCTranId { get; set; }
public abstract class nCTranId
: PX.Data.BQL.BqlInt.Field<nCTranId> { }
#endregion
}
[PXCacheName("Child DAC")]
public class DACChild : IBqlTable
{
#region TranId
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(DACParent.nCTranId))]
[PXParent(typeof(SelectFrom<DACParent>
.Where<DACParent.nCTranId.IsEqual<DACChild.tranId.FromCurrent>>))]
public virtual int? TranId { get; set; }
public abstract class tranId
: PX.Data.BQL.BqlInt.Field<tranId> { }
#endregion
#region MyData
[PXDBString()]
[PXUIField(DisplayName = "My Data Field")]
public virtual string MyData { get; set; }
public abstract class myData
: PX.Data.BQL.BqlString.Field<myData> { }
#endregion
}
}
我有 2 个场景,我遇到了问题。
- 我有3个DAC,一个是Parent,另外2个是child DAC。
- 我有选项卡视图,并相应地显示数据。 第一个选项卡显示父 DAC 数据。 第二个和第三个显示子 DAC 数据。
我正在创建新项目,现在我按添加 (+) 按钮并填写父选项卡中的信息,但未在第二和第三选项卡中填写任何数据,当我按保存时,只有父 DAC 保存,第二和数据库中没有创建第 3 个选项卡行,我也想保存第 2 个和第 3 个选项卡 DAC,我该怎么办?
另一种情况: 我不允许 DAC 更新,我正在设置 DAC.Cahce.AllowUpdated = false;除了 Checkbox 之外的所有控件都被禁用,为什么?
另外,当我们在第 3 个选项卡上并单击工具栏导航按钮时,第 1 个选项卡数据不会刷新,它显示的是之前选择的项目数据。如何解决这个问题?
我们没有将 PXGrid 用于任何子数据,所有 3 个 DAC 之间存在一对一的关系。
/// Parent View
public SelectFrom<Parent>.View parentTran;
/// Child view
public SelectFrom<Child> .Where<Child.tranId.IsEqual<Parent.nCTranId.AsOptional>>.View
childAnalysis;
#region TranId
// Child DAC Field.
public abstract class tranId:PX.Data.BQL.BqlInt.Field<tranId> {
}
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(Parent.nCTranId))]
[PXParent(typeof(Select<Parent, Where<Parent.nCTranId, Equal<Current<tranId>>>>))]
public virtual int? TranId {
get; set;
}
#endregion
查看有关 Master-Detail 关系的 T210。它包含一个关于插入默认记录的部分,这听起来像您尝试用 child DAC 做的事情。可以在 Acumatica 网站上的 https://openuni.acumatica.com/courses/development/t210-development-customized-forms-and-master-detail-relationship/ 找到培训。具体看103页和104页
在本部分的第 3 步中,您将看到使用 RowInserted 事件插入 child 记录。由于 RowInserted 事件仅在创建记录时触发,因此可以安全地插入 child 记录。
请参阅以下代码示例。我尝试尽可能多地使用您的示例,但我将其与培训指南中显示的技术合并。免责声明:它会编译,但我还没有构建完全测试代码的先决条件。
using PX.Data;
using PX.Data.BQL.Fluent;
namespace SSCS.CodeSample
{
public class CodeSampleEntry : PXGraph<CodeSampleEntry, DACParent>
{
#region Data Views
/// Parent View
[PXViewName("Parent View - Primary")]
public SelectFrom<DACParent>.View ParentTran;
/// Child view
[PXViewName("Child View")]
public SelectFrom<DACChild>
.Where<DACChild.tranId.IsEqual<DACParent.nCTranId.FromCurrent>>
.View ChildAnalysis;
#endregion
// RowInserted Event to Create a Default Child Record
// See T210 Master-Detail training guide from Acumatica
protected virtual void _(Events.RowInserted<DACParent> e)
{
// Ensure there isn't a child record already
if (ChildAnalysis.Select().Count == 0)
{
// Save state of IsDirty so that we can restore it
// after inserting the default child record
// so that we don't force the user to save
// unless they actually enter data somewhere
bool oldDirty = ChildAnalysis.Cache.IsDirty;
// Create an object for the child
// and fill in any data that should be
// populated by default
DACChild newChild = new DACChild();
newChild.MyData = "My Value";
// Insert the new child record into the cache
ChildAnalysis.Insert(newChild);
// Restore the IsDirty flag
// The insert above will have marked the view as
// dirty. If it wasn't dirty before, it should be
// treated as if it still isn't
ChildAnalysis.Cache.IsDirty = oldDirty;
}
}
}
[PXCacheName("Parent DAC")]
public class DACParent : IBqlTable
{
#region NCTranId
[PXDBIdentity]
public virtual int? NCTranId { get; set; }
public abstract class nCTranId
: PX.Data.BQL.BqlInt.Field<nCTranId> { }
#endregion
}
[PXCacheName("Child DAC")]
public class DACChild : IBqlTable
{
#region TranId
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(DACParent.nCTranId))]
[PXParent(typeof(SelectFrom<DACParent>
.Where<DACParent.nCTranId.IsEqual<DACChild.tranId.FromCurrent>>))]
public virtual int? TranId { get; set; }
public abstract class tranId
: PX.Data.BQL.BqlInt.Field<tranId> { }
#endregion
#region MyData
[PXDBString()]
[PXUIField(DisplayName = "My Data Field")]
public virtual string MyData { get; set; }
public abstract class myData
: PX.Data.BQL.BqlString.Field<myData> { }
#endregion
}
}