Example #1
0
        /// <summary>
        /// print a currency value (actually all sorts of values, e.g. dates) into a string
        /// </summary>
        /// <param name="value">the value to be printed</param>
        /// <param name="format">the format to be used; can be dayofyear for birthdays, currency, etc</param>
        /// <returns>the formatted string</returns>
        public static String FormatCurrency(TVariant value, String format)
        {
            String ReturnValue;
            decimal d;
            DateTime ThisYearDate;

            // for partnerkey
            String OrigFormat;

            ReturnValue = "";

            if (format.ToLower() == "dayofyear")
            {
                if (value.IsZeroOrNull())
                {
                    ReturnValue = "N/A";
                }
                else
                {
                    ThisYearDate = new DateTime(DateTime.Today.Year, value.ToDate().Month, value.ToDate().Day);
                    ReturnValue = DateToStr(ThisYearDate, "dd-MMM").ToUpper();
                }

                return ReturnValue;
            }

            if (format == null)
            {
                format = "";
            }

            OrigFormat = format;

            if (value.TypeVariant == eVariantTypes.eString)
            {
                format = "";
            }
            else
            {
                format = GetFormatString(value.FormatString, format);
            }

            if (value != null)
            {
                if ((format == null) || (format.Length == 0))
                {
                    return value.ToString();
                }

                String formatPositive = GetNextCSV(ref format, ";");
                String formatNegative = GetNextCSV(ref format, ";");
                String formatZero = GetNextCSV(ref format, ";");
                String formatNil = GetNextCSV(ref format, ";");

                if ((OrigFormat.ToLower() == "partnerkey") || (value.FormatString == "partnerkey"))
                {
                    if (value.ToInt64() <= 0)
                    {
                        ReturnValue = FormatCurrencyInternal(0, "0000000000");
                    }
                    else
                    {
                        ReturnValue = FormatCurrencyInternal(value.ToDecimal(), formatPositive);
                    }
                }
                else if ((value.TypeVariant == eVariantTypes.eDecimal)
                         || (value.TypeVariant == eVariantTypes.eCurrency)
                         || (value.TypeVariant == eVariantTypes.eInteger))
                {
                    d = value.ToDecimal();

                    if (d > 0)
                    {
                        ReturnValue = FormatCurrencyInternal(d, formatPositive);
                    }
                    else if (d < 0)
                    {
                        ReturnValue = FormatCurrencyInternal(Math.Abs(d), formatNegative);
                    }
                    else
                    {
                        // (d == 0)
                        ReturnValue = FormatCurrencyInternal(d, formatZero);
                    }
                }
                else if (value.IsZeroOrNull())
                {
                    ReturnValue = FormatCurrencyInternal(0, formatNil);
                }
                else
                {
                    ReturnValue = value.ToString();
                }
            }

            return ReturnValue;
        }
Example #2
0
        /// <summary>
        /// </summary>
        /// <returns>s 0 if equal, -1 if this object is less than the parameter, +1 if it is greater
        /// </returns>
        public System.Int16 CompareTo(TVariant v)
        {
            System.Int16 ReturnValue;
            ReturnValue = 0;

            if ((TypeVariant == eVariantTypes.eDecimal) || (TypeVariant == eVariantTypes.eInteger) || (TypeVariant == eVariantTypes.eInt64)
                || (TypeVariant == eVariantTypes.eCurrency))
            {
                if (ToDecimal() == v.ToDecimal())
                {
                    ReturnValue = 0;
                }
                else if (ToDecimal() < v.ToDecimal())
                {
                    ReturnValue = -1;
                }
                else
                {
                    ReturnValue = +1;
                }
            }
            else if (TypeVariant == eVariantTypes.eDateTime)
            {
                ReturnValue = (short)System.DateTime.Compare(ToDate(), v.ToDate());
            }
            else if (TypeVariant == eVariantTypes.eString)
            {
                // test if perhaps boolean values are compared; trouble is, yes and no and true and false are used
                if (ComparingBooleanValues(v))
                {
                    if (ToBool() == v.ToBool())
                    {
                        ReturnValue = 0;
                    }
                    else if (ToBool() == false)
                    {
                        ReturnValue = -1;
                    }
                    else
                    {
                        ReturnValue = 1;
                    }
                }
                else
                {
                    ReturnValue = (short)String.Compare(ToString(), v.ToString());
                }
            }
            else if (TypeVariant == eVariantTypes.eBoolean)
            {
                if (ToBool() == v.ToBool())
                {
                    ReturnValue = 0;
                }
                else if (ToBool() == false)
                {
                    ReturnValue = -1;
                }
                else
                {
                    ReturnValue = 1;
                }
            }
            else if (TypeVariant == eVariantTypes.eComposite)
            {
                // just compare the first elements
                ReturnValue = FirstCompositeValue().CompareTo(v.FirstCompositeValue());
            }

            return ReturnValue;
        }