//for 2019r1 //public bool AppendExpression(ref SQLExpression exp, PXGraph graph, BqlCommandInfo info, BqlCommand.Selection selection) //{ // if (graph == null || !info.BuildExpression) return true; // PXMutableCollection.AddMutableItem(this); // exp = new PX.Data.SQLTree.Constant(graph.Accessinfo.BranchID); // return true; //} //for 2020r1 public bool AppendExpression(ref SQLExpression exp, PXGraph graph, BqlCommandInfo info, BqlCommand.Selection selection) { if (graph == null || !info.BuildExpression) { return(true); } PXMutableCollection.AddMutableItem(this); exp = new SQLConst(graph.Accessinfo.BranchID); return(true); }
public bool AppendExpression(ref SQLExpression exp, PXGraph graph, BqlCommandInfo info, BqlCommand.Selection selection) { bool status = true; object val = null; if (_parameter == null) { _parameter = new Parameter(); } if (graph != null && info.BuildExpression) { if (_parameter.HasDefault) { Type ft = _parameter.GetReferencedType(); if (ft.IsNested) { Type ct = BqlCommand.GetItemType(ft); PXCache cache = graph.Caches[ct]; if (cache.Current != null) { val = cache.GetValue(cache.Current, ft.Name); } } } SQLExpression fld = BqlCommand.GetSingleExpression(typeof(Field), graph, info.Tables, selection, BqlCommand.FieldPlace.Condition); exp = fld.IsNull(); List <int> branches = null; if (val != null) { branches = GetSameOrganizationBranches((int?)val); } if (branches != null && branches.Count > 0) { SQLExpression inn = null; foreach (int numBranch in branches) { if (null == inn) { inn = new SQLConst(numBranch); } else { inn = inn.Seq(numBranch); } } exp = exp.Or(fld.In(inn)).Embrace(); } } if (info.Fields?.Contains(typeof(Field)) == false) { info.Fields.Add(typeof(Field)); } if (!selection.FromProjection) { exp = AddParameterExpression(exp, info, selection, val); } return(status); }