Exemplo n.º 1
0
    private void ShowExchangeRate()
    {
        try
        {
            CurrencyConverter cc = new CurrencyConverter();

            cc.AdjustToLocalTime = false;

            // Add a proxy here is needed. Example:
            // cc.Proxy = new System.Net.WebProxy("0.0.0.0", 80);
            CurrencyData cd = cc.GetCurrencyData("SGD", "MMK");
            lbl_ExchangeRate.Text = String.Format("1 SGD = {0} Kyats", (cd.Rate - 7).ToString("C0").Replace("$", "").Replace("RM", "").Replace("¥", ""));
            lbl_checkon.Text = "based on Yahoo! Finance";
        }
        catch (Exception ex)
        {
            lbl_checkon.Text = "Service unavailable :(";
        }
    }
Exemplo n.º 2
0
        private double ConvertValue(double value, string currencyOrigine, string currencyDestination, int nbRetry)
        {
            if (currencyDestination == currencyOrigine)
                return value;

            try
            {

                CurrencyConverter myCurrencyConverter = new CurrencyConverter();
                CurrencyData cd = new CurrencyData(currencyOrigine, currencyDestination);
                // Creates new structure and set Base currency
                // to Euro and Target to Russian Ruble

                myCurrencyConverter.GetCurrencyData(ref cd);

                double newValue = value * cd.Rate;

                newValue = Math.Round(newValue, 2, MidpointRounding.AwayFromZero);

                return newValue;

            }
            catch (Exception ex)
            {
                if (nbRetry < ServiceParametersHelper.nbAPIRetry())
                    this.ConvertValue(value,currencyOrigine,currencyDestination, nbRetry+1);
                else
                    throw ex;
            }

            return value;
        }