我正在尝试向分支添加默认分支位置字段。此字段将允许用户选择分支位置作为默认值,并在以后的几个自定义中具有此默认值。我的问题是,当我填充新的扩展字段时,该值将保存在所有分支记录而不是选定的分支上。
我扩展了分支DAC(因为这是存储数据的地方):
//Branch Extension
[PXTable(typeof(Branch.branchID), IsOptional = false)]
public class BranchExtension : PXCacheExtension<Branch>
{
#region DefaultBranchLocation
public abstract class defaultBranchLocation : IBqlField { }
[PXDBInt()]
[PXUIField(DisplayName = "Default Branch Location")]
[PXSelector(typeof(FSBranchLocation.branchLocationID),
DescriptionField = typeof(FSBranchLocation.descr),
SubstituteKey = typeof(FSBranchLocation.branchLocationCD))]
public virtual int? DefaultBranchLocation { get; set; }
#endregion
}
这是我创建的分支扩展表:
<Sql TableName="BranchExtension" TableSchemaXml="#CDATA">
<CDATA name="TableSchemaXml"><![CDATA[<table name="BranchExtension">
<col name="CompanyID" type="Int" default="Zero" />
<col name="BranchID" type="Int" />
<col name="DeletedDatabaseRecord" type="Bit" />
<col name="DefaultBranchLocation" type="Int" nullable="true" />
<index name="BranchExtension_PK" clustered="true" primary="true" unique="true">
<col name="CompanyID" />
<col name="BranchID" />
</index>
</table>]]></CDATA>
</Sql>
我创建了一个回填脚本(不包括在内)。 为了处理分支页面上使用的投影,我创建了以下BranchBAccount扩展名:
//BranchBAccount Projection Extension
public class BranchBAccountExtension : PXCacheExtension<BranchMaint.BranchBAccount>
{
#region DefaultBranchLocation
public abstract class defaultBranchLocation : IBqlField { }
[PXDBInt(BqlField = typeof(BranchExtension.defaultBranchLocation))]
[PXUIField(DisplayName = "Default Branch Location")]
[PXSelector(typeof(
Search2<FSBranchLocation.branchLocationID,
InnerJoin<Branch, On<Branch.branchID, Equal<FSBranchLocation.branchID>>>,
Where<Branch.branchCD, Equal<Current<BranchMaint.BranchBAccount.branchBranchCD>>>>),
DescriptionField = typeof(FSBranchLocation.descr),
SubstituteKey = typeof(FSBranchLocation.branchLocationCD))]
public virtual int? DefaultBranchLocation { get; set; }
#endregion
}
对于aspx,我只是将我的扩展字段添加到Branches页面(CS102000)作为General Info,MISC SETTINGS(SHARED)下的第一个字段。您可以看到它的放置方式:
...
<px:PXLayoutRule runat="server" StartGroup="True" GroupCaption="Misc Settings (Shared)" ></px:PXLayoutRule>
<px:PXSelector runat="server" ID="edDefaultBranchLocation" DataField="DefaultBranchLocation" CommitChanges="True" AutoRefresh="True" />
<px:PXFormView ID="CommonSettings" runat="server" DataMember="commonsetup" DataSourceID="ds" RenderStyle="Simple">
...
在我的测试公司中,我有3个分支(分支ID 1,2和3)。我导航到CS102000(分支)并选择其中一个分支(我们将分支ID 3)。我添加的默认分支位置字段存在,选择器似乎按照需要工作(无论我选择哪个分支,只显示其位置)。选择分支位置时不会显示错误。我点击“保存”按钮,一切看起来都不错。也就是说,在我查看任何其他分支记录之前,它们现在具有我选择的分支默认值。更改分支时,屏幕上的所有其他数据都会发生变化。当在数据库中查找时,我的扩展表具有与分支1,2和3相同的DefaultBranchLocation值。执行SQL跟踪显示它只是运行以下内容:
UPDATE BranchExtension SET [BranchExtension].[DefaultBranchLocation] = @P0 WHERE CompanyID = 2
请注意,它不会过滤关键字段。
我之前从未遇到过扩展表这个问题,所以我不确定我做错了什么。我的猜测是它与投影的扩展有关,但是我的扩展中的字段声明看起来与在该投影上声明的字段正确保存没有什么不同。
非常感谢任何帮助。先感谢您。
答案 0 :(得分:2)
真正的问题与您自定义投影的尾部有关。 我建议您考虑将数据存储在BAccount扩展名中。然后,如果需要,您可以使用PXDBScalarAttribute将BAccount中的字段映射到分支扩展。 如果您非常需要避免subselect或者您有其他要求,可以执行以下操作:将BranchID字段添加到分支扩展并手动处理此字段。
请参阅以下两个示例
public class BranchMaintExt : PXGraphExtension<BranchMaint>
{
protected void BranchBAccount_BranchID_CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
{
if ((e.Operation & PXDBOperation.Command) != PXDBOperation.Select && e.Table != typeof(BranchExtension))
{
e.Cancel = true;
}
else if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Update && e.Value == null && e.Row != null)
{
decimal? ident = PXDatabase.SelectIdentity<PX.Objects.GL.Branch>(typeof(PX.Objects.GL.Branch.branchID).Name);
if (ident != null && ident.Value > 0)
{
sender.SetValue<BranchBAccountExtension.branchID>(e.Row, Convert.ToInt32(ident));
e.Value = ident;
}
}
}
protected void BranchBAccount_BAccountID_CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
{
if (((e.Operation & PXDBOperation.Command) == PXDBOperation.Update)
&& sender.GetValue<BranchBAccountExtension.branchID>(e.Row) == null && e.Row != null)
{
decimal? ident = PXDatabase.SelectIdentity<PX.Objects.GL.Branch>(typeof(PX.Objects.GL.Branch.branchID).Name);
if (ident != null && ident.Value > 0)
{
sender.SetValue<BranchBAccountExtension.branchID>(e.Row, Convert.ToInt32(ident));
}
}
}
}
[PXTable(typeof(Branch.branchID), IsOptional = false)]
public class BranchExtension : PXCacheExtension<Branch>
{
#region DefaultBranchLocation
public abstract class defaultBranchLocation : IBqlField { }
[PXDBInt()]
[PXUIField(DisplayName = "Default Branch Location")]
public virtual int? DefaultBranchLocation { get; set; }
#endregion
#region BAccountDefaultBranchLocation
public abstract class bAccountDefaultBranchLocation : IBqlField { }
[PXDBScalar(typeof(Search<BAccountExtension.bAccountDefaultBranchLocation, Where<BAccount.bAccountID, Equal<Branch.bAccountID>>>))]
[PXInt()]
[PXUIField(DisplayName = "Default Branch Location")]
public virtual int? BAccountDefaultBranchLocation { get; set; }
#endregion
}
[PXTable(typeof(BAccount.bAccountID), IsOptional = false)]
public class BAccountExtension : PXCacheExtension<BAccount>
{
#region BAccountDefaultBranchLocation
public abstract class bAccountDefaultBranchLocation : IBqlField { }
[PXDBInt()]
[PXUIField(DisplayName = "Default Branch Location")]
public virtual int? BAccountDefaultBranchLocation { get; set; }
#endregion
}
public class BranchBAccountExtension : PXCacheExtension<BranchMaint.BranchBAccount>
{
#region BranchID
public abstract class branchID : PX.Data.IBqlField
{
}
[PXDBInt(BqlField = typeof(PX.Objects.GL.Branch.branchID))]
[PXUIField(DisplayName = "Branch ID", Visibility = PXUIVisibility.Invisible)]
public virtual int? BranchID { get; set; }
#endregion
#region DefaultBranchLocation
public abstract class defaultBranchLocation : IBqlField { }
[PXDBInt(BqlField = typeof(BranchExtension.defaultBranchLocation))]
[PXUIField(DisplayName = "Default Branch Location")]
public virtual int? DefaultBranchLocation { get; set; }
#endregion
#region BAccountDefaultBranchLocation
public abstract class bAccountDefaultBranchLocation : IBqlField { }
[PXDBInt]
[PXUIField(DisplayName = "Default Branch Location")]
public virtual int? BAccountDefaultBranchLocation { get; set; }
#endregion
}