Exemple #1
0
        /// <summary>
        /// Values at index options.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string ValueAtIndex(int index, UPFormatOption options)
        {
            var rawValue = this.RawValueAtIndex(index);
            var value    = this.Result.MetaInfo.ValueFromRawValueForColumnOptions(rawValue, index, options);

            return(value ?? string.Empty);
        }
Exemple #2
0
        /// <summary>
        /// Shorts the value from raw value options.
        /// </summary>
        /// <param name="rawValue">
        /// The raw value.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// short value
        /// </returns>
        public string ShortValueFromRawValueOptions(string rawValue, UPFormatOption options)
        {
            if (this.fieldMetaInfo == null)
            {
                this.fieldMetaInfo = new UPContainerFieldMetaInfo(this);
            }

            return(this.fieldMetaInfo.ShortValueFromRawValue(rawValue, options));
        }
Exemple #3
0
        /// <summary>
        /// Gets the short the value for raw value.
        /// </summary>
        /// <param name="rawValue">
        /// The raw value.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string ShortValueForRawValue(string rawValue, UPFormatOption options)
        {
            if (this.FieldType[0] != 'D')
            {
                return(this.ValueForRawValueOptions(rawValue, options, null));
            }

            DateTime?date = DateTime.Parse(rawValue);

            return(options == UPFormatOption.Report ? date?.ReportFormattedDate() : date.ShortLocalizedFormattedDate());
        }
Exemple #4
0
        /// <summary>
        /// Values for raw value options.
        /// </summary>
        /// <param name="rawValue">
        /// The raw value.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <param name="configField">
        /// The config field.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string ValueForRawValueOptions(string rawValue, UPFormatOption options, UPConfigFieldControlField configField)
        {
            if (string.IsNullOrEmpty(rawValue))
            {
                return(string.Empty);
            }

            if (string.IsNullOrEmpty(this.FieldType))
            {
                return(rawValue);
            }

            var fieldType      = this.FieldType[0];
            var fieldTypeValue = configField?.Attributes.RenderHooksForKey("FieldType");

            if (!string.IsNullOrWhiteSpace(fieldTypeValue))
            {
                fieldType = fieldTypeValue[0];
            }

            switch (fieldType)
            {
            case 'D':
                return(FieldValueFormatterDateTime.ConvertDate(rawValue, options));

            case 'T':
                return(FieldValueFormatterDateTime.ConvertTime(rawValue));

            case 'B':
                if (rawValue == "true")
                {
                    return(ServerSession.CurrentSession.UpTextForYES());
                }

                return(!string.IsNullOrEmpty(rawValue) ? ServerSession.CurrentSession.UpTextForNO() : string.Empty);


            case 'S':    //case 'L':
            case 'F':
                return(FieldValueFormatterNumeric.Convert(rawValue, fieldType, options, configField, this, this.fieldInfo));

            case 'X':
                return(UPCRMDataStore.DefaultStore.CatalogValueForFixedCatalogIdRawValue(this.fieldInfo.Cat, rawValue));

            case 'K':
                return(UPCRMDataStore.DefaultStore.CatalogValueForVariableCatalogIdRawValue(this.fieldInfo.Cat, rawValue));

            default:
                return(rawValue);
            }
        }
        /// <summary>
        /// Convert method
        /// </summary>
        /// <param name="rawValue">value</param>
        /// <param name="fieldType">field type</param>
        /// <param name="options">options</param>
        /// <param name="configField">config field</param>
        /// <param name="field">field</param>
        /// <param name="fieldInfo">field info</param>
        /// <returns>string</returns>
        public static string Convert(
            string rawValue,
            char fieldType,
            UPFormatOption options,
            UPConfigFieldControlField configField,
            UPCRMFieldInfo field,
            FieldInfo fieldInfo)
        {
            var convertedValue = string.Empty;

            // CLIENT-207 ( Value coming from database always in en culture so first convert to decimal with en)
            if (decimal.TryParse(rawValue, NumberStyles.Number, new CultureInfo("en"), out var numericValue))
            {
                if (IsPercentageField(field, configField))
                {
                    numericValue *= 100;
                }

                switch (fieldType)
                {
                case 'L':
                case 'S':
                {
                    if (!string.IsNullOrWhiteSpace(field.RepType))
                    {
                        int intValue;
                        var repName = UPCRMDataStore.DefaultStore.Reps.NameOfRepIdString(rawValue);
                        if (!string.IsNullOrWhiteSpace(repName))
                        {
                            return(repName);
                        }
                        else if (int.TryParse(rawValue, out intValue) && intValue == 0)
                        {
                            return(string.Empty);
                        }
                        else
                        {
                            return(rawValue);
                        }
                    }

                    if (string.IsNullOrWhiteSpace(rawValue) && (options == UPFormatOption.Show0))
                    {
                        convertedValue = "0";
                    }
                    else if (!field.ShowZero && field.IsEmptyValue(rawValue))
                    {
                        convertedValue = string.Empty;
                    }
                    else
                    {
                        convertedValue = numericValue.ToString("N0");
                    }

                    break;
                }

                case 'F':
                {
                    if (!field.ShowZero && numericValue == 0)
                    {
                        convertedValue = string.Empty;
                    }
                    else if (field.OneDecimalDigit)
                    {
                        convertedValue = $"{numericValue:N1}";
                    }
                    else if (field.NoDecimalDigits)
                    {
                        convertedValue = $"{numericValue:N0}";
                    }
                    else if (field.ThreeDecimalDigits)
                    {
                        convertedValue = $"{numericValue:N3}";
                    }
                    else if (field.FourDecimalDigits)
                    {
                        convertedValue = $"{numericValue:N4}";
                    }
                    else if (int.TryParse(configField?.Attributes.RenderHooksForKey("DecimalDigits"), out var digits))
                    {
                        convertedValue = numericValue.ToString($"N{digits}");
                    }
                    else
                    {
                        convertedValue = $"{numericValue:N}";
                    }

                    if (options != UPFormatOption.Report && fieldInfo.IsAmount)
                    {
                        convertedValue = $"{numericValue:N},-";
                    }

                    break;
                }
                }

                if (configField?.Attributes.RenderHooksForKey("GroupingSeparator") == false.ToString().ToLower())
                {
                    convertedValue = convertedValue.Replace(CultureInfo.CurrentUICulture.NumberFormat.NumberGroupSeparator, string.Empty);
                }

                if (IsPercentageField(field, configField) && !string.IsNullOrWhiteSpace(convertedValue))
                {
                    if (options != UPFormatOption.Report)
                    {
                        convertedValue = $"{convertedValue}%";
                    }
                }
            }

            return(convertedValue);
        }
 /// <summary>
 /// Strings from value array options.
 /// </summary>
 /// <param name="values">
 /// The values.
 /// </param>
 /// <param name="options">
 /// The options.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string StringFromValueArrayOptions(List <string> values, UPFormatOption options)
 {
     return(this.StringFromRowDataProviderValueArrayOptions(null, null, values, options));
 }
 /// <summary>
 /// Strings from row options.
 /// </summary>
 /// <param name="row">
 /// The row.
 /// </param>
 /// <param name="options">
 /// The options.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string StringFromRowOptions(UPCRMResultRow row, UPFormatOption options)
 {
     return(this.StringFromRowDataProviderValueArrayOptions(row, null, null, options));
 }
        /// <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());
        }
 /// <summary>
 /// Strings from data provider options.
 /// </summary>
 /// <param name="dataProvider">
 /// The data provider.
 /// </param>
 /// <param name="options">
 /// The options.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string StringFromDataProviderOptions(
     UPCRMListFormatterFunctionDataProvider dataProvider,
     UPFormatOption options)
 {
     return(this.StringFromRowDataProviderValueArrayOptions(null, dataProvider, null, options));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPCRMListFormatter"/> class.
        /// </summary>
        /// <param name="fieldControlTab">
        /// The field control tab.
        /// </param>
        /// <param name="fieldCount">
        /// The field count.
        /// </param>
        public UPCRMListFormatter(FieldControlTab fieldControlTab, int fieldCount)
        {
            List <UPCRMListFormatterPosition> positionArray = null;
            var childFieldCount = 0;
            UPCRMListFormatterPosition currentPosition = null;

            this.DisplayNo = ServerSession.CurrentSession.UpTextForNO();

            foreach (var field in fieldControlTab.Fields ?? new List <UPConfigFieldControlField>())
            {
                if (fieldCount-- == 0)
                {
                    break;
                }

                if (childFieldCount > 0)
                {
                    currentPosition?.AddField(field);
                    --childFieldCount;

                    // PVCS 87654 Kombinierte Personendarstellung (3 Felder) in GRID View
                    // wenn das letzte Feld einen colSpan hat, so erhöht sich der childFieldCount
                    if (childFieldCount == 0)
                    {
                        childFieldCount = field.Attributes.FieldCount - 1;
                    }
                }
                else
                {
                    if (field.TargetFieldNumber > 0 && field.TargetFieldNumber < 7)
                    {
                        if (positionArray == null)
                        {
                            positionArray = new List <UPCRMListFormatterPosition>();
                        }

                        int positionIndex = field.TargetFieldNumber - 1;
                        if (positionArray.Count <= positionIndex)
                        {
                            while (positionArray.Count < positionIndex)
                            {
                                positionArray.Add(null);
                            }

                            currentPosition = new UPCRMListFormatterPosition {
                                ListFormatter = this
                            };
                            positionArray.Add(currentPosition);
                        }
                        else if (positionArray[positionIndex] == null)
                        {
                            currentPosition = new UPCRMListFormatterPosition {
                                ListFormatter = this
                            };
                            positionArray[positionIndex] = currentPosition;
                        }
                        else
                        {
                            currentPosition = positionArray[positionIndex];
                        }
                    }
                    else
                    {
                        currentPosition = new UPCRMListFormatterPosition {
                            ListFormatter = this
                        };
                        if (positionArray == null)
                        {
                            positionArray = new List <UPCRMListFormatterPosition> {
                                currentPosition
                            };
                        }
                        else
                        {
                            positionArray.Add(currentPosition);
                        }
                    }

                    childFieldCount = field.Attributes.FieldCount - 1;
                    currentPosition.AddField(field);
                }
            }

            this._positions = positionArray;
            var configStore = ConfigurationUnitStore.DefaultStore;
            var show0       = configStore.ConfigValueIsSet("Format.Show0InLists");
            var show0Float  =
                configStore.ConfigValueIsSet(
                    configStore.WebConfigValueByName("Format.Show0InListsForFloat") != null
                        ? "Format.Show0InListsForFloat"
                        : "Format:Show0InListsForFloat");

            if (show0)
            {
                this._formatOptions |= UPFormatOption.Show0;
            }

            if (show0Float)
            {
                this._formatOptions |= UPFormatOption.Show0Float;
            }

            if (this._removeLineBreaks)
            {
                this._formatOptions |= UPFormatOption.DontRemoveLineBreak;
            }
        }
Exemple #11
0
        /// <summary>
        /// Convert date to string
        /// </summary>
        /// <param name="rawValue">value</param>
        /// <param name="options">options</param>
        /// <returns>string</returns>
        public static string ConvertDate(string rawValue, UPFormatOption options)
        {
            var date = rawValue.DateFromCrmValue();

            return(options == UPFormatOption.Report ? date?.ReportFormattedDate() : date.LocalizedFormattedDate());
        }
Exemple #12
0
 /// <summary>
 /// Values for raw value options.
 /// </summary>
 /// <param name="rawValue">
 /// The raw value.
 /// </param>
 /// <param name="options">
 /// The options.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string ValueForRawValueOptions(string rawValue, UPFormatOption options)
 {
     return(this.FieldInfo != null?this.FieldInfo.ValueForRawValueOptions(rawValue, options, null) : null);
 }