Last active
February 16, 2023 01:56
-
-
Save smarenich/099d7f5325a6c9cfe0dd1d27fc92296e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeatureEnabledBoolAttribute : PXDBBoolAttribute | |
{ | |
protected Type RecordType; | |
public BCFeatureEnabledBoolAttribute(Type recordType) | |
{ | |
RecordType = recordType; | |
} | |
public override void CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e) | |
{ | |
//On CommandPreparing the querry will be generated, we need only select, since this is virtual field | |
if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Select && (e.Operation & PXDBOperation.GroupBy) == 0) | |
{ | |
Type bqlTable = sender.GetItemType(); | |
//Here you can check in any way if you feature is enabled or disabled | |
List<String> listOfDisabledRecordTypes = GetListOfDisabledTypesByFeatures(); | |
//Here we can build a dynamic Swtch/Case that will validate the feature | |
SQLSwitch switchExpr = new SQLSwitch(); | |
if (listOfDisabledFieatures.Count > 0) | |
{ | |
foreach (String type in listOfDisabledRecordTypes) | |
{ | |
switchExpr = switchExpr.Case( | |
new Column(RecordType.Name, bqlTable.Name).EQ(new SQLConst(type)), | |
new SQLConst(false)); | |
} | |
} | |
else | |
switchExpr = switchExpr.Case(new SQLConst(1).EQ(1), new SQLConst(true)); | |
switchExpr = switchExpr.Default(new SQLConst(true)); | |
//Finally assemblying query. | |
Query q = new Query().Field(switchExpr); | |
e.Expr = new SubQuery(q); | |
e.Cancel = true; | |
e.BqlTable = bqlTable; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyDAC : IBqlTable | |
{ | |
//......... | |
#region IsFeatureEnabled | |
public abstract class isFeatureEnabled : PX.Data.BQL.BqlString.Field<isFeatureEnabled> { } | |
//Lets use our new attribute on a feield | |
[BCFeatureEnabledBool(typeof(MyDAC.recordType)))] | |
public virtual bool? IsFeatureEnabled { get; set; } | |
#endregion | |
//......... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyGraph : IBqlTable | |
{ | |
//......... | |
//And now we can use our new field anywhere, even in GI. | |
public PXSelect<MyDAC, Where<MyDAC.isFeatureEnabled, Equal<True>>> MyDataView; | |
//......... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment