//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); }
private bool IsItemRuleTrue(IBqlTable item, EPAssignmentRule rule) { if (item is EPEmployee && rule.FieldName.Equals(typeof(EPEmployee.workgroupID).Name, StringComparison.InvariantCultureIgnoreCase)) { return(IsEmployeeInWorkgroup((EPEmployee)item, rule)); } currentItem = item; Type viewType = BqlCommand.Compose(typeof(Select <>), item.GetType()); PXView itemView = new PXView(this, false, BqlCommand.CreateInstance(viewType), (PXSelectDelegate)getItemRecord); if (rule.Condition == null) { return(false); } PXFilterRow filter = new PXFilterRow( rule.FieldName, (PXCondition)rule.Condition.Value, GetFieldValue(item, rule.FieldName, rule.FieldValue), null); int startRow = 0; int totalRows = 0; List <object> result = itemView.Select(null, null, null, null, null, new PXFilterRow[] { filter }, ref startRow, 1, ref totalRows); return(result.Count > 0); }
private bool IsEmployeeInWorkgroup(EPEmployee employee, EPAssignmentRule rule) { object workgroupID = null; PXCache sourceCache = this.Caches[typeof(EPEmployee)]; object copy = sourceCache.CreateCopy(employee); if (rule.FieldValue != null) { sourceCache.SetValueExt(copy, rule.FieldName, rule.FieldValue); } else { object newValue; sourceCache.RaiseFieldDefaulting(rule.FieldName, copy, out newValue); sourceCache.SetValue(copy, rule.FieldName, newValue); } workgroupID = sourceCache.GetValue(copy, rule.FieldName); PXSelectBase <EPCompanyTreeMember> select = new PXSelect <EPCompanyTreeMember, Where <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> >, And <EPCompanyTreeMember.workGroupID, Equal <Required <EPCompanyTreeMember.workGroupID> >, And <EPCompanyTreeMember.active, Equal <True> > > > >(this); EPCompanyTreeMember member = select.SelectSingle(employee.UserID, workgroupID); return(member != null); }
private bool IsTrue(Table item, EPAssignmentRule rule) { return (rule.FieldName.EndsWith("_Attributes")? IsAttributeRuleTrue(item, rule) : IsItemRuleTrue(GetItemRecord(rule, item), rule)); }
protected virtual void EPAssignmentRule_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { EPAssignmentRule oldRow = e.OldRow as EPAssignmentRule; EPAssignmentRule newRow = e.Row as EPAssignmentRule; if (oldRow != null && newRow != null) { if (!String.Equals(newRow.Entity, oldRow.Entity, StringComparison.OrdinalIgnoreCase)) { newRow.FieldName = newRow.FieldValue = null; } if (!String.Equals(newRow.FieldName, oldRow.FieldName, StringComparison.OrdinalIgnoreCase)) { newRow.FieldValue = null; } EPAssignmentRule row = e.Row as EPAssignmentRule; if (row.Condition == null || (PXCondition)row.Condition == PXCondition.ISNULL || (PXCondition)row.Condition == PXCondition.ISNOTNULL) { newRow.FieldValue = null; } if (newRow.FieldValue == null) { PXFieldState state = sender.GetStateExt <EPAssignmentRule.fieldValue>(newRow) as PXFieldState; newRow.FieldValue = state != null && state.Value != null?state.Value.ToString() : null; } } }
protected virtual void EPAssignmentRule_FieldName_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e) { EPAssignmentRule row = e.Row as EPAssignmentRule; if (row != null && row.Entity != null) { e.ReturnState = CreateFieldStateForFieldName(e.ReturnState, AssigmentMap.Current.EntityType, AssigmentMap.Current.GraphType, row.Entity); } }
private bool IsTrue(Table item, EPAssignmentRule rule) { var target = GetItemRecord(rule, item); // gets actual item for the rule to be applied to return (rule.FieldName.EndsWith("_Attributes")? IsAttributeRuleTrue(target, rule) : IsItemRuleTrue(target, rule)); }
protected virtual void EPAssignmentRule_FieldValue_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e) { EPAssignmentRule row = e.Row as EPAssignmentRule; if (row != null && !string.IsNullOrEmpty(row.FieldName) && row.Condition != null && (PXCondition)row.Condition != PXCondition.ISNULL && (PXCondition)row.Condition != PXCondition.ISNOTNULL) { e.ReturnState = CreateFieldStateForFieldValue(e.ReturnState, AssigmentMap.Current.EntityType, row.Entity, row.FieldName); } }
protected virtual void EPAssignmentRule_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { EPAssignmentRule row = e.Row as EPAssignmentRule; if (row == null) { return; } PXUIFieldAttribute.SetEnabled <EPAssignmentRule.fieldValue>(sender, row, row.Condition != (int)PXCondition.ISNULL && row.Condition != (int)PXCondition.ISNOTNULL); }
private bool IsAttributeRuleTrue(object item, EPAssignmentRule rule) { string field = rule.FieldName.Substring(0, rule.FieldName.Length - "_Attribute".Length - 1); CSAttribute attribute = PXSelectReadonly <CSAttribute> .Search <CSAttribute.attributeID>(this, field); if (attribute == null || rule.Condition == null) { //Field Name is not a valid question. return(false); } var noteId = new EntityHelper(_Graph).GetEntityNoteID(item); CSAnswers ans = PXSelect <CSAnswers, Where <CSAnswers.refNoteID, Equal <Required <CSAnswers.refNoteID> >, And <CSAnswers.attributeID, Equal <Required <CSAnswers.attributeID> > > > > .Select(_Graph ?? this, noteId, field); if (ans == null) { //Answer for the given question doesnot exist. switch (rule.Condition.Value) { case (int)PXCondition.ISNULL: return(true); case (int)PXCondition.ISNOTNULL: return(false); case (int)PXCondition.EQ: return(string.IsNullOrEmpty(rule.FieldValue)); case (int)PXCondition.NE: return(!string.IsNullOrEmpty(rule.FieldValue)); } return(false); } this.currentAttribute = ans; PXFilterRow filter = new PXFilterRow(typeof(CSAnswers.value).Name, (PXCondition)rule.Condition.Value, rule.FieldValue, null); int startRow = 0; int totalRows = 0; List <object> result = attributeView.Select(null, null, null, null, null, new PXFilterRow[] { filter }, ref startRow, 1, ref totalRows); return(result.Count > 0); }
protected virtual void EPAssignmentRule_RowInserting(PXCache sender, PXRowInsertingEventArgs e) { EPAssignmentRule row = e.Row as EPAssignmentRule; if (row != null) { if (!IsImport) { row.AssignmentRouteID = PositionFilter.Current.ItemID; } else if (PositionFilter.Current.RouteItemID != null && PositionFilter.Current.RouteItemID != row.AssignmentRouteID) { row.AssignmentRouteID = PositionFilter.Current.RouteItemID; Items.Current = Items.Locate(new EPAssignmentRoute { AssignmentMapID = PositionFilter.Current.MapID, AssignmentRouteID = row.AssignmentRouteID }); } } }
private bool IsEmployeeInWorkgroup(EPEmployee employee, EPAssignmentRule rule) { PXFilterRow filter = new PXFilterRow( typeof(EPCompanyTree.description).Name, (PXCondition)rule.Condition.Value, rule.FieldValue, null); PXSelectBase <EPCompanyTree> select = new PXSelectJoin <EPCompanyTree, InnerJoin <EPCompanyTreeMember, On <EPCompanyTree.workGroupID, Equal <EPCompanyTreeMember.workGroupID> > >, Where <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> >, And <EPCompanyTreeMember.active, Equal <True> > > >(this); int startRow = 0; int totalRows = 0; List <object> result = select.View.Select(null, new object[] { employee.UserID }, null, null, null, new PXFilterRow[] { filter }, ref startRow, 1, ref totalRows); //select.SelectSingle(employee.UserID, workgroupID); return(result.Count > 0); }
protected virtual void EPAssignmentRule_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { EPAssignmentRule oldRow = e.OldRow as EPAssignmentRule; EPAssignmentRule newRow = e.Row as EPAssignmentRule; if (oldRow != null && newRow != null) { if (!String.Equals(newRow.Entity, oldRow.Entity, StringComparison.OrdinalIgnoreCase)) { newRow.FieldName = newRow.FieldValue = null; } if (!String.Equals(newRow.FieldName, oldRow.FieldName, StringComparison.OrdinalIgnoreCase)) { newRow.FieldValue = null; } EPAssignmentRule row = e.Row as EPAssignmentRule; if (row.Condition == null || (PXCondition)row.Condition == PXCondition.ISNULL || (PXCondition)row.Condition == PXCondition.ISNOTNULL) { newRow.FieldValue = null; } } }