Added Background fixed some code deleted useless stuff

This commit is contained in:
Mark Alexander Meyer 2025-05-06 08:52:57 +02:00
parent 754df1017e
commit b60eb3c7be
24 changed files with 192 additions and 152 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Compile Update="Form1.cs"> <Compile Update="MoneyConverter.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
</Project> </Project>

133
Form1.cs
View File

@ -1,133 +0,0 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace CurrencyConvert
{
public partial class Form1 : Form
{
private readonly HashSet<string> supportedCurrencies = new HashSet<string>
{
"AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK",
"EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "ISK",
"JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PLN",
"RON", "SEK", "SGD", "THB", "TRY", "USD", "ZAR"
};
public Form1()
{
InitializeComponent();
comboBox1.Items.Clear();
comboBox2.Items.Clear();
foreach (string currency in supportedCurrencies)
{
comboBox1.Items.Add(currency);
comboBox2.Items.Add(currency);
}
comboBox1.SelectedIndex = comboBox1.Items.IndexOf("EUR");
comboBox2.SelectedIndex = comboBox2.Items.IndexOf("USD");
label4.AutoSize = true;
label4.Font = new Font(label4.Font.FontFamily, 12, FontStyle.Bold);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != ',' && e.KeyChar != '.' && e.KeyChar != (char)Keys.Back)
{
e.Handled = true;
}
}
private async void button1_Click(object sender, EventArgs e)
{
try
{
label4.Text = "Berechne...";
button1.Enabled = false;
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("Bitte geben Sie einen Betrag ein.");
return;
}
string amount = textBox1.Text.Replace(',', '.');
if (!double.TryParse(amount, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out double menge))
{
MessageBox.Show("Bitte geben Sie einen gültigen Betrag ein.");
return;
}
if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
{
MessageBox.Show("Bitte wählen Sie beide Währungen aus.");
return;
}
string von = comboBox1.SelectedItem.ToString().Trim().ToUpper();
string zu = comboBox2.SelectedItem.ToString().Trim().ToUpper();
if (!supportedCurrencies.Contains(von) || !supportedCurrencies.Contains(zu))
{
MessageBox.Show($"Eine oder beide Währungen werden nicht unterstützt.\nUnterstützte Währungen: {string.Join(", ", supportedCurrencies)}");
return;
}
string url = $"https://api.frankfurter.app/latest?amount={amount}&from={von}&to={zu}";
using (HttpClient client = new HttpClient())
{
var response = await client.GetAsync(url);
string json = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
MessageBox.Show("Fehler beim Abrufen der Wechselkurse.");
return;
}
var data = JsonConvert.DeserializeObject<FrankfurterResponse>(json);
if (data?.rates == null || !data.rates.ContainsKey(zu))
{
MessageBox.Show("Fehler beim Abrufen der Wechselkurse.");
return;
}
double ergebnis = data.rates[zu];
label4.Text = $"{menge} {von} = {ergebnis:0.00} {zu}";
}
}
catch (Exception)
{
MessageBox.Show("Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.");
}
finally
{
button1.Enabled = true;
}
}
}
public class FrankfurterResponse
{
public double amount { get; set; }
public string base_currency { get; set; }
public string date { get; set; }
public Dictionary<string, double> rates { get; set; }
}
}

View File

@ -1,6 +1,6 @@
namespace CurrencyConvert namespace CurrencyConvert
{ {
partial class Form1 partial class MoneyConverter
{ {
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
@ -56,6 +56,7 @@
// label1 // label1
// //
label1.AutoSize = true; label1.AutoSize = true;
label1.BackColor = Color.Transparent;
label1.Location = new Point(184, 34); label1.Location = new Point(184, 34);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(97, 20); label1.Size = new Size(97, 20);
@ -65,6 +66,7 @@
// label2 // label2
// //
label2.AutoSize = true; label2.AutoSize = true;
label2.BackColor = Color.Transparent;
label2.Location = new Point(184, 82); label2.Location = new Point(184, 82);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(89, 20); label2.Size = new Size(89, 20);
@ -82,11 +84,13 @@
// label3 // label3
// //
label3.AutoSize = true; label3.AutoSize = true;
label3.BackColor = Color.Transparent;
label3.Location = new Point(184, 132); label3.Location = new Point(184, 132);
label3.Name = "label3"; label3.Name = "label3";
label3.Size = new Size(144, 20); label3.Size = new Size(144, 20);
label3.TabIndex = 5; label3.TabIndex = 5;
label3.Text = "Menge der Währung"; label3.Text = "Menge der Währung";
label3.Click += label3_Click;
// //
// button1 // button1
// //
@ -104,17 +108,20 @@
// label4 // label4
// //
label4.AutoSize = true; label4.AutoSize = true;
label4.BackColor = Color.Transparent;
label4.Location = new Point(28, 263); label4.Location = new Point(28, 263);
label4.Name = "label4"; label4.Name = "label4";
label4.Size = new Size(66, 20); label4.Size = new Size(66, 20);
label4.TabIndex = 7; label4.TabIndex = 7;
label4.Text = "Ergebnis"; label4.Text = "Ergebnis";
// //
// Form1 // MoneyConverter
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(709, 496); BackColor = SystemColors.HighlightText;
BackgroundImage = Properties.Resources.Background;
ClientSize = new Size(366, 328);
Controls.Add(label4); Controls.Add(label4);
Controls.Add(button1); Controls.Add(button1);
Controls.Add(label3); Controls.Add(label3);
@ -123,8 +130,9 @@
Controls.Add(label1); Controls.Add(label1);
Controls.Add(comboBox2); Controls.Add(comboBox2);
Controls.Add(comboBox1); Controls.Add(comboBox1);
Name = "Form1"; Name = "MoneyConverter";
Text = "Form1"; Text = "MoneyConverter";
Load += Form1_Load;
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }

152
MoneyConverter.cs Normal file
View File

@ -0,0 +1,152 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace CurrencyConvert
{
public partial class MoneyConverter : Form
{
private readonly string[] supportedCurrencies = new string[]
{
"AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK",
"EUR", "GBP", "HKD", "HUF", "IDR", "ILS", "INR", "ISK",
"JPY", "KRW", "MXN", "MYR", "NOK", "NZD", "PHP", "PLN",
"RON", "SEK", "SGD", "THB", "TRY", "USD", "ZAR"
};
public MoneyConverter()
{
InitializeComponent();
comboBox1.Items.Clear();
comboBox2.Items.Clear();
foreach (string currency in supportedCurrencies)
{
comboBox1.Items.Add(currency);
comboBox2.Items.Add(currency);
}
comboBox1.SelectedIndex = comboBox1.Items.IndexOf("EUR");
comboBox2.SelectedIndex = comboBox2.Items.IndexOf("USD");
label4.AutoSize = true;
label4.Font = new Font(label4.Font.FontFamily, 12, FontStyle.Bold);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != ',' && e.KeyChar != '.' && e.KeyChar != (char)Keys.Back)
{
e.Handled = true;
}
}
private async void button1_Click(object sender, EventArgs e)
{
label4.Text = "Berechne...";
button1.Enabled = false;
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("Bitte geben Sie einen Betrag ein.");
button1.Enabled = true;
return;
}
string amountText = textBox1.Text.Replace(',', '.');
double amount;
bool isNumber = double.TryParse(amountText, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out amount);
if (!isNumber)
{
MessageBox.Show("Bitte geben Sie einen gültigen Betrag ein.");
button1.Enabled = true;
return;
}
if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
{
MessageBox.Show("Bitte wählen Sie beide Währungen aus.");
button1.Enabled = true;
return;
}
string fromCurrency = comboBox1.SelectedItem.ToString().Trim().ToUpper();
string toCurrency = comboBox2.SelectedItem.ToString().Trim().ToUpper();
bool fromSupported = false;
bool toSupported = false;
foreach (string currency in supportedCurrencies)
{
if (currency == fromCurrency) fromSupported = true;
if (currency == toCurrency) toSupported = true;
}
if (!fromSupported || !toSupported)
{
MessageBox.Show("Eine oder beide Währungen werden nicht unterstützt.");
button1.Enabled = true;
return;
}
string url = "https://api.frankfurter.app/latest?amount=" + amountText + "&from=" + fromCurrency + "&to=" + toCurrency;
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(url);
string json = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
MessageBox.Show("Fehler beim Abrufen der Wechselkurse.");
button1.Enabled = true;
return;
}
FrankfurterResponse data = JsonConvert.DeserializeObject<FrankfurterResponse>(json);
if (data == null || data.rates == null || !data.rates.ContainsKey(toCurrency))
{
MessageBox.Show("Fehler beim Abrufen der Wechselkurse.");
button1.Enabled = true;
return;
}
double result = data.rates[toCurrency];
label4.Text = amount + " " + fromCurrency + " = " + result.ToString("0.00") + " " + toCurrency;
button1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
}
public class FrankfurterResponse
{
public double amount { get; set; }
public string base_currency { get; set; }
public string date { get; set; }
public Dictionary<string, double> rates { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace CurrencyConvert
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new MoneyConverter());
} }
} }
} }

View File

@ -60,6 +60,16 @@ namespace CurrencyConvert.Properties {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Background {
get {
object obj = ResourceManager.GetObject("Background", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>

View File

@ -118,10 +118,13 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Euro" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Euro.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Euro1" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="Euro1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Euro1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\Euro1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Euro" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Euro.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Background" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Background.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

BIN
Resources/Background.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("CurrencyConvert")] [assembly: System.Reflection.AssemblyCompanyAttribute("CurrencyConvert")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+49813f523c3f34dcd8f71e2715720478dba4336d")]
[assembly: System.Reflection.AssemblyProductAttribute("CurrencyConvert")] [assembly: System.Reflection.AssemblyProductAttribute("CurrencyConvert")]
[assembly: System.Reflection.AssemblyTitleAttribute("CurrencyConvert")] [assembly: System.Reflection.AssemblyTitleAttribute("CurrencyConvert")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
861cff0492995bfdf65c6a8287334b22d4a50ab65208d23816ade7ac77479a9c 5a969a5d6ad40d34e0088ed564d4ce93fdbd68bcc1aee708c09cc350f732b47d

View File

@ -1 +1 @@
4b3f8ed66ef892d49dcd4ec591dd76964fb33b7849e8269c41fd33a533999b3b d94f5a7fb60fe6f3c14e30e5724ba7ab2500f212694980dd3ec08fc32bf234f4

View File

@ -3,7 +3,6 @@ C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConve
C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConvert.runtimeconfig.json C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConvert.runtimeconfig.json
C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConvert.dll C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConvert.dll
C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConvert.pdb C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\CurrencyConvert.pdb
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.Form1.resources
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.csproj.GenerateResource.cache C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.csproj.GenerateResource.cache
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.GeneratedMSBuildEditorConfig.editorconfig C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.AssemblyInfoInputs.cache C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.AssemblyInfoInputs.cache
@ -18,3 +17,4 @@ C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConve
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.csproj.AssemblyReference.cache C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.csproj.AssemblyReference.cache
C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\Newtonsoft.Json.dll C:\Users\bib\source\repos\CurrencyConvert\bin\Debug\net8.0-windows\Newtonsoft.Json.dll
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\Currency.DEA7AA0F.Up2Date C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\Currency.DEA7AA0F.Up2Date
C:\Users\bib\source\repos\CurrencyConvert\obj\Debug\net8.0-windows\CurrencyConvert.MoneyConverter.resources

Binary file not shown.