public static PXAction GetSaveAction(this PXGraph graph) { PXAction saveAction = null; Type primary = !String.IsNullOrEmpty(graph.PrimaryView) ? graph.Views[graph.PrimaryView].GetItemType() : null; foreach (PXAction action in graph.Actions.Values) { PXButtonState state = action.GetState(null) as PXButtonState; if (state != null && state.SpecialType == PXSpecialButtonType.Save) { if (primary == null || state.ItemType == null || primary == state.ItemType || primary.IsSubclassOf(state.ItemType)) { saveAction = action; break; } } } if (saveAction == null) { throw new PXException("There is not a Save action in the graph " + graph.GetType()); } return(saveAction); }
public virtual IEnumerable <ApproveInfo> Assign(Table item, EPAssignmentMap map, bool isApprove) { path.Clear(); processMapType = GraphHelper.GetType(map.EntityType); Type itemType = item.GetType(); PXSelectBase <EPAssignmentRoute> rs = new PXSelectReadonly <EPAssignmentRoute, Where <EPAssignmentRoute.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> >, And <EPAssignmentRoute.parent, IsNull> >, OrderBy <Asc <EPAssignmentRoute.sequence> > >(this); PXResultset <EPAssignmentRoute> routes = rs.Select(map.AssignmentMapID, null); Type mapgraphtype = GraphHelper.GetType(map.GraphType); //impossible, but written to support purpose of legacy db states if (mapgraphtype == null) { mapgraphtype = EntityHelper.GetPrimaryGraphType(this, processMapType); } if (_Graph != null && mapgraphtype.IsAssignableFrom(_Graph.GetType())) { processGraph = _Graph; } else { processGraph = CreateInstance(GraphHelper.GetType(map.GraphType) ?? mapgraphtype); } if (processGraph != null && processMapType != null) { if (processMapType.IsAssignableFrom(itemType)) { this.processGraph.Caches[itemType].Current = item; } else if (itemType.IsAssignableFrom(processMapType)) { object placed = this.processGraph.Caches[processMapType].CreateInstance(); PXCache cache = (PXCache)Activator.CreateInstance(typeof(PXCache <>).MakeGenericType(itemType), this); cache.RestoreCopy(placed, item); this.processGraph.Caches[processMapType].Current = placed; } else { return(null); } } var result = ProcessLevel(item, map.AssignmentMapID, routes).ToList(); if (result.Any()) { return(result); } PXTrace.WriteWarning(Messages.DocumentPreApproved); throw new RequestApproveException(); }
public static bool IsRunningSelecting(PXGraph graph) { RunningSelectingScope <DAC> scope = PXContext.GetSlot <RunningSelectingScope <DAC> >(); if (scope == null) { return(false); } else { return(scope._GraphList.Exists(e => e == graph.GetType().FullName)); } }
public RunningSelectingScope(PXGraph myGraph) { _MyGraphSelecting = myGraph.GetType().FullName; _Previous = PXContext.GetSlot <RunningSelectingScope <DAC> >(); if (_Previous == null) { _GraphList = new List <string>(); } else { _GraphList = new List <string>(_Previous._GraphList); } _GraphList.Add(_MyGraphSelecting); PXContext.SetSlot <RunningSelectingScope <DAC> >(this); }
protected void BusinessAccountPaymentInstructionDetail_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity) { IEnumerable <EntityValueField> valueFields = targetEntity.Fields.OfType <EntityValueField>(); string targetID = valueFields.Single(f => f.Name.EndsWith("ID")).Value; string targetValue = valueFields.Single(f => f.Name.EndsWith("Value")).Value; switch (graph) { case VendorMaint vendorGraph: { CR.LocationExtAddress location = vendorGraph.DefLocation.Select(); foreach (VendorPaymentMethodDetail paymentMethodDetail in vendorGraph.PaymentDetails.Select(location.BAccountID, location.LocationID, location.VPaymentMethodID)) { if (paymentMethodDetail.DetailID == targetID) { vendorGraph.PaymentDetails.Cache.SetValueExt <VendorPaymentMethodDetail.detailValue>(paymentMethodDetail, targetValue); vendorGraph.PaymentDetails.Cache.Update(paymentMethodDetail); return; } } throw new PXException(Common.Messages.EntityWithIDDoesNotExist, Data.EntityHelper.GetFriendlyEntityName <VendorPaymentMethodDetail>(), targetID); } case CustomerMaint customerGraph: { CR.LocationExtAddress location = customerGraph.DefLocation.Select(); foreach (CustomerPaymentMethodDetail paymentMethodDetail in customerGraph.DefPaymentMethodInstanceDetails.Select(location.BAccountID, location.LocationID, location.VPaymentMethodID)) { if (paymentMethodDetail.DetailID == targetID) { customerGraph.DefPaymentMethodInstanceDetails.Cache.SetValueExt <CustomerPaymentMethodDetail.value>(paymentMethodDetail, targetValue); customerGraph.DefPaymentMethodInstanceDetails.Cache.Update(paymentMethodDetail); return; } } throw new PXException(Common.Messages.EntityWithIDDoesNotExist, Data.EntityHelper.GetFriendlyEntityName <CustomerPaymentMethodDetail>(), targetID); } default: throw new InvalidOperationException("Not applicable for " + graph.GetType()); } }
private static Guid?GetEntityNoteID(PXGraph graph, object row) { var helper = new EntityHelper(graph); Guid?refNoteId = null; if (row != null) { var cacheType = row.GetType(); var graphType = helper.GetPrimaryGraphType(cacheType, row, false); if (graphType != null) { var primaryGraph = graph.GetType() != graphType ? (PXGraph)PXGraph.CreateInstance(graphType) : graph; var primaryCache = primaryGraph.Caches[cacheType]; refNoteId = PXNoteAttribute.GetNoteID(primaryCache, row, EntityHelper.GetNoteField(cacheType)); } } return(refNoteId); }
/// <summary> /// Assigns Owner and Workgroup to the given IAssign instance based on the assigmentment rules. /// </summary> /// <param name="item">IAssign object</param> /// <param name="assignmentMapID">Assignment map</param> /// <returns>True if workgroup was assigned; otherwise false</returns> /// <remarks> /// You have to manualy persist the IAssign object to save the changes. /// </remarks> public virtual bool Assign(Table item, int?assignmentMapID) { if (item == null) { throw new ArgumentNullException("item"); } if (assignmentMapID < 0) { throw new ArgumentOutOfRangeException("assignmentMapID"); } path.Clear(); EPAssignmentMap map = PXSelect <EPAssignmentMap, Where <EPAssignmentMap.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> > > > .SelectWindowed(this, 0, 1, assignmentMapID); if (map == null) { return(false); } processMapType = GraphHelper.GetType(map.EntityType); Type itemType = item.GetType(); PXSelectBase <EPAssignmentRoute> rs = new PXSelectReadonly <EPAssignmentRoute, Where <EPAssignmentRoute.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> >, And <EPAssignmentRoute.parent, IsNull> >, OrderBy <Asc <EPAssignmentRoute.sequence> > >(this); PXResultset <EPAssignmentRoute> routes = rs.Select(assignmentMapID, null); Type mapgraphtype = GraphHelper.GetType(map.GraphType); //impossible, but written to support purpose of legacy db states if (mapgraphtype == null) { mapgraphtype = EntityHelper.GetPrimaryGraphType(this, processMapType); } if (_Graph != null && mapgraphtype.IsAssignableFrom(_Graph.GetType())) { processGraph = _Graph; } else { processGraph = CreateInstance(GraphHelper.GetType(map.GraphType) ?? mapgraphtype); } if (processGraph != null && processMapType != null) { if (processMapType.IsAssignableFrom(itemType)) { this.processGraph.Caches[itemType].Current = item; } else if (itemType.IsAssignableFrom(processMapType)) { object placed = this.processGraph.Caches[processMapType].CreateInstance(); PXCache cache = (PXCache)Activator.CreateInstance(typeof(PXCache <>).MakeGenericType(itemType), this); cache.RestoreCopy(placed, item); this.processGraph.Caches[processMapType].Current = placed; } else { return(false); } } return(ProcessLevel(item, assignmentMapID, routes)); }
//Refactor - Generalize if possible!!! private IBqlTable GetItemRecord(EPAssignmentRule rule, IBqlTable item) { PXGraph graph = this.processGraph; Type itemType = item.GetType(); Type ruleType = GraphHelper.GetType(rule.Entity); if (ruleType.IsAssignableFrom(itemType)) { return(item); } if (processMapType.IsAssignableFrom(ruleType) && graph != null) { return(graph.Caches[processMapType].Current as IBqlTable); } if (graph != null) { foreach (CacheEntityItem entry in EMailSourceHelper.TemplateEntity(this, null, item.GetType().FullName, graph.GetType().FullName)) { Type entityType = GraphHelper.GetType(entry.SubKey); if (ruleType.IsAssignableFrom(entityType) && graph.Views.ContainsKey(entry.Key)) { PXView view = graph.Views[entry.Key]; object result = view.SelectSingleBound(new object[] { item }); return((result is PXResult ? ((PXResult)result)[0] : result) as IBqlTable); } } } return(item); }
public virtual IEnumerable <ApproveInfo> Assign(Table item, EPAssignmentMap map, bool isApprove, int?currentStepSequence) { path.Clear(); processMapType = GraphHelper.GetType(map.EntityType); Type itemType = item.GetType(); PXSelectBase <EPRule> rs = new PXSelectReadonly < EPRule, Where < EPRule.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> > >, OrderBy < Asc <EPAssignmentRoute.sequence> > >(this); PXResultset <EPRule> rules; if (isApprove) { PXSelectBase <EPRule> ss = new PXSelectReadonly < EPRule, Where < EPRule.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> >, And <EPRule.sequence, Greater <Required <EPRule.sequence> >, And <EPRule.stepID, IsNull> > >, OrderBy < Asc <EPAssignmentRoute.sequence> > >(this); EPRule nextStep = ss.Select(map.AssignmentMapID, currentStepSequence ?? -1); if (nextStep == null) { yield break; } rs.WhereAnd <Where <EPRule.stepID, Equal <Required <EPRule.stepID> > > >(); rules = rs.Select(map.AssignmentMapID, nextStep.RuleID, null); rules.ForEach(_ => ((EPRule)_).StepName = nextStep.Name); } else { rules = rs.Select(map.AssignmentMapID, null); } Type mapgraphtype = GraphHelper.GetType(map.GraphType); //impossible, but written to support purpose of legacy db states if (mapgraphtype == null) { mapgraphtype = EntityHelper.GetPrimaryGraphType(this, processMapType); } if (_Graph != null && mapgraphtype.IsAssignableFrom(_Graph.GetType())) { processGraph = _Graph; } else { processGraph = CreateInstance(GraphHelper.GetType(map.GraphType) ?? mapgraphtype); } if (processGraph != null && processMapType != null) { if (processMapType.IsAssignableFrom(itemType)) { processGraph.Caches[itemType].Current = item; } else if (itemType.IsAssignableFrom(processMapType)) { object placed = processGraph.Caches[processMapType].CreateInstance(); PXCache cache = (PXCache)Activator.CreateInstance(typeof(PXCache <>).MakeGenericType(itemType), this); cache.RestoreCopy(placed, item); processGraph.Caches[processMapType].Current = placed; } else { yield break; } } foreach (var approveInfo in ProcessLevel(item, map.AssignmentMapID, rules)) { yield return(approveInfo); } }
private bool IsGraphApplicable(PXGraph graph) { var graphType = graph.GetType(); return(graphTypes.IsEmpty() || graphTypes.Contains(graphType)); }
protected bool IsReportGraph(PXGraph graph) => graph.GetType() == typeof(PXGraph);