Beispiel #1
0
        private void exchangeButton_Click(object sender, EventArgs e)
        {
            NbpTableRate fromRateTmp = (NbpTableRate)this.fromCurrentylComboBox.SelectedItem;

            this.fromCurrentylComboBox.SelectedItem = this.toCurrentlyComboBox.SelectedItem;
            this.toCurrentlyComboBox.SelectedItem   = fromRateTmp;
        }
        public static double calculate(double amount, NbpTableRate fromCurrency, NbpTableRate toCurrency, bool round = true)
        {
            double convertedValue;

            if (fromCurrency.Code.Equals("PLN"))
            {
                convertedValue = Calculator.calculatePlnToOther(amount, fromCurrency, toCurrency);
            }
            else if (toCurrency.Code.Equals("PLN"))
            {
                convertedValue = Calculator.calculateOtherToPln(amount, fromCurrency, toCurrency);
            }
            else
            {
                convertedValue = Calculator.calculateOtherToPln(amount, fromCurrency, toCurrency);
                convertedValue = Calculator.calculatePlnToOther(convertedValue, fromCurrency, toCurrency);
            }

            if (!round)
            {
                return(convertedValue);
            }
            else
            {
                return(Math.Floor(convertedValue * 100) / 100);
            }
        }
Beispiel #3
0
        public void addPlnToRates()
        {
            NbpTableRate pln = new NbpTableRate();

            pln.Code     = "PLN";
            pln.Currency = "Polish zloty";
            pln.Mid      = 1;

            this.nbpRates.Add(pln);
        }
Beispiel #4
0
        private NbpTableRate findCurrency(string code)
        {
            NbpTableRate foundRate = null;

            foreach (NbpTableRate rate in nbpRates)
            {
                if (rate.Code.Equals(code))
                {
                    foundRate = rate;
                }
            }

            return(foundRate);
        }
Beispiel #5
0
        private void convertButton_Click(object sender, EventArgs e)
        {
            double amount;

            if (double.TryParse(inputValueTextBox.Text, out amount))
            {
                NbpTableRate fromCurrency = this.findCurrency(((NbpTableRate)this.fromCurrentylComboBox.SelectedItem).Code);
                NbpTableRate toCurrency   = this.findCurrency(((NbpTableRate)this.toCurrentlyComboBox.SelectedItem).Code);

                double convertedAmount = Calculator.calculate(amount, fromCurrency, toCurrency);

                convertedValueLabel.Text = String.Format("{0:0.00}", convertedAmount);
            }
            else
            {
                MessageBox.Show("You input bad value", "Error input value");
            }
        }
 public static double calculateOtherToPln(double amount, NbpTableRate fromCurrency, NbpTableRate toCurrency)
 {
     return(amount * fromCurrency.Mid);
 }
 public static double calculatePlnToOther(double amount, NbpTableRate fromCurrency, NbpTableRate toCurrency)
 {
     return(amount / toCurrency.Mid);
 }