コード例 #1
0
        private void btnCalcRate_Click(object sender, RoutedEventArgs e)
        {
            CalcRate origin      = (CalcRate)cb_ActiveCountryRate.SelectedItem;
            CalcRate destination = (CalcRate)cb_AllcountriesRate.SelectedItem;

            if (origin != null && destination != null)
            {
                if (string.IsNullOrWhiteSpace(tb_insertRate.Text))
                {
                    MessageBox.Show("Insert a value to convert");
                    return;
                }

                string input = tb_insertRate.Text;
                if (Regex.IsMatch(input, @"^-?[0-9][0-9,\.]+$"))
                {
                    tb_rateResult.Text = $"{tb_insertRate.Text} {origin} correspond to: {Environment.NewLine}          " +
                                         $"   {Convert.ToString(decimal.Round(Convert.ToDecimal(UIData.CalculateRate(origin, destination, Convert.ToDecimal(input))), 2))} {destination.Name}";
                }
                else
                {
                    MessageBox.Show("The value to be converted must be numeric");
                    return;
                }
            }
            else
            {
                MessageBox.Show("You have to choose currencies to convert");
                return;
            }
        }