我会考虑PXProjection在 Acumatica 中使用投影(这样,您不必使用任何事件来对框架执行任何复杂/棘手的逻辑,正如您所描述的那样。
我在下面整理了一个简单的例子。请注意指向同一主 DAC 的 3 个投影 DAC。这允许记录全部存储在MyTable数据库中,但每个记录都有自己的缓存。
在这里,我定义了我的不同类型...
public class MyDacType
{
public const string TypeA = "A";
public const string TypeB = "B";
public const string TypeC = "B";
public class typeA : Constant<string>
{
public typeA() : base(TypeA) { }
}
public class typeB : Constant<string>
{
public typeB() : base(TypeB) { }
}
public class typeC : Constant<string>
{
public typeC() : base(TypeC) { }
}
/// <summary>
/// List attribute for display of user friendly value
/// </summary>
public class ListAttribute : PXStringListAttribute
{
public ListAttribute()
: base(new string[]
{
TypeA,
TypeB,
TypeC
}, new string[]
{
"Type A",
"Type B",
"Type C"
})
{
}
}
}
这是我的主桌...
/// <summary>
/// Main database DAC
/// </summary>
[Serializable]
public class MyTable : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true)]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1)]
[PXDefault]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type")]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true)]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
我创建了 3 个投影(每个选项卡一个)...
/// <summary>
/// DAC representing Type A (data stored in MyTable)
/// </summary>
[Serializable]
[PXProjection(typeof(Select<MyTable, Where<MyTable.dacType, Equal<MyDacType.typeA>>>), Persistent = true)]
public class MyTableTypeA : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true, BqlField = typeof(MyTable.someKeyField))]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1, BqlField = typeof(MyTable.dacType))]
[PXDefault(MyDacType.TypeA)]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type", Enabled = false, Visible = false)]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true, BqlField = typeof(MyTable.description))]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
/// <summary>
/// DAC representing Type B (data stored in MyTable)
/// </summary>
[Serializable]
[PXProjection(typeof(Select<MyTable, Where<MyTable.dacType, Equal<MyDacType.typeB>>>), Persistent = true)]
public class MyTableTypeB : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true, BqlField = typeof(MyTable.someKeyField))]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1, BqlField = typeof(MyTable.dacType))]
[PXDefault(MyDacType.TypeB)]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type", Enabled = false, Visible = false)]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true, BqlField = typeof(MyTable.description))]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
/// <summary>
/// DAC representing Type C (data stored in MyTable)
/// </summary>
[Serializable]
[PXProjection(typeof(Select<MyTable, Where<MyTable.dacType, Equal<MyDacType.typeC>>>), Persistent = true)]
public class MyTableTypeC : IBqlTable
{
#region SomeKeyField
public abstract class someKeyField : PX.Data.IBqlField
{
}
protected string _SomeKeyField;
[PXDBString(10, IsKey = true, IsUnicode = true, BqlField = typeof(MyTable.someKeyField))]
[PXDefault]
[PXUIField(DisplayName = "My Key Field", Enabled = false)]
public virtual string SomeKeyField
{
get
{
return this._SomeKeyField;
}
set
{
this._SomeKeyField = value;
}
}
#endregion
#region DacType
public abstract class dacType : PX.Data.IBqlField
{
}
protected string _DacType;
[PXDBString(1, BqlField = typeof(MyTable.dacType))]
[PXDefault(MyDacType.TypeC)]
[MyDacType.List]
[PXUIField(DisplayName = "Dac Type", Enabled = false, Visible = false)]
public virtual string DacType
{
get
{
return this._DacType;
}
set
{
this._DacType = value;
}
}
#endregion
#region Description
public abstract class description : PX.Data.IBqlField
{
}
protected string _Description;
[PXDBString(256, IsUnicode = true, BqlField = typeof(MyTable.description))]
[PXUIField(DisplayName = "Description")]
public virtual string Description
{
get
{
return this._Description;
}
set
{
this._Description = value;
}
}
#endregion
}
现在在我的图表中,我创建了 3 个视图(每个 PXProjection dac 1 个)。我也不需要显示 DacType 字段,因为它会自动默认为正确的值。
public class MyGraph : PXGraph<MyGraph>
{
// Some other views...
/// <summary>
/// View for tab 1
/// </summary>
public PXSelect<MyTableTypeA> TypeA;
/// <summary>
/// View for tab 2
/// </summary>
public PXSelect<MyTableTypeB> TypeB;
/// <summary>
/// View for tab 3
/// </summary>
public PXSelect<MyTableTypeC> TypeC;
// When using events and cache attached you use the DAC name. Ex:
// protected virtual void MyTableTypeB_RowDeleting(PXCache cache, RowDeletingEvents e) { }
}