C# :: Aufgabe #259 :: Lösung #1
3 Lösungen
#259
Währung's Rechner vom Aktuellen Kurs
Fortgeschrittener - C#
von maxi72501
- 29.04.2019 um 14:17 Uhr
Währungen: Euro, US-Dollar, Pfund Sterling, Dänische Krone, Yen, Rupie, Neue Lira, ...
Die Aufgabe Lautet: Schreibe ein Programm das mit den oben genannten Währungen eine Liste wo der Benutzer auswählen kann welche Währung er hat und in welche Währung er umrechnen will.
Das Datum des angegebenen Kurses der einzelnen Währung sollte angegeben werden!!!
Die Liste sollte Erweiterbar sein!!!
Die Aufgabe Lautet: Schreibe ein Programm das mit den oben genannten Währungen eine Liste wo der Benutzer auswählen kann welche Währung er hat und in welche Währung er umrechnen will.
Das Datum des angegebenen Kurses der einzelnen Währung sollte angegeben werden!!!
Die Liste sollte Erweiterbar sein!!!
#1
von Kotgreifer (1100 Punkte)
- 06.05.2019 um 15:45 Uhr
C#-Code
<Window x:Class="Geldrechner.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Geldrechner" mc:Ignorable="d" Title="MainWindow" Height="176.362" Width="446.693"> <Grid> <TextBox x:Name="textBox" PreviewTextInput="Begrenzer" HorizontalAlignment="Left" Height="23" Margin="23,22,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" /> <TextBox x:Name="txtBlockErg" IsReadOnly="True" HorizontalAlignment="Left" Height="23" Margin="288,22,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/> <Button x:Name="btn_switch" Content="---> <---" HorizontalAlignment="Left" Margin="181,22,0,0" VerticalAlignment="Top" Width="75" Click="switch_Click"/> <Button x:Name="btn_submit" Content="Submit" HorizontalAlignment="Left" Margin="144,87,0,0" VerticalAlignment="Top" Width="144" Click="submit_Click"/> <ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="23,50,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0"> <ComboBoxItem x:Name="Euro" Content="Euro" Tag="EUR"/> <ComboBoxItem x:Name="Usd" Content="US Dollar" Tag="USD"/> <ComboBoxItem x:Name="Yen" Content="Yen" Tag="JPY"/> <ComboBoxItem x:Name="Rupie" Content="Rupie" Tag="INR"/> <ComboBoxItem x:Name="Pfund" Content="Ind. Pfund" Tag="GBP"/> <ComboBoxItem x:Name="AUD" Content="Aust. Dollar" Tag="AUD"/> <ComboBoxItem x:Name="CNY" Content="Chin. Renminbi" Tag="CNY"/> <ComboBoxItem x:Name="CHF" Content="Schweizer Franken" Tag="CHF"/> <ComboBoxItem x:Name="Lira" Content="Türk. Lira" Tag="TRY"/> <ComboBoxItem x:Name="DKK" Content="Dänische Krone" Tag="DKK"/> <ComboBoxItem x:Name="CAD" Content="Kanad. Dollar" Tag="CAD"/> <ComboBoxItem x:Name="CZK" Content="Tschech. Krone" Tag="CZK"/> <ComboBoxItem x:Name="RUB" Content="Russischer Rubel" Tag="RUB"/> <ComboBoxItem x:Name="PLN" Content="Zloty" Tag="PLN"/> <ComboBoxItem x:Name="ZAR" Content="Rand" Tag="ZAR"/> </ComboBox> <ComboBox x:Name="comboBox1" HorizontalAlignment="Left" Margin="288,50,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="1"> <ComboBoxItem x:Name="Euro2" Content="Euro" Tag="EUR"/> <ComboBoxItem x:Name="Usd2" Content="US Dollar" Tag="USD"/> <ComboBoxItem x:Name="Yen2" Content="Yen" Tag="JPY"/> <ComboBoxItem x:Name="Rupie2" Content="Rupie" Tag="INR"/> <ComboBoxItem x:Name="Pfund2" Content="Ind. Pfund" Tag="GBP"/> <ComboBoxItem x:Name="AUD2" Content="Aust. Dollar" Tag="AUD"/> <ComboBoxItem x:Name="CNY2" Content="Chin. Renminbi" Tag="CNY"/> <ComboBoxItem x:Name="CHF2" Content="Schweizer Franken" Tag="CHF"/> <ComboBoxItem x:Name="Lira2" Content="Türk. Lira" Tag="TRY"/> <ComboBoxItem x:Name="DKK2" Content="Dänische Krone" Tag="DKK"/> <ComboBoxItem x:Name="CAD2" Content="Kanad. Dollar" Tag="CAD"/> <ComboBoxItem x:Name="CZK2" Content="Tschech. Krone" Tag="CZK"/> <ComboBoxItem x:Name="RUB2" Content="Russischer Rubel" Tag="RUB"/> <ComboBoxItem x:Name="PLN2" Content="Zloty" Tag="PLN"/> <ComboBoxItem x:Name="ZAR2" Content="Rand" Tag="ZAR"/> </ComboBox> </Grid> </Window>
C#-Code
using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Net; namespace Geldrechner { public partial class MainWindow : Window { private const string urlPattern = "http://rate-exchange-1.appspot.com/currency?from={0}&to={1}"; public MainWindow() { InitializeComponent(); } private void Begrenzer(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]"); e.Handled = regex.IsMatch(e.Text); } private void submit_Click(object sender, RoutedEventArgs e) { int amount; int.TryParse(textBox.Text, out amount); ComboBoxItem c1 = (ComboBoxItem) comboBox.SelectedItem; string currency1 = (string) c1.Tag; ComboBoxItem c2 = (ComboBoxItem)comboBox1.SelectedItem; string currency2 = (string)c2.Tag; string erg= CurrencyConversion(amount, currency1, currency2); txtBlockErg.Text = erg; } public string CurrencyConversion(int amount, string fromCurrency, string toCurrency) { string url = string.Format(urlPattern, fromCurrency, toCurrency); using (var wc = new WebClient()) { var json = wc.DownloadString(url); Newtonsoft.Json.Linq.JToken token = Newtonsoft.Json.Linq.JObject.Parse(json); decimal exchangeRate = (decimal)token.SelectToken("rate"); return (amount * exchangeRate).ToString(); } } private void switch_Click(object sender, RoutedEventArgs e) { int tmp = comboBox.SelectedIndex; comboBox.SelectedIndex = comboBox1.SelectedIndex; comboBox1.SelectedIndex = tmp; } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1