private void HandleResult(UPCRMResult result) { this.currencyDictionary = new Dictionary <int, object>(); if (result != null && result.RowCount > 0) { UPConfigFieldControlField currencyField = null, baseCurrencyField = null, exchangeRateField = null, baseCurrency2Field = null, exchangeRate2Field = null; foreach (FieldControlTab tab in this.fieldControl.Tabs) { foreach (UPConfigFieldControlField field in tab.Fields) { if (field.Function == "Currency") { currencyField = field; } else if (field.Function == "BaseCurrency") { baseCurrencyField = field; } else if (field.Function == "ExchangeRate") { exchangeRateField = field; } else if (field.Function == "BaseCurrency2") { baseCurrency2Field = field; } else if (field.Function == "ExchangeRate2") { exchangeRate2Field = field; } } } if (currencyField != null && baseCurrencyField != null && exchangeRateField != null && result.RowCount > 0) { int i, count = result.RowCount; for (i = 0; i < count; i++) { UPCRMResultRow row = result.ResultRowAtIndex(i) as UPCRMResultRow; int code = row.RawValueAtIndex(currencyField.TabIndependentFieldIndex).ToInt(); int baseCurrencyValue = row.RawValueAtIndex(baseCurrencyField.TabIndependentFieldIndex).ToInt(); double exchangeRate = row.RawValueAtIndex(exchangeRateField.TabIndependentFieldIndex).ToDouble(); double exchangeRate2 = 0; int baseCurrency2Value = 0; if (baseCurrency2Field != null && exchangeRate2Field != null) { baseCurrency2Value = row.RawValueAtIndex(baseCurrency2Field.TabIndependentFieldIndex).ToInt(); exchangeRate2 = row.RawValueAtIndex(exchangeRate2Field.TabIndependentFieldIndex).ToDouble(); } this.AddCurrency(new Currency(code, baseCurrencyValue, exchangeRate, baseCurrency2Value, exchangeRate2)); } } } }
/// <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; }
/// <summary> /// Functions the names. /// </summary> /// <param name="row"> /// The row. /// </param> /// <param name="fieldOffset"> /// The field offset. /// </param> /// <param name="displayPrefix"> /// The display prefix. /// </param> /// <returns> /// Function names lookup /// </returns> public Dictionary <string, object> FunctionNames(UPCRMResultRow row, int fieldOffset = 0, string displayPrefix = null) { if (row == null) { return(null); } var dictionary = new Dictionary <string, object>(); foreach (var tab in this.Tabs) { if (tab?.Fields == null) { continue; } foreach (var field in tab.Fields) { if (string.IsNullOrEmpty(field.Function)) { continue; } dictionary[field.Function] = row.RawValueAtIndex(field.TabIndependentFieldIndex + fieldOffset); if (!string.IsNullOrWhiteSpace(displayPrefix)) { dictionary[$"{displayPrefix}{field.Function}"] = row.ValueAtIndex(field.TabIndependentFieldIndex + fieldOffset); } } } return(dictionary); }
/// <summary> /// Results for row. /// </summary> /// <param name="row">The row.</param> /// <returns>the result for a row</returns> public virtual bool ResultForRow(UPCRMResultRow row) { var crmQuery = row?.Result?.MetaInfo; var resultPosition = crmQuery?.PositionForField(this.Field) ?? -1; return(resultPosition >= 0 && this.ResultForValue(row?.RawValueAtIndex(resultPosition))); }
/// <summary> /// The query table for result row. /// </summary> /// <param name="row"> /// The row. /// </param> /// <returns> /// The <see cref="UPConfigQueryTable"/>. /// </returns> public UPConfigQueryTable QueryTableForResultRow(UPCRMResultRow row) { var resultFieldMap = this.ResultFieldMap ?? this.ResultFeldMapFromCrmQuery(row.Result.MetaInfo); if (resultFieldMap == null) { return(null); } Dictionary <string, object> valueDictionary = new Dictionary <string, object>(resultFieldMap.Count); foreach (string key in resultFieldMap.Keys) { int position = resultFieldMap[key]; var value = position < 0 ? string.Empty : row.RawValueAtIndex(position); valueDictionary.Add(key, value); } UPConfigQueryTable foundTable = this.Filter.RootTable.QueryTableForValueDictionaryWithSubInfoAreas(valueDictionary, true); if (foundTable == null) { return(this.Filter.RootTable); } return(foundTable); }
/// <summary> /// Checks the specified row. /// </summary> /// <param name="row"> /// The row. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public override bool Check(UPCRMResultRow row) { return(this.Field.CheckValueMatchesValueCondition( row.RawValueAtIndex(this.ResultPosition), this.FieldValue, this.Condition)); }
/// <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); this.values = new List <string>(); if (this.AdditionalFields?.Count > 0) { if (this.Group.Characteristics.EditMode == false) { foreach (UPConfigFieldControlField field in this.AdditionalFields) { string value = row.RawValueAtIndex(field.TabIndependentFieldIndex); this.values.Add(field.IsEmptyValue(value) ? string.Empty : row.ValueAtIndex(field.TabIndependentFieldIndex)); } } else { foreach (UPConfigFieldControlField field in this.AdditionalFields) { this.values.Add(row.RawValueAtIndex(field.TabIndependentFieldIndex)); } } } this.OriginalValues = new List <string>(this.values); } else { this.Record = null; if (this.AdditionalFields?.Count > 0) { this.values = new List <string>(); for (int i = 0; i < this.AdditionalFields.Count; i++) { this.values.Add(string.Empty); } } this.OriginalValues = null; } this.Created = false; this.Deleted = false; this.Changed = false; }
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 HandleItemResult(UPCRMResult result) { int count = result.RowCount; UPConfigFieldControlField groupField = this.ItemFieldControl.FieldWithFunction(Constants.FieldGroupString); UPConfigFieldControlField itemField = this.ItemFieldControl.FieldWithFunction(Constants.FieldItemString); UPConfigFieldControlField destinationShowAdditionalFieldsField = this.ItemFieldControl.FieldWithFunction(Constants.FieldShowAdditionalFieldsString); List <UPCharacteristicsGroup> groupsWithAllItems = new List <UPCharacteristicsGroup>(); for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); string groupKey = row.RawValueAtIndex(groupField.TabIndependentFieldIndex); UPCharacteristicsGroup group = this.groupDict.ValueOrDefault(groupKey); if (group != null) { string itemKey = row.RawValueAtIndex(itemField.TabIndependentFieldIndex); bool showAdditionalFields = false; if (destinationShowAdditionalFieldsField != null) { showAdditionalFields = row.RawValueAtIndex(destinationShowAdditionalFieldsField.TabIndependentFieldIndex).ToBoolWithDefaultValue(false); } if (itemKey == "0") { group.ShowAdditionalFields = showAdditionalFields; if (!groupsWithAllItems.Contains(group)) { groupsWithAllItems.Add(group); } } else { group.AddItem(new UPCharacteristicsItem(row.ValueAtIndex(itemField.TabIndependentFieldIndex), itemKey, group, showAdditionalFields ? this.AdditionalFields : null)); } } } this.HandleGroupsWithAllItems(groupsWithAllItems); }
private void HandleGroupResult(UPCRMResult result) { int count = result.RowCount; UPConfigFieldControlField groupField = this.GroupFieldControl.FieldWithFunction(Constants.FieldGroupString); UPConfigFieldControlField singleField = this.GroupFieldControl.FieldWithFunction(Constants.FieldSingleString); UPConfigFieldControlField showGroupExpandedField = this.GroupFieldControl.FieldWithFunction(Constants.FieldShowGroupExpandedString); for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); string key = row.RawValueAtIndex(groupField.TabIndependentFieldIndex); if (!this.groupDict.ContainsKey(key)) { bool singleSelection = false; if (singleField != null) { string singleFieldValue = row.RawValueAtIndex(singleField.TabIndependentFieldIndex); if (singleFieldValue == "true") { singleSelection = true; } } bool showGroupExpanded = true; if (showGroupExpandedField != null) { showGroupExpanded = row.RawValueAtIndex(showGroupExpandedField.TabIndependentFieldIndex).ToBoolWithDefaultValue(true); } UPCharacteristicsGroup group = new UPCharacteristicsGroup(row.ValueAtIndex(groupField.TabIndependentFieldIndex), key, singleSelection, this, showGroupExpanded); this.groupDict[key] = group; this.Groups.Add(group); } } this.LoadItems(); }
/// <summary> /// Initializes a new instance of the <see cref="UPSelectorOption"/> class. /// </summary> /// <param name="row"> /// The row. /// </param> /// <param name="fieldControl"> /// The field control. /// </param> public UPSelectorOption(UPCRMResultRow row, FieldControl fieldControl) { string firstFieldName = null; var first = true; var dictionary = new Dictionary <string, object>(); var displayDictionary = new Dictionary <string, string>(); foreach (var tab in fieldControl.Tabs ?? new List <FieldControlTab>()) { if (tab?.Fields == null) { continue; } foreach (var field in tab.Fields) { if (first) { firstFieldName = row.ValueAtIndex(field.TabIndependentFieldIndex); first = false; } if (field.Function == "Name") { this.Name = row.ValueAtIndex(field.TabIndependentFieldIndex); firstFieldName = null; } else if (!string.IsNullOrEmpty(field.Function)) { dictionary[field.Function] = row.RawValueAtIndex(field.TabIndependentFieldIndex); displayDictionary[field.Function] = row.ValueAtIndex(field.TabIndependentFieldIndex); } } } if (this.Name == null) { this.Name = firstFieldName; if (string.IsNullOrEmpty(this.Name)) { this.Name = "?"; } } this.FieldValues = dictionary; this.DisplayFieldValues = displayDictionary; }
/// <summary> /// Valueses from result row. /// </summary> /// <param name="self">The self.</param> /// <param name="row">The row.</param> /// <returns></returns> public static Dictionary <string, object> ValuesFromResultRow(this Dictionary <string, UPConfigFieldControlField> self, UPCRMResultRow row) { if (row == null) { return(null); } Dictionary <string, object> valueDictionary = new Dictionary <string, object>(); foreach (string key in self.Keys) { UPConfigFieldControlField field = self[key]; valueDictionary[key] = row.RawValueAtIndex(field.TabIndependentFieldIndex); } return(valueDictionary); }
private void SourceCopyFieldGroupLoaded(UPCRMResultRow resultRow) { this.Parameters = resultRow.ValuesWithFunctions(); UPQuestionnaireManager questionnaireManager = null; //ServerSession.CurrentSession.QuestionnaireManager; if (this.QuestionnaireLinkName == "RecordLink") { string questionnaireRecordIdentification = resultRow.RecordIdentificationForLinkInfoAreaIdLinkId(questionnaireManager.QuestionnaireList.InfoAreaId, -1); if (questionnaireRecordIdentification.Length == 0 && this.questionnairelinkFieldMetaInfo != null) { string questionnaireRecordId = resultRow.RawValueAtIndex(this.questionnairelinkFieldMetaInfo.PositionInResult); if (!string.IsNullOrEmpty(questionnaireRecordId)) { questionnaireRecordIdentification = StringExtensions.InfoAreaIdRecordId(questionnaireManager.QuestionnaireList.InfoAreaId, questionnaireRecordId); } } if (!string.IsNullOrEmpty(questionnaireRecordIdentification)) { this.Questionnaire = questionnaireManager.LoadQuestionaire(questionnaireRecordIdentification, this); } else { this.TheDelegate.SurveyDidFailWithError(this, new Exception("cannot load questionnaire, recordIdentification empty")); return; } } else { int catalogCode = Convert.ToInt32(this.Parameters.ValueOrDefault(this.QuestionnaireLinkName)); if (catalogCode > 0) { this.Questionnaire = questionnaireManager.LoadQuestionaire(catalogCode, this); } else { this.TheDelegate.SurveyDidFailWithError(this, new Exception("cannot load questionnaire with code, catalogCode empty")); return; } } if (this.Questionnaire != null) { this.QuestionnaireLoaded(); } }
/// <summary> /// Searches the operation did finish with result. /// </summary> /// <param name="operation">The operation.</param> /// <param name="_result">The result.</param> public void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult _result) { this.result = _result; int count = this.result.RowCount; if (count > 0) { this.rowFromItemKey = new Dictionary <string, UPCRMResultRow>(); for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)this.result.ResultRowAtIndex(i); string itemKey = row.RawValueAtIndex(this.keyColumnIndex); this.rowFromItemKey[itemKey] = row; } } this.TheDelegate?.AdditionalItemInformationDidFinishWithResult(this, _result); }
private void ForeignFieldsLoaded(UPCRMResultRow row) { if (row != null) { foreach (UPSurveyForeignField foreignField in this.ForeignFields.Values) { if (foreignField.PositionInResult < 0) { continue; } foreignField.SetValueRecordIdentification(row.RawValueAtIndex(foreignField.PositionInResult), row.RecordIdentificationAtFieldIndex(foreignField.PositionInResult)); } } this.loadStep = 2; this.crmQuery = new UPContainerMetaInfo(this.SurveySearchAndList, this.Parameters); this.crmQuery.SetLinkRecordIdentification(this.RootRecordIdentification); this.crmQuery.Find(this.DestinationRequestOption, this); }
private bool RowHasHigherPriorityThanRow(UPCRMResultRow testRow, UPCRMResultRow row) { int columnCount = testRow.Result.ColumnCount; for (int i = 0; i < columnCount; i++) { string rowValue = row.RawValueAtIndex(i); if (!string.IsNullOrEmpty(rowValue) && rowValue != "0") { return(false); } rowValue = testRow.RawValueAtIndex(i); if (!string.IsNullOrEmpty(rowValue) && rowValue != "0") { return(true); } } return(false); }
/// <summary> /// Copies the field values for result. /// </summary> /// <param name="resultRow">The result row.</param> /// <returns></returns> public Dictionary <string, object> CopyFieldValuesForResult(UPCRMResultRow resultRow) { Dictionary <string, object> resultDictionary = new Dictionary <string, object>(); foreach (string key in this.FieldConfigsForFunction.Keys) { UPConfigFieldControlField fieldConfig = this.FieldConfigsForFunction[key]; string rawResult = resultRow.RawValueAtIndex(fieldConfig.TabIndependentFieldIndex); if (!string.IsNullOrEmpty(rawResult)) { resultDictionary[key] = rawResult; if (fieldConfig.Field.FieldType == "K") { int catval = Convert.ToInt32(rawResult); if (catval > 0) { UPCatalog catalog = fieldConfig.Field.Catalog; UPCatalogValue catalogValue = catalog.ValueForCode(catval); if (!string.IsNullOrEmpty(catalogValue?.ExtKey)) { resultDictionary[$"{key}.extkey"] = catalogValue.ExtKey; } resultDictionary[$"{key}.text"] = catalogValue?.Text ?? string.Empty; } } } else { resultDictionary[key] = string.Empty; } } return(resultDictionary.Count > 0 ? resultDictionary : null); }
private void HandleDestinationResult(UPCRMResult result) { int count = result.RowCount; bool expandOnData = ConfigurationUnitStore.DefaultStore.ConfigValue("Characteristics.CollapseGroups") == "empty"; for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); string groupKey = row.RawValueAtIndex(this.DestinationGroupField.TabIndependentFieldIndex); UPCharacteristicsGroup group = this.groupDict.ValueOrDefault(groupKey); if (group != null) { if (expandOnData) { group.ShowExpanded = true; } string itemKey = row.RawValueAtIndex(this.DestinationItemField.TabIndependentFieldIndex); UPCharacteristicsItem item = group.ItemDictionary.ValueOrDefault(itemKey); UPCRMRecord conflictRecord = null; if (this.conflictOfflineRequest != null) { foreach (UPCRMRecord currentConflictRecord in this.conflictOfflineRequest.Records) { if (currentConflictRecord.RecordIdentification == row.RecordIdentificationAtFieldIndex(0)) { conflictRecord = currentConflictRecord; break; } } } if (conflictRecord == null) { item?.SetFromResultRow(row); } else if (conflictRecord.Deleted) { item?.SetFromRecord(conflictRecord); } else { item?.SetFromResultRow(row); foreach (UPCRMFieldValue fieldValue in conflictRecord.FieldValues) { int position = this.PositionForCrmFieldId(fieldValue.FieldId); if (position >= 0) { item.SetValueForAdditionalFieldPosition(fieldValue.Value, position); } } } } } if (this.conflictOfflineRequest != null) { foreach (UPCRMRecord conflictRecord in this.conflictOfflineRequest.Records) { if (conflictRecord.IsNew) { string groupKey = conflictRecord.StringFieldValueForFieldIndex(this.DestinationGroupField.TabIndependentFieldIndex); UPCharacteristicsGroup group = this.groupDict.ValueOrDefault(groupKey); if (group != null) { string itemKey = conflictRecord.StringFieldValueForFieldIndex(this.DestinationItemField.TabIndependentFieldIndex); UPCharacteristicsItem item = group.ItemDictionary[itemKey]; item.SetFromRecord(conflictRecord); } } } } if (!this.EditMode) { this.RemoveEmptyItems(); } this.TheDelegate.CharacteristicsDidFinishWithResult(this, this); }
/// <summary> /// Results for row. /// </summary> /// <param name="row">The row.</param> /// <returns> /// the result for a row /// </returns> public override bool ResultForRow(UPCRMResultRow row) { return(this.ResultPosition >= 0 && this.ResultForValuePattern(row?.RawValueAtIndex(this.ResultPosition), this.FieldValue)); }
/// <summary> /// Creates the specified row. /// </summary> /// <param name="row">The row.</param> /// <param name="tabConfig">The tab configuration.</param> /// <returns></returns> public static UPGeoLocation Create(UPCRMResultRow row, FieldControlTab tabConfig) { try { string gpsXString = null, gpsYString = null, addressTitle = null; var currentFieldIndex = 0; var found = false; var numberOfFields = tabConfig.NumberOfFields; var address = new StringBuilder(); while (currentFieldIndex + 1 < numberOfFields) { gpsXString = row.RawValueAtIndex(tabConfig.FieldAtIndex(currentFieldIndex++).TabIndependentFieldIndex); gpsYString = row.RawValueAtIndex(tabConfig.FieldAtIndex(currentFieldIndex++).TabIndependentFieldIndex); if (string.IsNullOrEmpty(gpsXString) || Convert.ToDecimal(gpsXString, System.Globalization.CultureInfo.InvariantCulture) == 0m || string.IsNullOrEmpty(gpsYString) || Convert.ToDecimal(gpsYString) == 0m) { gpsXString = gpsYString = string.Empty; } else { found = true; } if (currentFieldIndex < numberOfFields) { UPConfigFieldControlField addressNameField = tabConfig.FieldAtIndex(currentFieldIndex++); int fieldCount = addressNameField.Attributes.FieldCount; if (fieldCount <= 1) { addressTitle = row.ValueAtIndex(addressNameField.TabIndependentFieldIndex); } else { addressTitle = FormattedValueForResultRowFieldControlTabFieldIndex(row, tabConfig, currentFieldIndex + 1); currentFieldIndex += fieldCount - 1; } } if (currentFieldIndex < numberOfFields) { UPConfigFieldControlField addressField = tabConfig.FieldAtIndex(currentFieldIndex++); int fieldCount = addressField.Attributes.FieldCount; if (fieldCount <= 1) { address.Append(row.ValueAtIndex(addressField.TabIndependentFieldIndex)); } else { address.Append(FormattedValueForResultRowFieldControlTabFieldIndex(row, tabConfig, currentFieldIndex - 1)); currentFieldIndex += fieldCount - 1; } if (address.Length > 1) { found = true; break; } } } if (found) { while (currentFieldIndex + 1 < numberOfFields) { if (currentFieldIndex < numberOfFields) { UPConfigFieldControlField addressField = tabConfig.FieldAtIndex(currentFieldIndex++); int fieldCount = addressField.Attributes.FieldCount; if (fieldCount <= 1) { address.Append($" , {row.ValueAtIndex(addressField.TabIndependentFieldIndex)}"); } else { address.Append($" , {FormattedValueForResultRowFieldControlTabFieldIndex(row, tabConfig, currentFieldIndex - 1)}"); currentFieldIndex += fieldCount - 1; } } } return(new UPGeoLocation(gpsXString, gpsYString, addressTitle, address.ToString())); } } catch (Exception error) { SimpleIoc.Default.GetInstance <ILogger>().LogError(error); } return(null); }
private void ProcessFields( ICollection <string> rawFieldValues, ICollection <string> fieldLabels, ICollection <string> fieldValues, int count, bool needsRawValues, bool needsLabels, IReadOnlyList <UPContainerFieldMetaInfo> resultFieldMap, UPCRMResultRow row) { var nextIndex = 1; for (var i = 0; i < count; i++) { var fieldIndexInTableCaption = this.hasFieldMap ? this.fieldMap[i].ToInt() : i + 1; while (nextIndex < fieldIndexInTableCaption) { fieldValues.Add(string.Empty); if (needsRawValues) { rawFieldValues.Add(string.Empty); } ++nextIndex; } string val, rawValue = null; if (resultFieldMap != null) { var fieldMetaInfo = resultFieldMap[i]; if (fieldMetaInfo != null) { val = row.ValueForField(fieldMetaInfo); if (needsRawValues) { rawValue = row.RawValueForField(fieldMetaInfo); } if (needsLabels) { var fieldLabel = fieldMetaInfo.CrmField?.Label; fieldLabels.Add(fieldLabel ?? string.Empty); } } else { val = string.Empty; rawValue = string.Empty; } } else { val = row.ValueAtIndex(i); if (needsRawValues) { rawValue = row.RawValueAtIndex(i); } } fieldValues.Add(val == null ? string.Empty : val.SingleLineString()); if (needsRawValues) { rawFieldValues.Add(rawValue ?? string.Empty); } ++nextIndex; } }
/// <summary> /// The document data for result row. /// </summary> /// <param name="resultRow"> /// The result row. /// </param> /// <returns> /// The <see cref="DocumentData"/>. /// </returns> public DocumentData DocumentDataForResultRow(UPCRMResultRow resultRow) { var tab = this.FieldControl.TabAtIndex(0); var title = this.ResultIndexOfTitle >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfTitle) : null; var length = this.ResultIndexOfLength >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfLength).ToUInt64() : 0; var dateString = this.ResultIndexOfDate >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfDate) : null; var mimeType = this.ResultIndexOfMimeType >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfMimeType) : null; var updDateString = this.ResultIndexOfUpdDate >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfUpdDate) : null; var updTimeString = this.ResultIndexOfUpdTime >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfUpdTime) : null; var displayText = this.ResultIndexOfDisplayText >= 0 ? resultRow.FormattedFieldValueAtIndex(this.ResultIndexOfDisplayText, null, tab) : null; var displayDateString = this.ResultIndexOfDisplayDate >= 0 ? resultRow.FormattedFieldValueAtIndex(this.ResultIndexOfDisplayDate, null, tab) : null; DateTime?documentDate = null; if (!string.IsNullOrEmpty(dateString)) { documentDate = dateString.DateFromCrmValue(); displayDateString = DateExtensions.LocalizedFormattedDate(documentDate); } DateTime?updateDate = null; if (!string.IsNullOrEmpty(updDateString)) { updateDate = updDateString.DateTimeFromCrmValue(); } string recordIdentification; if (resultRow.NumberOfRecordIds() > this.RecordIndex) { recordIdentification = resultRow.RecordIdentificationAtIndex(this.RecordIndex); } else { recordIdentification = resultRow.RootRecordIdentification; } string d1RecordId = resultRow.RecordIdentificationForLinkInfoAreaIdLinkId("D1", -1); return(new DocumentData( recordIdentification, title, mimeType, documentDate, length, updateDate, displayText, displayDateString, d1RecordId)); }
/// <summary> /// Edits the contexts for result row. /// </summary> /// <param name="resultRow">The result row.</param> /// <param name="tabConfig">The tab configuration.</param> /// <param name="editFieldDictionary">The edit field dictionary.</param> /// <param name="initialValues">The initial values.</param> /// <param name="fieldPostfix">The field postfix.</param> /// <param name="initialRecords">The initial records.</param> /// <returns></returns> public List <object> EditContextsForResultRow(UPCRMResultRow resultRow, FieldControlTab tabConfig, Dictionary <string, UPEditFieldContext> editFieldDictionary, Dictionary <string, object> initialValues, string fieldPostfix, List <UPCRMRecord> initialRecords) { var recordIdentification = resultRow?.RecordIdentificationAtIndex(0); var fieldArray = new List <object>(); UPCRMRecord offlineRootRecord = null; if (initialRecords?.Count > 0) { offlineRootRecord = initialRecords.FirstOrDefault(); } var identifierPrefix = recordIdentification; if (string.IsNullOrEmpty(identifierPrefix)) { identifierPrefix = $"{this.TabConfig.FieldControl.UnitName}_{this.TabIndex}"; } var fieldCount = tabConfig?.NumberOfFields ?? 0; for (var j = 0; j < fieldCount; j++) { var fieldConfig = tabConfig?.FieldAtIndex(j); if (fieldConfig == null) { continue; } var fieldAttributes = fieldConfig.Attributes; var currentInfoAreaId = fieldConfig.InfoAreaId; var currentLinkId = fieldConfig.LinkId; var fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(identifierPrefix, fieldConfig.Identification); UPSelector selector = null; var selectorDef = fieldConfig.Attributes?.Selector; if (selectorDef != null) { var filterParameters = this.EditPageContext?.ViewReference?.ContextValueForKey("copyFields")?.JsonDictionaryFromString(); if (resultRow?.Result != null && resultRow.IsNewRow) { selector = UPSelector.SelectorFor( resultRow.RootRecordIdentification?.InfoAreaId(), resultRow.Result.ParentRecordIdentification, resultRow.Result.LinkId, selectorDef, filterParameters, fieldConfig); } else { selector = UPSelector.SelectorFor(resultRow?.RootRecordIdentification, selectorDef, filterParameters, fieldConfig); } selector.Build(); if (selector.OptionCount == 0 && selector.IsStaticSelector) { selector = null; } } var isEditField = this.enableLinkedEditFields || selector != null || (tabConfig.FieldControl.InfoAreaId == currentInfoAreaId && currentLinkId <= 0); var isHidden = fieldAttributes.Hide; var isReadOnly = isEditField && fieldAttributes.ReadOnly; var rawFieldValue0 = resultRow?.RawValueAtIndex(fieldConfig.TabIndependentFieldIndex); var fieldInfo = fieldConfig.Field.FieldInfo; if (isEditField && !isReadOnly && !(selector is UPRecordSelector && ((UPRecordSelector)selector).IgnoreFieldInfo)) { if (fieldInfo.IsReadOnly) { isReadOnly = true; } else if (resultRow?.IsNewRow == true || string.IsNullOrEmpty(rawFieldValue0)) { if (fieldInfo.LockedOnNew) { isReadOnly = true; } } else if (fieldInfo.LockedOnUpdate && !fieldInfo.IsEmptyValue(rawFieldValue0)) { isReadOnly = true; } } string offlineValue = null; bool offlineChanged; string rawFieldValue; UPEditFieldContext editFieldContext; if (isEditField) { List <UPEditFieldContext> childFields = null; if (fieldAttributes.FieldCount > 1 && selector == null) { childFields = new List <UPEditFieldContext>(); for (var k = 1; k < fieldAttributes.FieldCount; k++) { var childFieldConfig = tabConfig.FieldAtIndex(++j); if (childFieldConfig != null) { rawFieldValue = resultRow.RawValueAtIndex(childFieldConfig.TabIndependentFieldIndex); if (initialValues != null) { rawFieldValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, childFieldConfig, initialValues); } offlineChanged = false; if (offlineRootRecord != null) { offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(childFieldConfig.FieldId); if (offlineValue != null && !offlineValue.Equals(rawFieldValue)) { offlineChanged = true; } } editFieldContext = UPEditFieldContext.ChildFieldContextForFieldConfigValue(childFieldConfig, rawFieldValue); if (offlineChanged) { editFieldContext.SetOfflineChangeValue(offlineValue); } childFields.Add(editFieldContext); } } } var markAsChanged = false; rawFieldValue = rawFieldValue0; if (initialValues != null) { string initialValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, fieldConfig, initialValues); if (!rawFieldValue.Equals(initialValue)) { markAsChanged = true; rawFieldValue = initialValue; } } offlineChanged = false; offlineValue = null; if (offlineRootRecord != null) { offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(fieldConfig.FieldId); if (offlineValue != null && !offlineValue.Equals(rawFieldValue)) { offlineChanged = true; } } if (selector != null) { // Sometimes it makes sense to add the Link field , so you have the link information on the EditPage , but the field is not displayed . // Thus, the field is interpreted as EditField Selector must be set. if (isHidden) { editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else if (isReadOnly && ConfigurationUnitStore.DefaultStore.ConfigValueIsSet("Disable.82213")) { editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else { editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, selector); } } else { if (isHidden) { editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else if (isReadOnly) { editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else { editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, childFields as List <UPEditFieldContext>); } } if (fieldInfo.DateFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId) { editFieldContext.DateOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.DateFieldId, currentInfoAreaId, -1); } else if (fieldInfo.TimeFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId) { editFieldContext.TimeOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.TimeFieldId, currentInfoAreaId, -1); } if (offlineChanged) { editFieldContext.SetOfflineChangeValue(offlineValue); } else if (markAsChanged) { editFieldContext.SetChanged(true); } if (editFieldContext != null) { if (!string.IsNullOrEmpty(fieldPostfix)) { editFieldContext.FieldLabelPostfix = fieldPostfix; } if (editFieldDictionary != null) { editFieldDictionary.SetObjectForKey(editFieldContext, fieldConfig.Identification); if (childFields != null) { foreach (var childFieldContext in childFields) { editFieldDictionary.SetObjectForKey(childFieldContext, childFieldContext.FieldConfig.Identification); } } } fieldArray.Add(editFieldContext); } } else { string fieldValue; if (fieldAttributes.FieldCount > 1) { fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex); if (string.IsNullOrEmpty(fieldValue)) { fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues); } var values = !string.IsNullOrEmpty(fieldValue) ? new List <string> { fieldValue } : new List <string>(); for (var k = 1; k < fieldAttributes.FieldCount; k++) { var childfieldConfig = tabConfig.FieldAtIndex(++j); if (childfieldConfig == null) { continue; } fieldValue = resultRow?.ValueAtIndex(childfieldConfig.TabIndependentFieldIndex); if (string.IsNullOrEmpty(fieldValue)) { fieldValue = this.ValueForLinkFieldFromInitialValues(childfieldConfig, initialValues); } if (string.IsNullOrEmpty(fieldValue)) { fieldValue = string.Empty; } values.Add(fieldValue); } fieldValue = fieldAttributes.FormatValues(values); } else { fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex); if (string.IsNullOrEmpty(fieldValue)) { fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues); } } UPMField field; if (!isHidden && !string.IsNullOrEmpty(fieldValue)) { field = new UPMStringField(fieldIdentifier); ((UPMStringField)field).StringValue = fieldValue; } else { field = null; } if (field != null) { if (!fieldConfig.Attributes.NoLabel) { field.LabelText = fieldConfig.Label; } SetAttributesOnField(fieldAttributes, field); fieldArray.Add(field); } } } return(fieldArray); }
private void HandlePricingResult(UPCRMResult result) { int count = result.RowCount; Dictionary <string, UPSEPrice> articleDictionary = new Dictionary <string, UPSEPrice>(count); bool pricingByItemNumber = this.PricingItemNumber.Length > 0; int pricingItemNumberIndex = 0; if (pricingByItemNumber) { pricingItemNumberIndex = result.MetaInfo.IndexOfFunctionName(this.PricingItemNumber); Logger.LogError($"cannot execute pricing by item number because function name {this.PricingItemNumber} was not found in the pricing result"); if (pricingItemNumberIndex < 0) { pricingByItemNumber = false; } } for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); string articleRecordId = pricingByItemNumber ? row.RawValueAtIndex(pricingItemNumberIndex) : row.RecordIdentificationAtIndex(1).RecordId(); if (articleRecordId == null) { continue; } UPSEPrice price = new UPSEPrice(row, articleRecordId, this); UPSEPrice existingPrice = articleDictionary.ValueOrDefault(articleRecordId); if (existingPrice == null) { articleDictionary.SetObjectForKey(price, articleRecordId); } else { bool checkCurrency = true; foreach (string priorityColumn in this.PriceListPriorityColumns) { string existingValue = existingPrice.DataDictionary.ValueOrDefault(priorityColumn) as string; string currentValue = price.DataDictionary.ValueOrDefault(priorityColumn) as string; if (string.IsNullOrEmpty(existingValue) || existingValue == "0") { if (!string.IsNullOrEmpty(currentValue) && currentValue != "0") { articleDictionary[articleRecordId] = price; checkCurrency = false; break; } } else if (string.IsNullOrEmpty(currentValue) || currentValue == "0") { checkCurrency = false; break; } } if (checkCurrency) { if (price.Currency > 0 && this.Currency == price.Currency) { articleDictionary.SetObjectForKey(price, articleRecordId); } else if (existingPrice.Currency != this.Currency) { int baseCurrency = 0; if (this.CurrencyConversion != null) { baseCurrency = this.CurrencyConversion.BaseCurrency.CatalogCode; } if (baseCurrency != existingPrice.Currency) { if (price.Currency == baseCurrency) { articleDictionary.SetObjectForKey(price, articleRecordId); } } } } } } this.priceForArticle = articleDictionary; if (this.BulkVolumes != null) { this.BulkVolumes.Load(this.filterParameters, this.SerialEntry.RequestOption); } else { this.HandleBulkVolumesResult(); } }
/// <summary> /// Strings from row data provider value array options. /// </summary> /// <param name="row"> /// The row. /// </param> /// <param name="dataProvider"> /// The data provider. /// </param> /// <param name="valueArray"> /// The value array. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public string StringFromRowDataProviderValueArrayOptions( UPCRMResultRow row, UPCRMListFormatterFunctionDataProvider dataProvider, List <string> valueArray, UPFormatOption options) { string result = null; var colSpanFieldCount = 0; UPConfigFieldControlField colSpanField = null; List <string> colSpanFieldValues = null; string combineString = null; foreach (var field in this._fields) { var rawColumnValue = string.Empty; var columnValue = string.Empty; if (dataProvider != null) { if (!string.IsNullOrEmpty(field?.Function)) { rawColumnValue = dataProvider.RawValueForFunctionName(field.Function); if (!string.IsNullOrEmpty(rawColumnValue)) { columnValue = field.ValueFromRawValueOptions(rawColumnValue, options); } } } else if (valueArray != null) { columnValue = valueArray.Count > field.TabIndependentFieldIndex ? valueArray[field.TabIndependentFieldIndex] : string.Empty; rawColumnValue = columnValue; } else { rawColumnValue = row.RawValueAtIndex(field.TabIndependentFieldIndex); columnValue = row.ValueAtIndex(field.TabIndependentFieldIndex); } bool emptyColumnValue = false; if (field.Field.FieldType == "F") { if (field.Attributes.ExtendedOptionIsSetToFalse("supportsDecimals") && !string.IsNullOrWhiteSpace(rawColumnValue) && decimal.TryParse(rawColumnValue, out var value)) { const string noDecimalPlacesFormat = "F0"; columnValue = value.ToString(noDecimalPlacesFormat); } if (string.IsNullOrEmpty(rawColumnValue) || field.Field.IsEmptyValue(rawColumnValue)) { columnValue = !options.HasFlag(UPFormatOption.Show0Float) ? string.Empty : StringExtensions.FloatDisplayTextFromFloat(0); emptyColumnValue = true; } } else if (field.Field.IsNumericField) { if (string.IsNullOrEmpty(rawColumnValue) || field.Field.IsEmptyValue(rawColumnValue)) { columnValue = !options.HasFlag(UPFormatOption.Show0) ? string.Empty : StringExtensions.IntegerDisplayTextFromInteger(0); emptyColumnValue = true; } } else if (string.IsNullOrEmpty(rawColumnValue) || field.Field.IsEmptyValue(rawColumnValue)) { if (field.Field.FieldType == "B") { if (string.IsNullOrEmpty(columnValue) || columnValue.Equals(this.ListFormatter.DisplayNo)) { columnValue = string.Empty; emptyColumnValue = true; } } else { if (!options.HasFlag(UPFormatOption.Show0) || columnValue != "0") { columnValue = string.Empty; } emptyColumnValue = true; } } var currentCombineString = field.Attributes.CombineString; var range = 0; if (!field.Attributes.NoPlaceHoldersInCombineString && !field.Attributes.CombineWithIndices && !string.IsNullOrEmpty(currentCombineString)) { range = currentCombineString.IndexOf("v", StringComparison.Ordinal); if (range > 0 && !string.IsNullOrEmpty(columnValue)) { columnValue = currentCombineString.Replace("v", columnValue); } else if (range == -1) { range = currentCombineString.IndexOf("n", StringComparison.Ordinal); if (range > 0) { columnValue = emptyColumnValue ? string.Empty : currentCombineString.Replace("n", columnValue); } } } if (colSpanFieldCount > 0) { colSpanFieldValues.Add(!string.IsNullOrEmpty(columnValue) ? columnValue : string.Empty); if (--colSpanFieldCount == 0) { columnValue = colSpanField?.Attributes?.FormatValues(colSpanFieldValues); } } else if (field.Attributes.FieldCount > 1) { colSpanFieldCount = field.Attributes.FieldCount - 1; colSpanField = field; colSpanFieldValues = new List <string> { columnValue }; } if (colSpanFieldCount == 0 && !string.IsNullOrEmpty(columnValue)) { if (string.IsNullOrEmpty(result)) { result = columnValue; } else { if (!string.IsNullOrEmpty(combineString)) { result += $"{combineString}{columnValue}"; } else if (range > 0) { result += columnValue; } else { result += $" {columnValue}"; } } combineString = range <= 0 ? currentCombineString : string.Empty; } } return(options.HasFlag(UPFormatOption.DontRemoveLineBreak) ? result : result?.SingleLineString()); }
private void ProcessResult(UPCRMResult result) { UPRecordCopyStep currentStep = this.stepQueue[0]; this.stepQueue.RemoveAt(0); UPConfigQueryTable queryTable = currentStep.QueryTable; int count = result.RowCount; int resultTableCount = result.NumberOfResultTables; UPContainerInfoAreaMetaInfo copyResultInfoArea = null; if (queryTable.InfoAreaId == currentStep.FieldControl.InfoAreaId) { copyResultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(0); } for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); UPCRMRecord record = new UPCRMRecord(queryTable.InfoAreaId); if (currentStep.DestinationRecord != null) { record.AddLink(new UPCRMLink(currentStep.DestinationRecord, queryTable.LinkId)); } for (int j = 1; j < resultTableCount; j++) { string linkRecordIdentification = row.RecordIdentificationAtIndex(j); if (string.IsNullOrEmpty(linkRecordIdentification) && !result.IsServerResult) { UPContainerInfoAreaMetaInfo resultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(j); UPCRMLinkReader linkReader = new UPCRMLinkReader(StringExtensions.InfoAreaIdRecordId(currentStep.FieldControl.InfoAreaId, row.RootRecordId), $"{resultInfoArea.InfoAreaId}:{resultInfoArea.LinkId}", null); linkRecordIdentification = linkReader.RequestLinkRecordOffline(); } int linkId = -1; if (linkRecordIdentification?.Length > 8) { if (currentStep.DestinationRecord == null || queryTable.LinkId != linkId || linkRecordIdentification.InfoAreaId() != currentStep.DestinationRecord.InfoAreaId) { record.AddLink(new UPCRMLink(linkRecordIdentification, linkId)); } } } Dictionary <string, object> fieldsWithFunctions = row.ValuesWithFunctions(); UPConfigQueryTable replacedTable = queryTable.QueryTableByApplyingValueDictionary(fieldsWithFunctions); if (copyResultInfoArea != null) { foreach (UPContainerFieldMetaInfo field in copyResultInfoArea.Fields) { string val = row.RawValueAtIndex(field.PositionInResult); if (!string.IsNullOrEmpty(val)) { record.AddValue(new UPCRMFieldValue(val, field.InfoAreaId, field.FieldId)); } } } if (replacedTable != null) { record.ApplyValuesFromTemplateFilter(replacedTable, true); } int numberOfSubTables = queryTable.NumberOfSubTables; if (numberOfSubTables > 0) { for (int k = 0; k < numberOfSubTables; k++) { UPRecordCopyStep subStep = new UPRecordCopyStep(); subStep.QueryTable = queryTable.SubTableAtIndex(k); subStep.SourceRecordIdentification = row.RootRecordIdentification; subStep.DestinationRecord = record; this.ConfigForStepFromQueryTable(subStep, subStep.QueryTable); this.stepQueue.Add(subStep); } } this.recordArray.Add(record); } this.ExecuteNextStep(); }
/// <summary> /// Section key raw value for row /// </summary> /// <param name="dataRow">Data row</param> /// <param name="context">Context</param> /// <returns><see cref="string"/></returns> private string SectionKeyRawValueForRow(UPCRMResultRow dataRow, UPCoreMappingResultContext context) { var sectionIndex = dataRow.RawValueAtIndex(context.SectionField?.TabIndependentFieldIndex ?? 0); return(this.CheckSectionIndex(sectionIndex, context)); }
/// <summary> /// Raws the value for item key result position. /// </summary> /// <param name="itemkey">The itemkey.</param> /// <param name="resultPosition">The result position.</param> /// <returns></returns> public string RawValueForItemKeyResultPosition(string itemkey, int resultPosition) { UPCRMResultRow row = this.rowFromItemKey.ValueOrDefault(itemkey); return(row != null?row.RawValueAtIndex(resultPosition) : string.Empty); }