protected virtual void EPRule_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { EPRule row = e.Row as EPRule; if (row == null) { return; } if (row.OwnerID != null) { var employee = EmployeeInactive.SelectSingle(row.OwnerID); if (employee != null) { sender.RaiseExceptionHandling <EPRule.ownerID>(row, null, new PXSetPropertyException(Messages.EmployeeIsInactive, PXErrorLevel.Warning)); } else { sender.RaiseExceptionHandling <EPRule.ownerID>(row, null, null); } } PXUIFieldAttribute.SetVisible <EPRule.ownerID>(this.Nodes.Cache, this.Nodes.Current, row.RuleType == EPRuleType.Direct); PXUIFieldAttribute.SetVisible <EPRule.ownerSource>(this.Nodes.Cache, this.Nodes.Current, row.RuleType == EPRuleType.Document); PXUIFieldAttribute.SetEnabled(CurrentNode.Cache, null, null, true); up.SetEnabled(true); down.SetEnabled(true); deleteRoute.SetEnabled(true); }
protected virtual void EPRule_RowDeleted(PXCache sender, PXRowDeletedEventArgs e) { EPRule row = e.Row as EPRule; if (row == null) { return; } if (row.StepID == null) { foreach (PXResult <EPRule> rule in PXSelect <EPRule, Where <EPRule.stepID, Equal <Required <EPRule.ruleID> > > > .Select(this, row.RuleID)) { if (Nodes.Cache.GetStatus((EPRule)rule) == PXEntryStatus.Inserted) { Nodes.Cache.SetStatus((EPRule)rule, PXEntryStatus.InsertedDeleted); } else { Nodes.Delete(rule); } } } }
protected virtual void EPRule_RowInserting(PXCache sender, PXRowInsertingEventArgs e) { EPRule row = e.Row as EPRule; if (row != null) { var rules = UpdateSequence(); if (row.StepID != null) { var isCurrent = false; foreach (var rule in rules) { if (isCurrent) { rule.Sequence++; Nodes.Update(rule); } else if (rule.RuleID == Nodes.Current.RuleID) { isCurrent = true; row.Sequence = rule.Sequence + 1; } } } else { row.Sequence = rules.Count + 1; } } }
public override void AddRule() { EPRule rule = null; if (Nodes.Current == null) { var step = Nodes.Insert(); step.Name = Messages.Step; rule = Nodes.Insert(); rule.StepID = step.RuleID; } else if (Nodes.Current.StepID == null) { var stepID = Nodes.Current.RuleID; rule = Nodes.Insert(); rule.StepID = stepID; } else { var stepID = Nodes.Current.StepID; rule = Nodes.Insert(); rule.StepID = stepID; } rule.Name = Messages.Rule; Nodes.Cache.ActiveRow = rule; }
protected virtual void EPRule_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { EPRule row = e.Row as EPRule; if (row == null) { return; } if (row.OwnerSource == null && row.StepID != null && row.RuleType == EPRuleType.Document) { throw new PXSetPropertyException <EPRule.ownerSource>(Messages.EmployeeCannotBeEmpty, PXErrorLevel.Error); } }
protected virtual IEnumerable nodes([PXDBGuid] Guid?ruleID) { List <EPRule> list = new List <EPRule>(); PXResultset <EPRule> resultSet; if (ruleID == null) { resultSet = PXSelect <EPRule, Where <EPRule.assignmentMapID, Equal <Current <EPAssignmentMap.assignmentMapID> >, And <EPRule.stepID, IsNull> > > .Select(this); } else { var rule = (EPRule)PXSelect <EPRule, Where <EPRule.assignmentMapID, Equal <Current <EPAssignmentMap.assignmentMapID> >, And <EPRule.ruleID, Equal <Required <EPRule.ruleID> > > > > .Select(this, ruleID); if (rule == null || rule.StepID != null) { return(list); } else { resultSet = PXSelect <EPRule, Where <EPRule.assignmentMapID, Equal <Current <EPAssignmentMap.assignmentMapID> >, And <EPRule.stepID, Equal <Required <EPRule.stepID> > > > > .Select(this, rule.RuleID); } } foreach (PXResult <EPRule> record in resultSet) { EPRule route = record; if (route.StepID != null) { route.Icon = PX.Web.UI.Sprite.Tree.GetFullUrl(PX.Web.UI.Sprite.Tree.Leaf); } else { route.Icon = PX.Web.UI.Sprite.Main.GetFullUrl(PX.Web.UI.Sprite.Main.Folder); } list.Add(route); } return(list); }
private List <object> ExecuteRule(Table item, EPRule rule, ref bool isSuccessful) { try { List <EPRuleBaseCondition> conditions = PXSelectReadonly <EPRuleCondition, Where <EPRuleCondition.ruleID, Equal <Required <EPRule.ruleID> >, And <EPRuleCondition.isActive, Equal <boolTrue> > > > .Select(this, rule.RuleID) .Select(_ => (EPRuleBaseCondition)_) .ToList(); if (conditions.Count == 0) { return(null); } Type resultViewType = CreateResultView(processGraph, conditions); PXView itemView = new PXView(processGraph, false, BqlCommand.CreateInstance(resultViewType), (PXSelectDelegate)getItemRecord); Select(item, itemView, conditions.Select(_ => GraphHelper.GetType(_.Entity)).Distinct().ToList(), null); PXFilterRow[] filters = GenerateFilters(item, conditions).ToArray <PXFilterRow>(); int startRow = 0; int totalRows = 0; List <object> result = itemView.Select(null, null, null, null, null, filters, ref startRow, 0, ref totalRows); results.Clear(); TraceResult(rule, conditions, result.Count); return(result); } catch (Exception e) { isSuccessful = false; PXTrace.WriteInformation(e); return(null); } }
protected override void EPRule_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { base.EPRule_RowSelected(sender, e); EPRule row = e.Row as EPRule; if (row == null) { return; } PXUIFieldAttribute.SetVisible <EPRule.ownerID>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null && row.RuleType == EPRuleType.Direct); PXUIFieldAttribute.SetVisible <EPRule.ownerSource>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null && row.RuleType == EPRuleType.Document); PXUIFieldAttribute.SetVisible(EmployeeCondition.Cache, null, row.StepID != null && row.RuleType == EPRuleType.Filter); PXUIFieldAttribute.SetVisible <EPRule.emptyStepType>(this.Nodes.Cache, this.Nodes.Current, row.StepID == null); PXUIFieldAttribute.SetVisible <EPRule.executeStep>(this.Nodes.Cache, this.Nodes.Current, row.StepID == null); PXUIFieldAttribute.SetVisible(Rules.Cache, null, null, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.ruleType>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.workgroupID>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.approveType>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.waitTime>(this.CurrentNode.Cache, this.CurrentNode.Current, row.StepID != null); bool isOfSupportedType = new List <string>() { typeof(EP.TimeCardMaint).FullName, typeof(EP.EquipmentTimeCardMaint).FullName, typeof(EP.ExpenseClaimEntry).FullName, typeof(PM.ProformaEntry).FullName, typeof(PM.ChangeOrderEntry).FullName, typeof(CR.QuoteMaint).FullName, typeof(PM.PMQuoteMaint).FullName, }.Contains(AssigmentMap.Current?.GraphType, new PX.Data.CompareIgnoreCase()); PXUIFieldAttribute.SetVisible <EPRule.reasonForApprove>(this.Nodes.Cache, this.Nodes.Current, isOfSupportedType && row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.reasonForReject>(this.Nodes.Cache, this.Nodes.Current, isOfSupportedType && row.StepID != null); Exception ex = (row.RuleType == EPRuleType.Filter) ? new PXSetPropertyException(Messages.AllEmployeesByFilterRequired, PXErrorLevel.Warning) : null; sender.RaiseExceptionHandling <EPRule.ruleType>(row, row.RuleType, ex); }
private IEnumerable <ApproveInfo> GetEmployeesByFilter(Table item, EPRule rule, List <EPRuleBaseCondition> conditions) { Type resultViewType = typeof(Select5 < EPEmployee, LeftJoin <Address, On <Address.addressID, Equal <EPEmployee.defAddressID> >, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> >, LeftJoin <EPCompanyTreeMember, On <EPCompanyTreeMember.userID, Equal <EPEmployee.userID> > > > >, Aggregate <GroupBy <EPEmployee.bAccountID> > >); PXView itemView = new PXView(this, false, BqlCommand.CreateInstance(resultViewType)); PXFilterRow[] filters = GenerateFilters(item, conditions).ToArray <PXFilterRow>(); int startRow = 0; int totalRows = 0; using (new PXFieldScope(itemView)) { IEnumerable <PXResult <EPEmployee, Address, Contact, EPCompanyTreeMember> > resultset = itemView .Select(null, null, null, null, null, filters, ref startRow, 0, ref totalRows) .Select(_ => (PXResult <EPEmployee, Address, Contact, EPCompanyTreeMember>)_); foreach (PXResult <EPEmployee, Address, Contact, EPCompanyTreeMember> res in resultset) { EPEmployee employee = res; EPCompanyTreeMember treeMember = res; yield return(new ApproveInfo() { OwnerID = employee.UserID, WorkgroupID = rule.WorkgroupID, RuleID = rule.RuleID, StepID = rule.StepID, WaitTime = rule.WaitTime }); } } }
protected override void EPRule_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { base.EPRule_RowSelected(sender, e); EPRule row = e.Row as EPRule; if (row == null) { return; } PXUIFieldAttribute.SetVisible <EPRule.ownerID>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null && row.RuleType == EPRuleType.Direct); PXUIFieldAttribute.SetVisible <EPRule.ownerSource>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null && row.RuleType == EPRuleType.Document); PXUIFieldAttribute.SetVisible(EmployeeCondition.Cache, null, row.StepID != null && row.RuleType == EPRuleType.Filter); PXUIFieldAttribute.SetVisible <EPRule.emptyStepType>(this.Nodes.Cache, this.Nodes.Current, row.StepID == null); PXUIFieldAttribute.SetVisible(Rules.Cache, null, null, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.ruleType>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.workgroupID>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.approveType>(this.Nodes.Cache, this.Nodes.Current, row.StepID != null); PXUIFieldAttribute.SetVisible <EPRule.waitTime>(this.CurrentNode.Cache, this.CurrentNode.Current, row.StepID != null); }
protected virtual IEnumerable nodes([PXDBGuid] Guid?ruleID) { List <EPRule> list = new List <EPRule>(); if (ruleID.HasValue) { return(list); } IEnumerable resultSet = PXSelectJoin <EPRule, LeftJoin <EPCompanyTree, On <EPRule.workgroupID, Equal <EPCompanyTree.workGroupID> > >, Where <EPRule.assignmentMapID, Equal <Current <EPAssignmentMap.assignmentMapID> > > > .Select(this); foreach (PXResult <EPRule, EPCompanyTree> record in resultSet) { EPRule route = record; route.Icon = PX.Web.UI.Sprite.Tree.GetFullUrl(PX.Web.UI.Sprite.Tree.Leaf); list.Add(route); } return(list); }
private void TraceResult(EPRule rule, List <EPRuleBaseCondition> conditions, int count) { PXTrace.WriteInformation(Messages.TraceRuleResult, rule.StepName, rule.Name, count, count > 0 ? "Satisfied" : "Unsatisfied"); string result = null; foreach (var condition in conditions) { result += string.Format(Messages.TraceCondition, GraphHelper.GetType(condition.Entity).Name, condition.FieldName, PXEnumDescriptionAttribute.GetInfo(typeof(PXCondition), (PXCondition)(condition.Condition ?? 0)).Value, condition.Value, condition.Value2); } PXTrace.WriteInformation(Messages.TraceConditions, result); }
private static int Comparison(EPRule x, EPRule y) { return(x.Sequence.Value.CompareTo(y.Sequence.Value)); }
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); } }