/// <summary> /// Initializes a new instance of the <see cref="UPObjectivesGroup"/> class. /// </summary> /// <param name="groupKey">The group key.</param> /// <param name="objectives">The objectives.</param> /// <param name="configuration">The configuration.</param> public UPObjectivesGroup(string groupKey, UPObjectives objectives, UPObjectivesConfiguration configuration) { this.GroupKey = groupKey; this.Objectives = objectives; this.Configuration = configuration; this.Items = new List <UPObjectivesItem>(); this.ItemDictionary = new Dictionary <string, UPObjectivesItem>(); }
private void BuildGroupWithConfigurationItemsUpdateableItems(UPObjectivesConfiguration groupConfiguration, List <UPCRMResultRow> items, Dictionary <string, UPCRMResultRow> updateableItems) { // search for group and create if not found string groupKey = groupConfiguration.SectionName; UPObjectivesGroup group = this.GroupDictionary.ValueOrDefault(groupKey); UPCRMFilterBasedDecision filterBasedDecision = groupConfiguration.FilterBasedDecision; if (group == null) { group = new UPObjectivesGroup(groupKey, this, groupConfiguration); this.Groups.Add(group); this.GroupDictionary.SetObjectForKey(group, groupKey); } int count = items?.Count ?? 0; if (count == 0) { this.LoadNextGroup(); return; } for (int i = 0; i < count; i++) { UPCRMResultRow row = items[i]; DateTime? date = row.RawValueAtIndex(groupConfiguration .FieldForFunction(Constants.FieldCompletedOnFunction) .TabIndependentFieldIndex) .DateFromCrmValue(); bool canBeDeleted = false; if (updateableItems != null) { canBeDeleted = updateableItems.ValueOrDefault(row.RootRecordIdentification) != null; } // create item UPObjectivesItem item = new UPObjectivesItem(row.RootRecordIdentification, date ?? DateTime.MinValue, group, canBeDeleted, this); if (filterBasedDecision != null) { List <UPConfigButton> actionButtons = filterBasedDecision.ButtonsForResultRow(row); foreach (UPConfigButton button in actionButtons) { item.AddButtonAction(button); } } item.SetFromResultRow(row); item.LoadDocumentsWithMaxResults(this.MaxDocuments); group.AddItem(item); } }
private void LoadNextGroup() { this.currentGroupIndex++; if (this.groupConfigurations != null && this.groupConfigurations.Count > this.currentGroupIndex) { UPObjectivesConfiguration configuration = this.groupConfigurations[this.currentGroupIndex]; this.LoadObjectivesForSectionConfiguration(configuration); } else { this.TheDelegate?.ObjectivesDidFinish(this); } }
/// <summary> /// Sets from result row. /// </summary> /// <param name="row">The row.</param> public void SetFromResultRow(UPCRMResultRow row) { if (row != null) { this.Record = new UPCRMRecord(row.RootRecordIdentification); UPObjectivesConfiguration groupConfiguration = this.Group.Configuration; if (groupConfiguration != null) { UPCRMListFormatter formatter = new UPCRMListFormatter(groupConfiguration.DestinationFieldControl); this.TitleField = formatter.FirstFieldForPosition(0); this.TitleFieldValue = formatter.StringFromRowForPosition(row, 0); this.SubTitleField = formatter.FirstFieldForPosition(1); this.SubTitelFieldValue = formatter.StringFromRowForPosition(row, 1); } if (this.AdditionalFields.Count > 0) { this.values = new List <string>(this.AdditionalFields.Count); foreach (UPConfigFieldControlField field in this.AdditionalFields) { this.values.Add(row.RawValueAtIndex(field.TabIndependentFieldIndex)); } } this.OriginalValues = new List <string>(this.values); this.completed = row.RawValueAtIndex(this.Group.Configuration.FieldForFunction(Constants.FieldCompletedFunction).TabIndependentFieldIndex).ToBoolWithDefaultValue(false); this.originalCompleted = this.completed; } else { this.Record = null; if (this.AdditionalFields.Count > 0) { this.values = new List <string>(this.AdditionalFields.Count); for (int i = 0; i < this.AdditionalFields.Count; i++) { this.values.Add(string.Empty); } } this.OriginalValues = null; this.completed = false; } this.Created = false; this.Deleted = false; this.Changed = false; }
private bool LoadObjectives() { this.GroupDictionary = new Dictionary <string, UPObjectivesGroup>(); this.Groups = new List <UPObjectivesGroup>(); this.rootRecordIdentification = this.LoadRootRecordIdentification(); this.companyRelated = this.rootRecordIdentification.InfoAreaId() == Constants.AccountInfoArea; if (this.groupConfigurations != null && this.groupConfigurations.Count > 0) { this.currentGroupIndex = 0; UPObjectivesConfiguration configuration = this.groupConfigurations[this.currentGroupIndex]; this.LoadObjectivesForSectionConfiguration(configuration); return(true); } SimpleIoc.Default.GetInstance <ILogger>().LogError("Objectives could not be loaded - groupConfiguration undefined"); return(false); }
private void LoadObjectivesForSectionConfiguration(UPObjectivesConfiguration section) { this.currentSectionConfiguration = section; FieldControl sourceFieldControl = section.SourceFieldControl; if (sourceFieldControl != null) { Dictionary <string, object> copyFieldValues = this.copyFieldsDictionary.ValueOrDefault(sourceFieldControl.UnitName); if (copyFieldValues == null) { this.currentCopyFields = new UPCopyFields(sourceFieldControl); this.currentCopyFields.CopyFieldValuesForRecord(this.record, false, this); return; } this.ContinueLoadWithFieldValueDictionary(copyFieldValues); } else { this.ContinueLoadWithFieldValueDictionary(null); } }
/// <summary> /// Creates the specified view reference. /// </summary> /// <param name="viewReference">The view reference.</param> /// <param name="sectionName">Name of the section.</param> /// <param name="parameters">The parameters.</param> /// <param name="editMode">if set to <c>true</c> [edit mode].</param> /// <returns></returns> public static UPObjectivesConfiguration Create(ViewReference viewReference, string sectionName, Dictionary <string, object> parameters, bool editMode) { var newObject = new UPObjectivesConfiguration(viewReference, sectionName); return(!newObject.SetControlsFromParametersEditMode(parameters, editMode) ? null : newObject); }
private bool SetControlsFromParametersEditMode(Dictionary <string, object> parameters, bool editMode) { IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; string destinationFieldgroupParameterName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterDestinationFieldGroupConfigurationName, this.SectionName); string configName = this.ContextValueForViewReferenceKeyParameters(this.ViewReference, destinationFieldgroupParameterName, parameters); if (!string.IsNullOrEmpty(configName)) { if (editMode) { FieldControl listFieldControl = configStore.FieldControlByNameFromGroup(Constants.ListConfigurationName, configName); this.DestinationFieldControl = configStore.FieldControlByNameFromGroup(Constants.EditConfigurationName, configName); if (listFieldControl?.CrmSortFields != null) { this.DestinationFieldControl = new FieldControl(this.DestinationFieldControl, listFieldControl); } } else { this.DestinationFieldControl = configStore.FieldControlByNameFromGroup(Constants.ListConfigurationName, configName); } } if (this.DestinationFieldControl == null) { return(false); } List <UPConfigFieldControlField> addFields = new List <UPConfigFieldControlField>(); Dictionary <string, UPConfigFieldControlField> tempFieldDictionary = new Dictionary <string, UPConfigFieldControlField>(); this.FieldsWithFunction = new Dictionary <string, UPConfigFieldControlField>(); foreach (FieldControlTab tab in this.DestinationFieldControl.Tabs) { foreach (UPConfigFieldControlField field in tab.Fields) { FieldAttributes fieldAttributes = field.Attributes; if (!fieldAttributes.Hide) { addFields.Add(field); } if (!string.IsNullOrEmpty(field.Function)) { tempFieldDictionary[field.Function] = field; } } this.FieldsWithFunction = new Dictionary <string, UPConfigFieldControlField>(tempFieldDictionary); this.AdditionalFields = new List <UPConfigFieldControlField>(addFields); } configName = this.ContextValueForViewReferenceKeyParameters(this.ViewReference, CombineConfigurationNameWithSection(Constants.ParameterSourceFieldControlConfigurationName, this.SectionName), parameters); if (!string.IsNullOrEmpty(configName)) { this.SourceFieldControl = configStore.FieldControlByNameFromGroup(Constants.ListConfigurationName, configName); } string destinationFilterParameterName = CombineConfigurationNameWithSection(Constants.ParameterDestinationFilterConfigurationName, this.SectionName); this.DestinationFilterName = this.ContextValueForViewReferenceKeyParameters(this.ViewReference, destinationFilterParameterName, parameters); UPConfigFilter filter = configStore.FilterByName(this.DestinationFilterName); if (filter != null) { this.SectionHeaderLabel = filter.DisplayName; } configName = this.ViewReference?.ContextValueForKey("ExecuteActionFilterName"); if (!string.IsNullOrEmpty(configName)) { this.ExecuteActionFilter = configStore.FilterByName(configName); } return(true); }
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); }