127 lines
1.9 KiB
C#
127 lines
1.9 KiB
C#
using System;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Controls;
|
|
|
|
namespace EuroToDollarConverter
|
|
|
|
{
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
{
|
|
|
|
public MainWindow()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
private void Convert_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
string eingabe = euroBox.Text;
|
|
|
|
bool Nummer = true;
|
|
|
|
foreach (char c in eingabe)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((c < '0' || c > '9') && c != ',')
|
|
|
|
{
|
|
|
|
Nummer = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Nummer)
|
|
|
|
{
|
|
|
|
MessageBox.Show("Nur Ziffern und maximal ein Komma erlaubt!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
double euro = Convert.ToDouble(eingabe);
|
|
|
|
double rate = 1;
|
|
|
|
ComboBoxItem Item = currencyBox.SelectedItem as ComboBoxItem;
|
|
|
|
if (Item == null)
|
|
|
|
{
|
|
|
|
MessageBox.Show("Bitte wählen Sie eine Währung aus.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string Währung = Item.Content.ToString();
|
|
|
|
switch (Währung)
|
|
|
|
{
|
|
|
|
case "Dollar $":
|
|
|
|
rate = 1.10;
|
|
|
|
break;
|
|
|
|
case "Pfund £":
|
|
|
|
rate = 0.85;
|
|
|
|
break;
|
|
|
|
case "Yen ¥":
|
|
|
|
rate = 160.50;
|
|
|
|
break;
|
|
|
|
case "Lira ₺":
|
|
|
|
rate = 35;
|
|
|
|
break;
|
|
|
|
case "Dirham د. إ ":
|
|
|
|
rate = 10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MessageBox.Show("Unbekannte Währung ausgewählt.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
double result = euro * rate;
|
|
|
|
dollarBox.Text = result.ToString("F2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |