MainWindow.xaml.cs aktualisiert
This commit is contained in:
parent
3d0e679230
commit
97ad1b3c1e
@ -1,127 +1,86 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
namespace EuroToDollarConverter
|
namespace EuroToDollarConverter
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Convert_Click(object sender, RoutedEventArgs e)
|
private void Convert_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
{
|
// Eingabe lesen
|
||||||
|
|
||||||
string eingabe = euroBox.Text;
|
string eingabe = euroBox.Text;
|
||||||
|
|
||||||
bool Nummer = true;
|
bool Nummer = true;
|
||||||
|
|
||||||
|
// Wir prüfen zuerst ob die Eingabe nur Zahlen und maximal ein Komma enthält
|
||||||
foreach (char c in eingabe)
|
foreach (char c in eingabe)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ((c < '0' || c > '9') && c != ',')
|
if ((c < '0' || c > '9') && c != ',')
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
Nummer = false;
|
Nummer = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Nummer)
|
if (eingabe == "")
|
||||||
|
|
||||||
{
|
{
|
||||||
|
MessageBox.Show("Bitte geben Sie einen Betrag in Euro ein.");
|
||||||
MessageBox.Show("Nur Ziffern und maximal ein Komma erlaubt!");
|
return;
|
||||||
|
}
|
||||||
|
// Wenn falsche Zeichen enthalten sind zeigen wir eine Fehlermeldung an und brechen ab
|
||||||
|
if (!Nummer)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Nur Ziffern und maximal ein Komma erlaubt!");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double euro = Convert.ToDouble(eingabe);
|
double euro = Convert.ToDouble(eingabe);
|
||||||
|
|
||||||
double rate = 1;
|
double rate = 1;
|
||||||
|
|
||||||
|
// Die ausgewählte Währung aus der ComboBox holen
|
||||||
ComboBoxItem Item = currencyBox.SelectedItem as ComboBoxItem;
|
ComboBoxItem Item = currencyBox.SelectedItem as ComboBoxItem;
|
||||||
|
|
||||||
if (Item == null)
|
if (Item == null)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
MessageBox.Show("Bitte wählen Sie eine Währung aus.");
|
MessageBox.Show("Bitte wählen Sie eine Währung aus.");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Den angezeigten Text der Währung z. B. Dollar auslesen
|
||||||
string Währung = Item.Content.ToString();
|
string Währung = Item.Content.ToString();
|
||||||
|
|
||||||
|
// Je nach Währung den passenden Umrechnungskurs setzen
|
||||||
switch (Währung)
|
switch (Währung)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
case "Dollar $": rate = 1.10;
|
||||||
case "Dollar $":
|
break;
|
||||||
|
|
||||||
rate = 1.10;
|
case "Pfund £": rate = 0.85;
|
||||||
|
break;
|
||||||
break;
|
|
||||||
|
case "Yen ¥": rate = 160.50;
|
||||||
case "Pfund £":
|
break;
|
||||||
|
|
||||||
rate = 0.85;
|
case "Lira ₺": rate = 35;
|
||||||
|
break;
|
||||||
break;
|
|
||||||
|
case "Dirham د. إ ": rate = 10;
|
||||||
case "Yen ¥":
|
break;
|
||||||
|
|
||||||
rate = 160.50;
|
default: MessageBox.Show("Unbekannte Währung ausgewählt.");
|
||||||
|
return;
|
||||||
break;
|
|
||||||
|
|
||||||
case "Lira ₺":
|
|
||||||
|
|
||||||
rate = 35;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "Dirham د. إ ":
|
|
||||||
|
|
||||||
rate = 10;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
MessageBox.Show("Unbekannte Währung ausgewählt.");
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Eurobetrag mit dem Wechselkurs multiplizieren
|
||||||
double result = euro * rate;
|
double result = euro * rate;
|
||||||
|
|
||||||
|
// Ergebnis mit 2 Nachkommastellen anzeigen
|
||||||
dollarBox.Text = result.ToString("F2");
|
dollarBox.Text = result.ToString("F2");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user