Exemplo n.º 1
0
 public static void SetDesignOddsFormat(DependencyObject obj, OddsFormatType value)
 {
     if (Instance.GetIsInDesignMode())
     {
         obj.SetValue(DesignOddsFormatProperty, value);
     }
 }
Exemplo n.º 2
0
        public static void SetDesignOddsFormat(DependencyObject obj, OddsFormatType value)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (Instance.IsInDesignMode)
            {
                obj.SetValue(DesignOddsFormatProperty, value);
            }
        }
        /// <summary>
        /// Converts a decimal odds into a localized odds string in the defined <see cref="OddsFormatType"/>.
        /// </summary>
        /// <param name="sourceOdds">
        /// The source odds.
        /// </param>
        /// <param name="oddsType">
        /// Type of the odds.
        /// </param>
        /// <param name="specificCulture">
        /// The specific culture.
        /// </param>
        /// <returns>
        /// The ready to use odds string.
        /// </returns>
        /// <remarks>
        /// The specific Culture has to be a "xx-xx" culture to support the value.<see cref="ToString"/> method.
        /// </remarks>
        public static string GetLocalizedOddsString(decimal sourceOdds, OddsFormatType oddsType, CultureInfo specificCulture)
        {
            switch (oddsType)
            {
            case OddsFormatType.UK:
                if (sourceOdds <= 0)
                {
                    return("0");
                }

                // versucht den decimal wert in der uk lookup table zu finden.
                // wenn nichts gefunden wurde, wird die quote berechnet.
                string lookupValue;
                if (TryGetUKOddsLookupValue(sourceOdds, out lookupValue))
                {
                    // wenn der decimal wert gefunden wurde, wird der lookup wert retuniert
                    return(lookupValue);
                }

                // Fraktionelle Quote
                // �berlegungen:
                // * Die Quote wird mit 2 Nachkommastellen angezeigt, d.h. max /100
                // * Alle Nachkommaquoten m�ssen f�r eine korrekte und zugleich
                // mathematisch maximal gek�rzte Darstellung entweder durch 2 oder durch 5 teilbar sein,
                // weitere K�rzungen wiederum durch 2 oder durch 5,
                // d.h. maximal /2/2/5/5 ( <= Primfaktorenzerlegung von 100 = {2, 2, 5, 5})
                decimal nachkommastellen = (sourceOdds % 1.0m) * 100;
                if (nachkommastellen == 0)
                {
                    // gerade Quote
                    return(string.Format(specificCulture, "{0:N0}/1", sourceOdds - 1));
                }
                else
                {
                    int     zweier  = 0;
                    int     fuenfer = 0;
                    decimal ggT     = 1; // Gr��ter gemeinsamer Teiler
                    while ((nachkommastellen > 1 && zweier < 2 && fuenfer < 2) &&
                           (nachkommastellen % 2 == 0 || nachkommastellen % 5 == 0))
                    {
                        if (nachkommastellen % 2 == 0)
                        {
                            ++zweier;
                            nachkommastellen = nachkommastellen / 2;
                            ggT = ggT * 2;
                        }

                        if (nachkommastellen % 5 == 0)
                        {
                            ++fuenfer;
                            nachkommastellen = nachkommastellen / 5;
                            ggT = ggT * 5;
                        }
                    }

                    // hier haben wir den ggT, mit dem 100 geteilt wird
                    decimal divisor  = 100 / ggT;
                    decimal ergebnis = (sourceOdds - 1) * divisor;

                    return(string.Format(specificCulture, "{0:N0}/{1:N0}", ergebnis, divisor));
                }

            case OddsFormatType.US:

                // bei Quote <=1 -> Fehler
                if (sourceOdds <= 1)
                {
                    return("0");
                }
                else
                {
                    if (sourceOdds < 2)
                    {
                        // negative US-Quote
                        return((-100 / (sourceOdds - 1)).ToString("N0", specificCulture));
                    }
                    else
                    {
                        // Positive US-Quote
                        return(string.Format(specificCulture, "+{0:N0}", (sourceOdds - 1) * 100));
                    }
                }

            case OddsFormatType.EU:
                return(sourceOdds.ToString("N2", specificCulture));

            default:
                throw new NotSupportedException();
            }
        }
 /// <summary>
 /// Converts a decimal odds into a localized odds string in the defined <see cref="OddsFormatType"/>.
 /// </summary>
 /// <param name="sourceOdds">
 /// The source odds.
 /// </param>
 /// <param name="oddsType">
 /// Type of the odds.
 /// </param>
 /// <returns>
 /// The ready to use odds string.
 /// </returns>
 public static string GetLocalizedOddsString(decimal sourceOdds, OddsFormatType oddsType)
 {
     return(GetLocalizedOddsString(sourceOdds, oddsType, LocalizeDictionary.Instance.SpecificCulture));
 }
        /// <summary>Converts a decimal odds into a localized odds string in the defined <c>OddsFormatType</c>.</summary>
        /// <param name="sourceOdds">The source odds.</param>
        /// <param name="oddsType">Type of the odds.</param>
        /// <param name="specificCulture">The specific culture.</param>
        /// <returns>The ready to use odds string.</returns>
        /// <remarks>The specific Culture has to be a "xx-xx" culture to support the value.<c>ToString</c> method.</remarks>
        static string GetLocalizedOddsString(
            decimal sourceOdds, OddsFormatType oddsType, IFormatProvider specificCulture)
        {
            switch (oddsType)
            {
            case OddsFormatType.UK:
                if (sourceOdds <= 0)
                {
                    return("0");
                }

                string lookupValue;
                if (TryGetUKOddsLookupValue(sourceOdds, out lookupValue))
                {
                    return(lookupValue);
                }

                decimal localeString = (sourceOdds % 1.0m) * 100;
                if (localeString == 0)
                {
                    return(string.Format(specificCulture, "{0:N0}/1", sourceOdds - 1));
                }

                int     two = 0;
                int     one = 0;
                decimal dec = 1;
                while ((localeString > 1 && two < 2 && one < 2) && (localeString % 2 == 0 || localeString % 5 == 0))
                {
                    if (localeString % 2 == 0)
                    {
                        ++two;
                        localeString = localeString / 2;
                        dec          = dec * 2;
                    }

                    if (localeString % 5 != 0)
                    {
                        continue;
                    }

                    ++one;
                    localeString = localeString / 5;
                    dec          = dec * 5;
                }

                decimal divisor = 100 / dec;
                decimal result  = (sourceOdds - 1) * divisor;

                return(string.Format(specificCulture, "{0:N0}/{1:N0}", result, divisor));

            case OddsFormatType.US:

                if (sourceOdds <= 1)
                {
                    return("0");
                }

                return(sourceOdds < 2
                               ? (-100 / (sourceOdds - 1)).ToString("N0", specificCulture)
                               : string.Format(specificCulture, "+{0:N0}", (sourceOdds - 1) * 100));

            case OddsFormatType.EU:
                return(sourceOdds.ToString("N2", specificCulture));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts a decimal odds into a localized odds string in the defined <see cref="OddsFormatType"/>.
        /// </summary>
        /// <param name="sourceOdds">
        /// The source odds.
        /// </param>
        /// <param name="oddsType">
        /// Type of the odds.
        /// </param>
        /// <param name="specificCulture">
        /// The specific culture.
        /// </param>
        /// <returns>
        /// The ready to use odds string.
        /// </returns>
        /// <remarks>
        /// The specific Culture has to be a "xx-xx" culture to support the value.<see cref="ToString"/> method.
        /// </remarks>
        public static string GetLocalizedOddsString(decimal sourceOdds, OddsFormatType oddsType, CultureInfo specificCulture)
        {
            switch (oddsType)
            {
                case OddsFormatType.UK:
                    if (sourceOdds <= 0)
                    {
                        return "0";
                    }

                    // versucht den decimal wert in der uk lookup table zu finden.
                    // wenn nichts gefunden wurde, wird die quote berechnet.
                    string lookupValue;
                    if (TryGetUKOddsLookupValue(sourceOdds, out lookupValue))
                    {
                        // wenn der decimal wert gefunden wurde, wird der lookup wert retuniert
                        return lookupValue;
                    }

                    // Fraktionelle Quote
                    // Überlegungen: 
                    // * Die Quote wird mit 2 Nachkommastellen angezeigt, d.h. max /100
                    // * Alle Nachkommaquoten müssen für eine korrekte und zugleich 
                    // mathematisch maximal gekürzte Darstellung entweder durch 2 oder durch 5 teilbar sein,
                    // weitere Kürzungen wiederum durch 2 oder durch 5, 
                    // d.h. maximal /2/2/5/5 (<= Primfaktorenzerlegung von 100 = {2, 2, 5, 5})
                    decimal nachkommastellen = (sourceOdds % 1.0m) * 100;
                    if (nachkommastellen == 0)
                    {
                        // gerade Quote
                        return string.Format(specificCulture, "{0:N0}/1", sourceOdds - 1);
                    }
                    else
                    {
                        int zweier = 0;
                        int fuenfer = 0;
                        decimal ggT = 1; // Größter gemeinsamer Teiler
                        while ((nachkommastellen > 1 && zweier < 2 && fuenfer < 2)
                               && (nachkommastellen % 2 == 0 || nachkommastellen % 5 == 0))
                        {
                            if (nachkommastellen % 2 == 0)
                            {
                                ++zweier;
                                nachkommastellen = nachkommastellen / 2;
                                ggT = ggT * 2;
                            }

                            if (nachkommastellen % 5 == 0)
                            {
                                ++fuenfer;
                                nachkommastellen = nachkommastellen / 5;
                                ggT = ggT * 5;
                            }
                        }

                        // hier haben wir den ggT, mit dem 100 geteilt wird
                        decimal divisor = 100 / ggT;
                        decimal ergebnis = (sourceOdds - 1) * divisor;

                        return string.Format(specificCulture, "{0:N0}/{1:N0}", ergebnis, divisor);
                    }

                case OddsFormatType.US:

                    // bei Quote <=1 -> Fehler
                    if (sourceOdds <= 1)
                    {
                        return "0";
                    }
                    else
                    {
                        if (sourceOdds < 2)
                        {
                            // negative US-Quote
                            return (-100 / (sourceOdds - 1)).ToString("N0", specificCulture);
                        }
                        else
                        {
                            // Positive US-Quote
                            return string.Format(specificCulture, "+{0:N0}", (sourceOdds - 1) * 100);
                        }
                    }

                case OddsFormatType.EU:
                    return sourceOdds.ToString("N2", specificCulture);
                default:
                    throw new NotSupportedException();
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Converts a decimal odds into a localized odds string in the defined <see cref="OddsFormatType"/>.
 /// </summary>
 /// <param name="sourceOdds">
 /// The source odds.
 /// </param>
 /// <param name="oddsType">
 /// Type of the odds.
 /// </param>
 /// <returns>
 /// The ready to use odds string.
 /// </returns>
 public static string GetLocalizedOddsString(decimal sourceOdds, OddsFormatType oddsType)
 {
     return GetLocalizedOddsString(sourceOdds, oddsType, LocalizeDictionary.Instance.SpecificCulture);
 }
 /// <summary>
 /// Converts a decimal odds into a localized odds string in the defined <see cref="OddsFormatType"/>.
 /// </summary>
 /// <param name="sourceOdds">The source odds.</param>
 /// <param name="oddsType">Type of the odds.</param>
 /// <returns>The ready to use odds string.</returns>
 public static string GetLocalizedOddsString(decimal sourceOdds, OddsFormatType oddsType)
 {
     return GetLocalizedOddsString(sourceOdds, oddsType, false);
 }
Exemplo n.º 9
0
 public static void SetDesignOddsFormat(DependencyObject obj, OddsFormatType value)
 {
     if (Instance.GetIsInDesignMode())
     {
         obj.SetValue(DesignOddsFormatProperty, value);
     }
 }
Exemplo n.º 10
0
        public static void SetDesignOddsFormat(DependencyObject obj, OddsFormatType value)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (Instance.IsInDesignMode)
            {
                obj.SetValue(DesignOddsFormatProperty, value);
            }
        }