/// <summary> /// Queries the table by applying value dictionary. /// </summary> /// <param name="valueDictionary"> /// The value dictionary. /// </param> /// <returns> /// The <see cref="UPConfigQueryTable"/>. /// </returns> public UPConfigQueryTable QueryTableByApplyingValueDictionary(Dictionary <string, object> valueDictionary) { if (valueDictionary == null) { return(this); } var replacements = new UPConditionValueReplacement(valueDictionary); return(this.QueryTableByApplyingReplacements(replacements)); }
/// <summary> /// Filters the by applying value dictionary defaults. /// </summary> /// <param name="valueDictionary"> /// The value dictionary. /// </param> /// <param name="defaults"> /// if set to <c>true</c> [defaults]. /// </param> /// <returns> /// filter configurations /// </returns> public UPConfigFilter FilterByApplyingValueDictionaryDefaults(Dictionary <string, object> valueDictionary, bool defaults) { if (!defaults) { return((UPConfigFilter)this.QueryByApplyingValueDictionary(valueDictionary)); } var replacements = UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(valueDictionary, true); return((UPConfigFilter)this.QueryByApplyingReplacements(replacements)); }
private UPSESingleAdditionalItemInformation(UPSerialEntry _serialEntry, string _configName, string _keyColumnName, Dictionary <string, object> filterParameters, UPSESingleAdditionalItemInformationDelegate theDelegate) { IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; SearchAndList searchAndListConfiguration = configStore.SearchAndListByName(_configName); if (searchAndListConfiguration == null) { throw new Exception("Search & List Config is null"); } this.FieldControl = configStore.FieldControlByNameFromGroup("List", searchAndListConfiguration.FieldGroupName); if (this.FieldControl == null) { throw new Exception("FieldControl is null"); } if (searchAndListConfiguration.FilterName != null) { this.Filter = configStore.FilterByName(searchAndListConfiguration.FilterName); if (this.Filter != null && filterParameters != null) { this.Filter = this.Filter.FilterByApplyingReplacements(UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(filterParameters)); } if (this.Filter == null) { throw new Exception("Filter is null"); } } UPConfigFieldControlField field = this.FieldControl.FieldWithFunction(_keyColumnName); if (field == null) { throw new Exception("Field is null"); } this.keyColumnIndex = field.TabIndependentFieldIndex; this.SerialEntry = _serialEntry; this.KeyColumnName = _keyColumnName; this.TheDelegate = theDelegate; }
/// <summary> /// Applies the filter on source query parameters. /// </summary> /// <param name="crmQuery">The CRM query.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public bool ApplyFilterOnSourceQueryParameters(UPContainerMetaInfo crmQuery, Dictionary <string, object> parameters) { if (this.CrmFilter != null) { if (parameters.Count > 0) { UPConfigFilter replacedFilter = this.CrmFilter. FilterByApplyingReplacements(UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(parameters)); crmQuery.ApplyFilter(replacedFilter); } else { crmQuery.ApplyFilter(this.CrmFilter); } } return(true); }
/// <summary> /// Filters for name. /// </summary> /// <param name="filtername">The filtername.</param> /// <param name="filterParameters">The filter parameters.</param> /// <returns>Filter</returns> public static UPMFilter FilterForName(string filtername, Dictionary <string, object> filterParameters = null) { var configStore = ConfigurationUnitStore.DefaultStore; var configFilter = configStore.FilterByName(filtername); UPMFilter filter = null; if (configFilter != null) { var selectCondition = configFilter.ConditionWith("Parameter:Select", true); if (selectCondition != null) { return(FilterForConfigFilter(configFilter, selectCondition.ValueAtIndex(0), filterParameters, false)); } selectCondition = configFilter.ConditionWith("Parameter:SingleSelect"); if (selectCondition != null) { return(FilterForConfigFilter(configFilter, selectCondition.ValueAtIndex(0), filterParameters, true)); } var replacements = UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(filterParameters, true); configFilter = configFilter.FilterByApplyingReplacements(replacements); var parameters = configFilter?.Parameters(); if (parameters?.NumberOfParameters > 0) { filter = GetFilter(filtername, parameters); } else { var identifier = FieldIdentifier.IdentifierWithInfoAreaIdRecordIdFieldId(configFilter.InfoAreaId, filtername, string.Empty); filter = new UPMNoParamFilter(identifier); } if (filter != null) { filter.Name = filtername; filter.DisplayName = !string.IsNullOrEmpty(configFilter?.DisplayName) ? configFilter.DisplayName : filtername; } } return(filter); }
/// <summary> /// Queries the by applying replacements. /// </summary> /// <param name="replacements"> /// The replacements. /// </param> /// <returns> /// The <see cref="UPConfigQueryFilterBase"/>. /// </returns> public virtual UPConfigQueryFilterBase QueryByApplyingReplacements(UPConditionValueReplacement replacements) { var newRoot = this.RootTable.QueryTableByApplyingReplacements(replacements); if (replacements.RemoveUnboundParameters()) { newRoot = newRoot.TableByRemovingUnboundParameters(); } if (newRoot == null) { return(null); } if (newRoot == this.RootTable) { return(this); } return(this.CopyWithRoot(newRoot)); }
/// <summary> /// Results for value. /// </summary> /// <param name="value">The value.</param> /// <returns>the result value</returns> public bool ResultForValue(string value) { if (string.IsNullOrEmpty(this.FieldValue)) { return(false); } if (this.FieldValue.StartsWith("$cur") || this.FieldValue.StartsWith("$par")) { var replaceValues = UPConditionValueReplacement.SessionParameterReplacements().ValueOrDefault(this.FieldValue); if (replaceValues != null && replaceValues.Count > 0) { return(this.ResultForValuePattern(value, replaceValues[0])); } if (!this.FieldValue.StartsWith("$cur")) { return(this.ResultForValuePattern(value, this.FieldValue)); } var replacedDate = this.FieldValue.ReplaceDateVariables(); if (replacedDate != this.FieldValue) { return(this.ResultForValuePattern(value, replacedDate)); } } else if (this.FieldValue.StartsWith("$")) { var replacedDate = this.FieldValue.ReplaceDateVariables(); if (!replacedDate.StartsWith("$")) { return(this.ResultForValuePattern(value, replacedDate)); } } return(this.ResultForValuePattern(value, this.FieldValue)); }
/// <summary> /// Initializes a new instance of the <see cref="UPConfigExpandConditionForQuery"/> class. /// </summary> /// <param name="condition">The condition.</param> /// <param name="crmQuery">The CRM query.</param> /// <param name="alternate">The alternate.</param> public UPConfigExpandConditionForQuery(UPConfigExpandCondition condition, UPContainerMetaInfo crmQuery, UPConfigExpandAlternate alternate) : base(condition, alternate) { this.ResultPosition = crmQuery?.PositionForField(this.Field) ?? 0; if (!this.FieldValue.StartsWith("$cur") && !this.FieldValue.StartsWith("$par")) { return; } var dateFieldValue = this.FieldValue.ReplaceDateVariables(); if (dateFieldValue.StartsWith("$")) { var replaceValues = UPConditionValueReplacement.SessionParameterReplacements().ValueOrDefault(this.FieldValue); if (replaceValues != null && replaceValues.Count > 0) { this.FieldValue = replaceValues[0]; } } else { this.FieldValue = dateFieldValue; } }
private void ContinueLoadWithFieldValueDictionary(Dictionary <string, object> fieldValueDictionary) { IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; if (fieldValueDictionary != null) { if (this.copyFieldsDictionary == null) { this.copyFieldsDictionary = new Dictionary <string, Dictionary <string, object> >(); } this.copyFieldsDictionary.SetObjectForKey(fieldValueDictionary, this.currentSectionConfiguration.SourceFieldControl.UnitName); } this.currentCopyFields = null; FieldControl destinationFieldControl = this.currentSectionConfiguration.DestinationFieldControl; string destinationFilterName = this.currentSectionConfiguration.DestinationFilterName; UPConfigFilter companyRelatedFilter = null; if (this.companyRelated) { string companyFilterName = $"{destinationFieldControl.InfoAreaId}.CompanyRelated"; companyRelatedFilter = configStore.FilterByName(companyFilterName); } UPContainerMetaInfo container = new UPContainerMetaInfo(destinationFieldControl); container.SetLinkRecordIdentification(this.rootRecordIdentification); List <UPConfigFilter> appliedFilters = new List <UPConfigFilter>(); UPConfigFilter filter = configStore.FilterByName(destinationFilterName); if (filter != null) { filter = filter.FilterByApplyingReplacements(UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(fieldValueDictionary)); container.ApplyFilter(filter); appliedFilters.Add(filter); } if (companyRelatedFilter != null && this.currentSectionConfiguration.SourceFieldControl != null) { companyRelatedFilter = companyRelatedFilter.FilterByApplyingReplacements(new UPConditionValueReplacement(fieldValueDictionary)); container.ApplyFilter(companyRelatedFilter); appliedFilters.Add(companyRelatedFilter); } this.objectivesForRecordOperation = null; this.rightFilterOperation = null; this.filterLoaded = true; if (this.RightsFilter != null && this.filterItemsResult == null) { this.filterLoaded = false; } if (this.currentSectionConfiguration.ExecuteActionFilter != null) { this.currentSectionConfiguration.ExecuteActionFilter = this.currentSectionConfiguration.ExecuteActionFilter.FilterByApplyingValueDictionaryDefaults(fieldValueDictionary, true); if (this.currentSectionConfiguration.ExecuteActionFilter != null) { this.currentSectionConfiguration.FilterBasedDecision = new UPCRMFilterBasedDecision(this.currentSectionConfiguration.ExecuteActionFilter); List <UPCRMField> fields = this.currentSectionConfiguration.FilterBasedDecision.FieldDictionary.Values.ToList(); if (fields.Count > 0) { container.AddCrmFields(fields); } this.currentSectionConfiguration.FilterBasedDecision.UseCrmQuery(container); } } this.objectivesForRecordOperation = container.Find(this.RequestOption, this); if (this.objectivesForRecordOperation == null) { SimpleIoc.Default.GetInstance <ILogger>().LogError("Could not create operation for loading objectives."); this.FailWithError(new Exception("ConnectionOfflineError")); } if (this.RightsFilter != null && this.filterItemsResult == null) { UPContainerMetaInfo clonedContainer = new UPContainerMetaInfo(new List <UPCRMField>(), destinationFieldControl.InfoAreaId); clonedContainer.SetLinkRecordIdentification(this.rootRecordIdentification); clonedContainer.ApplyFilter(this.RightsFilter); foreach (UPConfigFilter filter1 in appliedFilters) { clonedContainer.ApplyFilter(filter1); } this.rightFilterOperation = clonedContainer.Find(this.RequestOption, this); if (this.rightFilterOperation == null) { SimpleIoc.Default.GetInstance <ILogger>().LogError("Could not create operation for filtering objectives."); this.FailWithError(new Exception("ConnectionOfflineError")); } } }
private bool SetControlsFromParameters() { ViewReference viewReference = null; if (this.Parameters.ContainsKey("viewReference")) { viewReference = (ViewReference)this.Parameters["viewReference"]; } // create rightsfilter string rightsFilterName = viewReference?.ContextValueForKey(Constants.RightsFilterConfigurationName); if (!string.IsNullOrEmpty(rightsFilterName)) { IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; this.RightsFilter = configStore.FilterByName(rightsFilterName); } if (this.RightsFilter != null) { #if PORTING NSDictionary filterParameters = (NSDictionary)viewReference.ContextValueForKey(Constants.RightsFilterCopyFieldConfigurationName); if (filterParameters != null) { UPConditionValueReplacement replacement = new UPConditionValueReplacement(filterParameters); this.RightsFilter = this.RightsFilter.FilterByApplyingReplacements(replacement); } else #endif { this.RightsFilter = this.RightsFilter.FilterByApplyingDefaultReplacements(); } } this.RequestOption = UPCRMDataStore.RequestOptionFromString(viewReference?.ContextValueForKey(Constants.RequestOptionConfigurationName), UPRequestOption.Offline); this.groupConfigurations = new List <UPObjectivesConfiguration>(); UPObjectivesConfiguration individualConfiguration = UPObjectivesConfiguration.Create(viewReference, Constants.IndividualSectionPostFix, this.Parameters, this.EditMode); if (individualConfiguration != null) { this.groupConfigurations.Add(individualConfiguration); } UPObjectivesConfiguration salesConfiguration = UPObjectivesConfiguration.Create(viewReference, Constants.SalesSectionPostFix, this.Parameters, this.EditMode); if (salesConfiguration != null) { this.groupConfigurations.Add(salesConfiguration); } List <string> additionalFieldGroups = this.StringsFromCommaSeparatedString(viewReference?.ContextValueForKey(Constants.AdditionalFieldgroupsConfigurationName)); // load additional sections if (additionalFieldGroups?.Count > 0) { List <string> additionalDestinationFilter = this.StringsFromCommaSeparatedString(viewReference?.ContextValueForKey(Constants.AdditionalFilterConfigurationName)); List <string> additionalSourceFieldControl = this.StringsFromCommaSeparatedString(viewReference?.ContextValueForKey(Constants.AdditionalSourceFieldControlConfigurationName)); if ((additionalDestinationFilter != null && additionalSourceFieldControl != null) && (additionalFieldGroups.Count == additionalDestinationFilter.Count) && (additionalDestinationFilter.Count == additionalSourceFieldControl.Count)) { Dictionary <string, object> additionalParameterDictionary = new Dictionary <string, object>(this.Parameters); for (int additionalSectionIndex = 0; additionalSectionIndex < additionalDestinationFilter.Count; additionalSectionIndex++) { string sectionName = $"AdditionalSection_{additionalSectionIndex}"; string destinationFieldGroupName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterDestinationFieldGroupConfigurationName, sectionName); string destinationFilterName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterDestinationFilterConfigurationName, sectionName); string sourceFieldControlName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterSourceFieldControlConfigurationName, sectionName); additionalParameterDictionary[destinationFieldGroupName] = additionalFieldGroups[additionalSectionIndex]; additionalParameterDictionary[destinationFilterName] = additionalDestinationFilter[additionalSectionIndex]; additionalParameterDictionary.SetObjectForKey(additionalSourceFieldControl[additionalSectionIndex], sourceFieldControlName); UPObjectivesConfiguration additionalConfiguration = UPObjectivesConfiguration.Create(viewReference, sectionName, additionalParameterDictionary, this.EditMode); if (additionalConfiguration != null) { this.groupConfigurations.Add(additionalConfiguration); } } } } this.record = new UPCRMRecord(this.RecordIdentification); this.ParentLink = viewReference?.ContextValueForKey("ParentLink"); return(true); }
/// <summary> /// Results for row. /// </summary> /// <param name="serialEntryRow">The serial entry row.</param> /// <returns></returns> public override UPSerialEntryInfoResult ResultForRow(UPSERow serialEntryRow) { string sourceRecordIdentification = StringExtensions.InfoAreaIdRecordId(serialEntryRow.SerialEntry.SourceInfoAreaId, serialEntryRow.RowRecordId); UPSerialEntryInfoResultFromCRMResult result = this.cachedResults.ValueOrDefault(sourceRecordIdentification); if (result != null) { return(result); } UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(this.FieldControl); if (!this.IgnoreSourceRecord) { crmQuery.SetLinkRecordIdentification(sourceRecordIdentification); } if (this.MaxResults > 0) { crmQuery.MaxResults = this.MaxResults; } if (this.Filter != null) { Dictionary <string, object> parameterValues = serialEntryRow.SourceFunctionValues(); if (this.SerialEntry.InitialFieldValuesForDestination.Count > 0) { if (parameterValues.Count > 0) { Dictionary <string, object> dict = new Dictionary <string, object>(this.SerialEntry.InitialFieldValuesForDestination); foreach (var entry in parameterValues) { dict[entry.Key] = entry.Value; } parameterValues = dict; } else { parameterValues = this.SerialEntry.InitialFieldValuesForDestination; } } if (parameterValues.Count > 0) { UPConfigFilter applyFilter = this.Filter.FilterByApplyingReplacements(UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(parameterValues)); if (applyFilter != null) { crmQuery.ApplyFilter(applyFilter); } } else { crmQuery.ApplyFilter(this.Filter); } } UPCRMResult crmResult = crmQuery.Find(); result = new UPSerialEntryInfoResultFromCRMResult(crmResult, this); if (this.cachedResults == null) { this.cachedResults = new Dictionary <string, UPSerialEntryInfoResultFromCRMResult> { { sourceRecordIdentification, result } }; } else { this.cachedResults[sourceRecordIdentification] = result; } return(result); }
/// <summary> /// Queries the table by applying replacements. /// </summary> /// <param name="replacements"> /// The replacements. /// </param> /// <returns> /// The <see cref="UPConfigQueryTable"/>. /// </returns> public UPConfigQueryTable QueryTableByApplyingReplacements(UPConditionValueReplacement replacements) { List <UPConfigQueryTable> newSubTables = null; UPConfigQueryCondition newCondition = null; var changed = false; if (this.SubTables != null) { var count = this.SubTables.Count; newSubTables = new List <UPConfigQueryTable>(count); for (var i = 0; i < count; i++) { var oldSubTable = this.SubTables[i]; var newSubTable = oldSubTable.QueryTableByApplyingReplacements(replacements); if (newSubTable != null) { newSubTables.Add(newSubTable); if (newSubTable != oldSubTable) { changed = true; } } else { changed = true; } } if (!changed) { newSubTables = null; } } var propertyConditions = this.PropertyConditions; if (this.Condition != null) { newCondition = this.Condition.QueryConditionByApplyingReplacements(replacements); if (newCondition == null) { return(null); } if (newCondition.IsFixed) { newCondition = null; // TODO 20150126: result depending on fixedValue? } if (newCondition != null && newCondition != this.Condition) { if (newCondition.PropertyCondition) { propertyConditions = new Dictionary <string, UPConfigQueryCondition> { { newCondition.FunctionName, newCondition } }; newCondition = null; } else if (newCondition.PropertyConditions != null) { propertyConditions = newCondition.PropertyConditions; } changed = true; } if (newCondition?.RemoveTableCondition ?? false) { return(null); } } if (changed) { var temp = newSubTables ?? this.SubTables; return(this.CopyWithSubTablesConditionPropertyConditions(temp, newCondition, propertyConditions)); } return(this); }
/// <summary> /// Filters the by applying replacements. /// </summary> /// <param name="replacements"> /// The replacements. /// </param> /// <returns> /// filter configurations /// </returns> public UPConfigFilter FilterByApplyingReplacements(UPConditionValueReplacement replacements) { return((UPConfigFilter)this.QueryByApplyingReplacements(replacements)); }