Пример #1
0
        /// <summary>
        /// Actual currency conversion occurs when the user selects new currency from the drop-down menu.
        /// Although we have loaded the data in the drop-down for the user to view, and we need to load then again to compare with the user selected data.
        /// </summary>

        private void CmbNewCurrency_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            TxtResult.Clear(); // All previous result are clear before loading new result.

            string jason;

            using (StreamReader sr = new StreamReader(JCurrencyList))  // loading currecy from local CurrencyList.json file
            {
                jason = sr.ReadToEnd();
            }
            CurrencyList cl = new CurrencyList();

            JsonConvert.PopulateObject(jason, cl);

            foreach (var item in cl.Currency)
            {
                if (item.Key == CmbCurrentCurrency.SelectedItem.ToString())
                {
                    currentCurrency = item.Value; // based on user selected currency, values are selected . e.g Key: Pound Sterling (GBP), Value: GBP
                }
                if (item.Key == CmbNewCurrency.SelectedItem.ToString())
                {
                    newCurrency = item.Value; // based on user selected currency, values are selected . e.g Key: Swiss Franc (CHF), Value: CHF
                }
            }

            if (CmbCurrentCurrency.Text != "") // This will ensure that current currency are not empty before it start conversion processing
            {
                ProcessCurrencyConversion();
            }
        }
Пример #2
0
        /// <summary>
        /// LoadSuportedcurrency() method will load two drop down menu from CurrencyList.json file.
        /// </summary>
        private void LoadSuportedCurrency()
        {
            string jason;

            using (StreamReader sr = new StreamReader(JCurrencyList))
            {
                jason = sr.ReadToEnd();
            }
            CurrencyList cl = new CurrencyList();

            JsonConvert.PopulateObject(jason, cl);

            foreach (var item in cl.Currency)
            {
                CmbCurrentCurrency.Items.Add(item.Key);
                //if (!item.Key.Contains(CmbCurrentCurrency.Text))
                CmbNewCurrency.Items.Add(item.Key);
            }
        }