Ejemplo n.º 1
0
        /// <summary>Converts the string to a currency.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">
        /// A string containing a currency to convert.
        /// </param>
        /// <param name="formatProvider">
        /// The specified format provider.
        /// </param>
        /// <param name="result">
        /// The result of the parsing.
        /// </param>
        /// <returns>
        /// True if the string was converted successfully, otherwise false.
        /// </returns>
        public static bool TryParse(string s, IFormatProvider formatProvider, out Currency result)
        {
            result = Empty;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture;

            if (Qowaiv.Unknown.IsUnknown(s, culture) || s == Unknown.Symbol)
            {
                result = Unknown;
                return(true);
            }
            AddCulture(culture);

            var str = Parsing.ToUnified(s);

            if (Parsings[culture].TryGetValue(str, out string val) || Parsings[CultureInfo.InvariantCulture].TryGetValue(str, out val))
            {
                result = new Currency(val);
                return(true);
            }
            foreach (var currency in AllCurrencies.Where(c => !string.IsNullOrEmpty(c.Symbol)))
            {
                if (currency.Symbol == str)
                {
                    result = currency;
                    return(true);
                }
            }
            return(false);
        }
        private double CalculateConversion()
        {
            string CurrencyIn     = this.SelectorFrom.CurrencySelected?.Currency;
            string CurrencyOut    = this.SelectorTo.CurrencySelected?.Currency;
            var    inputCurrency  = AllCurrencies.SingleOrDefault(x => x.ISOCode == CurrencyIn);
            var    outputCurrency = AllCurrencies.SingleOrDefault(x => x.ISOCode == CurrencyOut);

            double currencyRate = CurrencyHelper.GetCurrencyRate(inputCurrency, outputCurrency);
            double InputValue   = this.EnteredValue;

            return(Math.Round(InputValue * currencyRate, 2));
        }
        private void InitializeCurrencyLists()
        {
            var currencySelectionGrouping = AllCurrencies.GroupBy(c => _selectedCurrencyTypes.Contains(c.Id)).ToList();

            _selectedCurrenciesDataSource   = new BindingList <Currency>(currencySelectionGrouping.Where(g => g.Key).SelectMany(c => c).ToList());
            _unselectedCurrenciesDataSource = new BindingList <Currency>(currencySelectionGrouping.Where(g => !g.Key).SelectMany(c => c).ToList());

            _lstSelectedCurrencies.DisplayMember = "NameAndSymbol";
            _lstSelectedCurrencies.ValueMember   = "Id";
            _lstSelectedCurrencies.DataSource    = _selectedCurrenciesDataSource;

            _lstUnselectedCurrencies.DisplayMember = "NameAndSymbol";
            _lstUnselectedCurrencies.ValueMember   = "Id";
            _lstUnselectedCurrencies.DataSource    = _unselectedCurrenciesDataSource;
        }
        public CurrencyConversionViewModel()
        {
            this.AllCurrencies   = IsoCurrencyCodes.AllCurrencies().ToList();
            this.InUseCurrencies = AllCurrencies.Where(x => x.InUse == true).ToList();

            ResetDefaults();

            this.CurrencyInput.ValueChanged += InputCurrency;
            this.CurrencyInput.InputValue    = 1.00;

            this.CurrencyOutput.IsReadOnly      = true;
            this.SelectorFrom.Id                = FromSelector;
            this.SelectorFrom.SelectionChanged += SelectionChanged;

            this.SelectorTo.Id = ToSelector;
            this.SelectorTo.SelectionChanged += SelectionChanged;

            RevertCommand = new RelayCommand(this.Revert);

            Mediator.Instance.Register(this);
        }
Ejemplo n.º 5
0
        /// <summary>Gets a currency by its ISO numeric code</summary>
        /// <param name="numericCode">The ISO numeric code of the desired currency</param>
        /// <exception cref="ArgumentException">
        ///     Thrown when no currency is found with the specified ISO numeric code
        /// </exception>
        /// <returns>A <see cref="Currency"/> instance</returns>
        public static Currency ByNumericCode(string numericCode)
        {
            var filteredCurrencies = AllCurrencies.Where(
                currency => currency.NumericCode == numericCode
                );

            if (filteredCurrencies.Count() > 0)
            {
                var currency = filteredCurrencies.First();

                return(new Currency(
                           currency.AlphabeticCode,
                           currency.NumericCode,
                           currency.MinorUnits,
                           currency.Sign,
                           currency.Name
                           ));
            }

            throw new ArgumentException(
                      $"There is no registered currency with the numeric code {numericCode}"
                      );
        }
        private IsoCurrencyModel CurrencyInfo(string currency)
        {
            var currencyInfo = AllCurrencies.SingleOrDefault(x => x.ISOCode == currency);

            return(currencyInfo);
        }
Ejemplo n.º 7
0
 /// <summary>Gets all countries existing on the specified measurement date.</summary>
 /// <param name="measurement">
 /// The measurement date.
 /// </param>
 /// <returns>
 /// A list of existing countries.
 /// </returns>
 public static IEnumerable <Currency> GetExisting(Date measurement)
 {
     return(AllCurrencies.Where(currency => currency.ExistsOnDate(measurement)));
 }